-
Notifications
You must be signed in to change notification settings - Fork 153
/
translation-management.sh
executable file
·77 lines (63 loc) · 2.12 KB
/
translation-management.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
#!/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="network-api/"
FOLDERS=(
"locale/"
"networkapi/templates/pages/buyersguide/about/locale/"
"networkapi/wagtailpages/templates/wagtailpages/pages/locale/"
"networkapi/wagtailpages/templates/wagtailpages/pages/youtube-regrets-2021/locale/"
"networkapi/wagtailpages/templates/wagtailpages/pages/youtube-regrets-2022/locale/"
"networkapi/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
cp -r "${L10N_REPO}${FOLDER}" "${CODE_REPO}${FOLDER}"
# Django >=3.2 stopped processing locale codes containing hyphens, we need to move the files between the two folders
for HYPHEN_LOCALE in "${LOCALES[@]}"; do
cp -r "${L10N_REPO}${FOLDER}${HYPHEN_LOCALE}/" "${CODE_REPO}${FOLDER}${HYPHEN_LOCALE//-/_}/"
done
done
esac
case $command in
"export")
echogreen "Exporting generated translation files to fomo-l10n repository"
for FOLDER in "${FOLDERS[@]}"; do
cp -r "${CODE_REPO}${FOLDER}" "${L10N_REPO}${FOLDER}"
# Django >=3.2 stopped processing locale codes containing hyphens, we need to move the files between the two folders
for HYPHEN_LOCALE in "${LOCALES[@]}"; do
cp -r "${CODE_REPO}${FOLDER}${HYPHEN_LOCALE//-/_}/" "${L10N_REPO}${FOLDER}${HYPHEN_LOCALE}/"
done
done
esac