Skip to content

Commit

Permalink
Remove LocaleHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Vermeulen committed Nov 26, 2024
1 parent 4f2284e commit 84c05c9
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions home/import_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
StructValue, # type: ignore
)
from wagtail.blocks.list_block import ListValue # type: ignore
from wagtail.coreutils import get_content_languages # type: ignore
from wagtail.models import Locale # type: ignore
from wagtail.rich_text import RichText # type: ignore
from wagtail.test.utils.form_data import nested_form_data, streamfield # type: ignore
Expand All @@ -39,40 +38,6 @@ def __init__(
super().__init__()


class LocaleHelper:
"""
Helper class to map language names to locales
"""

def __init__(self) -> None:
self.locale_map: dict[str, Locale] = {}

def locale_from_display_name(self, langname: str) -> Locale:
"""
Get a locale from its display name.
If the locale for the given language name does not exist, an exception is raised.
:param langname: The name of the language.
:return: The locale for the given language.
:raises ImportException: If the language name is not found or has multiple codes.
"""

if langname not in self.locale_map:
codes = []
for lang_code, lang_dn in get_content_languages().items():
if lang_dn == langname:
codes.append(lang_code)
if not codes:
raise ImportException(f"Language not found: {langname}")
if len(codes) > 1:
raise ImportException(
f"Multiple codes for language: {langname} -> {codes}"
)
self.locale_map[langname] = Locale.objects.get(language_code=codes[0])
return self.locale_map[langname]


def wagtail_to_formdata(val: Any) -> Any:
"""
Convert a model dict field that may be a nested streamfield (or associated
Expand Down

0 comments on commit 84c05c9

Please sign in to comment.