CultureExtensions is a set of methods that provide easy access to NCLDR data for cultures
Esempio n. 1
0
 /// <summary>
 /// GetNumbers gets the CLDR Numbers for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the Numbers</param>
 /// <returns>The CLDR Numbers for the CultureInfo</returns>
 public static Numbers GetNumbers(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetNumbers(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a CultureAndRegionInfoBuilder object for the NCLDR culture
        /// </summary>
        /// <param name="cldrCultureName">The name of the CLDR culture from which to create the .NET culture</param>
        /// <param name="dotNetCultureName">The name of the .NET custom culture to create</param>
        /// <returns>A CultureAndRegionInfoBuilder object for the NCLDR culture</returns>
        public static CultureAndRegionInfoBuilder CreateNCldrCultureAndRegionInfoBuilder(string cldrCultureName, string dotNetCultureName)
        {
            Culture culture = Culture.GetCulture(cldrCultureName);

            CultureAndRegionModifiers cultureAndRegionModifiers =
                culture.IsNeutralCulture ? CultureAndRegionModifiers.Neutral : CultureAndRegionModifiers.None;

            CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(dotNetCultureName, cultureAndRegionModifiers);

            CultureInfo parentCultureInfo = GetParentCultureInfo(culture);

            builder.Parent = parentCultureInfo;

            if (string.IsNullOrEmpty(culture.EnglishName))
            {
                builder.CultureEnglishName = culture.Identity.CultureName;
            }
            else
            {
                builder.CultureEnglishName = culture.EnglishName;
            }

            if (string.IsNullOrEmpty(culture.NativeName) && string.IsNullOrEmpty(culture.EnglishName))
            {
                builder.CultureNativeName = culture.Identity.CultureName;
            }
            else if (string.IsNullOrEmpty(culture.NativeName))
            {
                builder.CultureNativeName = culture.EnglishName;
            }
            else
            {
                builder.CultureNativeName = culture.NativeName;
            }

            builder.TwoLetterISOLanguageName = culture.Identity.Language.Id;

            // CLDR does not have data for ThreeLetterISOLanguageName but one must be assigned for the culture to be valid
            builder.ThreeLetterISOLanguageName = culture.Identity.Language.Id;

            // CLDR does not have data for ThreeLetterWindowsLanguageName but one must be assigned for the culture to be valid
            builder.ThreeLetterWindowsLanguageName = culture.Identity.Language.Id;

            // The CultureAndRegionInfoBuilder requires dummy values for these properties
            // even though there is no region or currency values
            builder.RegionEnglishName            = "xxx";
            builder.RegionNativeName             = "xxx";
            builder.ThreeLetterISORegionName     = "xxx";
            builder.ThreeLetterWindowsRegionName = "xxx";
            builder.TwoLetterISORegionName       = "xx";
            builder.ISOCurrencySymbol            = "xx";
            builder.CurrencyEnglishName          = "xxx";
            builder.CurrencyNativeName           = "xxx";

            if (culture.Identity.Region != null)
            {
                Region region = culture.Identity.Region;
                builder.RegionEnglishName = region.EnglishName;

                string regionNativeName = region.DisplayName(culture.Identity.Language.Id);
                if (string.IsNullOrEmpty(regionNativeName))
                {
                    builder.RegionNativeName = region.EnglishName;
                }
                else
                {
                    builder.RegionNativeName = regionNativeName;
                }

                RegionCode regionCode = RegionExtensions.GetRegionCode(region.Id);
                if (regionCode != null && regionCode.Alpha3 != null)
                {
                    builder.ThreeLetterISORegionName = regionCode.Alpha3;
                }
                else
                {
                    builder.ThreeLetterISORegionName = region.Id;
                }

                // CLDR does not have data for ThreeLetterWindowsRegionName but one must be assigned for the culture to be valid
                builder.ThreeLetterWindowsRegionName = region.Id;
                builder.TwoLetterISORegionName       = region.Id;

                builder.IsMetric = RegionExtensions.GetMeasurementSystem(region.Id).IsMetric;
            }
            else
            {
                builder.IsMetric = RegionExtensions.GetMeasurementSystem(NCldr.RegionIdForTheWorld).IsMetric;
            }

            // CLDR does not have data for KeyboardLayoutId or GeoId
            builder.IetfLanguageTag = cldrCultureName;

            builder.GregorianDateTimeFormat = CreateDateTimeFormatInfo(culture);
            builder.AvailableCalendars      = GetAvailableCalendars(culture);

            builder.NumberFormat = CreateNumberFormatInfo(culture);

            if (culture.Numbers != null &&
                culture.Numbers.CurrencyDisplayNameSets != null &&
                culture.Numbers.CurrentCurrencyPeriod != null)
            {
                string currencyName = culture.Numbers.CurrentCurrencyPeriod.Id;
                if (!string.IsNullOrEmpty(currencyName))
                {
                    builder.ISOCurrencySymbol = currencyName;

                    builder.CurrencyEnglishName = CultureExtensions.GetCurrencyDisplayName(currencyName, "en");

                    string currencyNativeName = CultureExtensions.GetCurrencyDisplayName(currencyName, culture.Identity.Language.Id);
                    builder.CurrencyNativeName = currencyNativeName == null ? builder.CurrencyEnglishName : currencyNativeName;
                }
            }

            builder.TextInfo    = parentCultureInfo.TextInfo;
            builder.CompareInfo = parentCultureInfo.CompareInfo;

            return(builder);
        }
Esempio n. 3
0
 /// <summary>
 /// GetLikelySubTag gets the most likely child culture name from a parent CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the sub tag for</param>
 /// <returns>The most likely child culture name for the parent CultureInfo</returns>
 public static string GetLikelySubTag(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetLikelySubTag(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 4
0
 /// <summary>
 /// GetListPatterns gets the CLDR ListPatterns for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR ListPatterns for</param>
 /// <returns>The CLDR ListPatterns for the CultureInfo</returns>
 public static ListPattern[] GetListPatterns(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetListPatterns(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 5
0
 /// <summary>
 /// GetGenderListId gets the CLDR GenderList identifier for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR DayPeriodRules for</param>
 /// <returns>The CLDR GenderList identifier for the CultureInfo</returns>
 public static string GetGenderListId(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetGenderListId(GetNeutralCultureInfo(cultureInfo).Name));
 }
Esempio n. 6
0
 /// <summary>
 /// GetLayout gets the CLDR Layout for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR Layout for</param>
 /// <returns>The CLDR Layout for the CultureInfo</returns>
 public static Layout GetLayout(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetLayout(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 7
0
 /// <summary>
 /// GetNo gets the localized short 'No' string for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the localized short 'No' string for</param>
 /// <returns>The localized short 'No' string for the CultureInfo</returns>
 public static string GetNoShort(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetNoShort(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 8
0
 /// <summary>
 /// GetDayPeriodRules gets the CLDR DayPeriodRules for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR DayPeriodRules for</param>
 /// <returns>The CLDR DayPeriodRules for the CultureInfo</returns>
 public static DayPeriodRule[] GetDayPeriodRules(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetDayPeriodRules(GetNeutralCultureInfo(cultureInfo).Name));
 }
Esempio n. 9
0
 /// <summary>
 /// GetRuleBasedNumberFormatting gets the CLDR RuleBasedNumberFormatting for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the RuleBasedNumberFormatting for</param>
 /// <returns>The CLDR RuleBasedNumberFormatting for the CultureInfo</returns>
 public static RuleBasedNumberFormatting GetRuleBasedNumberFormatting(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetRuleBasedNumberFormatting(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 10
0
 /// <summary>
 /// GetUnitPatternSets gets the CLDR UnitPatternSets for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the UnitPatternSets for</param>
 /// <returns>The CLDR UnitPatternSets for the CultureInfo</returns>
 public static UnitPatternSet[] GetUnitPatternSets(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetUnitPatternSets(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 11
0
 /// <summary>
 /// GetCasing gets the CLDR Casing for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR Casing for</param>
 /// <returns>The CLDR Casing for the CultureInfo</returns>
 public static Casing GetCasing(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetCasing(GetNCldrCultureName(cultureInfo)));
 }
Esempio n. 12
0
 /// <summary>
 /// GetOrdinalRule gets the CLDR ordinal PluralRule for the integer for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR ordinal PluralRule for</param>
 /// <param name="value">The integer to get the ordinal PluralRule for</param>
 /// <returns>The CLDR ordinal PluralRule for the integer for the CultureInfo</returns>
 public static PluralRule GetOrdinalRule(this CultureInfo cultureInfo, int value)
 {
     return(CultureExtensions.GetOrdinalRule(GetNCldrCultureName(GetNeutralCultureInfo(cultureInfo)), value));
 }
Esempio n. 13
0
 /// <summary>
 /// GetOrdinalRules gets the CLDR ordinal PluralRules for the CultureInfo
 /// </summary>
 /// <param name="cultureInfo">The CultureInfo to get the CLDR ordinal PluralRules for</param>
 /// <returns>The CLDR ordinal PluralRules for the CultureInfo</returns>
 public static PluralRule[] GetOrdinalRules(this CultureInfo cultureInfo)
 {
     return(CultureExtensions.GetOrdinalRules(GetNCldrCultureName(GetNeutralCultureInfo(cultureInfo))));
 }