public void ParseTests(string data, string expectedCode, LanguageSupportLevel expectedLevel)
        {
            var languageInfo = LanguageInfo.Parse(data);

            Assert.Equal(expectedCode, languageInfo.Code);
            Assert.Equal(expectedLevel, languageInfo.Support);
            Assert.NotNull(languageInfo.Culture);
        }
Example #2
0
        public static bool TryGetLanguageInfoFromEnglishName(string englishName, LanguageSupportLevel supportLevel, out ILanguageInfo?languageInfo)
        {
            var culture = AvailableCultures.FirstOrDefault(x =>
                                                           x.EnglishName.Equals(englishName, StringComparison.InvariantCultureIgnoreCase));

            languageInfo = default;
            if (culture == null)
            {
                return(false);
            }
            languageInfo = new LanguageInfo(culture.TwoLetterISOLanguageName)
            {
                Support = supportLevel
            };
            return(true);
        }
Example #3
0
        public static IEnumerable <ILanguageInfo> GetLanguages(string directory, Func <string, IEnumerable <string> > languageNameFinder, LanguageSupportLevel supportLevel)
        {
            var languages = languageNameFinder(directory).ToList();

            if (!languages.Any())
            {
                yield break;
            }

            foreach (var language in languages)
            {
                if (!TryGetLanguageInfoFromEnglishName(language, supportLevel, out var languageInfo))
                {
                    continue;
                }
                yield return(languageInfo !);
            }
        }
 /// <summary>
 /// Creates a new instance from a given <see cref="ILanguageInfo"/> instance.
 /// </summary>
 /// <param name="languageInfo">The instance that will copied.</param>
 public JsonLanguageInfo(ILanguageInfo languageInfo)
 {
     Requires.NotNull(languageInfo, nameof(languageInfo));
     Code    = languageInfo.Code;
     Support = languageInfo.Support;
 }