Exemple #1
0
        /**
         * Utility for getMeasurementSystem and getPaperSize
         */
        private static UResourceBundle MeasurementTypeBundleForLocale(ULocale locale, string measurementType)
        {
            // Much of this is taken from getCalendarType in impl/CalendarUtil.java
            UResourceBundle measTypeBundle = null;
            string          region         = ULocale.GetRegionForSupplementalData(locale, true);

            try
            {
                UResourceBundle rb = UResourceBundle.GetBundleInstance(
                    ICUData.ICU_BASE_NAME,
                    "supplementalData",
                    ICUResourceBundle.ICU_DATA_CLASS_LOADER);
                UResourceBundle measurementData = rb.Get("measurementData");
                UResourceBundle measDataBundle  = null;
                try
                {
                    measDataBundle = measurementData.Get(region);
                    measTypeBundle = measDataBundle.Get(measurementType);
                }
                catch (MissingManifestResourceException mre)
                {
                    // use "001" as fallback
                    measDataBundle = measurementData.Get("001");
                    measTypeBundle = measDataBundle.Get(measurementType);
                }
            }
            catch (MissingManifestResourceException mre)
            {
                // fall through
            }
            return(measTypeBundle);
        }
Exemple #2
0
        // ICU4N specific - de-nested PaperSize

        /// <summary>
        /// Returns the size of paper used in the locale. The paper sizes returned are always in
        /// <em>milli-meters</em>.
        /// </summary>
        /// <param name="locale">The locale for which the measurement system to be retrieved.</param>
        /// <returns>The paper size used in the locale.</returns>
        /// <stable>ICU 3.0</stable>
        public static PaperSize GetPaperSize(ULocale locale)
        {
            UResourceBundle obj = MeasurementTypeBundleForLocale(locale, PAPER_SIZE);

            int[] size = obj.GetInt32Vector();
            return(new PaperSize(size[0], size[1]));
        }
Exemple #3
0
        /// <summary>
        /// Utility for <see cref="GetMeasurementSystem(ULocale)"/> and <see cref="GetPaperSize(ULocale)"/>
        /// </summary>
        private static UResourceBundle MeasurementTypeBundleForLocale(ULocale locale, string measurementType)
        {
            // Much of this is taken from getCalendarType in impl/CalendarUtil.java
            UResourceBundle measTypeBundle = null;

#pragma warning disable 612, 618
            string region = ULocale.GetRegionForSupplementalData(locale, true);
#pragma warning restore 612, 618
            try
            {
                UResourceBundle rb = UResourceBundle.GetBundleInstance(
                    ICUData.IcuBaseName,
                    "supplementalData",
                    ICUResourceBundle.IcuDataAssembly);
                UResourceBundle measurementData = rb.Get("measurementData");
                UResourceBundle measDataBundle  = null;
                try
                {
                    measDataBundle = measurementData.Get(region);
                    measTypeBundle = measDataBundle.Get(measurementType);
                }
                catch (MissingManifestResourceException)
                {
                    // use "001" as fallback
                    measDataBundle = measurementData.Get("001");
                    measTypeBundle = measDataBundle.Get(measurementType);
                }
            }
            catch (MissingManifestResourceException)
            {
                // fall through
            }
            return(measTypeBundle);
        }
Exemple #4
0
        /// <summary>
        /// Gets the <see cref="LocaleData"/> object associated with the <see cref="ULocale"/> specified in <paramref name="locale"/>.
        /// </summary>
        /// <param name="locale"><see cref="ULocale"/> with thich the locale data object is associated.</param>
        /// <returns>A locale data object.</returns>
        /// <stable>ICU 3.4</stable>
        public static LocaleData GetInstance(ULocale locale)
        {
            LocaleData ld = new LocaleData();

            ld.bundle       = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale);
            ld.langBundle   = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuLanguageBaseName, locale);
            ld.noSubstitute = false;
            return(ld);
        }
Exemple #5
0
 /// <summary>
 /// Gets the <see cref="LocaleData"/> object associated with the <see cref="UCultureInfo"/> specified in <paramref name="locale"/>.
 /// </summary>
 /// <param name="locale"><see cref="UCultureInfo"/> with thich the locale data object is associated.</param>
 /// <returns>A locale data object.</returns>
 /// <stable>ICU 3.4</stable>
 public static LocaleData GetInstance(UCultureInfo locale)
 {
     return(new LocaleData
     {
         bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale),
         langBundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuLanguageBaseName, locale),
         noSubstitute = false
     });
 }
Exemple #6
0
        /**
         * Gets the LocaleData object associated with the ULocale specified in locale
         *
         * @param locale    Locale with thich the locale data object is associated.
         * @return          A locale data object.
         * @stable ICU 3.4
         */
        public static LocaleData GetInstance(ULocale locale)
        {
            LocaleData ld = new LocaleData();

            ld.bundle       = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.ICU_BASE_NAME, locale);
            ld.langBundle   = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.ICU_LANG_BASE_NAME, locale);
            ld.noSubstitute = false;
            return(ld);
        }
Exemple #7
0
 /// <summary>
 /// Returns the current CLDR version
 /// </summary>
 /// <stable>ICU 4.2</stable>
 public static VersionInfo GetCLDRVersion()
 {
     // fetching this data should be idempotent.
     if (gCLDRVersion == null)
     {
         // from ZoneMeta.java
         UResourceBundle supplementalDataBundle = UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, "supplementalData", ICUResourceBundle.IcuDataAssembly);
         UResourceBundle cldrVersionBundle      = supplementalDataBundle.Get("cldrVersion");
         gCLDRVersion = VersionInfo.GetInstance(cldrVersionBundle.GetString());
     }
     return(gCLDRVersion);
 }
Exemple #8
0
 /**
  * Returns the current CLDR version
  * @stable ICU 4.2
  */
 public static VersionInfo GetCLDRVersion()
 {
     // fetching this data should be idempotent.
     if (gCLDRVersion == null)
     {
         // from ZoneMeta.java
         UResourceBundle supplementalDataBundle = UResourceBundle.GetBundleInstance(ICUData.ICU_BASE_NAME, "supplementalData", ICUResourceBundle.ICU_DATA_CLASS_LOADER);
         UResourceBundle cldrVersionBundle      = supplementalDataBundle.Get("cldrVersion");
         gCLDRVersion = VersionInfo.GetInstance(cldrVersionBundle.GetString());
     }
     return(gCLDRVersion);
 }
Exemple #9
0
        internal static string GetTZDataVersion()
        {
            if (TZDATA_VERSION == null)
            {
                return(LazyInitializer.EnsureInitialized(ref TZDATA_VERSION, () =>
                {
                    UResourceBundle tzbundle = UResourceBundle.GetBundleInstance("Impl/Data/icudt"
#pragma warning disable 612, 618
                                                                                 + VersionInfo.IcuDataVersionPath, "zoneinfo64");
#pragma warning restore 612, 618
                    return tzbundle.GetString("TZVersion");
                }));
            }
            return(TZDATA_VERSION);
        }
Exemple #10
0
 internal static string GetTZDataVersion()
 {
     if (TZDATA_VERSION == null)
     {
         lock (syncLock)
         {
             if (TZDATA_VERSION == null)
             {
                 UResourceBundle tzbundle = UResourceBundle.GetBundleInstance("Impl/Data/icudt"
                                                                              + VersionInfo.ICU_DATA_VERSION_PATH, "zoneinfo64");
                 TZDATA_VERSION = tzbundle.GetString("TZVersion");
             }
         }
     }
     return(TZDATA_VERSION);
 }
Exemple #11
0
        internal static string GetTZDataVersion()
        {
            if (TZDATA_VERSION == null)
            {
                lock (syncLock)
                {
                    if (TZDATA_VERSION == null)
                    {
                        UResourceBundle tzbundle = UResourceBundle.GetBundleInstance("Impl/Data/icudt"
#pragma warning disable 612, 618
                                                                                     + VersionInfo.IcuDataVersionPath, "zoneinfo64");
#pragma warning restore 612, 618
                        TZDATA_VERSION = tzbundle.GetString("TZVersion");
                    }
                }
            }
            return(TZDATA_VERSION);
        }
Exemple #12
0
        /**
         * Returns the measurement system used in the locale specified by the locale.
         *
         * @param locale      The locale for which the measurement system to be retrieved.
         * @return MeasurementSystem the measurement system used in the locale.
         * @stable ICU 3.0
         */
        public static MeasurementSystem GetMeasurementSystem(ULocale locale)
        {
            UResourceBundle sysBundle = MeasurementTypeBundleForLocale(locale, MEASUREMENT_SYSTEM);

            switch (sysBundle.GetInt32())
            {
            case 0: return(MeasurementSystem.SI);

            case 1: return(MeasurementSystem.US);

            case 2: return(MeasurementSystem.UK);

            default:
                // return null if the object is null or is not an instance
                // of integer indicating an error
                return(null);
            }
        }
Exemple #13
0
        // ICU4N specific - de-nested MeasurementSystem

        /// <summary>
        /// Returns the measurement system used in the locale specified by the locale.
        /// </summary>
        /// <param name="locale">The locale for which the measurement system to be retrieved.</param>
        /// <returns>The <see cref="MeasurementSystem"/> used in the locale.</returns>
        /// <stable>ICU 3.0</stable>
        public static MeasurementSystem GetMeasurementSystem(ULocale locale)
        {
            UResourceBundle sysBundle = MeasurementTypeBundleForLocale(locale, MEASUREMENT_SYSTEM);

            return((MeasurementSystem)sysBundle.GetInt32());
        }