forked from tomas-mazak/wordpress-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-locale.sh
executable file
·62 lines (49 loc) · 1.44 KB
/
wp-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
#!/bin/bash
set -e
WORDPRESS_ROOT_DIR="/var/www/wordpress"
LANGUAGE_DIR="$WORDPRESS_ROOT_DIR/wp-content/languages"
if [ "$WORDPRESS_LOCALES" == "" ]; then
echo "ERROR: WORDPRESS_LOCALES is not set"
exit 1
fi
if [[
"$#" -eq 0 ||
"$#" -gt 2 ||
(( "$#" -eq 1 ) && ( "$1" != "core" )) ||
(( "$#" -eq 2 ) && ( "$1" != "plugin" && "$1" != "theme" ))
]]; then
echo "USAGE: $0 (plugin|theme) <slug> | $0 core"
exit 1
fi
type=$1
slug=$2
slug_param=""
if [ "$type" != "core" ]; then
slug_param="&slug=$slug"
type="${type}s"
LANGUAGE_DIR="$LANGUAGE_DIR/$type"
fi
if [ ! -d "$LANGUAGE_DIR" ]; then
echo "Language directory does not exist, creating it..."
mkdir -p "$LANGUAGE_DIR"
fi
echo "Downloading $1 language files..."
translation_json=$(curl -s -X POST "https://api.wordpress.org/translations/${type}/1.0/" -d "wp_version=${WORDPRESS_VERSION}$slug_param")
for lang in $WORDPRESS_LOCALES
do
if [ "$lang" == "en_US" ]; then
echo "Skip downloading default locale..."
continue
fi
download_url=$(echo "$translation_json" | jq -r '.translations | .[] | select(.language == "'"$lang"'") | .package' 2>/dev/null)
if [ "$download_url" == "" ]; then
echo "Warning: No download link for language ${lang} found, skipping..."
continue
fi
echo "Downloading $lang locale..."
tmpfile=$(mktemp)
curl -sL "$download_url" > "$tmpfile"
echo "Unpacking $lang locale..."
unzip -qq -d "$LANGUAGE_DIR" "$tmpfile"
rm "$tmpfile"
done