streamlit-gettext 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 insolor
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.2
2
+ Name: streamlit-gettext
3
+ Version: 0.0.3
4
+ Summary: A Streamlit extension for easy localization of your apps
5
+ Author-email: insolor <insolor@gmail.com>
6
+ Project-URL: homepage, https://github.com/insolor/streamlit-gettext
7
+ Project-URL: repository, https://github.com/insolor/streamlit-gettext
8
+ Keywords: streamlit,gettext,i18n
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Intended Audience :: Developers
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: streamlit<2.0.0,>=1.37.0
26
+
27
+ # streamlit-gettext
28
+
29
+ [![PyPI](https://img.shields.io/pypi/v/streamlit-gettext)](https://pypi.org/project/streamlit-gettext/)
30
+ ![Supported Python versions](https://img.shields.io/pypi/pyversions/streamlit-gettext)
31
+
32
+ > 🚧 WORK IN PROGRESS 🚧
33
+
34
+ A Streamlit extension for easy localization of your apps. Gets preferred languages from the browser, shows the the translated app to a user (it can be different translations for different users connected to the same app).
35
+
36
+ See a working app with such functionality: <https://github.com/dfint/package-build>
37
+
38
+ TODO:
39
+
40
+ - [x] [example](https://github.com/insolor/streamlit-gettext/blob/main/example)
41
+ - [ ] basic tests
42
+ - [ ] documentation
43
+ - [ ] support of manual switching with default language selected from the browser preferred languages
44
+ - ...
45
+
46
+ Feedback and suggestions are highliy appreciated.
@@ -0,0 +1,20 @@
1
+ # streamlit-gettext
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/streamlit-gettext)](https://pypi.org/project/streamlit-gettext/)
4
+ ![Supported Python versions](https://img.shields.io/pypi/pyversions/streamlit-gettext)
5
+
6
+ > 🚧 WORK IN PROGRESS 🚧
7
+
8
+ A Streamlit extension for easy localization of your apps. Gets preferred languages from the browser, shows the the translated app to a user (it can be different translations for different users connected to the same app).
9
+
10
+ See a working app with such functionality: <https://github.com/dfint/package-build>
11
+
12
+ TODO:
13
+
14
+ - [x] [example](https://github.com/insolor/streamlit-gettext/blob/main/example)
15
+ - [ ] basic tests
16
+ - [ ] documentation
17
+ - [ ] support of manual switching with default language selected from the browser preferred languages
18
+ - ...
19
+
20
+ Feedback and suggestions are highliy appreciated.
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "streamlit-gettext"
3
+ version = "0.0.3"
4
+ description = "A Streamlit extension for easy localization of your apps"
5
+ authors = [{name = "insolor", email = "insolor@gmail.com"}]
6
+ readme = "README.md"
7
+ keywords = ["streamlit", "gettext", "i18n"]
8
+ classifiers = [
9
+ "License :: OSI Approved :: MIT License",
10
+ "Development Status :: 3 - Alpha",
11
+ "Operating System :: OS Independent",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Programming Language :: Python",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.9",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Intended Audience :: Developers",
21
+ "Topic :: Software Development :: Libraries :: Python Modules",
22
+ ]
23
+ requires-python = ">=3.9"
24
+ dependencies = [
25
+ "streamlit>=1.37.0,<2.0.0",
26
+ ]
27
+
28
+ [project.urls]
29
+ homepage = "https://github.com/insolor/streamlit-gettext"
30
+ repository = "https://github.com/insolor/streamlit-gettext"
31
+ # documentation = "https://github.com/insolor/streamlit-gettext"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "pytest>=8.3.4",
36
+ "ruff>=0.8.2",
37
+ ]
38
+
39
+ [tool.ruff]
40
+ target-version = "py39"
41
+ line-length = 120
42
+
43
+ [tool.ruff.lint]
44
+ select = ["ALL"]
45
+ ignore = [
46
+ "D",
47
+ "COM812",
48
+ "ISC001",
49
+ ]
50
+
51
+ [tool.ruff.lint.per-file-ignores]
52
+ "example/*" = [
53
+ "DTZ011",
54
+ "E501",
55
+ "INP001",
56
+ "S311",
57
+ ]
58
+
59
+ [tool.uv.workspace]
60
+ members = ["example"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from .streamlit_gettext import GettextWrapper, get_preferred_languages
2
+
3
+ __all__ = [
4
+ "GettextWrapper",
5
+ "get_preferred_languages",
6
+ ]
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ import gettext as _gettext_module
4
+ import re
5
+ from pathlib import Path
6
+
7
+ import streamlit as st
8
+
9
+
10
+ def get_preferred_languages() -> list[str]:
11
+ accept_language = st.context.headers.get("Accept-Language") or ""
12
+ return re.findall(r"([a-zA-Z-]{2,})", accept_language) or []
13
+
14
+
15
+ class GettextWrapper:
16
+ """
17
+ A wrapper for the gettext module
18
+ """
19
+
20
+ locale_path: Path
21
+
22
+ def __init__(self, locale_path: str | Path) -> None:
23
+ self.locale_path = Path(locale_path)
24
+
25
+ def _translation(self) -> _gettext_module.NullTranslations:
26
+ return _gettext_module.translation(
27
+ "messages",
28
+ localedir=self.locale_path,
29
+ languages=get_preferred_languages(),
30
+ fallback=True,
31
+ )
32
+
33
+ def gettext(self, message: str) -> str:
34
+ translation = self._translation()
35
+ return translation.gettext(message)
36
+
37
+ def ngettext(self, singular: str, plural: str, n: int) -> str:
38
+ translation = self._translation()
39
+ return translation.ngettext(singular, plural, n)
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.2
2
+ Name: streamlit-gettext
3
+ Version: 0.0.3
4
+ Summary: A Streamlit extension for easy localization of your apps
5
+ Author-email: insolor <insolor@gmail.com>
6
+ Project-URL: homepage, https://github.com/insolor/streamlit-gettext
7
+ Project-URL: repository, https://github.com/insolor/streamlit-gettext
8
+ Keywords: streamlit,gettext,i18n
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Intended Audience :: Developers
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: streamlit<2.0.0,>=1.37.0
26
+
27
+ # streamlit-gettext
28
+
29
+ [![PyPI](https://img.shields.io/pypi/v/streamlit-gettext)](https://pypi.org/project/streamlit-gettext/)
30
+ ![Supported Python versions](https://img.shields.io/pypi/pyversions/streamlit-gettext)
31
+
32
+ > 🚧 WORK IN PROGRESS 🚧
33
+
34
+ A Streamlit extension for easy localization of your apps. Gets preferred languages from the browser, shows the the translated app to a user (it can be different translations for different users connected to the same app).
35
+
36
+ See a working app with such functionality: <https://github.com/dfint/package-build>
37
+
38
+ TODO:
39
+
40
+ - [x] [example](https://github.com/insolor/streamlit-gettext/blob/main/example)
41
+ - [ ] basic tests
42
+ - [ ] documentation
43
+ - [ ] support of manual switching with default language selected from the browser preferred languages
44
+ - ...
45
+
46
+ Feedback and suggestions are highliy appreciated.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ streamlit_gettext/__init__.py
5
+ streamlit_gettext/streamlit_gettext.py
6
+ streamlit_gettext.egg-info/PKG-INFO
7
+ streamlit_gettext.egg-info/SOURCES.txt
8
+ streamlit_gettext.egg-info/dependency_links.txt
9
+ streamlit_gettext.egg-info/requires.txt
10
+ streamlit_gettext.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ streamlit<2.0.0,>=1.37.0
@@ -0,0 +1 @@
1
+ streamlit_gettext