Răsfoiți Sursa

#874 renaming and documentation

Falko Schindler 2 ani în urmă
părinte
comite
49c104175b
6 a modificat fișierele cu 14 adăugiri și 11 ștergeri
  1. 1 1
      nicegui/client.py
  2. 1 1
      nicegui/globals.py
  3. 5 4
      nicegui/page.py
  4. 3 2
      nicegui/run.py
  5. 2 0
      nicegui/run_with.py
  6. 2 3
      nicegui/templates/index.html

+ 1 - 1
nicegui/client.py

@@ -84,7 +84,7 @@ class Client:
             'viewport': self.page.resolve_viewport(),
             'favicon_url': get_favicon_url(self.page, prefix),
             'dark': str(self.page.resolve_dark()),
-            'lang': self.page.resolve_lang(),
+            'language': self.page.resolve_language(),
             'prefix': prefix,
             'tailwind': globals.tailwind,
             'socket_io_js_extra_headers': globals.socket_io_js_extra_headers,

+ 1 - 1
nicegui/globals.py

@@ -36,7 +36,7 @@ title: str
 viewport: str
 favicon: Optional[str]
 dark: Optional[bool]
-lang: Optional[str]
+language: str
 binding_refresh_interval: float
 excludes: List[str]
 tailwind: bool

+ 5 - 4
nicegui/page.py

@@ -18,7 +18,7 @@ class page:
                  viewport: Optional[str] = None,
                  favicon: Optional[str] = None,
                  dark: Optional[bool] = ...,
-                 lang: Optional[str] = 'en-US',
+                 language: str = ...,
                  response_timeout: float = 3.0,
                  **kwargs,
                  ) -> None:
@@ -34,6 +34,7 @@ class page:
         :param viewport: optional viewport meta tag content
         :param favicon: optional relative filepath or absolute URL to a favicon (default: `None`, NiceGUI icon will be used)
         :param dark: whether to use Quasar's dark mode (defaults to `dark` argument of `run` command)
+        :param language: language of the page (defaults to `language` argument of `run` command)
         :param response_timeout: maximum time for the decorated function to build the page (default: 3.0)
         :param kwargs: additional keyword arguments passed to FastAPI's @app.get method
         """
@@ -42,7 +43,7 @@ class page:
         self.viewport = viewport
         self.favicon = favicon
         self.dark = dark
-        self.lang = lang
+        self.language = language
         self.response_timeout = response_timeout
         self.kwargs = kwargs
 
@@ -57,8 +58,8 @@ class page:
     def resolve_dark(self) -> Optional[bool]:
         return self.dark if self.dark is not ... else globals.dark
 
-    def resolve_lang(self) -> Optional[str]:
-        return self.lang if self.lang != 'en-US' else globals.lang
+    def resolve_language(self) -> Optional[str]:
+        return self.language if self.language is not ... else globals.language
 
     def __call__(self, func: Callable) -> Callable:
         globals.app.remove_route(self.path)  # NOTE make sure only the latest route definition is used

+ 3 - 2
nicegui/run.py

@@ -19,7 +19,7 @@ def run(*,
         viewport: str = 'width=device-width, initial-scale=1',
         favicon: Optional[str] = None,
         dark: Optional[bool] = False,
-        lang: Optional[str] = 'en-US',
+        language: str = 'en-US',
         binding_refresh_interval: float = 0.1,
         show: bool = True,
         native: bool = False,
@@ -44,6 +44,7 @@ def run(*,
     :param viewport: page meta viewport content (default: `'width=device-width, initial-scale=1'`, can be overwritten per page)
     :param favicon: relative filepath, absolute URL to a favicon (default: `None`, NiceGUI icon will be used) or emoji (e.g. `'🚀'`, works for most browsers)
     :param dark: whether to use Quasar's dark mode (default: `False`, use `None` for "auto" mode)
+    :param language: language for Quasar elements (default: `'en-US'`)
     :param binding_refresh_interval: time between binding updates (default: `0.1` seconds, bigger is more CPU friendly)
     :param show: automatically open the UI in a browser tab (default: `True`)
     :param native: open the UI in a native window of size 800x600 (default: `False`, deactivates `show`, automatically finds an open port)
@@ -65,7 +66,7 @@ def run(*,
     globals.viewport = viewport
     globals.favicon = favicon
     globals.dark = dark
-    globals.lang = lang
+    globals.language = language
     globals.binding_refresh_interval = binding_refresh_interval
     globals.excludes = [e.strip() for e in exclude.split(',')]
     globals.tailwind = tailwind

+ 2 - 0
nicegui/run_with.py

@@ -12,6 +12,7 @@ def run_with(
     viewport: str = 'width=device-width, initial-scale=1',
     favicon: Optional[str] = None,
     dark: Optional[bool] = False,
+    language: str = 'en-US',
     binding_refresh_interval: float = 0.1,
     exclude: str = '',
     mount_path: str = '/',
@@ -21,6 +22,7 @@ def run_with(
     globals.viewport = viewport
     globals.favicon = favicon
     globals.dark = dark
+    globals.language = language
     globals.binding_refresh_interval = binding_refresh_interval
     globals.excludes = [e.strip() for e in exclude.split(',')]
     globals.tailwind = True

+ 2 - 3
nicegui/templates/index.html

@@ -15,7 +15,7 @@
   <body>
     <script src="{{ prefix | safe }}/_nicegui/{{version}}/static/vue.global.prod.js"></script>
     <script src="{{ prefix | safe }}/_nicegui/{{version}}/static/quasar.umd.prod.js"></script>
-    <script src="https://cdn.jsdelivr.net/npm/quasar@2/dist/lang/{{lang}}.umd.prod.js"></script>
+    <script src="https://cdn.jsdelivr.net/npm/quasar@2/dist/lang/{{ language }}.umd.prod.js"></script>
 
     {{ body_html | safe }}
 
@@ -187,8 +187,7 @@
         }
       });
 
-      var lang = "{{ lang }}";
-      Quasar.lang.set(Quasar.lang[lang]);
+      Quasar.lang.set(Quasar.lang["{{ language }}"]);
 
       {{ vue_scripts | safe }}
       {{ js_imports | safe }}