mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(dev) script to upload i18n files to crowdin
This commit is contained in:
parent
80825a2113
commit
777bb1e5cd
3
.gitignore
vendored
3
.gitignore
vendored
@ -54,8 +54,9 @@
|
||||
.vagrant
|
||||
.docker
|
||||
|
||||
# Do not versionate coveralls token
|
||||
# Do not versionate access tokens
|
||||
.coveralls.yml
|
||||
.crowdin
|
||||
|
||||
# Plugins are versioned is their own repository
|
||||
/plugins/*
|
||||
|
65
scripts/translations/upload.sh
Executable file
65
scripts/translations/upload.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
jq() {
|
||||
docker run --rm -i -v "${PWD}:/data" --user "$UID" imega/jq "$@"
|
||||
}
|
||||
|
||||
config() {
|
||||
PROJECT_ID="382064"
|
||||
SCRIPT_PATH=$(dirname "$0")
|
||||
TOKEN_FILE="$SCRIPT_PATH/../../.crowdin"
|
||||
if test -f "$TOKEN_FILE"; then
|
||||
ACCESS_TOKEN=$(cat "$TOKEN_FILE")
|
||||
else
|
||||
printf "\e[91m[ ❌] file %s does not exists.\e[0m Please configure your API access token first.\n" "$(basename "$TOKEN_FILE")"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
authorization() {
|
||||
echo "Authorization: Bearer $ACCESS_TOKEN"
|
||||
}
|
||||
|
||||
add_storage() {
|
||||
# param: FILE_PATH
|
||||
data=$(curl -s --data-binary "@$1" https://api.crowdin.com/api/v2/storages -H "$(authorization)" -H "Crowdin-API-FileName: $(basename "$1")" -H "Content-Type: text/yaml")
|
||||
echo "$data" | jq -r '.data.id'
|
||||
}
|
||||
|
||||
list_files() {
|
||||
curl -s "https://api.crowdin.com/api/v2/projects/$PROJECT_ID/files" -H "$(authorization)"
|
||||
}
|
||||
|
||||
update_file() {
|
||||
# params: FILE_ID, STORAGE_ID
|
||||
curl -s -X PUT "https://api.crowdin.com/api/v2/projects/$PROJECT_ID/files/$1" -H "$(authorization)" -H "Content-Type: application/json" -d "{ \"storageId\": $2, \"updateOption\": \"keep_translations_and_approvals\" }"
|
||||
}
|
||||
|
||||
find_file_id() {
|
||||
# param : FILE_PATH
|
||||
filename=$(basename "$1")
|
||||
list_files | jq -c "[ .data[] | select( .data.name == \"$filename\") ]" | jq -r ".[].data.id"
|
||||
}
|
||||
|
||||
function trap_ctrlc()
|
||||
{
|
||||
echo "Ctrl^C, exiting..."
|
||||
exit 2
|
||||
}
|
||||
|
||||
run() {
|
||||
trap "trap_ctrlc" 2 # SIGINT
|
||||
config
|
||||
for file in "$SCRIPT_PATH"/../../config/locales/*en.yml; do
|
||||
if [[ ! "$file" =~ rails && ! "$file" =~ base && ! "$file" =~ devise ]]; then
|
||||
printf "\n\e[0;33m ⇧ uploading %s...\n\e[0m" "$(basename "$file")"
|
||||
storageId=$(add_storage "$file")
|
||||
update_file "$(find_file_id "$file")" "$storageId"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
run "$@"
|
Loading…
x
Reference in New Issue
Block a user