C# Class SIL.CoreImpl.LangTagUtils

This static utility class contains various methods for processing RFC-5646 language tags. The methods defined in this class can currently only support language tags with a single variant subtag and no extensions.
Mostrar archivo Open project: sillsdev/FieldWorks

Public Methods

Method Description
GetCodes ( string langTag, string &languageCode, string &scriptCode, string &regionCode, string &variantCode ) : bool

Gets the codes of the specified language tag.

GetLanguageSubtag ( string code ) : LanguageSubtag

Gets the language subtag with the specified code.

GetPrivateUseAndStandardVariant ( string wholeVariant, string &standardVariant ) : string

Standard way to split a Variant into the standard-variant part (before any -x-, or empty if it starts with x-) and the private-use part (after the x part, or empty if there is no x). Returns the private use part.

GetRegionSubtag ( string code ) : RegionSubtag

Gets the region subtag with the specified code.

GetRegionSubtag ( string code, string name ) : RegionSubtag

Get a region subtag with the specified code and name. If it is a standard region, the name passed in will be ignored, and the standard name used. If not, it will have the specified name and code, and be marked private use.

GetScriptSubtag ( string code ) : ScriptSubtag

Gets the script subtag with the specified code.

GetScriptSubtag ( string code, string name ) : ScriptSubtag

Gets the script subtag with the specified code. If it is not a known code, returns a private-use tag with the specified name and code; if it is known, the supplied name is ignored.

GetSubtags ( string langTag, LanguageSubtag &languageSubtag, ScriptSubtag &scriptSubtag, RegionSubtag &regionSubtag, VariantSubtag &variantSubtag ) : bool

Gets the subtags of the specified language tag.

GetVariantSubtag ( string code ) : VariantSubtag

Gets the variant subtag with the specified code.

GetVariantSubtag ( string code, string name, IEnumerable prefixes ) : VariantSubtag

Gets the variant subtag with the specified code. If it is not a known (non-private-use) one, make a private-use one with the specified values. Insert 'x' or move it earlier if any leading parts are not standard.

IsLanguageCodeValid ( string code ) : bool

Determines whether the specified language code is valid.

IsPrivateUseRegionCode ( string regionCode ) : bool

Determines whether the specified region code is private use.

IsRegionCodeValid ( string code ) : bool

Determines whether the specified region code is valid.

IsScriptCodeValid ( string code ) : bool

Determines whether the specified script code is valid.

IsValid ( string langTag ) : bool

Determines whether the specified language tag is valid.

IsVariantCodeValid ( string code ) : bool

Determines whether the specified variant code is valid.

ToIcuLocale ( LanguageSubtag languageSubtag, ScriptSubtag scriptSubtag, RegionSubtag regionSubtag, VariantSubtag variantSubtag ) : string

Generates an ICU locale from the specified language tag subtags.

ToIcuLocale ( string langTag ) : string

Converts the specified language tag to an ICU locale.

ToIcuLocale ( string languageCode, string scriptCode, string regionCode, string variantCode ) : string

Generates an ICU locale from the specified language tag codes.

ToLangTag ( LanguageSubtag languageSubtag, ScriptSubtag scriptSubtag, RegionSubtag regionSubtag, VariantSubtag variantSubtag ) : string

Generates a language tag from the specified subtags.

ToLangTag ( string icuLocale ) : string

Converts the specified ICU locale to a language tag. If the ICU locale is already a valid language tag, it will return it.

ToLangTag ( string languageCode, string scriptCode, string regionCode, string variantCode ) : string

Generates a language tag from the specified codes.

Private Methods

Method Description
LangTagUtils ( ) : System
NextSubTag ( string subTags, int &subTagIndex, bool &privateUsePrefix ) : string
TranslateVariantCode ( string variantCode, string>.Func defaultFunc ) : string

Translates standard variant codes to their expanded (semi-human-readable) format; all others are translated using the given function.

TreatAsCustomRegion ( string regionCode ) : bool
TreatAsCustomScript ( string scriptCode ) : bool

Method Details

GetCodes() public static method

Gets the codes of the specified language tag.
public static GetCodes ( string langTag, string &languageCode, string &scriptCode, string &regionCode, string &variantCode ) : bool
langTag string The lang tag.
languageCode string The language code.
scriptCode string The script code.
regionCode string The region code.
variantCode string The variant code.
return bool

GetLanguageSubtag() public static method

Gets the language subtag with the specified code.
public static GetLanguageSubtag ( string code ) : LanguageSubtag
code string The code.
return LanguageSubtag

GetPrivateUseAndStandardVariant() public static method

Standard way to split a Variant into the standard-variant part (before any -x-, or empty if it starts with x-) and the private-use part (after the x part, or empty if there is no x). Returns the private use part.
public static GetPrivateUseAndStandardVariant ( string wholeVariant, string &standardVariant ) : string
wholeVariant string
standardVariant string
return string

GetRegionSubtag() public static method

Gets the region subtag with the specified code.
public static GetRegionSubtag ( string code ) : RegionSubtag
code string The code.
return RegionSubtag

GetRegionSubtag() public static method

Get a region subtag with the specified code and name. If it is a standard region, the name passed in will be ignored, and the standard name used. If not, it will have the specified name and code, and be marked private use.
public static GetRegionSubtag ( string code, string name ) : RegionSubtag
code string
name string
return RegionSubtag

GetScriptSubtag() public static method

Gets the script subtag with the specified code.
public static GetScriptSubtag ( string code ) : ScriptSubtag
code string The code.
return ScriptSubtag

GetScriptSubtag() public static method

Gets the script subtag with the specified code. If it is not a known code, returns a private-use tag with the specified name and code; if it is known, the supplied name is ignored.
public static GetScriptSubtag ( string code, string name ) : ScriptSubtag
code string
name string
return ScriptSubtag

GetSubtags() public static method

Gets the subtags of the specified language tag.
public static GetSubtags ( string langTag, LanguageSubtag &languageSubtag, ScriptSubtag &scriptSubtag, RegionSubtag &regionSubtag, VariantSubtag &variantSubtag ) : bool
langTag string The language tag.
languageSubtag LanguageSubtag The language subtag.
scriptSubtag ScriptSubtag The script subtag.
regionSubtag RegionSubtag The region subtag.
variantSubtag VariantSubtag The variant subtag.
return bool

GetVariantSubtag() public static method

Gets the variant subtag with the specified code.
public static GetVariantSubtag ( string code ) : VariantSubtag
code string
return VariantSubtag

GetVariantSubtag() public static method

Gets the variant subtag with the specified code. If it is not a known (non-private-use) one, make a private-use one with the specified values. Insert 'x' or move it earlier if any leading parts are not standard.
public static GetVariantSubtag ( string code, string name, IEnumerable prefixes ) : VariantSubtag
code string
name string
prefixes IEnumerable
return VariantSubtag

IsLanguageCodeValid() public static method

Determines whether the specified language code is valid.
public static IsLanguageCodeValid ( string code ) : bool
code string The language code.
return bool

IsPrivateUseRegionCode() public static method

Determines whether the specified region code is private use.
public static IsPrivateUseRegionCode ( string regionCode ) : bool
regionCode string The region code.
return bool

IsRegionCodeValid() public static method

Determines whether the specified region code is valid.
public static IsRegionCodeValid ( string code ) : bool
code string The region code.
return bool

IsScriptCodeValid() public static method

Determines whether the specified script code is valid.
public static IsScriptCodeValid ( string code ) : bool
code string The script code.
return bool

IsValid() public static method

Determines whether the specified language tag is valid.
public static IsValid ( string langTag ) : bool
langTag string The language tag.
return bool

IsVariantCodeValid() public static method

Determines whether the specified variant code is valid.
public static IsVariantCodeValid ( string code ) : bool
code string The variant code.
return bool

ToIcuLocale() public static method

Generates an ICU locale from the specified language tag subtags.
public static ToIcuLocale ( LanguageSubtag languageSubtag, ScriptSubtag scriptSubtag, RegionSubtag regionSubtag, VariantSubtag variantSubtag ) : string
languageSubtag LanguageSubtag The language subtag.
scriptSubtag ScriptSubtag The script subtag.
regionSubtag RegionSubtag The region subtag.
variantSubtag VariantSubtag The variant subtag.
return string

ToIcuLocale() public static method

Converts the specified language tag to an ICU locale.
public static ToIcuLocale ( string langTag ) : string
langTag string The language tag.
return string

ToIcuLocale() public static method

Generates an ICU locale from the specified language tag codes.
public static ToIcuLocale ( string languageCode, string scriptCode, string regionCode, string variantCode ) : string
languageCode string The language code.
scriptCode string The script code.
regionCode string The region code.
variantCode string The variant code.
return string

ToLangTag() public static method

Generates a language tag from the specified subtags.
public static ToLangTag ( LanguageSubtag languageSubtag, ScriptSubtag scriptSubtag, RegionSubtag regionSubtag, VariantSubtag variantSubtag ) : string
languageSubtag LanguageSubtag The language subtag.
scriptSubtag ScriptSubtag The script subtag.
regionSubtag RegionSubtag The region subtag.
variantSubtag VariantSubtag The variant subtag.
return string

ToLangTag() public static method

Converts the specified ICU locale to a language tag. If the ICU locale is already a valid language tag, it will return it.
public static ToLangTag ( string icuLocale ) : string
icuLocale string The ICU locale.
return string

ToLangTag() public static method

Generates a language tag from the specified codes.
public static ToLangTag ( string languageCode, string scriptCode, string regionCode, string variantCode ) : string
languageCode string The language code.
scriptCode string The script code.
regionCode string The region code.
variantCode string The variant code.
return string