Skip to content

Commit

Permalink
Pull translations for kano-overworld
Browse files Browse the repository at this point in the history
This needs to be treated as a snowflake since po first need to be
converted into a lua dict and the resulting file needs to be added to
the love archive.

This commit also brings new dependency on polib.
  • Loading branch information
mandre committed May 30, 2019
1 parent 6204c1f commit b91ea3d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ We've created Zanata translation projects for the following apps:

The scripts depend on
[zanata-python-client](https://github.com/zanata/zanata-python-client) to
communicate with the Zanata server. To install this executable on Fedora, run:
communicate with the Zanata server and [polib](https://polib.readthedocs.io/).
To install these packages on Fedora, run:

```
sudo dnf install python3-zanata-client
sudo dnf install python3-zanata-client python3-polib
```

[Create yourself an account on
Expand Down
11 changes: 5 additions & 6 deletions kano-projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@
kano_i18n_package_name: kano-init-i18n-orig
pot_dir: /mnt/translations/translations/kano-init/

# TODO(mandre) Need to convert po files to lua dicts
# - name: kano-overworld
# zanata_project_id: kano-overworld
# zanata_project_type: gettext
# kano_i18n_package_name: kano-overworld-i18n-orig
# pot_dir: /mnt/translations/translations/kano-overworld/
- name: kano-overworld
zanata_project_id: kano-overworld
zanata_project_type: gettext
kano_i18n_package_name: kano-overworld-i18n-orig
pot_dir: /mnt/translations/translations/kano-overworld/

- name: kano-peripherals
zanata_project_id: kano-peripherals
Expand Down
36 changes: 34 additions & 2 deletions pull_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import glob
import os
import paramiko
import polib
import subprocess
import tempfile
import yaml
Expand Down Expand Up @@ -100,6 +101,33 @@ def copy_sudoers_file():
os.path.join("/etc", "sudoers.d", "kano-i18n-sync_conf"))


def generate_lua_dict(project, podir, lang):
print("Generate lua dict for %s" % project['name'])
pofile = os.path.join(podir, "%s.po" % lang)
if not os.path.isfile(pofile):
print("Could not read po file at %s" % pofile)
exit()
po = polib.pofile(pofile)
f = open(os.path.join(podir, "lang.lua"), "w")
f.write("return {\n")
for entry in po:
for occurrence in entry.occurrences:
value = entry.msgstr if entry.translated() else entry.msgid
f.write(" {} = \"{}\",\n".format(occurrence[0],
polib.escape(value)))
f.write("}")
f.close


def copy_kano_overworld_file(project, podir, lang):
# TODO(mandre) Properly get the locale. This will do for now
locale = "{}_{}".format(lang, lang.upper())
ssh.exec_command("mkdir -p res/locales/{}/".format(locale))
scp.put(os.path.join(podir, "lang.lua"),
os.path.join("/home/martin", "res", "locales", locale, "lang.lua"))
ssh.exec_command("sudo zip -9 -r /usr/share/kano-overworld/build/kanoOverworld.love res/")


# This assumes there is a kano host in your ~/.ssh/config with public key
# authentication setup
ssh = paramiko.SSHClient()
Expand All @@ -125,8 +153,12 @@ def copy_sudoers_file():
copy_pot_files(project['pot_dir'], tmpdirname)
pull_po(project, tmpdirname, lang)
if glob.glob(os.path.join(tmpdirname, "*.po")):
build_mo(project, tmpdirname, lang)
copy_mo_file(project, tmpdirname, lang)
if project["name"] == "kano-overworld":
generate_lua_dict(project, tmpdirname, lang)
copy_kano_overworld_file(project, tmpdirname, lang)
else:
build_mo(project, tmpdirname, lang)
copy_mo_file(project, tmpdirname, lang)

scp.close()
ssh.close()
1 change: 1 addition & 0 deletions sudoers.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
%sudo ALL=(root) NOPASSWD: /bin/mv *.mo /usr/share/locale/*
%sudo ALL=(root) NOPASSWD: /usr/bin/zip -9 -r /usr/share/kano-overworld/build/kanoOverworld.love res/
%sudo ALL=NOPASSWD: /usr/bin/apt-get

0 comments on commit b91ea3d

Please sign in to comment.