Skip to content

Commit c519316

Browse files
committed
Update list of language code
This commit will also create a Bash script to update that list in the future. Signed-off-by: Henrique Moody <[email protected]>
1 parent 8b8f7db commit c519316

File tree

2 files changed

+526
-486
lines changed

2 files changed

+526
-486
lines changed

bin/update-language-codes

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# Usage: {script} RULE_FILENAME
3+
# Update list of language codes (ISO-639-2)
4+
5+
set -euo pipefail
6+
7+
declare -r IFS=$'\n'
8+
declare -r URL="http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt"
9+
declare -r RULE_FILENAME="${1}"
10+
declare -r TEMPORARY_LIST=$(mktemp)
11+
12+
download_list()
13+
{
14+
echo "Downloading list from '${URL}'"
15+
curl --silent --location "${1}" --output "${2}"
16+
}
17+
18+
update_currency_codes()
19+
{
20+
local -r filename_rule="${1}"
21+
local -r filename_list="${2}"
22+
local -r temporary_rule=$(mktemp)
23+
24+
echo "Updating list in '${filename_rule}'"
25+
{
26+
sed -n '/^</,/ protected/p' "${filename_rule}"
27+
while read line; do
28+
local alpha_3=$(cut --delimiter '|' --fields 1 <<< "${line}" | tr -cd '[a-z]' | tr '[a-z]' '[A-Z]')
29+
local alpha_2=$(cut --delimiter '|' --fields 3 <<< "${line}" | tr '[a-z]' '[A-Z]')
30+
local name=$(cut --delimiter '|' --fields 4 <<< "${line}")
31+
echo " ['${alpha_2}', '${alpha_3}'], // ${name}"
32+
done < "${filename_list}"
33+
sed -n '/^ ]/,/^}/p' "${filename_rule}"
34+
} > "${temporary_rule}"
35+
36+
mv "${temporary_rule}" "${filename_rule}"
37+
}
38+
39+
download_list "${URL}" "${TEMPORARY_LIST}"
40+
update_currency_codes "${RULE_FILENAME}" "${TEMPORARY_LIST}"

0 commit comments

Comments
 (0)