瀏覽代碼

fix typing for supported language codes

Falko Schindler 2 月之前
父節點
當前提交
eec322b85b
共有 4 個文件被更改,包括 21 次插入1 次删除
  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/socket.*            linguist-vendored
 nicegui/static/tailwindcss.*       linguist-vendored
 nicegui/static/tailwindcss.*       linguist-vendored
 nicegui/static/vue.*               linguist-vendored
 nicegui/static/vue.*               linguist-vendored
+nicegui/language.py                linguist-generated
 website/**                         linguist-documentation
 website/**                         linguist-documentation
 website/static/fuse.js@*           linguist-vendored
 website/static/fuse.js@*           linguist-vendored
 examples/**                        linguist-documentation
 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',
     'az-Latn',
     'bg',
     'bg',
     'bn',
     'bn',
+    'bs-BA',
     'ca',
     'ca',
     'cs',
     'cs',
     'da',
     'da',
     'de',
     'de',
+    'de-CH',
+    'de-DE',
     'el',
     'el',
     'en-GB',
     'en-GB',
     'en-US',
     'en-US',
@@ -23,6 +26,7 @@ Language = Literal[
     'fr',
     'fr',
     'gn',
     'gn',
     'he',
     'he',
+    'hi',
     'hr',
     'hr',
     'hu',
     'hu',
     'id',
     'id',
@@ -36,9 +40,11 @@ Language = Literal[
     'lt',
     'lt',
     'lu',
     'lu',
     'lv',
     'lv',
+    'mk',
     'ml',
     'ml',
     'mm',
     'mm',
     'ms',
     'ms',
+    'ms-MY',
     'my',
     'my',
     'nb-NO',
     'nb-NO',
     'nl',
     'nl',
@@ -55,6 +61,7 @@ Language = Literal[
     'sv',
     'sv',
     'ta',
     'ta',
     'th',
     'th',
+    'tl',
     'tr',
     'tr',
     'ug',
     'ug',
     'uk',
     'uk',

+ 1 - 1
nicegui/page.py

@@ -90,7 +90,7 @@ class page:
         """Return whether the page should use dark mode."""
         """Return whether the page should use dark mode."""
         return self.dark if self.dark is not ... else core.app.config.dark
         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 the language of the page."""
         return self.language if self.language is not ... else core.app.config.language
         return self.language if self.language is not ... else core.app.config.language