mirror of
https://github.com/uroni/urbackup_backend.git
synced 2025-10-26 11:36:50 +00:00
Setup web interface translations to be pulled from transifex
This commit is contained in:
parent
b81a9e9cd2
commit
ceea235d3f
1
.gitignore
vendored
1
.gitignore
vendored
@ -210,3 +210,4 @@ urbackup/backup_client.db-journal
|
||||
session_idents.txt
|
||||
urbackup/server_ident.priv
|
||||
urbackup/server_ident.pub
|
||||
urbackupserver/www/polib.pyc
|
||||
|
||||
8
urbackupserver/www/.tx/config
Normal file
8
urbackupserver/www/.tx/config
Normal file
@ -0,0 +1,8 @@
|
||||
[main]
|
||||
host = https://www.transifex.com
|
||||
|
||||
[urbackup.webinterface]
|
||||
file_filter = translations/urbackup.webinterface/<lang>.po
|
||||
source_lang = en
|
||||
type = PO
|
||||
|
||||
1817
urbackupserver/www/polib.py
Normal file
1817
urbackupserver/www/polib.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
162
urbackupserver/www/translation_helper.py
Normal file
162
urbackupserver/www/translation_helper.py
Normal file
@ -0,0 +1,162 @@
|
||||
import re
|
||||
import codecs
|
||||
import collections
|
||||
import os
|
||||
import polib
|
||||
|
||||
def write_po_header(f, lang):
|
||||
|
||||
f.writelines(["# UrBackup translation\n",
|
||||
"# Copyright (C) 2011-2014 See translators\n",
|
||||
"# This file is distributed under the same license as the UrBackup package.\n",
|
||||
"msgid \"\"\n",
|
||||
"msgstr \"\"\n",
|
||||
"\"MIME-Version: 1.0\\n\"\n",
|
||||
"\"Content-Type: text/plain; charset=UTF-8\\n\"\n",
|
||||
"\"Content-Transfer-Encoding: 8bit\\n\"\n",
|
||||
"\"Language: "+lang+"\\n\"\n",
|
||||
"\n"]);
|
||||
|
||||
def po_from_translations():
|
||||
with codecs.open("translation.js", "r", encoding="utf8") as translation_file:
|
||||
|
||||
translation = translation_file.readlines();
|
||||
|
||||
lang = ""
|
||||
|
||||
translations = {};
|
||||
|
||||
for line in translation:
|
||||
|
||||
m = re.search("translations\.([A-Za-z_]*)={", line, 0)
|
||||
|
||||
if m:
|
||||
|
||||
lang = m.group(1)
|
||||
|
||||
translations[lang] = collections.OrderedDict()
|
||||
|
||||
|
||||
m = re.search("\"(.*?)\".*:.*\"(.*)\"", line, 0)
|
||||
|
||||
if m and len(lang)>0:
|
||||
|
||||
key = m.group(1)
|
||||
val = m.group(2)
|
||||
|
||||
translations[lang][key] = val
|
||||
|
||||
|
||||
enkeys = collections.OrderedDict()
|
||||
|
||||
for lang in translations:
|
||||
|
||||
with codecs.open(lang+".po" ,"w", encoding="utf8") as pofile:
|
||||
|
||||
write_po_header(pofile, lang)
|
||||
|
||||
trans = translations[lang]
|
||||
|
||||
for key in trans:
|
||||
|
||||
pofile.writelines(["msgid \""+key+"\"\n",
|
||||
"msgstr \""+trans[key]+"\"\n",
|
||||
"\n"])
|
||||
|
||||
enkeys[key] = True
|
||||
|
||||
templ_dir = r"www\templates"
|
||||
skip = ["target_db_version", "time" ]
|
||||
for file in os.listdir(templ_dir):
|
||||
if file.endswith(".htm"):
|
||||
|
||||
with codecs.open(templ_dir+"\\"+file ,"r", encoding="utf8") as templ:
|
||||
|
||||
for line in templ.readlines():
|
||||
|
||||
for m in re.finditer("{t([^\|]*?)(\|.*?)?}", line):
|
||||
|
||||
key = m.group(1)
|
||||
|
||||
if key not in enkeys and (not m.group(2) or "s" not in m.group(2)):
|
||||
|
||||
if "t"+key not in skip:
|
||||
enkeys["t"+key] = True
|
||||
|
||||
|
||||
with codecs.open("en.po" ,"w", encoding="utf8") as pofile:
|
||||
|
||||
write_po_header(pofile, "en")
|
||||
|
||||
for key in enkeys:
|
||||
if key in translations["en"]:
|
||||
|
||||
trans = translations["en"][key];
|
||||
|
||||
pofile.writelines(["msgid \""+key+"\"\n",
|
||||
"msgstr \""+trans+"\"\n",
|
||||
"\n"])
|
||||
|
||||
elif len(key)>0 and key[0]=="t":
|
||||
|
||||
pofile.writelines(["msgid \""+key+"\"\n",
|
||||
"msgstr \""+key[1:]+"\"\n",
|
||||
"\n"])
|
||||
|
||||
def translations_from_po():
|
||||
|
||||
lang_map = { "fa_IR": "fa" }
|
||||
|
||||
with codecs.open("translation.js", "w", encoding="utf8") as output:
|
||||
|
||||
output.write("if(!window.translations) translations=new Object();\n")
|
||||
|
||||
tdir = "translations/urbackup.webinterface"
|
||||
|
||||
prev_lang = False
|
||||
|
||||
for file in os.listdir(tdir):
|
||||
if file.endswith(".po"):
|
||||
|
||||
m = re.search("([A-Za-z_]*).*\.po", file);
|
||||
|
||||
if m:
|
||||
lang = m.group(1)
|
||||
|
||||
po = polib.pofile(tdir + "/" + file)
|
||||
|
||||
if len(po.translated_entries())>0:
|
||||
|
||||
if prev_lang:
|
||||
output.write("\n}\n")
|
||||
|
||||
prev_lang = True
|
||||
|
||||
if lang in lang_map:
|
||||
lang = lang_map[lang]
|
||||
|
||||
output.write("translations."+lang+" = {\n")
|
||||
|
||||
|
||||
prev_entry = False
|
||||
|
||||
for entry in po.translated_entries():
|
||||
|
||||
if prev_entry:
|
||||
output.write(",\n")
|
||||
|
||||
prev_entry = True
|
||||
|
||||
msgid = entry.msgid.replace("\"", "\\\"")
|
||||
msgstr = entry.msgstr.replace("\"", "\\\"")
|
||||
|
||||
output.write("\""+msgid+"\": \""+msgstr+"\"")
|
||||
|
||||
if prev_lang:
|
||||
output.write("\n}\n")
|
||||
|
||||
|
||||
translations_from_po()
|
||||
|
||||
|
||||
|
||||
1127
urbackupserver/www/translations/urbackup.webinterface/da_DK.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/da_DK.po
Normal file
File diff suppressed because it is too large
Load Diff
1129
urbackupserver/www/translations/urbackup.webinterface/de.po
Normal file
1129
urbackupserver/www/translations/urbackup.webinterface/de.po
Normal file
File diff suppressed because it is too large
Load Diff
1128
urbackupserver/www/translations/urbackup.webinterface/en.po
Normal file
1128
urbackupserver/www/translations/urbackup.webinterface/en.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/en_US.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/en_US.po
Normal file
File diff suppressed because it is too large
Load Diff
1128
urbackupserver/www/translations/urbackup.webinterface/es.po
Normal file
1128
urbackupserver/www/translations/urbackup.webinterface/es.po
Normal file
File diff suppressed because it is too large
Load Diff
1128
urbackupserver/www/translations/urbackup.webinterface/fa_IR.po
Normal file
1128
urbackupserver/www/translations/urbackup.webinterface/fa_IR.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/fi.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/fi.po
Normal file
File diff suppressed because it is too large
Load Diff
1128
urbackupserver/www/translations/urbackup.webinterface/fr.po
Normal file
1128
urbackupserver/www/translations/urbackup.webinterface/fr.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/he.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/he.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/it_IT.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/it_IT.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/nl.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/nl.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/no_NO.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/no_NO.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/pl.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/pl.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/pt_BR.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/pt_BR.po
Normal file
File diff suppressed because it is too large
Load Diff
1128
urbackupserver/www/translations/urbackup.webinterface/ru.po
Normal file
1128
urbackupserver/www/translations/urbackup.webinterface/ru.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/sk.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/sk.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/sv.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/sv.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/tr_TR.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/tr_TR.po
Normal file
File diff suppressed because it is too large
Load Diff
1127
urbackupserver/www/translations/urbackup.webinterface/uk.po
Normal file
1127
urbackupserver/www/translations/urbackup.webinterface/uk.po
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1128
urbackupserver/www/translations/urbackup.webinterface/zh_TW.Big5.po
Normal file
1128
urbackupserver/www/translations/urbackup.webinterface/zh_TW.Big5.po
Normal file
File diff suppressed because it is too large
Load Diff
3
urbackupserver/www/update_translation.bat
Normal file
3
urbackupserver/www/update_translation.bat
Normal file
@ -0,0 +1,3 @@
|
||||
tx pull -a
|
||||
tx pull -l en
|
||||
python translation_helper.py
|
||||
Loading…
Reference in New Issue
Block a user