private bool TryAddReader(TranslationReaderCollection collection, string filePath, ITranslationReader reader)
        {
            string fileName = Path.GetFileNameWithoutExtension(filePath);

            CultureInfo culture;

            if (CultureInfoParser.TryParse(fileName, out culture))
            {
                collection.Add(culture, reader);
                return(true);
            }

            // Everything before last '.' use as assembly name; everthing behind last '.' use as culture info.
            string assemblyName = Path.GetFileNameWithoutExtension(fileName);
            string cultureName  = Path.GetExtension(fileName);

            if (cultureName.StartsWith("."))
            {
                cultureName = cultureName.Substring(1);
            }

            if (CultureInfoParser.TryParse(cultureName, out culture))
            {
                collection.Add(culture, assemblyName, reader);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        static void TestParentCultures()
        {
            CultureInfo cultureInfo;

            if (CultureInfoParser.TryParse("cs-cz", out cultureInfo))
            {
                List <CultureInfo> cultureInfos = new List <CultureInfo>()
                {
                    cultureInfo
                };
                while (cultureInfo.Parent != CultureInfo.InvariantCulture)
                {
                    cultureInfo = cultureInfo.Parent;
                    cultureInfos.Add(cultureInfo);
                }

                foreach (CultureInfo foundCulture in cultureInfos)
                {
                    Console.WriteLine(foundCulture);
                }

                return;
            }

            Console.WriteLine("Unnable to parse...");
        }
Ejemplo n.º 3
0
        public bool MatchUrl(IRouteParameterMatchContext context)
        {
            if (String.IsNullOrEmpty(context.OriginalUrl))
            {
                if (!String.IsNullOrEmpty(defaultLocale))
                {
                    context.Values["locale"] = CultureInfo.GetCultureInfo(defaultLocale);
                    return(true);
                }
                return(false);
            }

            int         length      = 5;
            CultureInfo culfureInfo = null;

            if (context.OriginalUrl.Length >= 5)
            {
                if (!CultureInfoParser.TryParse(context.OriginalUrl.Substring(0, 5), out culfureInfo))
                {
                    CultureInfoParser.TryParse(context.OriginalUrl.Substring(0, 2), out culfureInfo);
                    length = 2;
                }
            }
            else if (context.OriginalUrl.Length >= 2)
            {
                CultureInfoParser.TryParse(context.OriginalUrl.Substring(0, 2), out culfureInfo);
                length = 2;
            }

            if (culfureInfo != null)
            {
                context.Values["locale"] = culfureInfo;
                context.RemainingUrl     = context.OriginalUrl.Substring(length);
                return(true);
            }

            if (!String.IsNullOrEmpty(defaultLocale))
            {
                context.Values["locale"] = CultureInfo.GetCultureInfo(defaultLocale);
                return(true);
            }
            return(false);
        }