Skip to content

Commit 583df73

Browse files
committed
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)
2 parents b397248 + 3a54ad9 commit 583df73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+9382
-62794
lines changed

.tx/config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[main]
2+
host = https://www.transifex.com
3+
4+
[bitcoin.tx]
5+
file_filter = src/qt/locale/bitcoin_<lang>.ts
6+
source_file = src/qt/locale/bitcoin_en.ts
7+
source_lang = en

contrib/devtools/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ If there are 'unsupported' symbols, the return value will be 1 a list like this
6969
.../64/test_bitcoin: symbol std::out_of_range::~out_of_range() from unsupported version GLIBCXX_3.4.15
7070
.../64/test_bitcoin: symbol _ZNSt8__detail15_List_nod from unsupported version GLIBCXX_3.4.15
7171

72+
update-translations.py
73+
=======================
74+
75+
Run this script from the root of the repository to update all translations from transifex.
76+
It will do the following automatically:
77+
78+
- fetch all translations
79+
- post-process them into valid and committable format
80+
- add missing translations to the build system (TODO)
81+
82+
See doc/translation-process.md for more information.
83+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/python
2+
# Copyright (c) 2014 Wladimir J. van der Laan
3+
# Distributed under the MIT/X11 software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
'''
6+
Run this script from the root of the repository to update all translations from
7+
transifex.
8+
It will do the following automatically:
9+
10+
- fetch all translations using the tx tool
11+
- post-process them into valid and committable format
12+
- remove invalid control characters
13+
- remove location tags (makes diffs less noisy)
14+
15+
TODO:
16+
- auto-add new translations to the build system according to the translation process
17+
- remove 'unfinished' translation items
18+
'''
19+
from __future__ import division, print_function
20+
import subprocess
21+
import re
22+
import sys
23+
import os
24+
25+
# Name of transifex tool
26+
TX = 'tx'
27+
# Name of source language file
28+
SOURCE_LANG = 'bitcoin_en.ts'
29+
# Directory with locale files
30+
LOCALE_DIR = 'src/qt/locale'
31+
32+
def check_at_repository_root():
33+
if not os.path.exists('.git'):
34+
print('No .git directory found')
35+
print('Execute this script at the root of the repository', file=sys.stderr)
36+
exit(1)
37+
38+
def fetch_all_translations():
39+
if subprocess.call([TX, 'pull', '-f']):
40+
print('Error while fetching translations', file=sys.stderr)
41+
exit(1)
42+
43+
def postprocess_translations():
44+
print('Postprocessing...')
45+
for filename in os.listdir(LOCALE_DIR):
46+
# process only language files, and do not process source language
47+
if not filename.endswith('.ts') or filename == SOURCE_LANG:
48+
continue
49+
filepath = os.path.join(LOCALE_DIR, filename)
50+
with open(filepath, 'rb') as f:
51+
data = f.read()
52+
# remove non-allowed control characters
53+
data = re.sub('[\x00-\x09\x0b\x0c\x0e-\x1f]', '', data)
54+
data = data.split('\n')
55+
# strip locations from non-origin translation
56+
# location tags are used to guide translators, they are not necessary for compilation
57+
# TODO: actually process XML instead of relying on Transifex's one-tag-per-line output format
58+
data = [line for line in data if not '<location' in line]
59+
with open(filepath, 'wb') as f:
60+
f.write('\n'.join(data))
61+
62+
if __name__ == '__main__':
63+
check_at_repository_root()
64+
fetch_all_translations()
65+
postprocess_translations()
66+

doc/translation_process.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,34 +71,15 @@ We are using https://transifex.com as a frontend for translating the client.
7171
https://www.transifex.com/projects/p/bitcoin/resource/tx/
7272

7373
The "Transifex client" (see: http://support.transifex.com/customer/portal/topics/440187-transifex-client/articles)
74-
will help with fetching new translations from Transifex. Use the following
75-
config to be able to connect with the client:
74+
is used to fetch new translations from Transifex. The configuration for this client (`.tx/config`)
75+
is part of the repository.
7676

77-
### .tx/config
78-
79-
[main]
80-
host = https://www.transifex.com
81-
82-
[bitcoin.tx]
83-
file_filter = src/qt/locale/bitcoin_<lang>.ts
84-
source_file = src/qt/locale/bitcoin_en.ts
85-
source_lang = en
86-
87-
### .tx/config (for Windows)
88-
89-
[main]
90-
host = https://www.transifex.com
91-
92-
[bitcoin.tx]
93-
file_filter = src\qt\locale\bitcoin_<lang>.ts
94-
source_file = src\qt\locale\bitcoin_en.ts
95-
source_lang = en
96-
97-
It is also possible to directly download new translations one by one from the Transifex website.
77+
Do not directly download translations one by one from the Transifex website, as we do a few
78+
postprocessing steps before committing the translations.
9879

9980
### Fetching new translations
10081

101-
1. `tx pull -a`
82+
1. `python contrib/devtools/update-translations.py`
10283
2. update `src/qt/bitcoin.qrc` manually or via
10384
`ls src/qt/locale/*ts|xargs -n1 basename|sed 's/\(bitcoin_\(.*\)\).ts/<file alias="\2">locale\/\1.qm<\/file>/'`
10485
3. update `src/qt/Makefile.am` manually or via

0 commit comments

Comments
 (0)