Update translations and use new translations infrastructure (#357)

* Align Lithuanian translation with text length restrictions

* Make translation generation script work also with Python 3

* Fix compilation error by introducing "OffString" string to translations

* Update translations

* Update remaining translations

* Add Finnish, Dutch, Portuguese and Ukrainian languages

* Add Swedish language, update build script

* Add Norwegian and Serbian (Latin) translations

* Update translation file, add automatically generated file warning

* PIDSETTINGS support. Thanks Andre Bernet (kilrah)

* Update Hungarian translation. Thanks adrianmihalko.
This commit is contained in:
Julius Vitkauskas
2018-09-18 02:55:52 +03:00
committed by Ben V. Brown
parent 056353ed6a
commit 54ec20cd9f
28 changed files with 4266 additions and 2319 deletions

View File

@@ -1,3 +1,4 @@
from __future__ import print_function
import json
import os
import io
@@ -13,7 +14,7 @@ except NameError:
# Loading a single JSON file
def loadJson(fileName, skipFirstLine):
with open(fileName) as f:
with io.open(fileName, mode="r", encoding="utf-8") as f:
if skipFirstLine:
f.readline()
@@ -54,7 +55,9 @@ def readTranslations(jsonDir):
def writeStart(f):
f.write(to_unicode("""#include "Translation.h"
f.write(to_unicode("""// WARNING: THIS FILE WAS AUTO GENERATED BY make_translation.py. PLEASE DO NOT EDIT.
#include "Translation.h"
#ifndef LANG
#define LANG_EN
#endif
@@ -66,7 +69,7 @@ def escapeC(s):
def writeLanguage(languageCode):
print "Generating block for " + languageCode
print("Generating block for " + languageCode)
lang = langDict[languageCode]
f.write(to_unicode("\n#ifdef LANG_" + languageCode + "\n"))
@@ -79,13 +82,17 @@ def writeLanguage(languageCode):
# ----- Writing SettingsDescriptions
obj = lang['menuOptions']
f.write(to_unicode("const char* SettingsDescriptions[" + str(len(obj)) + "] = {\n"))
f.write(to_unicode("const char* SettingsDescriptions[] = {\n"))
maxLen = 25
for mod in defs['menuOptions']:
eid = mod['id']
if 'feature' in mod:
f.write(to_unicode("#ifdef " + mod['feature'] + "\n"))
f.write(to_unicode(" /* " + eid.ljust(maxLen)[:maxLen] + " */ "))
f.write(to_unicode("\"" + escapeC(obj[eid]['desc']) + "\",\n"))
if 'feature' in mod:
f.write(to_unicode("#endif\n"))
f.write(to_unicode("};\n\n"))
@@ -116,16 +123,20 @@ def writeLanguage(languageCode):
# ----- Writing SettingsDescriptions
obj = lang['menuOptions']
f.write(to_unicode("const char* SettingsShortNames[" + str(len(obj)) + "][2] = {\n"))
f.write(to_unicode("const char* SettingsShortNames[][2] = {\n"))
maxLen = 25
for mod in defs['menuOptions']:
eid = mod['id']
if 'feature' in mod:
f.write(to_unicode("#ifdef " + mod['feature'] + "\n"))
f.write(to_unicode(" /* " + eid.ljust(maxLen)[:maxLen] + " */ "))
if lang['menuDouble']:
f.write(to_unicode("{ \"" + escapeC(obj[eid]['text2'][0]) + "\", \"" + escapeC(obj[eid]['text2'][1]) + "\" },\n"))
else:
f.write(to_unicode("\"" + escapeC(obj[eid]['text']) + "\",\n"))
f.write(to_unicode("{ \"" + escapeC(obj[eid]['text']) + "\" },\n"))
if 'feature' in mod:
f.write(to_unicode("#endif\n"))
f.write(to_unicode("};\n\n"))
@@ -163,7 +174,7 @@ Second parameter = target directory
'''
print "Making " + TRANSLATION_CPP + ":"
print("Making " + TRANSLATION_CPP + ":")
if len(sys.argv) > 1:
jsonDir = sys.argv[1]
@@ -175,7 +186,7 @@ jsonDir = os.path.abspath(jsonDir)
if len(sys.argv) > 2:
outDir = sys.argv[2]
else:
outDir = jsonDir
outDir = jsonDir + "/../workspace/TS100/src/"
langDict = readTranslations(jsonDir)
@@ -187,8 +198,7 @@ defs = loadJson(os.path.join(jsonDir, "translations_def.js"), True)
mandatoryOrder = ['EN']
# Then add all others in alphabetical order
sortedKeys = langDict.keys()
sortedKeys.sort()
sortedKeys = sorted(langDict.keys())
for key in sortedKeys:
if key not in mandatoryOrder:
@@ -205,4 +215,4 @@ with io.open(targetTranslationFile, 'w', encoding='utf-8', newline="\n") as f:
for langCode in mandatoryOrder:
writeLanguage(langCode)
print "Done"
print("Done")