Skip to content

Commit 935ffec

Browse files
committed
Merge pull request #1312 from sgk/i18nTransifexIntegration
Transifex API integration
2 parents bc90e3d + b6b9d4e commit 935ffec

Some content is hidden

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

78 files changed

+16801
-115
lines changed

app/src/processing/app/i18n/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Internationalization Tools
2+
3+
by @sgk at SwitchScience.
4+
5+
## Reflect the source code change
6+
7+
Sometimes, the developers add/delete/modify the strings which should be translated. You have to reflect the source code change to your translation. This can be done as below given your language code `xx`.
8+
9+
% ./update.sh xx
10+
11+
This will extract the up-to-date set of strings from the source code, set the translated strings from the current "`Resources_xx.po`" file, and then write back to "`Resources_xx.po`" file. If the developers delete/modify the strings, corresponding translated strings disappear from the file. You may want to do like this.
12+
13+
% git commit
14+
% ./update.sh xx
15+
% git diff Resrouces_xx.po
16+
% git add Resources_xx.po Resources_xx.properties
17+
% git commit
18+
19+
## Get the translated catalog from Transifex
20+
21+
You may want to retrieve the translation contribution from Transifex. This can be done as below given your language code `xx`.
22+
23+
% ./pull.sh xx
24+
25+
Translation strings for only strings already in "`Resources_xx.po`" file will be updated. If Transifex has translated strings which are not in "`Resources_xx.po`" file, the strings will not appear in the file.
26+
27+
If you want to retrieve the newly translated language which is not in the Git repository, you will want to do like this.
28+
29+
% cp Resources_en.po Resources_xx.po
30+
% ./pull.sh xx
31+
% more Resources_xx.po
32+
% git add Resources_xx.po Resources_xx.properties
33+
% git commit
34+
35+
## Send the translated catalog to Transifex
36+
37+
You can send the translated catalog file "`Resources_xx.po`" to Transifex using the following command line where `xx` is the language code.
38+
39+
% ./push.sh xx
40+
41+
Be aware that this will overwrite the current result on Transifex. You may want to do "./update.sh" and "./pull.sh" before doing "./push.sh".
42+
43+
## Select "all" languages
44+
45+
**For the comitter only.** For all above scripts, you can select all languages by specifying "-a" instead of language codes like this.
46+
47+
% ./update.sh -a
48+
49+
The "all" means all the languages currently in your working directory. This does not mean the languages on Transifex.

app/src/processing/app/i18n/i18n_update.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/src/processing/app/i18n/i18n_update.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/src/processing/app/i18n/pull.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
if [ $0 != "./pull.sh" ]; then
4+
echo "pull.sh: Invoke this script as ./pull.sh"
5+
exit 1
6+
fi
7+
8+
while [ $# -gt 0 ]; do
9+
if [ $1 = '-a' ]; then
10+
for f in Resources_*.po; do
11+
f=$(expr "$f" : "Resources_\(.*\).po")
12+
langs="$langs $f"
13+
done
14+
else
15+
langs="$langs $1"
16+
fi
17+
shift
18+
done
19+
20+
if [ "$langs" = "" ]; then
21+
echo "pull.sh: Give at least one language code."
22+
exit 1
23+
fi
24+
25+
python python/pull.py $langs
26+
27+
for lang in $langs; do
28+
if [ -f "Resources_$lang.po" ]; then
29+
msgcat -p Resources_$lang.po > Resources_$lang.properties
30+
fi
31+
done

app/src/processing/app/i18n/push.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
if [ $0 != "./push.sh" ]; then
4+
echo "push.sh: Invoke this script as ./push.sh"
5+
exit 1
6+
fi
7+
8+
while [ $# -gt 0 ]; do
9+
if [ $1 = '-a' ]; then
10+
for f in Resources_*.po; do
11+
f=$(expr "$f" : "Resources_\(.*\).po")
12+
langs="$langs $f"
13+
done
14+
else
15+
langs="$langs $1"
16+
fi
17+
shift
18+
done
19+
20+
if [ "$langs" = "" ]; then
21+
echo "push.sh: Give at least one language code."
22+
exit 1
23+
fi
24+
25+
exec python python/push.py $langs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
#vim:set fileencoding=utf-8 sw=2 expandtab
3+
4+
from transifex import Transifex
5+
6+
def main():
7+
import getpass
8+
import sys
9+
10+
print 'Use your account to talk with Transifex.'
11+
user = raw_input('Username: ')
12+
passwd = getpass.getpass('Password: ')
13+
trans = Transifex(user, passwd)
14+
15+
for lang in sys.argv[1:]:
16+
fname = 'Resources_%s.po' % lang
17+
print "Updating %s from Transifex..." % fname,
18+
sys.stdout.flush()
19+
try:
20+
lang = trans.canonical_lang(lang)
21+
trans.pull(lang, fname)
22+
except RuntimeError, e:
23+
print e.message
24+
continue
25+
except IOError, e:
26+
print e.strerror
27+
continue
28+
print
29+
30+
if __name__ == '__main__':
31+
main()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
#vim:set fileencoding=utf-8 sw=2 expandtab
3+
4+
from transifex import Transifex
5+
6+
def main():
7+
import getpass
8+
import sys
9+
10+
print 'Use your account to talk with Transifex.'
11+
user = raw_input('Username: ')
12+
passwd = getpass.getpass('Password: ')
13+
trans = Transifex(user, passwd)
14+
15+
for lang in sys.argv[1:]:
16+
fname = 'Resources_%s.po' % lang
17+
print "Updating %s on Transifex using %s..." % (lang, fname),
18+
sys.stdout.flush()
19+
try:
20+
lang = trans.canonical_lang(lang)
21+
trans.push(lang, ''.join(open(fname)))
22+
except RuntimeError, e:
23+
print e.message
24+
continue
25+
except IOError, e:
26+
print e.strerror
27+
continue
28+
print
29+
30+
if __name__ == '__main__':
31+
main()
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# __
4+
# /__) _ _ _ _ _/ _
5+
# / ( (- (/ (/ (- _) / _)
6+
# /
7+
8+
"""
9+
requests HTTP library
10+
~~~~~~~~~~~~~~~~~~~~~
11+
12+
Requests is an HTTP library, written in Python, for human beings. Basic GET
13+
usage:
14+
15+
>>> import requests
16+
>>> r = requests.get('http://python.org')
17+
>>> r.status_code
18+
200
19+
>>> 'Python is a programming language' in r.content
20+
True
21+
22+
... or POST:
23+
24+
>>> payload = dict(key1='value1', key2='value2')
25+
>>> r = requests.post("http://httpbin.org/post", data=payload)
26+
>>> print r.text
27+
{
28+
...
29+
"form": {
30+
"key2": "value2",
31+
"key1": "value1"
32+
},
33+
...
34+
}
35+
36+
The other HTTP methods are supported - see `requests.api`. Full documentation
37+
is at <http://python-requests.org>.
38+
39+
:copyright: (c) 2013 by Kenneth Reitz.
40+
:license: Apache 2.0, see LICENSE for more details.
41+
42+
"""
43+
44+
__title__ = 'requests'
45+
__version__ = '1.1.0'
46+
__build__ = 0x010100
47+
__author__ = 'Kenneth Reitz'
48+
__license__ = 'Apache 2.0'
49+
__copyright__ = 'Copyright 2013 Kenneth Reitz'
50+
51+
52+
from . import utils
53+
from .models import Request, Response, PreparedRequest
54+
from .api import request, get, head, post, patch, put, delete, options
55+
from .sessions import session, Session
56+
from .status_codes import codes
57+
from .exceptions import (
58+
RequestException, Timeout, URLRequired,
59+
TooManyRedirects, HTTPError, ConnectionError
60+
)
61+
62+
# Set default logging handler to avoid "No handler found" warnings.
63+
import logging
64+
try: # Python 2.7+
65+
from logging import NullHandler
66+
except ImportError:
67+
class NullHandler(logging.Handler):
68+
def emit(self, record):
69+
pass
70+
71+
logging.getLogger(__name__).addHandler(NullHandler())

0 commit comments

Comments
 (0)