Browse Source

fix typing for supported language codes

Falko Schindler 2 months ago
parent
commit
eec322b85b
4 changed files with 21 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 12 0
      fetch_languages.py
  3. 7 0
      nicegui/language.py
  4. 1 1
      nicegui/page.py

+ 1 - 0
.gitattributes

@@ -11,6 +11,7 @@ nicegui/static/quasar.*            linguist-vendored
 nicegui/static/socket.*            linguist-vendored
 nicegui/static/tailwindcss.*       linguist-vendored
 nicegui/static/vue.*               linguist-vendored
+nicegui/language.py                linguist-generated
 website/**                         linguist-documentation
 website/static/fuse.js@*           linguist-vendored
 examples/**                        linguist-documentation

+ 12 - 0
fetch_languages.py

@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+from pathlib import Path
+
+codes = sorted(path.name.split('.')[0] for path in Path('nicegui/static/lang').glob('*.umd.prod.js'))
+
+with (Path(__file__).parent / 'nicegui' / 'language.py').open('w') as f:
+    f.write('from typing import Literal\n')
+    f.write('\n')
+    f.write('Language = Literal[\n')
+    for code in codes:
+        f.write(f"    '{code}',\n")
+    f.write(']\n')

+ 7 - 0
nicegui/language.py

@@ -6,10 +6,13 @@ Language = Literal[
     'az-Latn',
     'bg',
     'bn',
+    'bs-BA',
     'ca',
     'cs',
     'da',
     'de',
+    'de-CH',
+    'de-DE',
     'el',
     'en-GB',
     'en-US',
@@ -23,6 +26,7 @@ Language = Literal[
     'fr',
     'gn',
     'he',
+    'hi',
     'hr',
     'hu',
     'id',
@@ -36,9 +40,11 @@ Language = Literal[
     'lt',
     'lu',
     'lv',
+    'mk',
     'ml',
     'mm',
     'ms',
+    'ms-MY',
     'my',
     'nb-NO',
     'nl',
@@ -55,6 +61,7 @@ Language = Literal[
     'sv',
     'ta',
     'th',
+    'tl',
     'tr',
     'ug',
     'uk',

+ 1 - 1
nicegui/page.py

@@ -90,7 +90,7 @@ class page:
         """Return whether the page should use dark mode."""
         return self.dark if self.dark is not ... else core.app.config.dark
 
-    def resolve_language(self) -> Optional[str]:
+    def resolve_language(self) -> Language:
         """Return the language of the page."""
         return self.language if self.language is not ... else core.app.config.language