Skip to content

Commit

Permalink
Merge pull request #215 from wasade/language-docs
Browse files Browse the repository at this point in the history
babel notes and gtranslate
  • Loading branch information
cassidysymons authored Apr 13, 2022
2 parents f64c9e1 + 9b957ec commit d042fb3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/babel.md
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
```
35 changes: 35 additions & 0 deletions naive_translate.py
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()

0 comments on commit d042fb3

Please sign in to comment.