streamlit-gettext 0.0.1__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,44 @@
1
+ Metadata-Version: 2.1
2
+ Name: streamlit-gettext
3
+ Version: 0.0.1
4
+ Summary: A Streamlit extension for easy localization of your apps
5
+ Author-email: insolor <insolor@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 insolor
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: homepage, https://github.com/insolor/streamlit-gettext
29
+ Project-URL: repository, https://github.com/insolor/streamlit-gettext
30
+ Keywords: streamlit,gettext,i18n
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
37
+ Requires-Python: >=3.9
38
+ Description-Content-Type: text/markdown
39
+ License-File: LICENSE
40
+ Requires-Dist: streamlit<2.0.0,>=1.37.0
41
+
42
+ # streamlit-gettext
43
+
44
+ A Streamlit extension for easy localization of your apps.
@@ -0,0 +1,3 @@
1
+ # streamlit-gettext
2
+
3
+ A Streamlit extension for easy localization of your apps.
@@ -0,0 +1,41 @@
1
+ [project]
2
+ name = "streamlit-gettext"
3
+ version = "0.0.1"
4
+ description = "A Streamlit extension for easy localization of your apps"
5
+ authors = [{name = "insolor", email = "insolor@gmail.com"}]
6
+ readme = "README.md"
7
+ license = { file = "LICENSE" }
8
+ keywords = ["streamlit", "gettext", "i18n"]
9
+ classifiers = [
10
+ "License :: OSI Approved :: MIT License",
11
+ "Development Status :: 3 - Alpha",
12
+ "Operating System :: OS Independent",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Intended Audience :: Developers",
15
+ "Topic :: Software Development :: Libraries :: Python Modules",
16
+ ]
17
+ requires-python = ">=3.9"
18
+ dependencies = [
19
+ "streamlit>=1.37.0,<2.0.0",
20
+ ]
21
+
22
+ [project.urls]
23
+ homepage = "https://github.com/insolor/streamlit-gettext"
24
+ repository = "https://github.com/insolor/streamlit-gettext"
25
+ # documentation = "https://github.com/insolor/streamlit-gettext"
26
+
27
+ [dependency-groups]
28
+ dev = [
29
+ "pytest>=8.3.4",
30
+ "ruff>=0.8.2",
31
+ ]
32
+
33
+ [tool.ruff]
34
+ target-version = "py39"
35
+ line-length = 120
36
+
37
+ [tool.ruff.lint]
38
+ select = ["ALL"]
39
+ ignore = [
40
+ "D",
41
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,44 @@
1
+ Metadata-Version: 2.1
2
+ Name: streamlit-gettext
3
+ Version: 0.0.1
4
+ Summary: A Streamlit extension for easy localization of your apps
5
+ Author-email: insolor <insolor@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 insolor
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: homepage, https://github.com/insolor/streamlit-gettext
29
+ Project-URL: repository, https://github.com/insolor/streamlit-gettext
30
+ Keywords: streamlit,gettext,i18n
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Development Status :: 3 - Alpha
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
37
+ Requires-Python: >=3.9
38
+ Description-Content-Type: text/markdown
39
+ License-File: LICENSE
40
+ Requires-Dist: streamlit<2.0.0,>=1.37.0
41
+
42
+ # streamlit-gettext
43
+
44
+ A Streamlit extension for easy localization of your apps.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ streamlit_gettext.py
5
+ streamlit_gettext.egg-info/PKG-INFO
6
+ streamlit_gettext.egg-info/SOURCES.txt
7
+ streamlit_gettext.egg-info/dependency_links.txt
8
+ streamlit_gettext.egg-info/requires.txt
9
+ streamlit_gettext.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ streamlit<2.0.0,>=1.37.0
@@ -0,0 +1 @@
1
+ streamlit_gettext
@@ -0,0 +1,42 @@
1
+ import gettext as gettext_module
2
+ import re
3
+ from functools import lru_cache
4
+ from pathlib import Path
5
+
6
+ import streamlit as st
7
+
8
+
9
+ def get_preferred_languages() -> list[str]:
10
+ accept_language = st.context.headers.get("Accept-Language") or ""
11
+ return re.findall(r"([a-zA-Z-]{2,})", accept_language) or []
12
+
13
+
14
+ @lru_cache(maxsize=128, typed=False)
15
+ def _get_lang(languages: tuple[str]) -> gettext_module.NullTranslations:
16
+ locale_dir = Path(__file__).parent / "locale"
17
+
18
+ return gettext_module.translation(
19
+ "messages",
20
+ localedir=locale_dir,
21
+ languages=languages,
22
+ fallback=True,
23
+ )
24
+
25
+
26
+ class LanguageWrapper:
27
+ @staticmethod
28
+ def _get_lang() -> gettext_module.NullTranslations:
29
+ return _get_lang(tuple(get_preferred_languages()))
30
+
31
+ def gettext(self, message: str) -> str:
32
+ lang = self._get_lang()
33
+ return lang.gettext(message)
34
+
35
+ def ngettext(self, singular: str, plural: str, n: int) -> str:
36
+ lang = self._get_lang()
37
+ return lang.ngettext(singular, plural, n)
38
+
39
+
40
+ lang = LanguageWrapper()
41
+ gettext = lang.gettext
42
+ ngettext = lang.ngettext