public PlatformCulture(string platformCultureString)
        {
            if (String.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException(
                          "Expected culture identifier", nameof(platformCultureString));
            }

            /// .NET expects dash, not underscore.
            PlatformString = platformCultureString.Replace("_", "-");

            var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (dashIndex > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocaleCode   = parts[1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocaleCode   = "";
            }
        }
        /// <summary>
        /// Creates a new .NET compliant <see cref="PlatformCulture"/> instance
        /// from a platform-specific culture string. <para> </para>
        /// iOS uses underscores as language/locale separator; Android uses dashes. Lovely.
        /// </summary>
        /// <param name="platformCultureString">Platform-specific culture identifier <c>string</c>.</param>
        public PlatformCulture(string platformCultureString)
        {
            if (string.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException("Expected a valid culture identifier!", nameof(platformCultureString));
            }

            PlatformString = platformCultureString.Replace("_", "-"); // .NET expects a dash, not an underscore.

            var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (dashIndex > 0)
            {
                string[] parts = PlatformString.Split('-');

                if (parts.Length != 2)
                {
                    throw new ArgumentException("Invalid culture identifier (multiple dashes/underscores detected; only one allowed).", nameof(platformCultureString));
                }

                LanguageCode = parts[0];
                LocaleCode   = parts[1];
            }
            else
            {
                LocaleCode   = string.Empty;
                LanguageCode = PlatformString;
            }
        }
Example #3
0
        public PlatformCulture(string platformCultureString)
        {
            if (string.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException("Expected culture identifier", "platformCultureString");
            }
            PlatformString = platformCultureString.Replace("_", "-");
            var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (dashIndex > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocalCode    = "";
            }
        }
        public PlatformCulture(string platformCultureString)
        {
            if (string.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException("Expected Culture Identifier", "platformCultureString");
            }

            PlatformString = platformCultureString.Replace("_", "-");
            if (PlatformString.IndexOf("-", StringComparison.Ordinal) > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocalCode    = parts[1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocalCode    = string.Empty;
            }
        }
Example #5
0
        public PlatformCulture(string platformCultureString)
        {
            if (string.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException("Expected culture identifier", "platformCultureString"); // in C# 6 use nameof(platformCultureString)
            }

            PlatformString = platformCultureString.Replace("_", "-"); // .NET expects dash, not underscore
            var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);
            if (dashIndex > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocaleCode = parts[1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocaleCode = "";
            }
        }
Example #6
0
        public PlatformCulture(string platformCultureString)
        {
            if (String.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException(Helpers.TranslateServices.GetResourceString(Helpers.CommonConstants.ExpectedCultureIdentifier), "platformCultureString"); // in C# 6 use nameof(platformCultureString)
            }
            PlatformString = platformCultureString.Replace("_", "-");                                                                                                 // .NET expects dash, not underscore
            var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (dashIndex > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocaleCode   = parts[1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocaleCode   = "";
            }
        }
        /// <summary>
        /// 言語選択クラス
        /// </summary>
        /// <param name="platformCultureString">指定言語</param>
        public PlatformCulture(string platformCultureString)
        {
            if (string.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException(nameof(platformCultureString));
            }

            PlatformString = platformCultureString.Replace('_', '-');
            int index = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (index > 0)
            {
                string[] values = PlatformString.Split('-');
                LanguageCode = values[0];
                LocalCode    = values[1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocalCode    = "";
            }
        }
Example #8
0
        public PlatformCulture(string PlatformCultureString)
        {
            if (string.IsNullOrEmpty(PlatformCultureString))
            {
                throw new ArgumentException("Expected culture identifier", "PlatformCultureString");// in C# 6 use nameof(platformCultureString)
            }
            ;

            PlatformString = PlatformCultureString.Replace("_", "-");
            var dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (dashIndex > 0)
            {
                var parts = PlatformString.Split('-');
                LanguageCode = parts[0];
                LocaleCode   = parts[1];
            }
            else
            {
                LanguageCode = PlatformString;
                LocaleCode   = "";
            }
        }
Example #9
0
        public PlatformCulture(String platformCultureString)
        {
            if (String.IsNullOrEmpty(platformCultureString))
            {
                throw new ArgumentException("Expected culture identifier", nameof(platformCultureString));
            }

            this.PlatformString = platformCultureString.Replace("_", "-"); // .NET expects dash, not underscore

            Int32 dashIndex = PlatformString.IndexOf("-", StringComparison.Ordinal);

            if (dashIndex > 0)
            {
                String[] parts = PlatformString.Split('-');

                this.LanguageName = parts[0];
                this.LocaleName   = parts[1];
            }
            else
            {
                this.LanguageName = this.PlatformString;
                this.LocaleName   = String.Empty;
            }
        }