Skip to content

Commit 98bdebf

Browse files
committed
Update fluent anvil version
1 parent f9cb42b commit 98bdebf

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

app/anvil.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- source: /runtime/services/tables.yml
1010
client_config: {enable_v2: true}
1111
server_config: {}
12-
startup: {type: form, module: _test_validator}
12+
startup: {type: form, module: _test_display_names}
1313
package_name: fluent_anvil
1414
allow_embedding: false
1515
name: fluent_anvil

app/client_code/_test_display_names/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def __init__(self, **properties):
1717
# Set Form properties and Data Bindings.
1818
self.init_components(**properties)
1919

20-
fluent.configure(["de-AT"], "test_localization/{locale}/main.ftl")
20+
fluent.configure(["en-US"], "test_localization/{locale}/main.ftl")
21+
print(fluent.get_currency_name("ISK"))
2122

2223
self.assertEqual(fluent.get_locale_name("de-DE", fluent.STYLE_STANDARD_LONG), "Deutsch (Deutschland)")
2324
self.assertEqual(fluent.get_locale_name("de-AT", fluent.STYLE_STANDARD_LONG), "Deutsch (Österreich)")

app/client_code/fluent.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,6 @@ def _get_display_name(self, code: list, typename: str, style: tuple):
356356
return names[0] if isinstance(code, str) else names
357357

358358
def _get_options(self, displaytype:str, typename: str, style = STYLE_DIALECT_LONG, translatable_only: bool = True) -> dict:
359-
"""Return the options available for the given type.
360-
361-
Args:
362-
displaytype: The type ("language", "region", "currency") to translate the
363-
options to.
364-
typename: The type of entry in the database to load.
365-
style: Style constant. Can be one of the following:
366-
STYLE_DIALECT_LONG, STYLE_DIALECT_SHORT, STYLE_DIALECT_NARROW,
367-
STYLE_STANDARD_LONG, STYLE_STANDARD_SHORT, STYLE_STANDARD_NARROW.
368-
translatable_only: If True, only the entries that the user's browser was
369-
able to translate will be returned. If False, untranslatable entries
370-
will show up in English.
371-
"""
372359
registry = LocalSubtagRegistry(True).get_tags(typename)
373360
tags = list(registry.keys()) if isinstance(registry, dict) else registry
374361
transl = self._get_display_name(tags, displaytype, style)
@@ -467,7 +454,22 @@ def get_language_options(self, style = STYLE_DIALECT_LONG, translatable_only: bo
467454
return self._get_options("language", "language", style, translatable_only)
468455

469456
def get_script_options(self, style = STYLE_DIALECT_LONG, translatable_only: bool = False) -> dict:
470-
"""Return all known script subtags and their translations as dictionary.
457+
"""Return the translated name of the given script(s).
458+
459+
The name of the given script code is returned in the language fluent has
460+
been configured for.
461+
462+
Args:
463+
code: The script code (e.g. "Arab", "Latn", etc.) or list of
464+
script codes to get the translated name for.
465+
style: Style constant. Can be one of the following:
466+
STYLE_DIALECT_LONG, STYLE_DIALECT_SHORT, STYLE_DIALECT_NARROW,
467+
STYLE_STANDARD_LONG, STYLE_STANDARD_SHORT, STYLE_STANDARD_NARROW.
468+
"""
469+
return self._get_options("script", "script", style, translatable_only)
470+
471+
def get_locale_options(self, style = STYLE_DIALECT_LONG, translatable_only: bool = False) -> dict:
472+
"""Return common locales from CLDR and their translations as dictionary.
471473
472474
style: Style constant to determine the style of the translation. Can be one of
473475
the following: STYLE_DIALECT_LONG, STYLE_DIALECT_SHORT,
@@ -477,10 +479,10 @@ def get_script_options(self, style = STYLE_DIALECT_LONG, translatable_only: bool
477479
able to translate will be returned. If False, untranslatable entries
478480
will show up in English.
479481
"""
480-
return self._get_options("script", "script", style, translatable_only)
482+
return self._get_options("language", "locale", style, translatable_only)
481483

482-
def get_locale_options(self, style = STYLE_DIALECT_LONG, translatable_only: bool = False) -> dict:
483-
"""Return common locales from CLDR and their translations as dictionary.
484+
def get_currency_options(self, style = STYLE_DIALECT_LONG, translatable_only: bool = False) -> dict:
485+
"""Return common currencies from CLDR and their translations as dictionary.
484486
485487
style: Style constant to determine the style of the translation. Can be one of
486488
the following: STYLE_DIALECT_LONG, STYLE_DIALECT_SHORT,
@@ -490,6 +492,10 @@ def get_locale_options(self, style = STYLE_DIALECT_LONG, translatable_only: bool
490492
able to translate will be returned. If False, untranslatable entries
491493
will show up in English.
492494
"""
493-
return self._get_options("language", "locale", style, translatable_only)
495+
return self._get_options("currency", "currency", style, translatable_only)
496+
497+
498+
499+
494500

495501
fluent = __Fluent(None, "localization/{locale}/main.ftl")

app/server_code/update_tag_registry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def task_update_subtag_registry():
5151
translated = {key: cldr.format(key) for key in locales}
5252
translated = {k: v for k,v in translated.items() if v is not None}
5353
local_reg.update_or_create("locale", translated, updated_on)
54+
55+
56+
## Update currency registry
57+
CURRENCY_FILE = "cldr-json/cldr-numbers-full/main/en/currencies.json"
58+
file = CLDRFile(CURRENCY_FILE)
59+
currencies = file.drill("main", "en", "numbers", "currencies")
60+
currencies = {k: v.get("displayName", None) for k, v in currencies.items()}
61+
local_reg.update_or_create("currency", currencies, updated_on)
5462

5563
@anvil.server.callable
5664
def launch_registry_update():

app/theme/assets/fluent_subtag_registry.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)