-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathupdate_locale.sh
68 lines (52 loc) · 1.87 KB
/
update_locale.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
#!/bin/bash
#
# Pull the localization data from CurseForge
#
# Setup:
# Ensure this environment variable is set!
#
# CF_API_TOKEN
#
# Raider.IO Project ID
CF_PROJECT_ID=279257
LOCALE_FOLDER=$1
if [ ! -d "$LOCALE_FOLDER" ]; then
echo "Usage: $0 <locale_folder>"
exit 1
fi
echo "Updating latest locale files from CurseForge..."
CF_LOCALE_FILE=locale_temp_cf.$$
for locale in deDE esES frFR itIT koKR ptBR ruRU zhCN zhTW ; do
# where we will write out the newly created locale file
NEW_LOCALE_FILE=locale_temp_new.$$
curl -s -H "x-api-token: $CF_API_TOKEN" -XGET "https://wow.curseforge.com/api/projects/$CF_PROJECT_ID/localization/export?table-name=L&export-type=TableAdditions&unlocalized=ShowBlankAsComment&lang=$locale" > $CF_LOCALE_FILE
if [ "x$?" != "x0" ]; then
echo "Failed to get locale $locale"
rm $CF_LOCALE_FILE
exit 1
fi
grep 'L = L or' $CF_LOCALE_FILE > /dev/null
if [ "x$?" != "x0" ]; then
echo "Invalid results from locale query $locale"
rm $CF_LOCALE_FILE
exit 1
fi
# where we are reading the source locale template file from
LOCALE_TEMPLATE_FILE=${LOCALE_FOLDER}/${locale}.lua
grep -- '--@localization' $LOCALE_TEMPLATE_FILE > /dev/null
if [ "x$?" != "x0" ]; then
echo "Failed to find localization tag in template file $LOCALE_TEMPLATE_FILE"
rm $CF_LOCALE_FILE
exit
fi
cat $CF_LOCALE_FILE | grep -v 'L = L or ' > $NEW_LOCALE_FILE
DATE_TAG=$(date)
echo "-- Generated from CurseForge on ${DATE_TAG}" > $NEW_LOCALE_FILE
# append lines before the localization tag
awk '/--@localization/ {exit} {print}' $LOCALE_TEMPLATE_FILE >> $NEW_LOCALE_FILE
cat $CF_LOCALE_FILE | grep -v 'L = L or ' >> $NEW_LOCALE_FILE
# append lines after the localization tag
awk 'x==1 {print} /--@localization/ {x=1}' $LOCALE_TEMPLATE_FILE >> $NEW_LOCALE_FILE
mv -v $NEW_LOCALE_FILE $LOCALE_TEMPLATE_FILE
done
rm $CF_LOCALE_FILE