-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathtranslation-management.sh
More file actions
executable file
·118 lines (97 loc) · 3.76 KB
/
translation-management.sh
File metadata and controls
executable file
·118 lines (97 loc) · 3.76 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Pretty printing functions
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function echored() {
echo -e "$RED$*$NORMAL"
}
function echogreen() {
echo -e "$GREEN$*$NORMAL"
}
function echoyellow() {
echo -e "$YELLOW$*$NORMAL"
}
if [ $# -lt 1 ]
then
echored "ERROR: not enough arguments supplied."
echo "Usage: translation-management.sh *action*"
echo " - action: import, export"
exit 1
fi
command="$1"
# Read path to local string repository from .env file
L10N_REPO=$(grep LOCAL_PATH_TO_L10N_REPO .env | cut -d '=' -f2)
L10N_REPO+="foundation/translations/"
CODE_REPO="foundation_cms/"
FOLDERS=(
"locale/"
"legacy_apps/locale/"
"legacy_apps/templates/pages/buyersguide/about/locale/"
"legacy_apps/wagtailpages/templates/wagtailpages/pages/locale/"
"legacy_apps/wagtailpages/templates/wagtailpages/pages/youtube-regrets-2021/locale/"
"legacy_apps/wagtailpages/templates/wagtailpages/pages/youtube-regrets-2022/locale/"
"legacy_apps/mozfest/locale/"
)
# Array of locale codes in ab-CD format that need to be converted into ab_CD for Django
LOCALES=(
"fy-NL"
"pt-BR"
)
case $command in
"import")
echogreen "Importing latest translation files from fomo-l10n repository"
for FOLDER in "${FOLDERS[@]}"; do
# Step 1: Reset Django folder(s)
echoyellow " Removing existing folder: ${CODE_REPO}${FOLDER}"
rm -rf "${CODE_REPO}${FOLDER}"
# Step 2: Copy l10n (source of truth) to Django
echoyellow " Copying l10n folder: ${L10N_REPO}${FOLDER} into ${CODE_REPO}${FOLDER}"
cp -r "${L10N_REPO}${FOLDER}" "${CODE_REPO}${FOLDER}"
# Step 3: Remove stray underscore-locale dirs / symlinks (cleanup)
for HYPHEN_LOCALE in "${LOCALES[@]}"; do
UNDERSCORE="${CODE_REPO}${FOLDER}${HYPHEN_LOCALE//-/_}"
if [[ -e "$UNDERSCORE" ]]; then
echoyellow " Removing stray underscore locale (usually symlinks): $UNDERSCORE"
rm -rf "$UNDERSCORE"
fi
done
# Step 4: Copy hyphenated → underscore for Django
for HYPHEN_LOCALE in "${LOCALES[@]}"; do
cp -r "${L10N_REPO}${FOLDER}${HYPHEN_LOCALE}/" "${CODE_REPO}${FOLDER}${HYPHEN_LOCALE//-/_}/"
# Step 5: Remove hyphenated l10n dirs since not needed in Django repo (i.e. pt-BR)
HYPHEN_LOCALE_PATH="${CODE_REPO}${FOLDER}${HYPHEN_LOCALE}"
if [[ -e "$HYPHEN_LOCALE_PATH" ]]; then
echoyellow " Removing hyphen locale from code repo: $HYPHEN_LOCALE_PATH"
rm -rf "$HYPHEN_LOCALE_PATH"
fi
done
done
;;
esac
case $command in
"export")
echogreen "Exporting generated translation files to fomo-l10n repository"
for FOLDER in "${FOLDERS[@]}"; do
# Step 1: Reset l10n folder(s)
echoyellow " Removing existing folder: ${L10N_REPO}${FOLDER}"
rm -rf "${L10N_REPO}${FOLDER}"
# Step 2: Copy Django (new source of truth) to l10n
echoyellow " Copying Django folder: ${CODE_REPO}${FOLDER} into ${L10N_REPO}${FOLDER}"
mkdir -p "${L10N_REPO}${FOLDER}"
cp -r "${CODE_REPO}${FOLDER}"* "${L10N_REPO}${FOLDER}"
# Step 3: Copy Django underscore dirs to l10n hyphen dirs for Pontoon (i.e. pt_BR in Django to pt-BR in l10n)
for HYPHEN_LOCALE in "${LOCALES[@]}"; do
cp -r "${CODE_REPO}${FOLDER}${HYPHEN_LOCALE//-/_}/" "${L10N_REPO}${FOLDER}${HYPHEN_LOCALE}/"
# Step 4: Remove underscore locale dirs in l10n since not needed in l10n repo (i.e. pt_BR)
UNDERSCORE_LOCALE_PATH="${L10N_REPO}${FOLDER}${HYPHEN_LOCALE//-/_}"
if [[ -e "$UNDERSCORE_LOCALE_PATH" ]]; then
echoyellow " Removing underscore locale from l10n: $UNDERSCORE_LOCALE_PATH"
rm -rf "$UNDERSCORE_LOCALE_PATH"
fi
done
done
;;
esac