Skip to content

Commit 81c5085

Browse files
jacalataCopilotbcantoni
authored
Replace raw strings with translation calls (#286)
* All strings are fetched from *.properties files * clean out unused strings * clarify comment * more global_options settings Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tabcmd/locales/en/tabcmd_messages_en.properties Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tabcmd/commands/datasources_and_workbooks/delete_command.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tabcmd/execution/global_options.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tabcmd_messages_en.properties Add or edit some changed messages * Update global_options.py * Update tabcmd/execution/parent_parser.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tabcmd/execution/parent_parser.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tabcmd/locales/en/tabcmd_messages_en.properties Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * format w black * Add script for double-checking messages found in source code vs properties files * Add a "launching" message which was referenced everywhere * document loc process, fix misreferenced string ids - cleaned up string ids that either added "tabcmd" as a prefix or took it off as a prefix incorrectly - add back some deleted strings - incorporate check_strings into the localization build and pushed some output into a log file - added docs in Contributing.md and i18n/README * format --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Brian Cantoni <bcantoni@salesforce.com>
1 parent 9b227d4 commit 81c5085

17 files changed

Lines changed: 771 additions & 929 deletions

bin/i18n/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
### Strings and localization
3+
4+
New text should not be hardcoded into the python, but added to tabcmd/locales/en/extra.properties. This file can be given to the translation team and they will return a copy for each other language. Until then, the english string will be used as a fallback.
5+
6+
To handle localizing text we used the python standard library tool [gettext](https://docs.python.org/3/library/gettext.html). This expects .mo files. I couldn't find a tool that transformed .properties -> .mo directly so we go through .po format.
7+
(FYI: to read mo files for debugging use https://poedit.net/download)
8+
9+
10+
These steps are separated for easier troubleshooting: each step is idempotent and will overwrite the existing output. More details about implementation are in the script code at dodo.py
11+
12+
1. convert strings from .properties files to .mo for bundling
13+
This step combines the .properties files into a single file, discarding any strings that are not present in code and normalizing curly quotes and unrecognized characters in the strings it keeps. (These files are separate because they are pulled from separate translation sources internally.)
14+
> python -m doit properties
15+
16+
2. Convert the combined .properties file into a .po file (these are human readable)
17+
> python -m doit po
18+
19+
3. Convert the .po files into .mo files (these are not human readable)
20+
This also checks the .mo files for validity by loading them with gettext
21+
> python -m doit mo

bin/i18n/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
i18n utilities for tabcmd localization.
3+
4+
This package contains tools for checking and processing localization strings.
5+
"""
6+
7+
from .check_strings import (
8+
find_python_files,
9+
extract_string_keys_from_file,
10+
load_properties_files,
11+
load_properties_file,
12+
find_missing_strings,
13+
check_build_mode,
14+
check_dev_mode
15+
)
16+
17+
__all__ = [
18+
'find_python_files',
19+
'extract_string_keys_from_file',
20+
'load_properties_files',
21+
'load_properties_file',
22+
'find_missing_strings',
23+
'check_build_mode',
24+
'check_dev_mode'
25+
]

0 commit comments

Comments
 (0)