forked from mirrors/linphone-iphone
i18n: add script to update .strings files
This commit is contained in:
parent
f1243168ed
commit
d111b84d6f
5 changed files with 100 additions and 3 deletions
|
|
@ -1,5 +1,25 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2012 Belledonne Comunications, Grenoble, France
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Created by Gautier Pelloux-Prayer on 2014.
|
||||
# Generate English translation files so that they can be pushed to Transifex
|
||||
# for translation
|
||||
|
||||
root_directory=$(cd "$(dirname $0)" && pwd)/../
|
||||
|
||||
set -e
|
||||
76
Tools/i18n_update_strings_files.py
Executable file
76
Tools/i18n_update_strings_files.py
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2012 Belledonne Comunications, Grenoble, France
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
# Created by Gautier Pelloux-Prayer on 2014.
|
||||
# Update non-English translation by regenerating .strings files and reapplying
|
||||
# existing translations after that
|
||||
|
||||
import codecs
|
||||
import re
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
kvpattern = re.compile('^(.*) = (.*);$')
|
||||
|
||||
|
||||
def find_english_for_key(file, key):
|
||||
with codecs.open(file, 'r', 'utf-16') as fp:
|
||||
for line in fp:
|
||||
match = kvpattern.match(line)
|
||||
|
||||
if match is None:
|
||||
continue
|
||||
|
||||
if key == match.groups()[0]:
|
||||
return match.groups()[1]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def update_messages_for_file(old_file, new_file):
|
||||
translations = {}
|
||||
with codecs.open(old_file, 'r', 'utf-16') as fp:
|
||||
for line in fp:
|
||||
match = kvpattern.match(line)
|
||||
|
||||
if match is None:
|
||||
continue
|
||||
|
||||
english_value = find_english_for_key(new_file, match.groups()[0])
|
||||
foreign_value = match.groups()[1]
|
||||
|
||||
translations[english_value] = foreign_value
|
||||
with codecs.open(new_file, 'r', 'utf-16') as f:
|
||||
lines = f.read()
|
||||
for english_value, foreign_value in translations.items():
|
||||
print("replace {} with {}".format(english_value, foreign_value))
|
||||
lines = lines.replace("{};".format(english_value), "{};".format(foreign_value))
|
||||
with codecs.open(new_file, 'w', 'utf-16') as f1:
|
||||
f1.write(lines)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: {} English.strings CustomLanguage.strings".format(sys.argv[0]))
|
||||
print("CustomLanguage.strings will be modified to take all English strings with its own translations")
|
||||
else:
|
||||
new_file = sys.argv[2] + ".new"
|
||||
shutil.copyfile(sys.argv[1], new_file)
|
||||
if (update_messages_for_file(sys.argv[2], new_file)):
|
||||
shutil.move(new_file, sys.argv[2])
|
||||
|
|
@ -328,7 +328,8 @@ pull-transifex:
|
|||
\ttx pull -af
|
||||
|
||||
push-transifex:
|
||||
\t&& ./Tools/generate_strings_files.sh && tx push -s -t -f --no-interactive
|
||||
\t./Tools/i18n_generate_strings_files.sh && \\
|
||||
\ttx push -s -t -f --no-interactive
|
||||
|
||||
zipres:
|
||||
\t@tar -czf ios_assets.tar.gz Resources iTunesArtwork
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit cfd87c55acee96699ce8306a3734b477fee3a00a
|
||||
Subproject commit a8e42a55d48404634ed95664a234aa3514be941a
|
||||
|
|
@ -173,7 +173,7 @@ pull-transifex:
|
|||
cd ../../ && tx pull -af
|
||||
|
||||
push-transifex:
|
||||
cd ../../ && ./Tools/generate_strings_files.sh && tx push -s -t -f --no-interactive
|
||||
cd ../../ && ./Tools/i18n_generate_strings_files.sh && tx push -s -t -f --no-interactive
|
||||
|
||||
zipres:
|
||||
@tar -C ../.. -czf ../../ios_assets.tar.gz Resources iTunesArtwork
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue