aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-02 11:50:56 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-02 11:50:59 +0200
commit583df73acd748db366f5367590ca2860ab4f227d (patch)
tree23307000a83c4d14b255cd9ce02666f5f561c156 /contrib
parentb397248436f70bda48f82ddcbaf4bdf7574d7e51 (diff)
parent3a54ad9abae1fab4e5caa42a2375850ffb88588d (diff)
downloadbitcoin-583df73acd748db366f5367590ca2860ab4f227d.tar.xz
Merge pull request #4110
3a54ad9 Full translation update (Wladimir J. van der Laan) 9dd5d79 devtools: add a script to fetch and postprocess translations (Wladimir J. van der Laan) 58c01a3 qt: add transifex configuration file (Wladimir J. van der Laan)
Diffstat (limited to 'contrib')
-rw-r--r--contrib/devtools/README.md12
-rwxr-xr-xcontrib/devtools/update-translations.py66
2 files changed, 78 insertions, 0 deletions
diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md
index 697a714a47..a57b4e561e 100644
--- a/contrib/devtools/README.md
+++ b/contrib/devtools/README.md
@@ -69,3 +69,15 @@ If there are 'unsupported' symbols, the return value will be 1 a list like this
.../64/test_bitcoin: symbol std::out_of_range::~out_of_range() from unsupported version GLIBCXX_3.4.15
.../64/test_bitcoin: symbol _ZNSt8__detail15_List_nod from unsupported version GLIBCXX_3.4.15
+update-translations.py
+=======================
+
+Run this script from the root of the repository to update all translations from transifex.
+It will do the following automatically:
+
+- fetch all translations
+- post-process them into valid and committable format
+- add missing translations to the build system (TODO)
+
+See doc/translation-process.md for more information.
+
diff --git a/contrib/devtools/update-translations.py b/contrib/devtools/update-translations.py
new file mode 100755
index 0000000000..1950a42678
--- /dev/null
+++ b/contrib/devtools/update-translations.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+# Copyright (c) 2014 Wladimir J. van der Laan
+# Distributed under the MIT/X11 software license, see the accompanying
+# file COPYING or http://www.opensource.org/licenses/mit-license.php.
+'''
+Run this script from the root of the repository to update all translations from
+transifex.
+It will do the following automatically:
+
+- fetch all translations using the tx tool
+- post-process them into valid and committable format
+ - remove invalid control characters
+ - remove location tags (makes diffs less noisy)
+
+TODO:
+- auto-add new translations to the build system according to the translation process
+- remove 'unfinished' translation items
+'''
+from __future__ import division, print_function
+import subprocess
+import re
+import sys
+import os
+
+# Name of transifex tool
+TX = 'tx'
+# Name of source language file
+SOURCE_LANG = 'bitcoin_en.ts'
+# Directory with locale files
+LOCALE_DIR = 'src/qt/locale'
+
+def check_at_repository_root():
+ if not os.path.exists('.git'):
+ print('No .git directory found')
+ print('Execute this script at the root of the repository', file=sys.stderr)
+ exit(1)
+
+def fetch_all_translations():
+ if subprocess.call([TX, 'pull', '-f']):
+ print('Error while fetching translations', file=sys.stderr)
+ exit(1)
+
+def postprocess_translations():
+ print('Postprocessing...')
+ for filename in os.listdir(LOCALE_DIR):
+ # process only language files, and do not process source language
+ if not filename.endswith('.ts') or filename == SOURCE_LANG:
+ continue
+ filepath = os.path.join(LOCALE_DIR, filename)
+ with open(filepath, 'rb') as f:
+ data = f.read()
+ # remove non-allowed control characters
+ data = re.sub('[\x00-\x09\x0b\x0c\x0e-\x1f]', '', data)
+ data = data.split('\n')
+ # strip locations from non-origin translation
+ # location tags are used to guide translators, they are not necessary for compilation
+ # TODO: actually process XML instead of relying on Transifex's one-tag-per-line output format
+ data = [line for line in data if not '<location' in line]
+ with open(filepath, 'wb') as f:
+ f.write('\n'.join(data))
+
+if __name__ == '__main__':
+ check_at_repository_root()
+ fetch_all_translations()
+ postprocess_translations()
+