public LyricsForSong(Song song, string val, string source, string url, TranslationType translationType, string cultureCode) { Song = song; Source = source; URL = url; TranslationType = translationType; CultureCode = new OptionalCultureCode(cultureCode); Value = val; }
/// <summary> /// Gets the culture with the specific name, or the application default culture (English basically). /// </summary> /// <param name="culture">Culture name, for example "en-US".</param> /// <returns>The specified culture, or application default culture. Cannot be null.</returns> public static CultureInfo GetCultureOrDefault(OptionalCultureCode culture) { return(culture.GetCultureInfoSafe() ?? Default); }
public UserKnownLanguage(User user, string cultureCode, UserLanguageProficiency proficiency) { User = user; CultureCode = new OptionalCultureCode(cultureCode); Proficiency = proficiency; }
public static LyricsForSongContract GetDefaultLyrics(LyricsForSongContract[] lyrics, OptionalCultureCode uiCultureCode, IEnumerable <OptionalCultureCode> userLanguages, Lazy <IEnumerable <UserKnownLanguage> > knownLanguages) { if (!lyrics.Any()) { return(null); } var dict = lyrics.Where(l => !string.IsNullOrEmpty(l.CultureCode)).Distinct(l => l.CultureCode).ToDictionary(l => l.CultureCode); var uiCulture = uiCultureCode.CultureInfo; if (uiCulture != null && dict.ContainsKey(uiCulture.TwoLetterISOLanguageName)) { return(dict[uiCulture.TwoLetterISOLanguageName]); } var userLang = userLanguages?.Select(c => c.GetCultureInfoSafe()) .Where(c => c != null) .Select(l => l.TwoLetterISOLanguageName) .FirstOrDefault(l => dict.ContainsKey(l)); if (!string.IsNullOrEmpty(userLang)) { return(dict[userLang]); } var lang = knownLanguages.Value? .OrderByDescending(l => l.Proficiency) .Select(l => l.CultureCode.CultureCode) .FirstOrDefault(l => dict.ContainsKey(l)); if (lang != null) { return(dict[lang]); } var original = lyrics.FirstOrDefault(l => l.TranslationType == TranslationType.Original); return(original ?? lyrics.First()); }