-
Notifications
You must be signed in to change notification settings - Fork 0
/
transifex.sh
73 lines (69 loc) · 3.11 KB
/
transifex.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
#!/bin/bash
#colors
RED='\033[0;31m'
GREEN='\033[1;32m'
NC='\033[0m'
SOURCE_LANGUAGE="en"
if [ "$#" = 0 ]
then
echo -e "${RED}ERR${NC}: Usage = ${GREEN}./transifex.sh pt_BR de ${NC}or ${GREEN}./transifex all${NC}"
else
read -p "Enter Transifex Username: " USER
read -p "password: " -s PW
echo -e "\n----------------------------------\nchecking project info\n----------------------------------"
PROJECT_INFO=$( curl -L --user "$USER":"$PW" -X GET https://www.transifex.com/api/2/project/bigbluebutton-v22-html5-client/languages/ )
if [ "$PROJECT_INFO" == "Authorization Required" ]
then
echo -e "${RED}Err${NC} : $PROJECT_INFO"
else
echo -e "Project Information Found :${GREEN} ✓${NC}"
if [ "$PROJECT_INFO" == "Forbidden" ]
then
echo -e "${RED}Err${NC}: Invalid User Permissions"
else
for ARG in "$@"
do
if [ "$ARG" == "all" ]
then
AVAILABLE_TRANSLATIONS=$( echo "$PROJECT_INFO" | grep 'language_code' | cut -d':' -f2 | tr -d '[",]' )
echo "$AVAILABLE_TRANSLATIONS" | while read l
do
LOCALE=$( echo "$l" | tr -d '[:space:]' )
if [ "$LOCALE" == "$SOURCE_LANGUAGE" ]; then
continue # do not pull the source file
fi
TRANSLATION=$(curl -L --user "$USER":"$PW" -X GET "https://www.transifex.com/api/2/project/bigbluebutton-v22-html5-client/resource/enjson/translation/$LOCALE/?mode=onlytranslated&file")
NO_EMPTY_STRINGS=$(echo "$TRANSLATION" | sed '/: *\"\"/D' | sed '/}$/D')
if [ $(echo "$NO_EMPTY_STRINGS" | wc -l) == 1 ]
then
echo -e "${RED}WARN:${NC} translation file $LOCALE.json is empty\n${RED}WARN:${NC} $LOCALE.json not created"
continue
else
NO_TRAILING_COMMA=$(echo "$NO_EMPTY_STRINGS" | sed '$ s/,$//')
echo "$NO_TRAILING_COMMA" > ./private/locales/"$LOCALE".json
echo -e "\n}\n" >> ./private/locales/"$LOCALE".json
echo -e "Added translation file $LOCALE.json : ${GREEN}✓${NC}"
fi
done
else
TRANSLATION=$(curl -L --user "$USER":"$PW" -X GET "https://www.transifex.com/api/2/project/bigbluebutton-v22-html5-client/resource/enjson/translation/$ARG/?mode=onlytranslated&file")
if [ "$TRANSLATION" == "Not Found" ]
then
echo -e "${RED}Err${NC}: Translations not found for locale ->${RED}$ARG${NC}<-"
else
NO_EMPTY_STRINGS=$(echo "$TRANSLATION" | sed '/: *\"\"/D' | sed '/}$/D')
if [ $(echo "$NO_EMPTY_STRINGS" | wc -l) == 1 ]
then
echo -e "${RED}WARN:${NC} translation file $ARG.json is empty\n${RED}WARN:${NC} $ARG.json not created"
else
NO_TRAILING_COMMA=$(echo "$NO_EMPTY_STRINGS" | sed '$ s/,//')
echo "$NO_TRAILING_COMMA" > ./private/locales/"$ARG".json
echo -e "\n}\n" >> ./private/locales/"$ARG".json
echo -e "Added translation file $ARG.json :${GREEN} ✓${NC}"
fi
fi
fi
done
fi
fi
fi