Skip to content

Commit c4d4743

Browse files
committed
add updated translation scripts and instructions to dev branch
1 parent ecb9bf4 commit c4d4743

13 files changed

+625
-239
lines changed

Scripts/LocalizationInstructions.md

Lines changed: 258 additions & 125 deletions
Large diffs are not rendered by default.

Scripts/archive_translations.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
#!/bin/zsh
22

3-
# archive previously created translation branches as test_translations as a "reset" action
3+
# archive previously created translation branches as a "reset" action
4+
# you can edit branch names in Scripts/define_common.sh prior to running
45

56
set -e
67
set -u
78

8-
date=`date`
9+
source Scripts/define_common.sh
910

10-
archive_dir="test_translations"
11-
translation_dir="translations"
12-
13-
projects=(LoopKit:AmplitudeService:dev LoopKit:CGMBLEKit:dev LoopKit:G7SensorKit:main LoopKit:LogglyService:dev LoopKit:Loop:dev LoopKit:LoopKit:dev LoopKit:LoopOnboarding:dev LoopKit:LoopSupport:dev LoopKit:NightscoutRemoteCGM:dev LoopKit:NightscoutService:dev LoopKit:OmniBLE:dev LoopKit:TidepoolService:dev LoopKit:dexcom-share-client-swift:dev LoopKit:RileyLinkKit:dev LoopKit:OmniKit:main LoopKit:MinimedKit:main LoopKit:LibreTransmitter:main)
11+
# use a common message with the time at which xliff files were downloaded from lokalise
12+
if [[ -e "${message_file}" ]]; then
13+
message_string=$(<"${message_file}")
14+
else
15+
message_string="message not defined"
16+
fi
17+
echo "message_string = ${message_string}"
1418

1519
for project in ${projects}; do
16-
echo "Archive ${translation_dir} branch for $project"
20+
echo "Archive ${translation_branch} branch for $project"
1721
IFS=":" read user dir branch <<< "$project"
1822
echo "parts = $user $dir $branch"
1923
cd $dir
20-
if git switch ${translation_dir}; then
21-
echo "in $dir, configure $archive_dir"
22-
git branch -D ${archive_dir} || true
23-
git switch -c ${archive_dir}
24+
if git switch ${translation_branch}; then
25+
echo "in $dir, configure $archive_branch"
26+
git branch -D ${archive_branch} || true
27+
git switch -c ${archive_branch}
2428
git add .
25-
if git commit -am "Updated translations from Lokalise on ${date}"; then
26-
echo "updated $dir with new translations in ${archive_dir} branch"
29+
if git commit -m "${message_string}"; then
30+
echo "updated $dir with ${message_string} in ${archive_branch} branch"
2731
fi
28-
git branch -D ${translation_dir}
32+
git branch -D ${translation_branch}
2933
fi
3034
cd -
3135
done

Scripts/define_common.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/zsh
2+
3+
# define variables used by more than one script
4+
# variables are:
5+
# message_file
6+
# archive_branch
7+
# translation_branch
8+
# projects
9+
# LANGUAGES
10+
11+
# include this file in each script using
12+
# source Scripts/define_commont.sh
13+
14+
# define name of file used to save the commit message and title for pull requests
15+
message_file="xlate_message_file.txt"
16+
17+
# define the branch names used by the translation scripts
18+
archive_branch="archive_translations"
19+
translation_branch="translations"
20+
target_loopworkspace_branch="dev"
21+
22+
# define the languages used by the translation scripts
23+
# matches lokalise order, en plus alphabetical order by language name in English
24+
LANGUAGES=(en \
25+
ar \
26+
zh-Hans \
27+
cs \
28+
da \
29+
nl \
30+
fi \
31+
fr \
32+
de \
33+
he \
34+
hi ]
35+
it \
36+
ja \
37+
nb \
38+
pl \
39+
pt-BR \
40+
ro \
41+
ru \
42+
sk \
43+
es \
44+
sv \
45+
tr \
46+
vi \
47+
)
48+
49+
# define the projects used by the translation scripts
50+
projects=( \
51+
LoopKit:AmplitudeService:dev \
52+
LoopKit:CGMBLEKit:dev \
53+
LoopKit:dexcom-share-client-swift:dev \
54+
loopandlearn:DanaKit:dev \
55+
LoopKit:G7SensorKit:main \
56+
LoopKit:LibreTransmitter:main \
57+
LoopKit:LogglyService:dev \
58+
LoopKit:Loop:dev \
59+
LoopKit:LoopKit:dev \
60+
LoopKit:LoopOnboarding:dev \
61+
LoopKit:LoopSupport:dev \
62+
LoopKit:MinimedKit:main \
63+
LoopKit:NightscoutRemoteCGM:dev \
64+
LoopKit:NightscoutService:dev \
65+
LoopKit:OmniBLE:dev \
66+
LoopKit:OmniKit:main \
67+
LoopKit:RileyLinkKit:dev \
68+
LoopKit:TidepoolService:dev \
69+
)
70+
71+
function section_divider() {
72+
echo -e ""
73+
echo -e "--------------------------------"
74+
echo -e ""
75+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/zsh
2+
3+
set -e
4+
set -u
5+
6+
# this script prepares a branch of LoopWorkspace based on current local branch.
7+
# It brings in the tip of all the submodule branches which should have just
8+
# been updated with the manual download, import, review and finalize scripts.
9+
# After all those PR are merged and the translation branches trimmed,
10+
# the next step is to prepare the PR to update LoopWorkspace dev branch
11+
12+
source Scripts/define_common.sh
13+
14+
section_divider
15+
16+
echo "You must be in the LoopWorkspace folder ready to bring in "
17+
echo " all the latest versions of the submodules which were "
18+
echo " just translated"
19+
echo ""
20+
echo "This script will prepare a PR to LoopWorkspace '${target_loopworkspace_branch}' branch"
21+
echo ""
22+
echo "1. If the branch name is not already '${translation_branch}', then"
23+
echo " that branch will be created and used for this PR"
24+
echo "2. ./Scripts/update_submodule_refs.sh will be executed"
25+
echo "3. The commit message in the ${message_file} will be used"
26+
cat ${message_file}
27+
echo "4. Once the PR is prepared, additional commits can be added as needed"
28+
29+
section_divider
30+
31+
echo "Enter y to proceed, any other character exits"
32+
read query
33+
34+
if [[ ${query} == "y" ]]; then
35+
36+
current_branch=$(git branch --show-current 2>/dev/null)
37+
echo "current_branch = $current_branch"
38+
39+
if [[ "${current_branch}" == "${translation_branch}" ]]; then
40+
echo "already on $translation_branch, ok to continue"
41+
42+
elif [ -n "$(git branch --list "$translation_branch")" ]; then
43+
echo "Local branch '$translation_branch' exists."
44+
echo "You are on '$current_branch' and '$translation_branch' already exists"
45+
echo "quitting"
46+
exit 1 # exit with failure
47+
48+
else
49+
echo "Local branch $translation_branch does not exist,"
50+
echo "creating $translation_branch from the current branch, $current_branch."
51+
git switch -c "${translation_branch}"
52+
fi
53+
54+
section_divider
55+
56+
./Scripts/update_submodule_refs.sh
57+
58+
section_divider
59+
60+
# only create a PR if there are changes
61+
if git commit -a -F "${message_file}"; then
62+
git push --set-upstream origin ${translation_branch}
63+
pr=$(gh pr create -B ${target_loopworkspace_branch} --fill 2>&1 | grep http)
64+
echo "PR = $pr"
65+
open $pr
66+
67+
section_divider
68+
echo "After you review, ${pr}, get approvals and merge the PR"
69+
echo " be sure to trim the '${translation_branch}' branch,"
70+
echo " and then run the export and upload scripts again from the updated '${target_loopworkspace_branch}' branch"
71+
section_divider
72+
73+
else
74+
section_divider
75+
echo "No changes were found, no PR created"
76+
section_divider
77+
fi
78+
79+
else
80+
section_divider
81+
echo "user opted to exit the script"
82+
section_divider
83+
fi

Scripts/manual_cleanup.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/zsh
2+
3+
# This script deletes temporary files and directories created during the translation process
4+
# You must be in the LoopWorkspace folder
5+
6+
# ensure you really want to do this before executing with:
7+
# ./Scripts/manual_cleanup.sh
8+
9+
set -e
10+
set -u
11+
12+
echo " /////////// WARNING ///////////"
13+
echo "Be sure you are completely done with the translations process or"
14+
echo " that you want to discard all your work to date"
15+
echo " This deletes the xclocs, xliff_in, xliff_out folders"
16+
echo " This deletes the standard title for the PRs for submodules and LoopWorkspace"
17+
echo ""
18+
echo "Enter y return to continue, any other key to quit"
19+
read query
20+
echo ""
21+
22+
if [[ ${query} == "y" ]]; then
23+
24+
rm -rf xclocs
25+
rm -rf xliff_in
26+
rm -rf xliff_out
27+
rm "${message_file}"
28+
echo "Temporary folders and ${message_file} removed from LoopWorkspace"
29+
30+
else
31+
echo "Exited without deleting folders and files"
32+
33+
fi
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/zsh
2+
3+
# This script will import the latest translations from lokalise and
4+
# generate a standard commit message for subsequent pull requires
5+
6+
# Install the lokalise command line tools from https://github.com/lokalise/lokalise-cli-2-go
7+
# Generate an API Token (not an SDK Token!) following the instructions here: https://docs.lokalise.com/en/articles/1929556-api-tokens
8+
# export LOKALISE_TOKEN="<yourtokenhere>"
9+
10+
# You must be in the LoopWorkspace folder before executing with:
11+
# ./Scripts/manual_download_from_lokalise.sh
12+
13+
set -e
14+
set -u
15+
16+
: "$LOKALISE_TOKEN"
17+
18+
date=`date`
19+
20+
source Scripts/define_common.sh
21+
22+
# Fetch translations from lokalise
23+
rm -rf xliff_in
24+
lokalise2 \
25+
--token "$LOKALISE_TOKEN" \
26+
--project-id "414338966417c70d7055e2.75119857" \
27+
file download \
28+
--format xliff \
29+
--bundle-structure "%LANG_ISO%.%FORMAT%" \
30+
--original-filenames=false \
31+
--placeholder-format ios \
32+
--export-empty-as skip \
33+
--replace-breaks=false \
34+
--unzip-to ./xliff_in
35+
36+
# create the temporary file xlate_pr_title.txt using the date of the import from localize
37+
# this overwrites any existing file because we want to capture the date of the actual download
38+
39+
echo "Updated translations from lokalise on ${date}" > "${message_file}"
40+
41+
echo "The standard translation commit message is stored in ${message_file}"
42+
43+
echo ""
44+
echo "Continue by reviewing the importing the files in xliff_in"
45+
echo " for each submodule with command:"
46+
echo "./Scripts/manual_import_localizations.sh"

Scripts/manual_export_localizations.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/bin/zsh
22

3+
# This script creates the xliff files suitable to upload to lokalise
4+
5+
# You must be in the LoopWorkspace folder before executing with:
6+
# ./Scripts/manual_export_localizations.sh
7+
38
set -e
49
set -u
510

6-
LANGUAGES=(ar cs ru en zh-Hans nl fr de it nb pl es ja pt-BR vi da sv fi ro tr he sk hi)
11+
source Scripts/define_common.sh
712

813
argstring="${LANGUAGES[@]/#/-exportLanguage }"
914
IFS=" "; args=( $=argstring )
@@ -13,3 +18,6 @@ xcodebuild -scheme LoopWorkspace -exportLocalizations -localizationPath xclocs $
1318
mkdir -p xliff_out
1419
find xclocs -name '*.xliff' -exec cp {} xliff_out \;
1520

21+
echo ""
22+
echo "Next step is to upload the xliff_out files to lokalise with"
23+
echo "./Scripts/manual_upload_to_lokalise.sh"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/zsh
2+
3+
set -e
4+
set -u
5+
6+
# this script commits the changes to translations branch, pushes and opens PR
7+
8+
source Scripts/define_common.sh
9+
10+
for project in ${projects}; do
11+
echo "Commiting $project"
12+
IFS=":" read user dir branch <<< "$project"
13+
echo "parts = $user $dir $branch"
14+
cd $dir
15+
git add .
16+
# skip repositories with no changes
17+
if git commit -F "../${message_file}"; then
18+
git push --set-upstream origin ${translation_branch}
19+
pr=$(gh pr create -B $branch -R $user/$dir --fill 2>&1 | grep http)
20+
echo "PR = $pr"
21+
open $pr
22+
fi
23+
cd -
24+
done

0 commit comments

Comments
 (0)