rewrite: Setting input strings and localisation.
This commit is contained in:
@@ -136,7 +136,7 @@ class BabelCog(LionCog):
|
||||
if language:
|
||||
lang_data = await lang_setting._parse_string(ctx.guild.id, language)
|
||||
if force_language is not None:
|
||||
force_data = bool(force_language)
|
||||
force_data = bool(force_language.value)
|
||||
|
||||
if force_language is not None and not (lang_data if language is not None else lang_setting.value):
|
||||
# Setting force without having a language!
|
||||
@@ -204,12 +204,8 @@ class BabelCog(LionCog):
|
||||
new_data = await setting._parse_string(ctx.author.id, language)
|
||||
await setting.interactive_set(new_data, ctx.interaction, ephemeral=True)
|
||||
else:
|
||||
embed = setting.embed
|
||||
if setting.value:
|
||||
desc = t(_p(
|
||||
'cmd:userconfig_language|response:set',
|
||||
"Your preferred language is currently set to {language}"
|
||||
)).format(language=setting.formatted)
|
||||
|
||||
@AButton(
|
||||
label=t(_p('cmd:userconfig_language|button:reset|label', "Reset")),
|
||||
style=ButtonStyle.red
|
||||
@@ -220,15 +216,7 @@ class BabelCog(LionCog):
|
||||
|
||||
view = AsComponents(reset_button)
|
||||
else:
|
||||
desc = t(_p(
|
||||
'cmd:userconfig_language|response:unset',
|
||||
"You have not set a preferred language!"
|
||||
))
|
||||
view = None
|
||||
embed = discord.Embed(
|
||||
colour=discord.Colour.orange(),
|
||||
description=desc
|
||||
)
|
||||
await ctx.reply(embed=embed, ephemeral=True, view=view)
|
||||
|
||||
@userconfig_language_cmd.autocomplete('language')
|
||||
|
||||
@@ -4,6 +4,7 @@ from settings.setting_types import StringSetting, BoolSetting
|
||||
from settings.groups import SettingGroup
|
||||
|
||||
from meta.errors import UserInputError
|
||||
from meta.context import ctx_bot
|
||||
from core.data import CoreData
|
||||
|
||||
from .translator import ctx_translator
|
||||
@@ -17,11 +18,30 @@ class LocaleSetting(StringSetting):
|
||||
"""
|
||||
Base class describing a LocaleSetting.
|
||||
"""
|
||||
_accepts = _p(
|
||||
'settype:locale|accepts',
|
||||
"Enter a supported language (e.g. 'en-GB')."
|
||||
)
|
||||
|
||||
def _desc_table(self) -> list[str]:
|
||||
translator = ctx_translator.get()
|
||||
t = translator.t
|
||||
|
||||
lines = super()._desc_table()
|
||||
lines.append((
|
||||
t(_p(
|
||||
'settype:locale|summary_table|field:supported|key',
|
||||
"Supported"
|
||||
)),
|
||||
', '.join(f"`{locale}`" for locale in translator.supported_locales)
|
||||
))
|
||||
return lines
|
||||
|
||||
@classmethod
|
||||
def _format_data(cls, parent_id, data, **kwargs):
|
||||
t = ctx_translator.get().t
|
||||
if data is None:
|
||||
formatted = t(_p('set_type:locale|formatted:unset', "Unset"))
|
||||
formatted = t(_p('settype:locale|formatted:unset', "Unset"))
|
||||
else:
|
||||
name = locale_names.get(data, None)
|
||||
if name:
|
||||
@@ -37,7 +57,7 @@ class LocaleSetting(StringSetting):
|
||||
lang = string[:20]
|
||||
raise UserInputError(
|
||||
translator.t(
|
||||
_p('set_type:locale|error', "Sorry, we do not support the language `{lang}` at this time!")
|
||||
_p('settype:locale|error', "Sorry, we do not support the language `{lang}` at this time!")
|
||||
).format(lang=lang)
|
||||
)
|
||||
return string
|
||||
@@ -54,6 +74,11 @@ class LocaleSettings(SettingGroup):
|
||||
|
||||
_display_name = _p('userset:locale', 'language')
|
||||
_desc = _p('userset:locale|desc', "Your preferred language for interacting with me.")
|
||||
_long_desc = _p(
|
||||
'userset:locale|long_desc',
|
||||
"The language you would prefer me to respond to commands and interactions in. "
|
||||
"Servers may be configured to override this with their own language."
|
||||
)
|
||||
|
||||
_model = CoreData.User
|
||||
_column = CoreData.User.locale.name
|
||||
@@ -68,6 +93,12 @@ class LocaleSettings(SettingGroup):
|
||||
lang=self.formatted
|
||||
)
|
||||
|
||||
@property
|
||||
def set_str(self):
|
||||
bot = ctx_bot.get()
|
||||
if bot:
|
||||
return bot.core.mention_cmd('my language')
|
||||
|
||||
class ForceLocale(ModelData, BoolSetting):
|
||||
"""
|
||||
Guild configuration for whether to force usage of the guild locale.
|
||||
@@ -108,10 +139,11 @@ class LocaleSettings(SettingGroup):
|
||||
"I will now allow the members to set their own language here."
|
||||
))
|
||||
|
||||
@classmethod
|
||||
def _format_data(cls, parent_id, data, **kwargs):
|
||||
t = ctx_translator.get().t
|
||||
return t(cls._outputs[data])
|
||||
@property
|
||||
def set_str(self):
|
||||
bot = ctx_bot.get()
|
||||
if bot:
|
||||
return bot.core.mention_cmd('configure language')
|
||||
|
||||
class GuildLocale(ModelData, LocaleSetting):
|
||||
"""
|
||||
@@ -142,3 +174,9 @@ class LocaleSettings(SettingGroup):
|
||||
return t(_p('guildset:locale|response', "You have set the guild language to {lang}.")).format(
|
||||
lang=self.formatted
|
||||
)
|
||||
|
||||
@property
|
||||
def set_str(self):
|
||||
bot = ctx_bot.get()
|
||||
if bot:
|
||||
return bot.core.mention_cmd('configure language')
|
||||
|
||||
@@ -80,7 +80,7 @@ class LocaleSettingUI(ConfigUI):
|
||||
class LocaleDashboard(DashboardSection):
|
||||
section_name = _p(
|
||||
'dash:locale|title',
|
||||
"Server Language Configuration"
|
||||
"Server Language Configuration ({commands[configure language]})"
|
||||
)
|
||||
configui = LocaleSettingUI
|
||||
setting_classes = LocaleSettingUI.setting_classes
|
||||
|
||||
Reference in New Issue
Block a user