-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from wasade/language-docs
babel notes and gtranslate
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,17 @@ | ||
# To update translation files | ||
|
||
```bash | ||
cd microsetta-interface | ||
pybabel extract -F ../babel.cfg -o translations/base.pot . | ||
pybabel update -i translations/base.pot -d translations | ||
``` | ||
|
||
# To generate naive automatic translations | ||
|
||
GTranslate translations can be generated with the following. These should undergo a sanity check as, in particular, countries may get translated unusually and it will stand out. Automated entries are remarked as fuzzy and will be flagged as such in POEdit. | ||
|
||
The translation script has been tested with polib==1.1.1 and googletrans==3.1.0a0, installable from pypi. | ||
|
||
``` | ||
python naive_translate.py --pofile path/to/the/pofile --locale locale_to_translate_into --output path/to/new/pofile | ||
``` |
This file contains 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,35 @@ | ||
import googletrans | ||
import polib | ||
import click | ||
|
||
|
||
@click.command() | ||
@click.option('--pofile', help='The file to translate', | ||
type=click.Path(exists=True), required=True) | ||
@click.option('--locale', help='The locale to translate into', type=str, | ||
required=True) | ||
@click.option('--output', help='A file to save into (if not specified, ' | ||
'saves inplace)', required=False, type=click.Path(exists=False)) | ||
def trans(pofile, locale, output): | ||
# verify the locale name is in the path of the pofile | ||
assert locale in pofile | ||
pofile = polib.pofile(pofile) | ||
|
||
# example interaction based on https://github.com/Brandon1016/poTranslate (MIT license) | ||
translator = googletrans.Translator() | ||
entries = pofile.untranslated_entries() | ||
entries.extend(pofile.fuzzy_entries()) | ||
for entry in pofile.untranslated_entries(): | ||
print(entry.msgid) | ||
translated = translator.translate(entry.msgid, dest=locale) | ||
entry.msgstr = translated.text | ||
entry.flags.append('fuzzy') | ||
|
||
if output is not None: | ||
pofile.save(output) | ||
else: | ||
pofile.save() | ||
|
||
|
||
if __name__ == '__main__': | ||
trans() |