public void DeserializeByaml(IDictionary <string, object> dictionary) { // Create new dictionaries Name = new Dictionary <Language, string>(); ShortName = new Dictionary <Language, string>(); void PopulateDictionary(string sourceDictKey, Dictionary <Language, string> targetDict) { // Check if the source dictionary even exists if (dictionary.TryGetValue(sourceDictKey, out object value)) { // Get the dictionary Dictionary <string, object> sourceDict = (Dictionary <string, object>)value; // Loop over every short name foreach (KeyValuePair <string, object> pair in sourceDict) { targetDict.Add(LanguageExtensions.FromSeadCode(pair.Key), (string)pair.Value); } } } PopulateDictionary("Name", Name); PopulateDictionary("ShortName", ShortName); }
private void load(FrameworkConfigManager frameworkConfig) { frameworkLocale = frameworkConfig.GetBindable <string>(FrameworkSetting.Locale); Children = new Drawable[] { languageSelection = new SettingsEnumDropdown <Language> { LabelText = GeneralSettingsStrings.LanguageDropdown, }, new SettingsCheckbox { LabelText = GeneralSettingsStrings.PreferOriginalMetadataLanguage, Current = frameworkConfig.GetBindable <bool>(FrameworkSetting.ShowUnicode) }, }; if (!LanguageExtensions.TryParseCultureCode(frameworkLocale.Value, out var locale)) { locale = Language.en; } languageSelection.Current.Value = locale; languageSelection.Current.BindValueChanged(val => frameworkLocale.Value = val.NewValue.ToCultureCode()); }
public async Task <Either <BaseError, Unit> > Handle(BuildPlayout request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Playout> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, playout => ApplyUpdateRequest(dbContext, request, playout))); }
public static void Initialize() { Localizations = new Dictionary <Language, Dictionary <string, string> >(); // Check if the new framework-specific strings directory is available if (System.IO.Directory.Exists(Path.Combine(Configuration.LoadedConfiguration.LocalizerConfig.LocalizationsDirectory, "framework"))) { // Populate the Dictionary for each Language foreach (Language language in LanguageExtensions.GetAllLanguages()) { // Read the framework JSONs string path = Path.Combine(Configuration.LoadedConfiguration.LocalizerConfig.LocalizationsDirectory, "framework", language.GetCode() + ".json"); // Check if the file exists if (File.Exists(path)) { // Load the file Localizations[language] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(path)); } else { // Create a new blank Dictionary Localizations[language] = new Dictionary <string, string>(); } } } // Populate the Dictionary for each Language foreach (Language language in LanguageExtensions.GetAllLanguages()) { // Create the localization file path string path = Path.Combine(Configuration.LoadedConfiguration.LocalizerConfig.LocalizationsDirectory, "application", language.GetCode() + ".json"); // Check if the file exists if (File.Exists(path)) { // Load the file Dictionary <string, string> applicationStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(path)); // Get every pair foreach (KeyValuePair <string, string> pair in applicationStrings) { // Check if this key does not exist if (!Localizations[language].TryGetValue(pair.Key, out string existTestVal)) { // Write the key into the master Dictionary Localizations[language][pair.Key] = pair.Value; } } } } // Check that the localizable missing message is available if (!Localizations[Language.EnglishUS].TryGetValue("localizer.missing_localizable", out string missingMessage)) { throw new Exception("Special message for missing localizable (\"localizer.missing_localizable\") is missing"); } }
public async Task <Either <BaseError, UpdateProgramScheduleResult> > Handle( UpdateProgramSchedule request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, ProgramSchedule> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, ps => ApplyUpdateRequest(dbContext, ps, request))); }
public async Task <Either <BaseError, Unit> > Handle( AddSeasonToCollection request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Parameters> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, parameters => ApplyAddSeasonRequest(dbContext, parameters))); }
public async Task <Either <BaseError, LocalLibraryViewModel> > Handle( CreateLocalLibrary request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, LocalLibrary> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, localLibrary => PersistLocalLibrary(dbContext, localLibrary))); }
public async Task <Either <BaseError, Unit> > Handle( DeleteLocalLibrary request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, LocalLibrary> validation = await LocalLibraryMustExist(dbContext, request); return(await LanguageExtensions.Apply(validation, localLibrary => DoDeletion(dbContext, localLibrary))); }
public async Task <Either <BaseError, Unit> > Handle( UpdateCollectionCustomOrder request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Collection> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, c => ApplyUpdateRequest(dbContext, c, request))); }
public async Task <Either <BaseError, Unit> > Handle( MoveLocalLibraryPath request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, Parameters> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, parameters => MovePath(dbContext, parameters))); }
public async Task <Either <BaseError, IEnumerable <ProgramScheduleItemViewModel> > > Handle( ReplaceProgramScheduleItems request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); Validation <BaseError, ProgramSchedule> validation = await Validate(dbContext, request); return(await LanguageExtensions.Apply(validation, ps => PersistItems(dbContext, request, ps))); }
public static void LanguageSeter(ComboBox comboBox) { var Items = comboBox.Items; comboBox.Font = font; foreach (Language l in LanguageExtensions.Values()) { Items.Add(LanguageExtensions.FullText(l)); } comboBox.SelectedItem = LanguageExtensions.FullText(CurrentLanguage); comboBox.SelectedIndexChanged += EventHandler; }
public async Task <Either <BaseError, string> > Handle( GetHlsPlaylistByChannelNumber request, CancellationToken cancellationToken) { await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); DateTimeOffset now = DateTimeOffset.Now; Validation <BaseError, Parameters> validation = await Validate(dbContext, request, now); return(await LanguageExtensions.Apply( validation, parameters => GetPlaylist(dbContext, request, parameters, now))); }
public static Dictionary <Language, string> LocalizeDateTimeToAllLanguages(DateTime dateTime) { // Create a new Dictionary Dictionary <Language, string> valueDict = new Dictionary <Language, string>(); // Populate the Dictionary foreach (Language language in LanguageExtensions.GetAllLanguages()) { // Localize the key to this Language valueDict.Add(language, LocalizeDateTime(dateTime, language)); } // Return the Dictionary return(valueDict); }
public static Dictionary <Language, string> CreateDummyLocalizedValues(string value) { // Create a new Dictionary Dictionary <Language, string> valueDict = new Dictionary <Language, string>(); // Populate the Dictionary foreach (Language language in LanguageExtensions.GetAllLanguages()) { // Localize the key to this Language valueDict.Add(language, value); } // Return the Dictionary return(valueDict); }
public static Language GetDefaultLanguage(IGuild guild, IChannel channel = null, string specifiedLanguage = null) { // Check if a language was specified if (specifiedLanguage == null) { // Check if this is not a DM if (guild != null) { // Attempt to get the GuildSettings for this guild GuildSettings guildSettings = Configuration.LoadedConfiguration.DiscordConfig.GuildSettings.Where(x => x.GuildId == guild.Id).FirstOrDefault(); // Check if there is a GuildSettings if (guildSettings != null) { // Check if there is a channel specified if (channel != null) { // Attempt to get a DynamicSettingsData for this channel DynamicSettingsData channelSettings = guildSettings.ChannelSettings.Where(c => c.Key == channel.Id).FirstOrDefault().Value; // Check if it exists if (channelSettings != null) { // Return the channel's language return((Language)channelSettings.GetSetting("language")); } } // Return the guild's default language return((Language)guildSettings.GetSetting("default_language")); } } // Default to en-US return(Language.EnglishUS); } else { try { return(LanguageExtensions.FromCode(specifiedLanguage)); } catch (Exception) { throw new LocalizedException("discord.error.bad_code"); } } }
private void InitializeInternationalization() { // Set up language information if (string.IsNullOrWhiteSpace(GW2PAO.Properties.Settings.Default.Language)) { var lang = LanguageExtensions.FromTwoLetterISOLanguageName(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName); GW2PAO.Properties.Settings.Default.Language = lang.ToTwoLetterISOLanguageName(); GW2PAO.Properties.Settings.Default.Save(); } // Note: this conversion, while it may seem redundant, ensures that we use only use a known language // If the CurrentUICulture is something other than the supported languages, this call defaults it to english. var savedLang = LanguageExtensions.FromTwoLetterISOLanguageName(GW2PAO.Properties.Settings.Default.Language); CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(savedLang.ToTwoLetterISOLanguageName()); }
public void DeserializeByaml(IDictionary <string, object> dictionary) { // Deserialize the VersusRule VersusRule = (VersusRule)EnumUtil.GetEnumValueFromString(typeof(VersusRule), (string)dictionary["Rule"]); // Create the News dictionary News = new Dictionary <string, Dictionary <Language, List <ScriptCommand> > >(); // Get the news list List <object> newsList = (List <object>)dictionary["News"]; // Loop over every news foreach (object obj in newsList) { // Create a new inner dictionary Dictionary <Language, List <ScriptCommand> > innerDict = new Dictionary <Language, List <ScriptCommand> >(); // Get the news dictionary Dictionary <string, object> news = (Dictionary <string, object>)obj; // Loop over every language key foreach (string code in news.Keys) { // Skip NewsType if (code == "NewsType") { continue; } // Create the script list List <ScriptCommand> commandList = ScriptParser.ParseCommandList((List <object>)news[code]); // Get the language code Language language = LanguageExtensions.FromSeadCode(code); // Add this to the inner dictionary innerDict.Add(language, commandList); } // Add the inner dictionary News.Add((string)news["NewsType"], innerDict); } // Load the Glicko constants GlickoConstants = new GlickoConstants(); GlickoConstants.DeserializeByaml((Dictionary <string, object>)dictionary[VersusRule.ToString()]); }
public async Task <Either <BaseError, Unit> > Handle( DeleteTraktList request, CancellationToken cancellationToken) { try { await using TvContext dbContext = _dbContextFactory.CreateDbContext(); Validation <BaseError, TraktList> validation = await TraktListMustExist(dbContext, request.TraktListId); return(await LanguageExtensions.Apply(validation, c => DoDeletion(dbContext, c))); } finally { _entityLocker.UnlockTrakt(); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { // Get the target Dictionary if it exists Dictionary <Language, string> textMappings = existingValue != null ? (Dictionary <Language, string>)existingValue : new Dictionary <Language, string>(); // Get the object JObject jObject = JObject.Load(reader); // Loop over each propery foreach (JProperty jProperty in jObject.Properties()) { // Add this property's key and value to the Dictionary textMappings.Add(LanguageExtensions.FromCode(jProperty.Name), (string)jProperty.Value); } // Return the Dictionary return(textMappings); }
public override void Invoke(string[] param) { if (param == null || param.Length == 0) { OutputInformation(string.Format("Current language: {0}", _Realm.GameData.ActiveLanguage)); return; } var paramList = string.Join(" ", param).Trim(); if (!Enum.TryParse <Language>(paramList, out var newLang)) { newLang = LanguageExtensions.GetFromCode(paramList); if (newLang == Language.Unsupported) { OutputError(string.Format("Unknown language.")); } } _Realm.GameData.ActiveLanguage = newLang; }
public override async Task <bool> InvokeAsync(string paramList) { if (string.IsNullOrWhiteSpace(paramList)) { OutputInformation("Current language: {0}", _Realm.GameData.ActiveLanguage); return(true); } paramList = paramList.Trim(); if (!Enum.TryParse <Language>(paramList, out var newLang)) { newLang = LanguageExtensions.GetFromCode(paramList); if (newLang == Language.Unsupported) { OutputError("Unknown language."); return(false); } } _Realm.GameData.ActiveLanguage = newLang; return(true); }
private void onPathChanged(ValueChangedEvent <string> e) { cancellationToken?.Cancel(); request?.Cancel(); string[] values = e.NewValue.Split('/', 2); if (values.Length > 1 && LanguageExtensions.TryParseCultureCode(values[0], out var language)) { request = new GetWikiRequest(values[1], language); } else { request = new GetWikiRequest(e.NewValue); } Loading.Show(); request.Success += response => Schedule(() => onSuccess(response)); request.Failure += _ => Schedule(onFail); api.PerformAsync(request); }
public static Dictionary <Language, string> LocalizeToAllLanguagesWithFormat(string key, Dictionary <Language, object[]> param) { return(LocalizeToAllLanguagesWithFormat(key, LanguageExtensions.GetAllLanguages(), param)); }
public async Task Register(IGuildChannel channel, string languageCode) { if (Context.Guild == null) { throw new LocalizedException("registration.in_dm"); } // Check that that the user has the manage guild permission if (!((SocketGuildUser)Context.User).GuildPermissions.Has(GuildPermission.ManageGuild)) { throw new LocalizedException("registration.user_no_manage_permission"); } // Check that we can write to this channel first if (!Context.Guild.CurrentUser.GetPermissions(channel).Has(ChannelPermission.SendMessages)) { throw new LocalizedException("registration.bot_no_write_permission"); } // Check the language code Language language; try { language = LanguageExtensions.FromCode(languageCode); } catch (Exception) { throw new LocalizedException("registration.bad_code"); } // Get any existing GuildSettings for this server GuildSettings guildSettings = Configuration.LoadedConfiguration.DiscordConfig.GuildSettings.Where(x => x.GuildId == Context.Guild.Id).FirstOrDefault(); // Check if the GuildSettings doesn't exist if (guildSettings == null) { // Create a GuildSettings instance guildSettings = new GuildSettings(); // Add this to the Configuration Configuration.LoadedConfiguration.DiscordConfig.GuildSettings.Add(guildSettings); } // Set the GuildSettings fields guildSettings.GuildId = Context.Guild.Id; guildSettings.TargetChannelId = channel.Id; guildSettings.DefaultLanguage = language; // Get the localized embed fields string embedTitle = Localizer.Localize("registration.title", guildSettings.DefaultLanguage); string embedDescription = Localizer.Localize("registration.description", guildSettings.DefaultLanguage); // Build the Embed Embed embed = new EmbedBuilder() .WithTitle(embedTitle) .WithDescription(embedDescription) .WithColor(Color.Green) .Build(); // Send the Embed await Context.Channel.SendMessageAsync(embed : embed); await DiscordBot.LoggingChannel.SendMessageAsync($"**[RegistrationCommand]** Registered \"{Context.Guild.Name}\" ({Context.Guild.Id}) to #{channel.Name} ({channel.Id}) using language {language.ToString()}"); }
/// <summary> /// Determines if the current language can be applied (e.g. if it is different) /// </summary> private bool CanApplyLanguage() { return(LanguageExtensions.FromTwoLetterISOLanguageName(Settings.Default.Language) != this.currentLanguage); }
/// <summary> /// Default constructor /// </summary> public GeneralSettingsViewModel() { this.ApplyLanguageCommand = new DelegateCommand(this.ApplyLanguage, this.CanApplyLanguage); this.currentLanguage = LanguageExtensions.FromTwoLetterISOLanguageName(Settings.Default.Language); }
private static void EventHandler(object sender, EventArgs e) => CurrentLanguage = LanguageExtensions.FullText((string)((ComboBox)sender).SelectedItem);
public void proper_descriptions_of_language_code_should_render_proper_enum_values(string desc, LanguageCode expectedCode) { var code = LanguageExtensions.GetCode(desc); Assert.AreEqual(expectedCode, code); }
public void improper_descriptions_of_language_code_should_render_unknown_enum_values(string desc) { var code = LanguageExtensions.GetCode(desc); Assert.AreEqual(LanguageCode.Unknown, code); }