Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CLangCodeExpander Class Reference

#include <LangCodeExpander.h>

Public Types

enum  LANGFORMATS { ISO_639_1 , ISO_639_2 , ENGLISH_NAME , ISO_NAME }
 
enum class  LANG_LIST { DEFAULT , INCLUDE_ADDONS , INCLUDE_USERDEFINED , INCLUDE_ADDONS_USERDEFINED }
 

Public Member Functions

 CLangCodeExpander ()=delete
 

Static Public Member Functions

static void LoadUserCodes (const TiXmlElement *pRootElement)
 
static void Clear ()
 
static bool Lookup (const std::string &code, std::string &desc)
 
static bool CompareISO639Codes (const std::string &code1, const std::string &code2)
 Determines if two languages given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B codes represent the same language.
 
static bool ConvertToISO6391 (const std::string &lang, std::string &code)
 Converts a language given as 2-Char (ISO 639-1), 3-Char (ISO 639-2/T or ISO 639-2/B), or full english name string to a 2-Char (ISO 639-1) code.
 
static std::string AsISO6392B (const std::string &lang)
 Converts a language to a 3-Char ISO 639-2/B code, whatever notation it is given in: 2-Char (ISO 639-1), 3-Char (ISO 639-2/T or ISO 639-2/B), BCP 47 language tag, or full English name.
 
static bool ConvertISO6391ToISO6392B (const std::string &strISO6391, std::string &strISO6392B)
 Converts a language given as 2-Char (ISO 639-1) to a 3-Char (ISO 639-2/B) code.
 
static bool ConvertISO6392ToISO6391 (std::string iso6392, std::string &iso6391)
 Converts a language given as 3-Char (ISO 639-2/B or /T) to a 2-Char (ISO 639-1) code.
 
static bool ConvertToISO6392B (const std::string &strCharCode, std::string &strISO6392B)
 Converts a language given as 2-Char (ISO 639-1), 3-Char (ISO 639-2/T or ISO 639-2/B), or full english name string to a 3-Char ISO 639-2/B code.
 
static std::vector< std::string > GetLanguageNames (LANGFORMATS format=ISO_639_1, LANG_LIST list=LANG_LIST::DEFAULT)
 
static bool ConvertToBcp47 (const std::string &text, std::string &bcp47)
 
static std::string AsBcp47 (const std::string &lang)
 Converts a language to a BCP 47 tag, whatever notation it is given in: 2-Char (ISO 639-1), 3-Char (ISO 639-2/T, ISO 639-2/B), BCP 47 language tag, or full English name.
 

Protected Types

typedef std::map< std::string, std::string > STRINGLOOKUPTABLE
 

Static Protected Member Functions

static bool LookupInISO639Tables (const std::string &code, std::string &desc)
 
static std::optional< std::string > LookupInLangAddons (const std::string &code)
 Looks up the language description for the given language code in the installed language addons.
 
static bool LookupInUserMap (const std::string &code, std::string &desc)
 
static bool ReverseLookup (const std::string &desc, std::string &code)
 Looks up the ISO 639-1 or ISO 639-2/T, whichever it finds first, code of the given english language name.
 
static bool LookupUserCode (const std::string &desc, std::string &userCode)
 Looks up the user defined code of the given code or language name.
 
static STRINGLOOKUPTABLEGetUserCodes ()
 The language codes a user defined in advancedsettings.xml, for media tagged with codes that are not in any standard.
 

Member Typedef Documentation

◆ STRINGLOOKUPTABLE

std::map<std::string, std::string> CLangCodeExpander::STRINGLOOKUPTABLE
protected

Member Enumeration Documentation

◆ LANG_LIST

enum class CLangCodeExpander::LANG_LIST
strong
Enumerator
DEFAULT 
INCLUDE_ADDONS 
INCLUDE_USERDEFINED 
INCLUDE_ADDONS_USERDEFINED 

◆ LANGFORMATS

Enumerator
ISO_639_1 
ISO_639_2 
ENGLISH_NAME 
ISO_NAME 

Constructor & Destructor Documentation

◆ CLangCodeExpander()

CLangCodeExpander::CLangCodeExpander ( )
delete

Member Function Documentation

◆ AsBcp47()

std::string CLangCodeExpander::AsBcp47 ( const std::string & lang)
static

Converts a language to a BCP 47 tag, whatever notation it is given in: 2-Char (ISO 639-1), 3-Char (ISO 639-2/T, ISO 639-2/B), BCP 47 language tag, or full English name.

Widening: BCP 47 adds region, script and variant subtags to ISO 639, so nothing is lost. Intended for the boundaries where a language enters the application.

Note
Always returns a value. ConvertToBcp47 reports whether the language was recognized at all.
Parameters
[in]langThe language that should be converted.
Returns
The BCP 47 tag of lang if one exists, lang otherwise.

◆ AsISO6392B()

std::string CLangCodeExpander::AsISO6392B ( const std::string & lang)
static

Converts a language to a 3-Char ISO 639-2/B code, whatever notation it is given in: 2-Char (ISO 639-1), 3-Char (ISO 639-2/T or ISO 639-2/B), BCP 47 language tag, or full English name.

Narrowing: only the primary language subtag of a BCP 47 tag survives, as region, script and variant subtags have no ISO 639 equivalent. Intended for interfaces with an ISO 639-2/B contract; elsewhere the BCP 47 tag is carried whole.

Note
Always returns a value. ConvertToISO6392B reports whether the language was recognized at all.
Parameters
[in]langThe language that should be converted.
Returns
The 3-Char ISO 639-2/B code of lang if that code exists, lang otherwise. A language with no ISO 639-2 code (ISO 639-3/-5 only, ex: zyg) is returned unchanged.

◆ Clear()

void CLangCodeExpander::Clear ( )
static

◆ CompareISO639Codes()

bool CLangCodeExpander::CompareISO639Codes ( const std::string & code1,
const std::string & code2 )
static

Determines if two languages given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B codes represent the same language.

Parameters
[in]code1The first language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
[in]code2The second language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
Returns
true if the two language codes represent the same language, false otherwise. For example "ger", "deu" and "de" represent the same language.

◆ ConvertISO6391ToISO6392B()

bool CLangCodeExpander::ConvertISO6391ToISO6392B ( const std::string & strISO6391,
std::string & strISO6392B )
static

Converts a language given as 2-Char (ISO 639-1) to a 3-Char (ISO 639-2/B) code.

Parameters
[in]strISO6391The language that should be converted.
[out]strISO6392BThe 3-Char (ISO 639-2/B) language code of the given language strISO6391.
Returns
true if the conversion succeeded, false otherwise.

◆ ConvertISO6392ToISO6391()

bool CLangCodeExpander::ConvertISO6392ToISO6391 ( std::string iso6392,
std::string & iso6391 )
static

Converts a language given as 3-Char (ISO 639-2/B or /T) to a 2-Char (ISO 639-1) code.

Parameters
[in]iso6392The language that should be converted. Case-insensitive.
[out]iso6391The 2-Char (ISO 639-1) language code of the given language.
Returns
true if the conversion succeeded, false otherwise.

◆ ConvertToBcp47()

bool CLangCodeExpander::ConvertToBcp47 ( const std::string & text,
std::string & bcp47 )
static

◆ ConvertToISO6391()

bool CLangCodeExpander::ConvertToISO6391 ( const std::string & lang,
std::string & code )
static

Converts a language given as 2-Char (ISO 639-1), 3-Char (ISO 639-2/T or ISO 639-2/B), or full english name string to a 2-Char (ISO 639-1) code.

Parameters
[out]codeThe 2-Char language code of the given language lang.
[in]langThe language that should be converted.
Returns
true if the conversion succeeded, false otherwise.

◆ ConvertToISO6392B()

bool CLangCodeExpander::ConvertToISO6392B ( const std::string & strCharCode,
std::string & strISO6392B )
static

Converts a language given as 2-Char (ISO 639-1), 3-Char (ISO 639-2/T or ISO 639-2/B), or full english name string to a 3-Char ISO 639-2/B code.

Parameters
[in]strCharCodeThe language that should be converted.
[out]strISO6392BThe 3-Char (ISO 639-2/B) language code of the given language.
Returns
true if the conversion succeeded, false otherwise.

◆ GetLanguageNames()

std::vector< std::string > CLangCodeExpander::GetLanguageNames ( LANGFORMATS format = ISO_639_1,
LANG_LIST list = LANG_LIST::DEFAULT )
static

◆ GetUserCodes()

CLangCodeExpander::STRINGLOOKUPTABLE & CLangCodeExpander::GetUserCodes ( )
staticprotected

The language codes a user defined in advancedsettings.xml, for media tagged with codes that are not in any standard.

Note
Loaded once at startup and shared process-wide.

◆ LoadUserCodes()

void CLangCodeExpander::LoadUserCodes ( const TiXmlElement * pRootElement)
static

◆ Lookup()

bool CLangCodeExpander::Lookup ( const std::string & code,
std::string & desc )
static

◆ LookupInISO639Tables()

bool CLangCodeExpander::LookupInISO639Tables ( const std::string & code,
std::string & desc )
staticprotected

◆ LookupInLangAddons()

std::optional< std::string > CLangCodeExpander::LookupInLangAddons ( const std::string & code)
staticprotected

Looks up the language description for the given language code in the installed language addons.

Parameters
[in]codeThe language code for which a description is looked for.
Returns
The english language name, or nullopt when no addon answers for the code.

◆ LookupInUserMap()

bool CLangCodeExpander::LookupInUserMap ( const std::string & code,
std::string & desc )
staticprotected

◆ LookupUserCode()

bool CLangCodeExpander::LookupUserCode ( const std::string & desc,
std::string & userCode )
staticprotected

Looks up the user defined code of the given code or language name.

Parameters
[in]descThe language code or name that should be converted.
[out]userCodeThe user defined language code of the given language desc.
Returns
true if desc was found, false otherwise.

◆ ReverseLookup()

bool CLangCodeExpander::ReverseLookup ( const std::string & desc,
std::string & code )
staticprotected

Looks up the ISO 639-1 or ISO 639-2/T, whichever it finds first, code of the given english language name.

Parameters
[in]descThe english language name for which a code is looked for.
[out]codeThe ISO 639-1 or ISO 639-2/T code of the given language desc.
Returns
true if a code was found, false otherwise.

The documentation for this class was generated from the following files: