예제 #1
0
        public async Task SetLanguage(string language)
        {
            var eb = new EmbedBuilder();
            var ts = await TranslationManager.CreateFor(Context.Channel);

            eb.Title = ts.GetMessage("commands/language:embed_title");

            try
            {
                CultureInfo lang = new CultureInfo(language);
                if (!TranslationManager.HasLanguage(lang))
                {
                    // Please translate :)
                    eb = EmbedFactory.CreateError()
                         .WithTitle(ts.GetMessage("commands/language:embed_title"))
                         .WithDescription(MessageFormatter.Format(ts.GetMessage("commands/language:error_language_not_found"), lang.TwoLetterISOLanguageName));
                }
                else
                {
                    eb.Color       = EmbedFactory.Success;
                    eb.Description = MessageFormatter.Format(ts.GetMessage("commands/language:language_set_message"), lang.TwoLetterISOLanguageName);
                    await TranslationManager.SetLanguageAsync(TranslationManager.GetId(Context.Channel), lang);
                }
            }
            catch (CultureNotFoundException)
            {
                eb.Description = ts.GetMessage("commands/language:error_unknown_language");
                eb.Color       = EmbedFactory.Error;
            }
            await ReplyAsync(embed : eb.Build());
        }