From d111b84d6fc1b0971b1e5f129a10129349972058 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 25 Jun 2015 15:51:04 +0200 Subject: [PATCH] i18n: add script to update .strings files --- ...iles.sh => i18n_generate_strings_files.sh} | 20 +++++ Tools/i18n_update_strings_files.py | 76 +++++++++++++++++++ prepare.py | 3 +- submodules/belle-sip | 2 +- submodules/build/Makefile | 2 +- 5 files changed, 100 insertions(+), 3 deletions(-) rename Tools/{generate_strings_files.sh => i18n_generate_strings_files.sh} (80%) create mode 100755 Tools/i18n_update_strings_files.py diff --git a/Tools/generate_strings_files.sh b/Tools/i18n_generate_strings_files.sh similarity index 80% rename from Tools/generate_strings_files.sh rename to Tools/i18n_generate_strings_files.sh index b4ef23abc..6c18305cb 100755 --- a/Tools/generate_strings_files.sh +++ b/Tools/i18n_generate_strings_files.sh @@ -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 diff --git a/Tools/i18n_update_strings_files.py b/Tools/i18n_update_strings_files.py new file mode 100755 index 000000000..966923c5c --- /dev/null +++ b/Tools/i18n_update_strings_files.py @@ -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]) diff --git a/prepare.py b/prepare.py index 8022d53d9..ae27c19ff 100755 --- a/prepare.py +++ b/prepare.py @@ -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 diff --git a/submodules/belle-sip b/submodules/belle-sip index cfd87c55a..a8e42a55d 160000 --- a/submodules/belle-sip +++ b/submodules/belle-sip @@ -1 +1 @@ -Subproject commit cfd87c55acee96699ce8306a3734b477fee3a00a +Subproject commit a8e42a55d48404634ed95664a234aa3514be941a diff --git a/submodules/build/Makefile b/submodules/build/Makefile index c724b9165..756be5d91 100644 --- a/submodules/build/Makefile +++ b/submodules/build/Makefile @@ -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