-
Notifications
You must be signed in to change notification settings - Fork 2
/
CurseForge_UpldateTranslations.sh
executable file
·51 lines (42 loc) · 1.66 KB
/
CurseForge_UpldateTranslations.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
#!/bin/bash
if [ -f ".env" ]; then
. ".env"
fi
declare -A translationStrings
translationTempFile=$(mktemp)
regex='L\[\"([^]]+)\"\]'
projectID=299998
process_addon_translations(){
while read -r line || [ -n "$line" ] ; do
if [[ $line =~ $regex ]] ; then
translationStrings["${BASH_REMATCH[1]}"]=true
fi
done < <(cat "$1" | grep -oP $regex);
}
while IFS= read -r -d '' line; do
process_addon_translations "$line"
done < <(find . -type f -name "*.lua" -not -path "*/Locales/*" -not -path "*/Libs/*" -not -path "*/.release/*" -print0)
for x in "${!translationStrings[@]}"; do
printf "L[\"%s\"] = %s\n" "$x" "${translationStrings[$x]}" >> "$translationTempFile"
done
#language: "enUS", //[enUS, deDE, esES, ect], Required, No Default
# namespace: "toc", //Any namespace name, comma delimited. Default: Base Namespace
# formatType: TableAdditions, //['GlobalStrings','TableAdditions','SimpleTable']. Default: TableAdditions
# missing-phrase-handling: DoNothing //['DoNothing', 'DeleteIfNoTranslations', 'DeleteIfTranslationsOnlyExistForSelectedLanguage', 'DeletePhrase']. Default: DoNothing
# localizations: "Localizations To Import"
result=$( curl -sS -0 -o /dev/null -X POST -w "%{http_code}" \
-H "X-Api-Token: $CF_API_KEY" \
-F "metadata={ language: \"enUS\", formatType: \"TableAdditions\", \"missing-phrase-handling\": \"DeletePhrase\" }" \
-F "localizations=<$translationTempFile" \
"https://legacy.curseforge.com/api/projects/$projectID/localization/import"
) || exit 1
case $result in
200)
echo "Exported localisation string to curse forge."
exit 0
;;
*)
echo -e "Error exporting localisation to curse forge. Response:\n $result \n"
exit 1
;;
esac