forked from boek/ios-l10n-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-locales.sh
executable file
·151 lines (132 loc) · 5.34 KB
/
export-locales.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /usr/bin/env bash
#
# Assumes the following is installed:
#
# git
# brew
# python via brew
# virtualenv via pip in brew
#
# Syntax is:
# ./export-locales.sh (name of project file) (name of l10n repo) (name of xliff file) [clean]
#
# We can probably check all that for the sake of running this hands-free
# in an automated manner.
#
clean_run=false
if [ $# -ge 3 ]
then
if [ $# -eq 4 ]
then
if [ "$4" == "clean" ]
then
clean_run=true
else
echo "Unknown parameter: $4"
echo "Leave empty to reuse an existing venv, use 'clean' to create a new one"
exit 1
fi
fi
xcodeproj="$1"
l10n_repo="$2"
l10n_file="$3"
else
echo "Not enough parameters."
echo "Syntax: ./export-locales.sh (name of .xcodeproj file) (name of l10n repo) (name of xliff file) [clean]"
echo "Example: ./export-locales.sh Client.xcodeproj firefoxios-l10n firefox-ios.xliff clean"
echo "You should call this script via wrappers like export-locales-firefox.sh"
exit 1
fi
if [ ! -d ${xcodeproj} ]
then
echo "Please run this from the project root that contains ${xcodeproj}"
exit 1
fi
if [ -d ${l10n_repo} ]
then
echo "There already is a ${l10n_repo} checkout. Aborting to let you decide what to do."
exit 1
fi
SDK_PATH=`xcrun --show-sdk-path`
SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# If the virtualenv with the Python modules that we need doesn't exist,
# or a clean run was requested, create the virtualenv.
if [ ! -d export-locales-env ] || [ "${clean_run}" = true ]
then
rm -rf export-locales-env || exit 1
echo "Setting up new virtualenv..."
virtualenv export-locales-env --python=python2.7 || exit 1
source export-locales-env/bin/activate || exit 1
# install libxml2
CFLAGS=-I"$SDK_PATH/usr/include/libxml2" LIBXML2_VERSION=2.9.2 pip install lxml || exit 1
else
echo "Reusing existing virtualenv found in export-locales-env"
source export-locales-env/bin/activate || exit 1
fi
# Check out a clean copy of the l10n repo
git clone https://github.com/mozilla-l10n/${l10n_repo} || exit 1
# Export English base to /tmp/en.xliff
rm -f /tmp/en.xliff || exit 1
rm -f "/tmp/en.xcloc/Localized Contents/en.xliff" # for Xcode >= 10
echo "Exporting en-US with xcodebuild"
xcodebuild -exportLocalizations -localizationPath /tmp -project ${xcodeproj} -exportLanguage en || exit 1
if [ -f "/tmp/en.xcloc/Localized Contents/en.xliff" ]
then
# Xcode >= 10 puts the file in en.xcloc
cp "/tmp/en.xcloc/Localized Contents/en.xliff" /tmp/en.xliff || exit 1
fi
if [ ! -f /tmp/en.xliff ]
then
echo "Export failed. No /tmp/en.xliff generated."
exit 1
fi
# Fix the Focus export
/usr/bin/perl -p -i -e "s|Blockzilla/en.lproj/Intro.strings|Blockzilla/Intro.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|Blockzilla/en.lproj/InfoPlist.strings|Blockzilla/InfoPlist.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|Blockzilla/en.lproj/Intro.strings|Blockzilla/Intro.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|Blockzilla/en.lproj/Intents.strings|Blockzilla/Intents.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|ContentBlocker/en.lproj/InfoPlist.strings|ContentBlocker/InfoPlist.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|OpenInFocus/en.lproj/InfoPlist.strings|OpenInFocus/InfoPlist.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|CredentialProvider/en.lproj/InfoPlist.strings|CredentialProvider/InfoPlist.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|CredentialProvider/en.lproj/Localizable.strings|CredentialProvider/Localizable.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|lockbox-ios/Common/Resources/en.lproj/InfoPlist.strings|lockbox-ios/Common/Resources/InfoPlist.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|lockbox-ios/Common/Resources/Strings/en.lproj/Localizable.strings|lockbox-ios/Common/Resources/Strings/Localizable.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|Shared/Supporting Files/Intro.strings|Client/Intro.strings|g" /tmp/en.xliff
/usr/bin/perl -p -i -e "s|Shared/Supporting Files/Storage.strings|Storage.strings|g" /tmp/en.xliff
# Create a branch in the repository
cd ${l10n_repo}
branch_name=$(date +"%Y%m%d_%H%M")
git branch ${branch_name}
git checkout ${branch_name}
# Copy the English XLIFF file into the repository and commit
cp /tmp/en.xliff en-US/${l10n_file} || exit 1
git add en-US/${l10n_file}
git commit -m "en-US: update ${l10n_file}"
# Update all locales
${SCRIPTS}/update-xliff.py . ${l10n_file} || exit 1
# Commit each locale separately
locale_list=$(find . -mindepth 1 -maxdepth 1 -type d \( ! -iname ".*" \) | sed 's|^\./||g' | sort)
for locale in ${locale_list};
do
# Exclude en-US and templates
if [ "${locale}" != "en-US" ] && [ "${locale}" != "templates" ]
then
git add ${locale}/${l10n_file}
git commit -m "${locale}: Update ${l10n_file}"
fi
done
# Copy the en-US file in /templates
cp en-US/${l10n_file} templates/${l10n_file} || exit 1
# Clean up /templates removing target-language and translations
${SCRIPTS}/clean-xliff.py templates ${l10n_file} || exit 1
git add templates/${l10n_file}
git commit -m "templates: update ${l10n_file}"
echo
echo "NOTE"
echo "NOTE Use the following command to push the branch to Github where"
echo "NOTE you can create a Pull Request:"
echo "NOTE"
echo "NOTE cd ${l10n_repo}"
echo "NOTE git push --set-upstream origin $branch_name"
echo "NOTE"
echo