Setting locales done? Needs testing

This commit is contained in:
Kwoth 2017-02-13 10:50:58 +01:00
parent 3f420f78f2
commit db79177f0c
4 changed files with 87 additions and 6 deletions

View File

@ -19,7 +19,7 @@ namespace NadekoBot.Modules.Administration.Commands
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.Administrator)]
public async Task SetLocale([Remainder] string name)
public async Task SetLocale([Remainder] string name = null)
{
CultureInfo ci = null;
try
@ -42,17 +42,17 @@ namespace NadekoBot.Modules.Administration.Commands
[NadekoCommand, Usage, Description, Aliases]
[OwnerOnly]
public async Task SetDefaulLocale(string name)
public async Task SetDefaultLocale(string name)
{
CultureInfo ci = null;
try
{
if (name.Trim().ToLowerInvariant() == "default")
{
NadekoBot.Localization.RemoveGuildCulture(Context.Guild);
NadekoBot.Localization.ResetDefaultCulture();
}
ci = new CultureInfo(name);
NadekoBot.Localization.SetGuildCulture(Context.Guild, ci);
NadekoBot.Localization.SetDefaultCulture(ci);
await Context.Channel.SendConfirmAsync($"Your guild's locale is now {ci}.").ConfigureAwait(false);
}

View File

@ -6755,6 +6755,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to setdefaultlocale sdl.
/// </summary>
public static string setdefaultlocale_cmd {
get {
return ResourceManager.GetString("setdefaultlocale_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sets the bot&apos;s default locale. All servers which use a default locale will use this one. Setting to `default` will use the host&apos;s current culture..
/// </summary>
public static string setdefaultlocale_desc {
get {
return ResourceManager.GetString("setdefaultlocale_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}sdl en-US` or `{0}sdl default`.
/// </summary>
public static string setdefaultlocale_usage {
get {
return ResourceManager.GetString("setdefaultlocale_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to setgame.
/// </summary>
@ -6782,6 +6809,33 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to setlocale sl.
/// </summary>
public static string setlocale_cmd {
get {
return ResourceManager.GetString("setlocale_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Sets this server&apos;s response locale (language). If bot&apos;s response strings have been translated to that language, bot will use that language in this server. Reset by using `default` as the locale name..
/// </summary>
public static string setlocale_desc {
get {
return ResourceManager.GetString("setlocale_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{}sl de-DE ` or `{0}sl default`.
/// </summary>
public static string setlocale_usage {
get {
return ResourceManager.GetString("setlocale_usage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to setmaxplaytime smp.
/// </summary>

View File

@ -3105,4 +3105,22 @@
<data name="timezone_usage" xml:space="preserve">
<value>`{0}timezone`</value>
</data>
<data name="setdefaultlocale_cmd" xml:space="preserve">
<value>setdefaultlocale sdl</value>
</data>
<data name="setdefaultlocale_desc" xml:space="preserve">
<value>Sets the bot's default locale. All servers which use a default locale will use this one. Setting to `default` will use the host's current culture.</value>
</data>
<data name="setdefaultlocale_usage" xml:space="preserve">
<value>`{0}sdl en-US` or `{0}sdl default`</value>
</data>
<data name="setlocale_cmd" xml:space="preserve">
<value>setlocale sl</value>
</data>
<data name="setlocale_desc" xml:space="preserve">
<value>Sets this server's response locale (language). If bot's response strings have been translated to that language, bot will use that language in this server. Reset by using `default` as the locale name.</value>
</data>
<data name="setlocale_usage" xml:space="preserve">
<value>`{}sl de-DE ` or `{0}sl default`</value>
</data>
</root>

View File

@ -14,6 +14,7 @@ namespace NadekoBot.Services
public class Localization
{
public ConcurrentDictionary<ulong, CultureInfo> GuildCultureInfos { get; }
public CultureInfo DefaultCultureInfo { get; private set; } = CultureInfo.CurrentCulture;
private Localization() { }
public Localization(IDictionary<ulong, string> cultureInfoNames)
@ -68,11 +69,19 @@ namespace NadekoBot.Services
}
}
internal void SetDefaultCulture(CultureInfo ci)
{
DefaultCultureInfo = ci;
}
public void ResetDefaultCulture()
{
DefaultCultureInfo = CultureInfo.CurrentCulture;
}
public CultureInfo GetCultureInfo(IGuild guild) =>
GetCultureInfo(guild.Id);
public CultureInfo DefaultCultureInfo { get; } = CultureInfo.CurrentCulture;
public CultureInfo GetCultureInfo(ulong guildId)
{
CultureInfo info = null;