I18n locale
This commit is contained in:
@@ -137,6 +137,47 @@ function fail_miaou_count {
|
||||
failures+=("$cmd 3>$TMP_MIAOU")
|
||||
return 1
|
||||
}
|
||||
|
||||
function assert_locales_equally_populated {
|
||||
((test_count++))
|
||||
local locales_dir="$MIAOU_BASH_DIR"/locales
|
||||
local main_locale_file="$locales_dir"/"$1".sh
|
||||
if [[ ! -f $main_locale_file ]]; then
|
||||
echo -n F
|
||||
failures+=("missing locale file: $main_locale_file for locale: $1")
|
||||
return 1
|
||||
fi
|
||||
shift
|
||||
if [[ $# -gt 0 ]]; then
|
||||
local extra_locale_file difference variable_name
|
||||
for extra in "$@"; do
|
||||
extra_locale_file="$locales_dir"/"$extra".sh
|
||||
if [[ ! -f $extra_locale_file ]]; then
|
||||
echo -n F
|
||||
failures+=("missing locale file: $extra_locale_file for locale: $extra")
|
||||
return 1
|
||||
fi
|
||||
mapfile -t difference < <(
|
||||
diff <(grep -oP '^\s*[A-Za-z_][A-Za-z0-9_]*' "$main_locale_file" | sort) \
|
||||
<(grep -oP '^\s*[A-Za-z_][A-Za-z0-9_]*' "$extra_locale_file" | sort) \
|
||||
2>&1 | head -n2
|
||||
)
|
||||
if [[ ${#difference[@]} -gt 0 ]]; then
|
||||
variable_name=$(echo "${difference[1]}" | cut -d' ' -f2)
|
||||
change_type="${difference[0]}"
|
||||
echo -n F
|
||||
if [[ "$change_type" =~ d ]]; then
|
||||
failures+=("locale=$extra (in $extra_locale_file) misses variable (to add): ${variable_name}")
|
||||
else
|
||||
failures+=("locale=$extra (in $extra_locale_file) useless variable (to remove): ${variable_name}")
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo -n .
|
||||
}
|
||||
|
||||
# main
|
||||
|
||||
set -uo pipefail
|
||||
@@ -181,6 +222,7 @@ time {
|
||||
fail_stderr_grep script_not_found "ERROR: script 'doesnt_exist' not found!"
|
||||
fail_stderr_grep no_script 'ERROR: script expected!'
|
||||
|
||||
assert_locales_equally_populated en es fr
|
||||
# TODO: I18n tests for:
|
||||
# /opt/miaou-bash/test/stub/scenario.bash unbound_variable
|
||||
# /opt/miaou-bash/test/stub/scenario.bash unbound_associative
|
||||
|
||||
Reference in New Issue
Block a user