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,14 @@ import json import os import datetime +import urllib +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" +from urllib.parse import quote + +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 +47,58 @@ 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': 'https://bugs.kde.org/enter_bug.cgi?product=gcompris', + 'POT-Creation-Date': modtime_utc_string, + 'PO-Revision-Date': modtime_utc_string, + 'Last-Translator': 'FULL NAME \n', + 'Language-Team': 'LANGUAGE \n', + '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_by_section.html#" + \ + urllib.parse.quote(word['description'].split('/')[-1].split(".")[0]) + if displayInConsole: + print("#. " + chapter['name'] + \ + " / " + lesson['name'] + \ + " / " + word['description'] + \ + ": "+ imageLink) + print('msgctxt "'+voice+'"|"') + print('msgid "' + word['description'] + '"') + print('msgstr "' + getManualTranslation(manualData, voice) + '"') + print("") + + entry = polib.POEntry( + msgid = word['description'], + msgstr = getManualTranslation(manualData, voice), + msgctxt = voice, + comment = chapter['name'] + " / " + lesson['name'] + " / " + word['description'] + + "\n" + 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,42 @@ +# -* 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 +import urllib + +from urllib.parse import unquote + +if len(sys.argv) != 3: + print("Usage: po2Dataset.py po_file json_file") + sys.exit(1) + +poFile = polib.pofile(sys.argv[1], encoding='utf-8') +jsonFile = sys.argv[2] +data = {} + +for entry in poFile.translated_entries(): + word = entry.msgctxt + data[word] = entry.msgstr + +with open(jsonFile, "w", encoding='utf-8') as data_file: + json.dump(data, data_file, indent=4, sort_keys=True, ensure_ascii=False) +