2017-08-03 02:11:33 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#colors
|
|
|
|
RED='\033[0;31m'
|
|
|
|
GREEN='\033[1;32m'
|
|
|
|
NC='\033[0m'
|
2018-01-26 00:41:25 +08:00
|
|
|
SOURCE_LANGUAGE="en"
|
2021-03-11 19:42:41 +08:00
|
|
|
LOCALES_DIRECTORY="./public/locales"
|
|
|
|
PULL_SOURCE=false
|
|
|
|
|
|
|
|
if [[ ! -e $LOCALES_DIRECTORY ]]; then
|
|
|
|
echo -e "Directory ${RED}$LOCALES_DIRECTORY${NC} does not exist, creating"
|
|
|
|
mkdir $LOCALES_DIRECTORY
|
|
|
|
PULL_SOURCE=true
|
|
|
|
fi
|
2017-08-03 02:11:33 +08:00
|
|
|
|
|
|
|
if [ "$#" = 0 ]
|
|
|
|
then
|
2018-01-20 04:44:25 +08:00
|
|
|
echo -e "${RED}ERR${NC}: Usage = ${GREEN}./transifex.sh pt_BR de ${NC}or ${GREEN}./transifex all${NC}"
|
2017-08-03 02:11:33 +08:00
|
|
|
else
|
2018-01-16 00:13:21 +08:00
|
|
|
read -p "Enter Transifex Username: " USER
|
|
|
|
read -p "password: " -s PW
|
|
|
|
echo -e "\n----------------------------------\nchecking project info\n----------------------------------"
|
2020-09-10 11:02:19 +08:00
|
|
|
PROJECT_INFO=$( curl -L --user "$USER":"$PW" -X GET https://www.transifex.com/api/2/project/bigbluebutton-v23-html5-client/languages/ )
|
2017-08-03 02:11:33 +08:00
|
|
|
|
2018-01-16 00:13:21 +08:00
|
|
|
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" ]
|
2018-01-26 00:02:15 +08:00
|
|
|
then
|
|
|
|
AVAILABLE_TRANSLATIONS=$( echo "$PROJECT_INFO" | grep 'language_code' | cut -d':' -f2 | tr -d '[",]' )
|
2017-08-03 02:11:33 +08:00
|
|
|
|
2018-01-16 00:13:21 +08:00
|
|
|
echo "$AVAILABLE_TRANSLATIONS" | while read l
|
2018-01-26 00:02:15 +08:00
|
|
|
do
|
|
|
|
LOCALE=$( echo "$l" | tr -d '[:space:]' )
|
2021-03-11 19:42:41 +08:00
|
|
|
if [ "$LOCALE" == "$SOURCE_LANGUAGE" ] && [ "$PULL_SOURCE" == false ]; then
|
|
|
|
continue # only pull source file if locales folder did not exist
|
2018-01-26 00:41:25 +08:00
|
|
|
fi
|
2020-09-10 11:02:19 +08:00
|
|
|
TRANSLATION=$(curl -L --user "$USER":"$PW" -X GET "https://www.transifex.com/api/2/project/bigbluebutton-v23-html5-client/resource/enjson/translation/$LOCALE/?mode=onlytranslated&file")
|
2018-01-26 00:02:15 +08:00
|
|
|
NO_EMPTY_STRINGS=$(echo "$TRANSLATION" | sed '/: *\"\"/D' | sed '/}$/D')
|
2021-03-11 19:42:41 +08:00
|
|
|
if [ $(echo "$NO_EMPTY_STRINGS" | wc -l) -lt 100 ]
|
2018-01-26 00:02:15 +08:00
|
|
|
then
|
2021-03-11 19:42:41 +08:00
|
|
|
echo -e "${RED}WARN:${NC} translation file $LOCALE.json contains less than 100 lines\n${RED}WARN:${NC} $LOCALE.json not created"
|
2018-01-26 00:02:15 +08:00
|
|
|
continue
|
|
|
|
else
|
|
|
|
NO_TRAILING_COMMA=$(echo "$NO_EMPTY_STRINGS" | sed '$ s/,$//')
|
2021-03-11 19:42:41 +08:00
|
|
|
echo "$NO_TRAILING_COMMA" > "$LOCALES_DIRECTORY/$LOCALE".json
|
|
|
|
echo -e "\n}\n" >> "$LOCALES_DIRECTORY/$LOCALE".json
|
2018-01-26 00:02:15 +08:00
|
|
|
echo -e "Added translation file $LOCALE.json : ${GREEN}✓${NC}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2020-09-10 11:02:19 +08:00
|
|
|
TRANSLATION=$(curl -L --user "$USER":"$PW" -X GET "https://www.transifex.com/api/2/project/bigbluebutton-v23-html5-client/resource/enjson/translation/$ARG/?mode=onlytranslated&file")
|
2018-01-26 00:02:15 +08:00
|
|
|
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')
|
2021-03-11 19:42:41 +08:00
|
|
|
if [ $(echo "$NO_EMPTY_STRINGS" | wc -l) -lt 100 ]
|
2018-01-26 00:02:15 +08:00
|
|
|
then
|
2021-03-11 19:42:41 +08:00
|
|
|
echo -e "${RED}WARN:${NC} translation file $ARG.json contains less than 100 lines\n${RED}WARN:${NC} $ARG.json not created"
|
2018-01-26 00:02:15 +08:00
|
|
|
else
|
|
|
|
NO_TRAILING_COMMA=$(echo "$NO_EMPTY_STRINGS" | sed '$ s/,//')
|
2021-03-11 19:42:41 +08:00
|
|
|
echo "$NO_TRAILING_COMMA" > "$LOCALES_DIRECTORY/$ARG".json
|
|
|
|
echo -e "\n}\n" >> "$LOCALES_DIRECTORY/$ARG".json
|
2018-01-26 00:02:15 +08:00
|
|
|
echo -e "Added translation file $ARG.json :${GREEN} ✓${NC}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2018-01-16 00:13:21 +08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
2017-08-03 02:11:33 +08:00
|
|
|
fi
|