diff --git a/uber/configspec.ini b/uber/configspec.ini index b5a57ec94..fd6b0405f 100644 --- a/uber/configspec.ini +++ b/uber/configspec.ini @@ -11,7 +11,7 @@ dev_box = boolean(default=True) plugins = string_list(default=list()) # Sets the fallback locale in case a translation can't be found. -default_locale = string(default="en_US") +default_locale = string(default="en-US") # List of directories we should look in for our templates # This list is appended to by plugins, we'll look for a template diff --git a/uber/custom_tags.py b/uber/custom_tags.py index b2746dbce..6ae9be322 100644 --- a/uber/custom_tags.py +++ b/uber/custom_tags.py @@ -864,4 +864,4 @@ def javascript_bool(val): @JinjaEnv.jinja_export def l10n(key: str) -> str: - return L10n.translation('en-US').format_value(key) + return L10n.translation(c.DEFAULT_LOCALE).format_value(key) diff --git a/uber/forms/__init__.py b/uber/forms/__init__.py index 1d5e1ac97..ac14b24c5 100644 --- a/uber/forms/__init__.py +++ b/uber/forms/__init__.py @@ -14,6 +14,7 @@ from wtforms.utils import unset_value from wtforms.validators import StopValidation, ValidationError +from uber.config import c from uber.forms.widgets import ( DateMaskInput, IntSelect, MultiCheckbox, Ranking, SelectButtonGroup, SwitchInput, UniqueList @@ -531,7 +532,7 @@ def wrap_formdata(self, form, formdata): return super().wrap_formdata(form, formdata) def get_translations(self, _): - return L10n.gettext('en-US') + return L10n.gettext(c.DEFAULT_LOCALE) class AddressForm(MagForm): diff --git a/uber/l10n.py b/uber/l10n.py index a423fc6fa..194d82ddb 100644 --- a/uber/l10n.py +++ b/uber/l10n.py @@ -1,7 +1,6 @@ from fluent.runtime import FluentLocalization, FluentResourceLoader from itertools import chain from os import listdir -from pathlib import PurePath from typing import ClassVar from uber.config import c @@ -32,17 +31,13 @@ def load_l10ns(cls, plugin_dir: str) -> None: cls.__loader = FluentResourceLoader([ f'{dir}/{{locale}}' for dir in cls.__plugin_dirs ]) - plugin_locales = [ - filter(lambda file: not PurePath(file).suffix, listdir(dir)) - for dir in cls.__plugin_dirs - ] cls.__translations = { locale: FluentLocalization( [locale] + ([c.DEFAULT_LOCALE] if locale != c.DEFAULT_LOCALE else []), ['main.ftl'], cls.__loader ) - for locale in set(chain(*plugin_locales)) + for locale in set(chain(*map(listdir, cls.__plugin_dirs))) } cls.__gettext = { key: FluentGettext(value) diff --git a/uber/l10n/.gitkeep b/uber/l10n/en-US/.gitkeep similarity index 100% rename from uber/l10n/.gitkeep rename to uber/l10n/en-US/.gitkeep