fix(babel): Standardise locale format.
This commit is contained in:
@@ -11,7 +11,7 @@ from discord.enums import Locale
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SOURCE_LOCALE = 'en-GB'
|
SOURCE_LOCALE = 'en_GB'
|
||||||
ctx_locale: ContextVar[str] = ContextVar('locale', default=SOURCE_LOCALE)
|
ctx_locale: ContextVar[str] = ContextVar('locale', default=SOURCE_LOCALE)
|
||||||
ctx_translator: ContextVar['LeoBabel'] = ContextVar('translator', default=None) # type: ignore
|
ctx_translator: ContextVar['LeoBabel'] = ContextVar('translator', default=None) # type: ignore
|
||||||
|
|
||||||
@@ -71,6 +71,7 @@ class LeoBabel(Translator):
|
|||||||
self.translators.clear()
|
self.translators.clear()
|
||||||
|
|
||||||
def get_translator(self, locale, domain):
|
def get_translator(self, locale, domain):
|
||||||
|
locale = locale.replace('-', '_') if locale else None
|
||||||
if locale == SOURCE_LOCALE:
|
if locale == SOURCE_LOCALE:
|
||||||
translator = null
|
translator = null
|
||||||
elif locale in self.supported_locales and domain in self.supported_domains:
|
elif locale in self.supported_locales and domain in self.supported_domains:
|
||||||
@@ -93,7 +94,8 @@ class LeoBabel(Translator):
|
|||||||
return lazystr._translate_with(translator)
|
return lazystr._translate_with(translator)
|
||||||
|
|
||||||
async def translate(self, string: locale_str, locale: Locale, context):
|
async def translate(self, string: locale_str, locale: Locale, context):
|
||||||
if locale.value in self.supported_locales:
|
loc = locale.value.replace('-', '_')
|
||||||
|
if loc in self.supported_locales:
|
||||||
domain = string.extras.get('domain', None)
|
domain = string.extras.get('domain', None)
|
||||||
if domain is None and isinstance(string, LazyStr):
|
if domain is None and isinstance(string, LazyStr):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@@ -101,7 +103,7 @@ class LeoBabel(Translator):
|
|||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
translator = self.get_translator(locale.value, domain)
|
translator = self.get_translator(loc, domain)
|
||||||
if not isinstance(string, LazyStr):
|
if not isinstance(string, LazyStr):
|
||||||
lazy = LazyStr(Method.GETTEXT, string.message)
|
lazy = LazyStr(Method.GETTEXT, string.message)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user