Skip to content

Commit

Permalink
Integrate config.toml into Weblate
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsisyk committed Dec 23, 2022
1 parent f5ae149 commit 1d6ce8f
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.DS_Store
node_modules
public
translations.yaml
1 change: 1 addition & 0 deletions .po4a.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
[type: markdown] content/privacy/index.md $lang:content/privacy/index.$lang.md
[type: markdown] content/support-us/index.md $lang:content/support-us/index.$lang.md
[type: markdown] content/terms/index.md $lang:content/terms/index.$lang.md
[type: yaml] translations.yaml $lang:/tmp/ignore.yaml
8 changes: 4 additions & 4 deletions TRANSLATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ brew install po4a
### I am a content writer

- Add/edit source **English** Markdown files in the repo.
- Refresh `.pot` and `.po` files when English is changed by running `./i18n.sh`.
- Refresh `.pot` and `.po` files when English is changed by running `./tools/i18n.sh`.
- Push both updated content and refreshed `.pot`/`.po` files in the single PR to GitHub.
- Translation teams will be notified via Weblate when your PR is merged.
- All new strings will be in English until localized (see the next step).
Expand All @@ -69,7 +69,7 @@ brew install po4a
### I am a repository maintainer

- Checkout `weblate-i18n` branch when it is updated by Weblate.
- Run `./i18n.sh` tool to regenerate `.lang.md` files from updated `.po` files.
- Run `./tools/i18n.sh` tool to regenerate `.lang.md` files from updated `.po` files.
- Update `.config.toml` if a new language is added.
- Translate `menu.title` YAML Front Matters key manually, this is a [well-known limitation](https://github.com/mquinson/po4a/issues/392).
- Run `zola server` to check changes locally.
Expand All @@ -79,8 +79,8 @@ brew install po4a

## Known Limitations

- `./i18n.sh` removes line wrapping in `.po` files when a new language is added initially via WebLate.
- New web-site pages should be added to `.po4a.cfg` configuration file manually.
- `./tools/i18n.sh` removes line wrapping in `.po` files when a new language is added initially via WebLate.
- New web-site pages and languages should be added to `.po4a.cfg` configuration file manually.

[po4a]: https://po4a.org/index.php.en
[weblate]: https://hosted.weblate.org/projects/organicmaps/website/
Expand Down
36 changes: 10 additions & 26 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,81 +44,70 @@ contact = "Kontakt"
install-appgallery = "Organic Maps aus der Huawei AppGallery installieren"
install-appstore = "Installiere Organic Maps aus dem AppStore"
install-googleplay = "Organic Maps von Google Play installieren"
install-fdroid="Organic Maps von F-Droid installieren"
install-fdroid = "Organic Maps von F-Droid installieren"
language = "Deutsch"
name = "Name"
token = "Token"

[languages.fr]
[languages.fr.translations]
address = "Adresse"
back = "Retour aux actualités"
contact = "Contact"
donate = "Donner"
home = "Page d'accueil"
install-appgallery = "Installez Organic Maps depuis l'AppGallery"
install-appstore = "Installez Organic Maps depuis l'AppStore"
install-googleplay = "Installez Organic Maps depuis Google Play"
install-fdroid="Installez Organic Maps depuis F-Droid"
install-fdroid = "Installez Organic Maps depuis F-Droid"
language = "Français"
name = "Nom"
news = "Actualités"
support-us = "Contribuer"
token = "Jeton"
terms = "Termes"

[languages.it]
[languages.it.translations]
address = "Indirizzo"
back = "Indietro"
contact = "Contattaci"
install-appgallery = "Installa Organic Maps da Huawei AppGallery"
install-appstore = "Installa Organic Maps dall'AppStore"
install-fdroid="Installa Organic Maps da F-Droid"
install-googleplay = "Installa Organic Maps da Google Play"
install-fdroid = "Installa Organic Maps da F-Droid"
language = "Italiano"
name = "Nome"
token = "Token"

[languages.pl]
[languages.pl.translations]
address = "Adres"
back = "Z powrotem"
contact = "Kontakt"
install-appgallery = "Zainstaluj Organic Maps z Huawei AppGallery"
install-appstore = "Zainstaluj Organic Maps z App Store"
install-fdroid="Zainstaluj Organic Maps z F-Droid"
install-googleplay = "Zainstaluj Organic Maps z Google Play"
name = "Nazwa"
install-fdroid = "Zainstaluj Organic Maps z F-Droid"
language = "Polski"
name = "Nazwa"
token = "Token"

[languages.ru]
[languages.ru.translations]
address = "Адрес"
back = "Назад"
contact = "Связаться с нами"
install-appgallery = "Установить Organic Maps из Huawei AppGallery"
install-appstore = "Установить Organic Maps из Apple AppStore"
install-fdroid="Установить Organic Maps из F-Droid"
install-googleplay = "Установить Organic Maps из Google Play"
install-fdroid = "Установить Organic Maps из F-Droid"
language = "Русский"
name = "Название"
token = "Токен"

[languages.tr]
[languages.tr.translations]
address = "Adres"
back = "Haberlere geri dön"
contact = "Bize ulaşın"
install-appgallery = "Organic Maps'i Huawei AppGallery'den İndir"
install-appstore = "Organic Maps'i AppStore'dan İndir"
install-fdroid="Organic Maps'i F-Droid'den İndir"
install-googleplay = "Organic Maps'i Google Play'den İndir"
install-fdroid = "Organic Maps'i F-Droid'den İndir"
language = "Türkçe"
name = "İsim"
token = "Token"

[languages.id]
[languages.id.translations]
address = "Alamat"
Expand All @@ -127,24 +116,19 @@ contact = "Hubungi Kami"
install-appgallery = "Instal Organic Maps dari Huawei AppGallery"
install-appstore = "Instal Organic Maps dari AppStore"
install-googleplay = "Instal Organic Maps dari Google Play"
install-fdroid="Instal Peta Organik dari F-Droid"
install-fdroid = "Instal Peta Organik dari F-Droid"
language = "Bahasa Indonesia"
name = "Nama"
token = "Token"

[languages.cs]
[languages.cs.translations]
address = "Adresa"
back = "Zpátky na Novinky"
contact = "Kontakt"
donate = "Darujte"
home = "Domů"
install-appgallery = "Nainstalujte Organic Maps z Huawei AppGallery"
install-appstore = "Nainstalujte Organic Maps z App Store"
install-fdroid= "Nainstalujte Organic Maps z F-Droid"
install-googleplay = "Nainstalujte Organic Maps z Google Play"
name = "Název"
news = "Novinky"
install-fdroid = "Nainstalujte Organic Maps z F-Droid"
language = "čeština"
support-us = "Podpořte nás"
name = "Název"
token = "Token"
49 changes: 28 additions & 21 deletions po/content.id.po
Original file line number Diff line number Diff line change
Expand Up @@ -794,55 +794,62 @@ msgstr "[license]: http://www.apache.org/licenses/LICENSE-2.0\n"
msgid "[copyright]: https://github.com/organicmaps/organicmaps/blob/master/data/copyright.html\n"
msgstr "[copyright]: https://github.com/organicmaps/organicmaps/blob/master/data/copyright.html\n"

#. type: Zola TOML Translations: address
#: config.toml
#. type: Hash Value: address
#: translations.yaml
#, no-wrap
msgid "Address"
msgstr "Alamat"

#. type: Zola TOML Translations: back
#: config.toml
#. type: Hash Value: back
#: translations.yaml
#, no-wrap
msgid "Back to News"
msgstr "Kembali ke Berita"

#. type: Zola TOML Translations: install-appgallery
#: config.toml
#. type: Hash Value: contact
#: translations.yaml
#, no-wrap
msgid "Contact Us"
msgstr ""

#. type: Hash Value: install-appgallery
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from Huawei AppGallery"
msgstr "Instal Organic Maps dari Huawei AppGallery"

#. type: Zola TOML Translations: install-appstore
#: config.toml
#. type: Hash Value: install-appstore
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from the AppStore"
msgstr "Instal Organic Maps dari AppStore"

#. type: Zola TOML Translations: install-googleplay
#: config.toml
#, no-wrap
msgid "Install Organic Maps from Google Play"
msgstr "Instal Organic Maps dari Google Play"

#. type: Zola TOML Translations: install-fdroid
#: config.toml
#. type: Hash Value: install-fdroid
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from F-Droid"
msgstr "Instal Peta Organik dari F-Droid"

#. type: Zola TOML Translations: language
#. type: Hash Value: install-googleplay
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from Google Play"
msgstr "Instal Organic Maps dari Google Play"

#. type: Hash Value: language
#: translations.yaml
#, no-wrap
msgid "English"
msgstr "Bahasa Indonesia"

#. type: Zola TOML Translations: name
#: config.toml
#. type: Hash Value: name
#: translations.yaml
#, no-wrap
msgid "Name"
msgstr "Nama"

#. type: Zola TOML Translations: token
#: config.toml
#. type: Hash Value: token
#: translations.yaml
#, no-wrap
msgid "Token"
msgstr "Token"
45 changes: 26 additions & 19 deletions po/content.pot
Original file line number Diff line number Diff line change
Expand Up @@ -898,55 +898,62 @@ msgstr ""
msgid "[copyright]: https://github.com/organicmaps/organicmaps/blob/master/data/copyright.html\n"
msgstr ""

#. type: Zola TOML Translations: address
#: config.toml
#. type: Hash Value: address
#: translations.yaml
#, no-wrap
msgid "Address"
msgstr ""

#. type: Zola TOML Translations: back
#: config.toml
#. type: Hash Value: back
#: translations.yaml
#, no-wrap
msgid "Back to News"
msgstr ""

#. type: Zola TOML Translations: install-appgallery
#: config.toml
#. type: Hash Value: contact
#: translations.yaml
#, no-wrap
msgid "Contact Us"
msgstr ""

#. type: Hash Value: install-appgallery
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from Huawei AppGallery"
msgstr ""

#. type: Zola TOML Translations: install-appstore
#: config.toml
#. type: Hash Value: install-appstore
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from the AppStore"
msgstr ""

#. type: Zola TOML Translations: install-googleplay
#: config.toml
#. type: Hash Value: install-fdroid
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from Google Play"
msgid "Install Organic Maps from F-Droid"
msgstr ""

#. type: Zola TOML Translations: install-fdroid
#: config.toml
#. type: Hash Value: install-googleplay
#: translations.yaml
#, no-wrap
msgid "Install Organic Maps from F-Droid"
msgid "Install Organic Maps from Google Play"
msgstr ""

#. type: Zola TOML Translations: language
#. type: Hash Value: language
#: translations.yaml
#, no-wrap
msgid "English"
msgstr ""

#. type: Zola TOML Translations: name
#: config.toml
#. type: Hash Value: name
#: translations.yaml
#, no-wrap
msgid "Name"
msgstr ""

#. type: Zola TOML Translations: token
#: config.toml
#. type: Hash Value: token
#: translations.yaml
#, no-wrap
msgid "Token"
msgstr ""
1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/
25 changes: 25 additions & 0 deletions tools/extract-zola-translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3

import os
import tomlkit
import yaml
import shutil

os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..")

ZOLA_CONFIG_TOML = "config.toml"
TRANSLATIONS_YAML = "translations.yaml"

# Read config.yaml
with open(ZOLA_CONFIG_TOML, "r") as f:
config = tomlkit.loads(f.read())

# Extract [translations]
translations = {}
for (k, v) in config['translations'].items():
translations[str(k)] = str(v)

# Write translations.yaml
with open(TRANSLATIONS_YAML, "w") as f:
yaml.dump(translations, f, allow_unicode=True, sort_keys=False)
shutil.copystat(ZOLA_CONFIG_TOML, TRANSLATIONS_YAML)
11 changes: 11 additions & 0 deletions i18n.sh → tools/i18n.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -euo pipefail

TOOLS="$(cd "$(dirname "$0")"; pwd)"

if ! which po4a; then
echo "ERROR: Missing po4a">&2
echo " brew install po4a">&2
Expand All @@ -10,7 +12,16 @@ if ! which po4a; then
exit 1
fi

cd "$TOOLS/.."

set -x

$TOOLS/extract-zola-translations.py

touch content/_index.md # force re-generation
po4a .po4a.cfg

sed -e '/"PO-Revision-Date/d' -e '/"POT-Creation-Date/d' -i'~' po/content.*.po po/content.pot
rm -f po/content.*.po*~ po/content.pot~

$TOOLS/update-zola-translations.py
1 change: 1 addition & 0 deletions tools/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autopep8==2.0.1
3 changes: 3 additions & 0 deletions tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tomlkit==0.11.6
polib==1.1.1
PyYAML==6.0
Loading

0 comments on commit 1d6ce8f

Please sign in to comment.