Index: src/Messages.sh =================================================================== --- src/Messages.sh +++ src/Messages.sh @@ -8,3 +8,17 @@ # create a pot for the voices text to keep them up-to-date with the audio files grep -R "intro: " --include="ActivityInfo.qml" | awk -F'[:/]' '{print "//i18n: intro voices, see GCompris-voices/README.md - activity: \""$2"\"\ni18n("$7");"}' | $XGETTEXT - -o $podir/gcompris_voices.pot +# create a pot for the lang dataset to keep them up-to-date with inner json files +# it parses the activities/lang/resource/words.json file and for each triplet: +# "description": "alphabet", +# "image": "words/alphabet.png", +# "voice": "voices-$CA/$LOCALE/words/alphabet.$CA" +# write a translator comment containing the description and the corresponding image +# and let the translation to be the voice (just the word, not the full path). +# For above: +# #. i18n: lang dataset - description:"alphabet", corresponding image: https://www.gcompris.net/incoming/lang/lang/words/alphabet.png +#: standard input:2 +# msgid "alphabet" +# msgstr "" +lang_dataset=$(find . -type f -iname "words.json"); +awk '/"description"/{ desc = $2; } /"image"/ { gsub(/"/, "", $2);gsub(/,/, "", $2);img = $2 } /"voice"/ { gsub ("voices.\\$CA/\\$LOCALE/[a-z]*/", "", $2);gsub (".\\$CA", "", $2);print "//i18n: lang dataset - description:"desc, "corresponding image:", "https://www.gcompris.net/incoming/lang/lang/"img "\ni18n(", $2,")" }' $lang_dataset | $XGETTEXT - -o $podir/gcompris_lang.pot Index: src/StaticMessages.sh =================================================================== --- /dev/null +++ src/StaticMessages.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copied from https://cgit.kde.org/plasma-browser-integration.git/tree/StaticMessages.sh + +# We fill in the en "translations" manually. We extract this to the KDE system as pot as normal, then populate the other json files + +# The name of catalog we create (without the.pot extension), sourced from the scripty scripts +FILENAME="gcompris_lang" + +function export_pot_file # First parameter will be the path of the pot file we have to create, includes $FILENAME +{ + potfile=$1 + python3 ./activities/lang/resource/datasetToPo.py ./activities/lang/resource/words.json $potfile +} + +function import_po_files # First parameter will be a path that will contain several .po files with the format LANG.po +{ + podir=$1 + for file in `ls $podir` + do + lang=${file%.po} #remove .po from end of file + #python3 ./activities/lang/resource/poToDataset.py $podir/$file ./activities/lang/resource/content-$lang.json + echo "${PWD} - ./activities/lang/resource/poToDataset.py $podir/$file ./activities/lang/resource/content-$lang.json" + done +} Index: src/activities/lang/resource/datasetToPo.py =================================================================== --- src/activities/lang/resource/datasetToPo.py +++ src/activities/lang/resource/datasetToPo.py @@ -21,10 +21,11 @@ import json import os import datetime +import polib -if(len(sys.argv) < 2): - print "Usage: dataSetToPo.py dataset.json [content-fr.json]" - print " The optional argument is used to backport manually created json" +if(len(sys.argv) < 3): + print("Usage: dataSetToPo.py dataset.json output.po [content-fr.json]") + print(" The optional argument is used to backport manually created json") sys.exit(1) def loadManualFile(manual): @@ -43,41 +44,59 @@ return "" manualData = None -if(len(sys.argv) == 3): - manualData = loadManualFile(sys.argv[2]) - +if(len(sys.argv) == 4): + manualData = loadManualFile(sys.argv[3]) dataset = sys.argv[1] json_data = open(dataset) data = json.load(json_data) json_data.close() +displayInConsole = False + # Get last modification time of data set modtime = os.path.getmtime(dataset) modtime_utc = datetime.datetime.utcfromtimestamp(modtime) modtime_utc_string = modtime_utc.strftime('%Y-%m-%d %H:%M') + '+0000' # Header -print 'msgid ""' -print 'msgstr ""' -print '"Project-Id-Version: gcompris_qt\\n"' -print '"POT-Creation-Date: ' + modtime_utc_string + '\\n"' -print '"MIME-Version: 1.0\\n"' -print '"Content-Type: text/plain; charset=UTF-8\\n"' -print '"Content-Transfer-Encoding: 8bit\\n"' -print '' +po = polib.POFile() +po.metadata = { + 'Project-Id-Version': 'gcompris_qt\\n', + 'Report-Msgid-Bugs-To': 'you@example.com', + 'POT-Creation-Date': modtime_utc_string, + 'PO-Revision-Date': modtime_utc_string, + 'Last-Translator': 'you ', + 'Language-Team': 'English ', + 'MIME-Version': '1.0', + 'Content-Type': 'text/plain; charset=utf-8', + 'Content-Transfer-Encoding': '8bit', +} for chapter in data: for lesson in chapter['content']: for word in lesson['content']: - print "#. " + chapter['name'] + \ - " / " + lesson['name'] + \ - " / " + word['description'] + \ - ": https://gcompris.net/incoming/lang/words.html#" + \ - word['image'].split('/')[-1].split(".")[0] - print "#: " + "https://gcompris.net/incoming/lang/words.html#" + \ - word['image'].split('/')[-1].split(".")[0] - print 'msgctxt "LangWords|"' - print 'msgid "' + word['description'] + '"' - print 'msgstr "' + getManualTranslation(manualData, word['voice']).encode('utf-8') + '"' - print "" + voice = word['voice'].split('/')[-1].split(".")[0] + ".ogg" + imageLink = "https://gcompris.net/incoming/lang/words.html#" + \ + word['image'].split('/')[-1].split(".")[0] + if displayInConsole: + print("#. " + chapter['name'] + \ + " / " + lesson['name'] + \ + " / " + voice + \ + ": "+ imageLink) + print("#: " + imageLink) + print('msgctxt "LangWords|"') + print('msgid "' + word['description'] + '"') + print('msgstr "' + getManualTranslation(manualData, voice) + '"') + print("") + + entry = polib.POEntry( + msgid = word['description'], + msgstr = getManualTranslation(manualData, voice), + comment = chapter['name'] + " / " + lesson['name'] + " / " + voice + + "\n" + imageLink, + occurrences = [(imageLink, '')] + ) + po.append(entry) + +po.save(sys.argv[2]) Index: src/activities/lang/resource/poToDataset.py =================================================================== --- /dev/null +++ src/activities/lang/resource/poToDataset.py @@ -0,0 +1,53 @@ +# -* coding: utf-8 -*- +#!/usr/bin/python +# +# GCompris - po2Dataset.py +# +# Copyright (C) 2019 Johnny Jazeix +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +import json +import polib +import sys + +if len(sys.argv) != 3: + print("Usage: po2Dataset.py po_file json_file") + sys.exit(1) + +jsonFile=sys.argv[2] + +with open(jsonFile) as data_file: + try: + data = json.load(data_file) + except ValueError as e: + print(dir(e)) + print("Processing KO " + wordsFile) + print("Parser error: {0}".format(e.message)) + +poFile = polib.pofile(sys.argv[1], encoding='utf-8') + +for entry in poFile: + word = entry.comment.split('\n')[0].split(' ')[-1] + if word in data: + if entry.msgstr != "": + data[word] = entry.msgstr + else: + print(word, "not translated") + else: + print(word, "not found in json file") + +with open(jsonFile, "w", encoding='utf-8') as data_file: + json.dump(data, data_file, indent=4, sort_keys=True, ensure_ascii=False) +