Skip to content

Commit 2a36274

Browse files
committed
Update translations Scripts
1 parent 59b7926 commit 2a36274

12 files changed

Lines changed: 395 additions & 268 deletions

Scripts/LocalizationInstructions.md

Lines changed: 111 additions & 89 deletions
Large diffs are not rendered by default.

Scripts/archive_translations.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ set -u
99
source Scripts/define_common.sh
1010

1111
# 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}")
12+
if [[ -e "${MESSAGE_FILE}" ]]; then
13+
message_string=$(<"${MESSAGE_FILE}")
1414
else
1515
message_string="message not defined"
1616
fi
1717
echo "message_string = ${message_string}"
1818

19-
for project in ${projects}; do
20-
echo "Archive ${translation_branch} branch for $project"
19+
for project in ${PROJECTS}; do
20+
echo "Archive ${TRANSLATION_BRANCH} branch for $project"
2121
IFS=":" read user dir branch <<< "$project"
2222
echo "parts = $user $dir $branch"
2323
cd $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}
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}
2828
git add .
2929
if git commit -m "${message_string}"; then
30-
echo "updated $dir with ${message_string} in ${archive_branch} branch"
30+
echo "updated $dir with ${message_string} in ${ARCHIVE_BRANCH} branch"
3131
fi
32-
git branch -D ${translation_branch}
32+
git branch -D ${TRANSLATION_BRANCH}
3333
fi
3434
cd -
3535
done
@@ -38,4 +38,3 @@ git submodule update
3838
git status
3939

4040
echo "You may need to manually clean branches not in the project list"
41-

Scripts/define_common.sh

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

3-
# define variables used by more than one script
4-
# variables are:
5-
# message_file
6-
# archive_branch
7-
# translation_branch
8-
# projects
3+
# define parameters and arrays used by more than one script
4+
# These are always capitalized
5+
# First two can be replaced with arguments
6+
# TRANSLATION_BRANCH (arg 1)
7+
# TARGET_LOOPWORKSPACE_BRANCH (arg 2)
8+
# MESSAGE_FILE
9+
# ARCHIVE_BRANCH
10+
# PROJECTS
911
# LANGUAGES
1012

1113
# include this file in each script using
1214
# source Scripts/define_commont.sh
1315

14-
# define name of file used to save the commit message and title for pull requests
15-
message_file="xlate_message_file.txt"
16-
1716
# define the branch names used by the translation scripts
18-
archive_branch="archive_translations"
19-
translation_branch="translations"
20-
target_loopworkspace_branch="dev"
17+
# Any script that uses define_common can be called with one or two optional arguments
18+
# first argument replaces default for TRANSLATION_BRANCH
19+
# second argument replaces default for TARGET_LOOPWORKSPACE_BRANCH
20+
# Note: went for simplicity here - if you want to modify TARGET_LOOPWORKSPACE_BRANCH
21+
# via argument, you must also include TRANSLATION_BRANCH as an argument
22+
DEFAULT_TRANSLATION_BRANCH="translations"
23+
DEFAULT_TARGET_LOOPWORKSPACE_BRANCH="dev"
24+
25+
TRANSLATION_BRANCH=${1:-$DEFAULT_TRANSLATION_BRANCH}
26+
TARGET_LOOPWORKSPACE_BRANCH=${2:-$DEFAULT_TARGET_LOOPWORKSPACE_BRANCH}
27+
28+
ARCHIVE_BRANCH="archive_translations"
29+
30+
# define name of file used to save the commit message and title for pull requests
31+
MESSAGE_FILE="xlate_message_file.txt"
2132

2233
# define the languages used by the translation scripts
2334
# matches lokalise order, en plus alphabetical order by language name in English
@@ -46,8 +57,8 @@ LANGUAGES=(en \
4657
vi \
4758
)
4859

49-
# define the projects used by the translation scripts
50-
projects=( \
60+
# define the PROJECTS used by the translation scripts
61+
PROJECTS=( \
5162
LoopKit:AmplitudeService:dev \
5263
LoopKit:CGMBLEKit:dev \
5364
LoopKit:dexcom-share-client-swift:dev \
@@ -73,3 +84,26 @@ function section_divider() {
7384
echo -e "--------------------------------"
7485
echo -e ""
7586
}
87+
88+
function continue_or_quit() {
89+
local script_name=$1
90+
section_divider
91+
echo "Enter y to proceed, any other character exits"
92+
read query
93+
94+
if [[ ${query} != "y" ]]; then
95+
section_divider
96+
echo "User opted to exit ${script_name}."
97+
section_divider
98+
exit 1
99+
fi
100+
}
101+
102+
function next_script() {
103+
local next_script_name=$1
104+
if [[ ${TRANSLATION_BRANCH} == ${DEFAULT_TRANSLATION_BRANCH} ]]; then
105+
echo "$next_script_name"
106+
else
107+
echo "$next_script_name ${TRANSLATION_BRANCH}"
108+
fi
109+
}

Scripts/import_localizations.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ lokalise2 \
2727
--replace-breaks=false \
2828
--unzip-to ./xliff_in
2929

30-
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)
30+
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)
3131

32-
for project in ${projects}; do
32+
for project in ${PROJECTS}; do
3333
echo "Prepping $project"
3434
IFS=":" read user dir branch <<< "$project"
3535
echo "parts = $user $dir $branch"
@@ -52,7 +52,7 @@ end
5252

5353

5454
# Generate branches, commit and push.
55-
for project in ${projects}; do
55+
for project in ${PROJECTS}; do
5656
echo "Commiting $project"
5757
IFS=":" read user dir branch <<< "$project"
5858
echo "parts = $user $dir $branch"
@@ -68,7 +68,7 @@ for project in ${projects}; do
6868
done
6969

7070
# Reset
71-
#for project in ${projects}; do
71+
#for project in ${PROJECTS}; do
7272
# echo "Commiting $project"
7373
# IFS=":" read user dir branch <<< "$project"
7474
# echo "parts = $user $dir $branch"

Scripts/manual_LoopWorkspace_prepare_pr.sh

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,62 @@
33
set -e
44
set -u
55

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
6+
# this script prepares a PR for LoopWorkspace based on current local branch
117

128
source Scripts/define_common.sh
139

1410
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"
11+
echo "You are running ${0}"
12+
echo " You must be in the LoopWorkspace folder ready to commit changes to"
13+
echo " tracked files in this clone, see 'git status' results below:"
14+
section_divider
15+
git status
16+
section_divider
17+
echo "This script will prepare a PR to LoopWorkspace '${TARGET_LOOPWORKSPACE_BRANCH}' branch"
18+
echo
19+
echo "1. If the local clone LoopWorkspace branch name is not already '${TRANSLATION_BRANCH}', then"
2320
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"
21+
echo "2. The commit message in the ${MESSAGE_FILE} will be used"
22+
cat ${MESSAGE_FILE}
23+
echo "3. Once the PR is prepared, additional commits can be added as needed"
2824

29-
section_divider
25+
continue_or_quit ${0}
3026

31-
echo "Enter y to proceed, any other character exits"
32-
read query
27+
current_branch=$(git branch --show-current 2>/dev/null)
28+
echo "current_branch = $current_branch"
3329

34-
if [[ ${query} == "y" ]]; then
30+
if [[ "${current_branch}" == "${TRANSLATION_BRANCH}" ]]; then
31+
echo "already on $TRANSLATION_BRANCH, ok to continue"
3532

36-
current_branch=$(git branch --show-current 2>/dev/null)
37-
echo "current_branch = $current_branch"
33+
elif [ -n "$(git branch --list "$TRANSLATION_BRANCH")" ]; then
34+
echo "Local branch '$TRANSLATION_BRANCH' exists."
35+
echo "You are on '$current_branch' and '$TRANSLATION_BRANCH' already exists"
36+
echo "quitting"
37+
exit 1 # exit with failure
3838

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
39+
else
40+
echo "Local branch $TRANSLATION_BRANCH does not exist,"
41+
echo "creating $TRANSLATION_BRANCH from the current branch, $current_branch."
42+
git switch -c "${TRANSLATION_BRANCH}"
43+
fi
5344

54-
section_divider
45+
continue_or_quit ${0}
5546

56-
./Scripts/update_submodule_refs.sh
47+
# only create a PR if there are changes
48+
if git commit -a -F "${MESSAGE_FILE}"; then
49+
git push --set-upstream origin ${TRANSLATION_BRANCH}
50+
pr=$(gh pr create -B ${TARGET_LOOPWORKSPACE_BRANCH} --fill 2>&1 | grep http)
51+
echo "PR = $pr"
52+
open $pr
5753

5854
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
55+
echo "After you review, ${pr}, get approvals and merge the PR"
56+
echo " be sure to trim the '${TRANSLATION_BRANCH}' branch,"
57+
echo " and then run the export and upload scripts again from the updated '${TARGET_LOOPWORKSPACE_BRANCH}' branch"
58+
section_divider
7859

7960
else
8061
section_divider
81-
echo "user opted to exit the script"
62+
echo "No changes were found, no PR created"
8263
section_divider
8364
fi

Scripts/manual_cleanup.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,36 @@
99
set -e
1010
set -u
1111

12+
source Scripts/define_common.sh
13+
14+
section_divider
15+
echo "You are running ${0}"
16+
echo " Be sure you are completely done with the translation process"
17+
echo " or that you want to discard all your work to date"
18+
echo
1219
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"
20+
echo
1521
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 ""
22+
echo " This deletes the file, ${MESSAGE_FILE}, with the lokalise download timestamp"
23+
echo " This restores all submodules to their current branch (reset, clean)"
24+
25+
continue_or_quit ${0}
2126

22-
if [[ ${query} == "y" ]]; then
27+
rm -rf xclocs
28+
rm -rf xliff_in
29+
rm -rf xliff_out
30+
rm -f "${MESSAGE_FILE}"
2331

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"
32+
for project in ${PROJECTS}; do
33+
IFS=":" read user dir branch <<< "$project"
34+
echo "Reset and clean $dir"
35+
cd $dir
36+
git reset --hard; git clean -fd;
37+
cd -
38+
done
2939

30-
else
31-
echo "Exited without deleting folders and files"
3240

33-
fi
41+
section_divider
42+
echo "Temporary folders and ${MESSAGE_FILE} removed from LoopWorkspace"
43+
echo "All folders in PROJECTS reset and cleaned"
44+
section_divider

Scripts/manual_download_from_lokalise.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ date=`date`
1919

2020
source Scripts/define_common.sh
2121

22+
section_divider
23+
echo "You are running ${0}"
24+
echo " This requests localization files from lokalise"
25+
2226
# Fetch translations from lokalise
2327
rm -rf xliff_in
2428
lokalise2 \
2529
--token "$LOKALISE_TOKEN" \
2630
--project-id "414338966417c70d7055e2.75119857" \
2731
file download \
32+
--async\
2833
--format xliff \
2934
--bundle-structure "%LANG_ISO%.%FORMAT%" \
3035
--original-filenames=false \
@@ -33,14 +38,17 @@ lokalise2 \
3338
--replace-breaks=false \
3439
--unzip-to ./xliff_in
3540

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}"
41+
# create xlate_pr_title.txt using the date of the import from localize
42+
# this overwrites any existing file because we want to capture the date of the latest download
4043

41-
echo "The standard translation commit message is stored in ${message_file}"
44+
section_divider
45+
echo "Updated translations from lokalise on ${date}" > "${MESSAGE_FILE}"
46+
echo "The standard translation commit message is stored in ${MESSAGE_FILE}"
4247

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"
48+
section_divider
49+
echo "To import from the xliff_in folder for each submodule, execute"
50+
echo "./Scripts/manual_import_localizations.sh"
51+
echo
52+
echo "If you prefer to use a path other than '${DEFAULT_TRANSLATION_BRANCH}',"
53+
echo " add that as the first argument on the import script"
54+
section_divider

0 commit comments

Comments
 (0)