Class CultureInfoExtensions
Utilities related to System.Globalization.CultureInfo objects.
Inheritance
Inherited Members
Namespace: Sdl.LanguagePlatform.Core
Assembly: Sdl.LanguagePlatform.Core.dll
Syntax
public static class CultureInfoExtensions
Properties
LegacyLanguageCodeMapping
Gets a mapping from legacy language codes to .Net language codes. The mapping maps from legacy language codes as they are used by SDLX and Trados Translator's Workbench and related applications to the closest language code used by .Net.
This is an internal data structure which should not be directly used and not be modified. To look up a legacy code, use GetMappedCultureCodeForLegacyCode(String).
Declaration
public static Dictionary<string, string> LegacyLanguageCodeMapping { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.Dictionary<System.String, System.String> |
Methods
AreCompatible(CultureInfo, CultureInfo)
Checks whether two cultures (languages) are compatible. Two cultures are compatible if they denote the same language which means they have to be identical or their closest region-neutral parents are identical.
Declaration
[Obsolete("Use AreCompatibleCodesAsync")]
public static bool AreCompatible(CultureInfo c1, CultureInfo c2)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | c1 | |
| System.Globalization.CultureInfo | c2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |
AreCompatibleCodesAsync(CultureCode, CultureCode, ICultureMetadataManager)
Checks whether two cultures (languages) are compatible. Two cultures are compatible if they denote the same language which means they have to be identical or their closest region-neutral parents are identical.
Declaration
public static Task<bool> AreCompatibleCodesAsync(CultureCode c1, CultureCode c2, ICultureMetadataManager cultureMetadataManager)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | c1 | |
| Sdl.Core.Globalization.CultureCode | c2 | |
| Sdl.Core.Globalization.CultureMetadataManager.ICultureMetadataManager | cultureMetadataManager |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Boolean> |
GetCultureInfo(Int32)
Returns the culture which corresponds to the specified LCID. If the LCID is unknown or invalid, an exception is thrown. Note that this will also be the case for custom cultures, which seem to always get the same LCID (4096).
Declaration
[Obsolete("Use GetRegistryCultureInfoAsync")]
public static CultureInfo GetCultureInfo(int lcid)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | lcid | The locale identifier (lcid) |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | A CultureInfo object, or throws for unknown LCIDs. |
GetCultureInfo(Int32, Boolean)
Returns the culture which corresponds to the specified locale, which may be a legacy LCID used internally by SDLX or Trados Translator's Workbench.
Declaration
[Obsolete("Use GetRegistryCultureInfoAsync")]
public static CultureInfo GetCultureInfo(int lcid, bool returnNullForUnknowns)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | lcid | The locale identifier (lcid) |
| System.Boolean | returnNullForUnknowns | If true, null is returned for unknown languages. Otherwise, an exception is thrown. This will also be the case if the lcid represets a custom culture (in most cases, the lcid will be 4096 in this case). |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | A System.Globalization.CultureInfo object, or null if |
GetCultureInfo(String)
Similar to System.Globalization.CultureInfo.GetCultureInfo(System.String), but covers culture names (<language-code>-<region-code>) which are used by SDLX and Trados Translator's Workbench, but have a different code in .Net.
Use this method to transparently map language codes (current and legacy ones) to cultures, for example when processing TTX, ITD, or TMX.
Declaration
[Obsolete("Use GetRegistryCultureInfoAsync")]
public static CultureInfo GetCultureInfo(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The culture code |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | A CultureInfo object, using appropriate fallbacks for backwards compatibility. Throws an exeption if neither the fallback heuristics nor .Net can resolve the culture name. |
Remarks
To avoid an exception to be thrown, and to get null for unknown
culture codes, use GetCultureInfo(String, Boolean).
GetCultureInfo(String, Boolean)
Similar to System.Globalization.CultureInfo.GetCultureInfo(System.String), but covers culture names (<language-code>-<region-code>) which are used by SDLX and Trados Translator's Workbench, but have a different code in .Net.
Use this method to transparently map language codes (current and legacy ones) to cultures, for example when processing TTX, ITD, or TMX.
Declaration
[Obsolete("Use GetRegistryCultureInfoAsync")]
public static CultureInfo GetCultureInfo(string name, bool returnNullForUnknowns)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The culture code |
| System.Boolean | returnNullForUnknowns | If true, null is returned for unknown culture codes. If false, an exception is thrown if the culture code cannot be resolved. |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | A CultureInfo object, using appropriate fallbacks for backwards compatibility, or
null if the culture code cannot be resolved and |
GetLanguageGroupID(CultureInfo)
Returns the LanguageGroupID associated with the specified culture.
Declaration
[Obsolete("Use GetLanguageGroupNameAsync")]
public static CultureInfoExtensions.LanguageGroupID GetLanguageGroupID(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture |
Returns
| Type | Description |
|---|---|
| CultureInfoExtensions.LanguageGroupID |
GetLanguageGroupName(CultureInfo)
Returns the name of the language group for the specified culture as a string.
Declaration
[Obsolete("Use GetLanguageGroupNameAsync")]
public static string GetLanguageGroupName(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture | The culture (may not be null) |
Returns
| Type | Description |
|---|---|
| System.String | The name of the language group the culture belongs to, or |
GetLanguageGroupNameAsync(String, ICultureMetadataManager)
Returns the name of the language group for the specified culture, or for a parent culture if not defined for this culture, or null if unknown
Declaration
public static Task<string> GetLanguageGroupNameAsync(string cultureName, ICultureMetadataManager cultureMetadataManager)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | cultureName | |
| Sdl.Core.Globalization.CultureMetadataManager.ICultureMetadataManager | cultureMetadataManager |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.String> |
GetLeadingClitics(CultureCode)
Returns a case-sensitive string hash set containing the leading separable clitics for the provided
culture, or null if none are defined.
Declaration
public static HashSet<string> GetLeadingClitics(CultureCode culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.HashSet<System.String> |
GetMappedCultureCodeForLegacyCode(String)
Assumes the passed culture code is a legacy code and returns the mapped equivalent. null is returned if no mapping exists (which means that the code is not a legacy code or no mapping is required or yet specified).
Declaration
public static string GetMappedCultureCodeForLegacyCode(string legacyCode)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | legacyCode |
Returns
| Type | Description |
|---|---|
| System.String |
GetRegionNeutralCulture(CultureInfo)
Computes and returns the region-neutral parent culture of the input culture. If the input culture is already neutral, it is returned. Otherwise, the parent culture hierarchy is traversed until a region-neutral culture is found.
Declaration
[Obsolete("Use GetRegionNeutralCultureCodeAsync")]
public static CultureInfo GetRegionNeutralCulture(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture | The input culture |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | The region-neutral parent culture of the input culture |
Remarks
A region-neutral culture is not necessarily one "without dashes". For example,
the region-neutral parent culture of zh-CN (Chinese, PRC) is zh-CHS or zh-Hans (Simplified
Chinese). The exact result may depend on the operating system version and the .Net version.
GetRegionNeutralCultureCodeAsync(CultureCode, ICultureMetadataManager)
Returns the region-neutral parent culture of the input culture. If the input culture is already neutral, it is returned. Otherwise, the parent culture hierarchy is traversed until a region-neutral culture is found.
Declaration
public static Task<CultureCode> GetRegionNeutralCultureCodeAsync(CultureCode culture, ICultureMetadataManager cultureMetadataManager)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture | The input culture |
| Sdl.Core.Globalization.CultureMetadataManager.ICultureMetadataManager | cultureMetadataManager |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<Sdl.Core.Globalization.CultureCode> | The region-neutral parent culture of the input culture |
Remarks
A region-neutral culture is not necessarily one "without dashes". For example,
the region-neutral parent culture of zh-CN (Chinese, PRC) is zh-CHS or zh-Hans (Simplified
Chinese).
GetRegionQualifiedCulture(CultureInfo)
Heuristically computes and returns the region-specified ("default") culture for a given language. If the input culture is not neutral (i.e. it is region-specific), it is returned. Otherwise the method will find the region-qualified culture which most likely represents the culture's default/major region.
Declaration
[Obsolete("Use GetRegionQualifiedCultureAsync")]
public static CultureInfo GetRegionQualifiedCulture(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture | The input culture |
Returns
| Type | Description |
|---|---|
| System.Globalization.CultureInfo | The input parameter, if it's a region-qualified/non-neutral culture, or the default region-qualified culture otheriwise. |
GetRegionQualifiedCulture(String)
Heuristically computes and returns the region-specified ("default") culture code for a given language code. If the input culture is not neutral or does not have a region-qualified equivalent, null is returned.
Declaration
[Obsolete("Use GetRegionQualifiedCultureAsync")]
public static string GetRegionQualifiedCulture(string cultureCode)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | cultureCode |
Returns
| Type | Description |
|---|---|
| System.String |
GetRegionQualifiedCultureAsync(CultureCode, ICultureMetadataManager)
Rturns the region-specified ("default") culture code for a given language code. If the input culture is not neutral, null is returned.
Declaration
public static Task<CultureCode> GetRegionQualifiedCultureAsync(CultureCode cultureCode, ICultureMetadataManager cultureMetadataManager)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | cultureCode | |
| Sdl.Core.Globalization.CultureMetadataManager.ICultureMetadataManager | cultureMetadataManager |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<Sdl.Core.Globalization.CultureCode> |
GetRegistryCultureInfoAsync(CultureCode, Boolean, ICultureMetadataManager)
Declaration
public static Task<CultureInfo> GetRegistryCultureInfoAsync(CultureCode cultureCode, bool returnNullForUnknowns, ICultureMetadataManager cultureMetadataManager)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | cultureCode | |
| System.Boolean | returnNullForUnknowns | |
| Sdl.Core.Globalization.CultureMetadataManager.ICultureMetadataManager | cultureMetadataManager |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Globalization.CultureInfo> |
GetTrailingClitics(CultureInfo)
Returns a case-sensitive string hash set containing the trailing separable clitics for the provided
culture, or null if none are defined.
Declaration
public static HashSet<string> GetTrailingClitics(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.HashSet<System.String> |
IsRomanceLanguage(CultureCode)
Determines whether the specified culture info is any of the romance languages: French, Spanish, Portuguese, Italian, Romanian, Galician or Catalan.
Declaration
public static bool IsRomanceLanguage(CultureCode culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture | The culture info. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if culture is any of the romance languages, otherwise false. |
UseBlankAsSentenceSeparator(CultureCode)
Determines whether the specified culture uses blanks as sentence separators. This is currently only true for Thai.
Declaration
public static bool UseBlankAsSentenceSeparator(CultureCode culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture | The culture to test. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true iff the language associated with the culture uses blanks as sentence separators. |
UseBlankAsWordSeparator(CultureCode)
Determines whether the specified culture uses blanks as word separators. This is true for all cultures except those based on Japanese, Thai, or Chinese.
Declaration
public static bool UseBlankAsWordSeparator(CultureCode culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture | The culture to test. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true iff the language associated with the culture uses blanks as word separators. |
UseFullWidth(CultureCode)
returns true for CJK cultures
Declaration
public static bool UseFullWidth(CultureCode culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture |
Returns
| Type | Description |
|---|---|
| System.Boolean |
UsesClitics(CultureCode)
Determines whether the specified culture uses clitics (English and the romance languages).
Declaration
public static bool UsesClitics(CultureCode culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Sdl.Core.Globalization.CultureCode | culture | The culture. |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if culture contains clitics, otherwise false. |
UsesDefaultDigits(CultureInfo)
Determines whether the specified culture uses the standard default digits.
Declaration
public static bool UsesDefaultDigits(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture | The culture, which must not be null or a neutral culture |
Returns
| Type | Description |
|---|---|
| System.Boolean |
|
UsesStandardNumberGrouping(CultureInfo)
Determines whether the provided culture uses standard three-digit grouping for number formatting.
Declaration
public static bool UsesStandardNumberGrouping(CultureInfo culture)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Globalization.CultureInfo | culture | The culture, which must not be null or a neutral culture |
Returns
| Type | Description |
|---|---|
| System.Boolean | true if the culture uses standard three-digit grouping, and false otherwise |