1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Merge pull request #1235 from sgk/i18nResourcesRearrange

Rearrange i18n Resource files into a directory
This commit is contained in:
Cristian Maglie
2013-03-08 07:07:39 -08:00
87 changed files with 2259 additions and 2163 deletions

View File

@ -34,7 +34,7 @@ public class I18n {
if (language != null && language.trim().length() > 0) {
Locale.setDefault(new Locale(language));
}
i18n = ResourceBundle.getBundle("processing.app.Resources", Locale.getDefault());
i18n = ResourceBundle.getBundle("processing.app.i18n.Resources", Locale.getDefault());
PROMPT_YES = _("Yes");
PROMPT_NO = _("No");

View File

@ -30,11 +30,11 @@ def read_po(fp):
rvalue += line
elif line.startswith('msgid '):
st = 1
key = unquote(line[5:])
key = unquote(line[6:])
rkey = line
elif line.startswith('msgstr '):
st = 2
value = unquote(line[6:])
value = unquote(line[7:])
rvalue = line
else:
raise RuntimeError
@ -45,34 +45,29 @@ def read_po(fp):
def main():
import sys
# Read the current text catalog.
# Read the new text catalog template.
d = {}
firstcomment = ''
it = read_po(file(sys.argv[1]))
try:
(comment, key, value, rkey, rvalue) = it.next()
d[key] = rvalue
firstcomment = comment # Preserve the first comment block
except StopIteration:
pass
for (comment, key, value, rkey, rvalue) in it:
d[key] = rvalue
for (comment, key, value, rkey, rvalue) in read_po(sys.stdin):
d[key] = (comment, rkey, rvalue)
# Override existing entries with current text catalog.
for (comment, key, value, rkey, rvalue) in read_po(file(sys.argv[1])):
if d.has_key(key):
d[key] = (comment, rkey, rvalue)
# Read the new text catalog template and output.
# The translated values come from the current text catalog read above.
out = file(sys.argv[1], 'w')
out.write(firstcomment)
it = read_po(sys.stdin)
try:
(comment, key, value, rkey, rvalue) = it.next()
out.write(rkey)
out.write(d.get(key, rvalue))
except StopIteration:
pass
for (comment, key, value, rkey, rvalue) in it:
if d.has_key(''):
(comment, rkey, rvalue) = d['']
out.write(comment)
out.write(rkey)
out.write(d.get(key, rvalue))
out.write(rvalue)
del d['']
for key in sorted(d.keys()):
(comment, rkey, rvalue) = d[key]
out.write(comment)
out.write(rkey)
out.write(rvalue)
if __name__ == '__main__':
main()

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Extract the text catalog from the source code,
@ -18,14 +18,25 @@ trap "rm -f '$catalog' '$files'" 0 1 2 15
# Generate the new text catalog without the already translated texts.
# The 'merge existing' option for xgetext does not work propery for our purpose.
find . -name '*.java' -print > "$files"
find .. -name '*.java' -print > "$files"
xgettext -L Java --from-code=utf-8 -k_ --output="$catalog" --files-from="$files"
# Then, merge with already translated texts.
for target in *.po; do
echo "Updating $target..."
cat "$catalog" | python i18n_update.py "$target"
msgcat -p "$target" > $(basename "$target" .po).properties
update()
{
echo "Updating $1..."
cat "$catalog" | python i18n_update.py "$1"
msgcat -p "$1" > $(basename "$1" .po).properties
# msgcat may complain about "CHARSET" if you didn't replace "CHARSET" with
# your correct charset.
done
}
# Then, merge with already translated texts.
if [ $# = 0 ]; then
for target in *.po; do
update $target
done
else
for target in $*; do
update Resources_$target.po
done
fi