Exemple #1
0
        /// <summary>
        /// Init different locales format,
        /// Supporting English, French, Deutsche and Chinese Locales.
        /// </summary>
        private void InitLocales()
        {
            if (_mapLocaleToFunction.Count > 0)
            {
                return;
            }
            DateAndTimeLocaleFormat yearMonthDay = new DateAndTimeLocaleFormat
            {
                TimeFormat = "{0:hh:mm tt}",
                DateFormat = "{0:yyyy-MM-dd}"
            };
            DateAndTimeLocaleFormat dayMonthYear = new DateAndTimeLocaleFormat
            {
                TimeFormat = "{0:hh:mm tt}",
                DateFormat = "{0:dd/MM/yyyy}"
            };
            DateAndTimeLocaleFormat monthDayYEar = new DateAndTimeLocaleFormat
            {
                TimeFormat = "{0:hh:mm tt}",
                DateFormat = "{0:MM/dd/yyyy}"
            };

            foreach (string locale in new string[] { "en-za", "en-ie", "en-gb", "en-ca", "fr-ca", "zh-cn", "zh-sg", "zh-hk", "zh-mo", "zh-tw" })
            {
                _mapLocaleToFunction[locale] = yearMonthDay;
            }
            foreach (string locale in new string[] { "en-au", "fr-be", "fr-ch", "fr-fr", "fr-lu", "fr-mc", "de-at", "de-ch", "de-de", "de-lu", "de-li" })
            {
                _mapLocaleToFunction[locale] = dayMonthYear;
            }
            _mapLocaleToFunction["en-us"] = monthDayYEar;
        }
        /// <summary>
        /// Init different locales format,
        /// Supporting English, French, Deutsche and Chinese Locales.
        /// </summary>
        private void InitLocales()
        {
            if (_mapLocaleToFunction.Count > 0)
            {
                return;
            }

            var supportedLocales = new string[]
            {
                "en-us", "en-za", "en-ie", "en-gb", "en-ca", "fr-ca", "zh-cn", "zh-sg", "zh-hk", "zh-mo", "zh-tw",
                "en-au", "fr-be", "fr-ch", "fr-fr", "fr-lu", "fr-mc", "de-at", "de-ch", "de-de", "de-lu", "de-li",
                "es-es",
            };

            foreach (var locale in supportedLocales)
            {
                var cultureInfo  = new CultureInfo(locale);
                var dateTimeInfo = new DateAndTimeLocaleFormat()
                {
                    DateFormat = $"{{0:{cultureInfo.DateTimeFormat.ShortDatePattern}}}",
                    TimeFormat = $"{{0:{cultureInfo.DateTimeFormat.ShortTimePattern}}}",
                };
                _mapLocaleToFunction[locale] = dateTimeInfo;
            }
        }