-
Notifications
You must be signed in to change notification settings - Fork 18
Add i18n support & general improvements #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c73f345
Add i18n support and translations for togglebutton
douden 1124fef
Include translation files in package data
douden f4f9e43
Sync toggle button hints with external state changes
douden 7af7c7b
Preserve existing IDs for admonition toggle items
douden 2038552
Refactor sphinx_togglebutton/__init__.py for readability
douden 1bf80c9
Refactor formatting in setup.py and _convert.py
douden 935deac
Reorder imports for consistency and PEP8 compliance
douden 3df379c
Refactor formatting and remove unused import
douden 599c46b
Add i18n support and document toggle button languages
douden ae85df8
Specify Sphinx configuration path in readthedocs.yml
douden dcf1351
Update changelog with details on toggle hint functions
douden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ coverage.xml | |
| .pytest_cache/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
| # *.mo | ||
| *.pot | ||
|
|
||
| # Django stuff: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| graft doc/ | ||
|
|
||
| recursive-include sphinx_togglebutton *.js | ||
| recursive-include sphinx_togglebutton *.css | ||
|
|
||
| recursive-include sphinx_togglebutton *.json | ||
| recursive-include sphinx_togglebutton *.mo | ||
| recursive-include sphinx_togglebutton *.po | ||
| recursive-include sphinx_togglebutton *.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| JSONs created using GitHub Copilot Pro. | ||
|
|
||
| To convert to locale files run `_convert.py` in this folder. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import json | ||
| import os | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| MESSAGE_CATALOG_NAME = "togglebutton" | ||
|
|
||
|
|
||
| def convert_json(folder=None): | ||
| folder = folder or Path(__file__).parent | ||
|
|
||
| # remove exising | ||
| for path in (folder / "locales").glob(f"**/{MESSAGE_CATALOG_NAME}.po"): | ||
| path.unlink() | ||
|
|
||
| # compile po | ||
| for path in (folder / "jsons").glob("*.json"): | ||
| data = json.loads(path.read_text("utf8")) | ||
| assert data[0]["symbol"] == "en" | ||
| english = data[0]["text"] | ||
| for item in data[1:]: | ||
| language = item["symbol"] | ||
| out_path = ( | ||
| folder | ||
| / "locales" | ||
| / language | ||
| / "LC_MESSAGES" | ||
| / f"{MESSAGE_CATALOG_NAME}.po" | ||
| ) | ||
| if not out_path.parent.exists(): | ||
| out_path.parent.mkdir(parents=True) | ||
| if not out_path.exists(): | ||
| header = f""" | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Sphinx-ToggleButton\\n" | ||
| "MIME-Version: 1.0\\n" | ||
| "Content-Type: text/plain; charset=UTF-8\\n" | ||
| "Content-Transfer-Encoding: 8bit\\n" | ||
| "Language: {language}\\n" | ||
| "Plural-Forms: nplurals=2; plural=(n != 1);\\n" | ||
| """ | ||
| out_path.write_text(header) | ||
|
|
||
| with out_path.open("a", encoding="utf8") as f: | ||
| f.write("\n") | ||
| f.write(f'msgid "{english}"\n') | ||
| text = item["text"].replace('"', '\\"') | ||
| f.write(f'msgstr "{text}"\n') | ||
|
|
||
| # compile mo | ||
| for path in (folder / "locales").glob(f"**/{MESSAGE_CATALOG_NAME}.po"): | ||
| print(path) | ||
| subprocess.check_call( | ||
| [ | ||
| "msgfmt", | ||
| os.path.abspath(path), | ||
| "-o", | ||
| os.path.abspath(path.parent / f"{MESSAGE_CATALOG_NAME}.mo"), | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| convert_json() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.