Load translations properly when forgebuild is not setup, just cloned
This commit is contained in:
parent
9150acbf61
commit
07889f19b3
|
@ -32,15 +32,44 @@ if [[ "$LANG" != "NONE" ]]; then
|
|||
# Extract two letters from $LANG
|
||||
locale="${LANG:0:2}"
|
||||
|
||||
# Ensure translations have been setup
|
||||
# Figure out where to load translations from. If the person is hacking on a new version and/or forgebuild
|
||||
# hasn't been setup, it's very likely that the build spec repo can be found at either ../build or ./spec
|
||||
# relative to forgebuild.sh. If none of these exist, try to load translations from a normal setup:
|
||||
# from ~/.local/forgebuild/i18n or /usr/share/forgebuild/i18n
|
||||
BINDIR="$(dirname "$0")"
|
||||
# ../build has higher precedence in case you're hacking on several implementations
|
||||
if [ -d "$BINDIR"/../build/i18n ]; then
|
||||
I18N_DIR="$BINDIR"/../build/i18n
|
||||
elif [ -d "$BINDIR"/spec/i18n ]; then
|
||||
# We are in a cloned repo and submodule has been initialized
|
||||
I18N_DIR="$BINDIR"/spec/i18n
|
||||
else
|
||||
# Either submodule hasn't been initalized, or we are not in a repo at all
|
||||
# First try normal install paths, then try to clone spec submodule
|
||||
# In this order because we'd like to rely on Internet access as last resort only
|
||||
if [ -d /usr/share/forgebuild/i18n ]; then
|
||||
I18N_DIR=/usr/share/forgebuild/i18n
|
||||
elif [ -d $HOME/.local/share/forgebuild/i18n ]; then
|
||||
I18N_DIR=$HOME/.local/share/forgebuild/i18n
|
||||
elif [ -d "$BINDIR"/spec ]; then
|
||||
# Submodule isn't initialized
|
||||
PREVDIR="$(pwd)"
|
||||
cd "$BINDIR"
|
||||
git submodule init
|
||||
if ! git submodule update; then
|
||||
echo "ERROR: Failed to find local translations and to download them from the Internet"
|
||||
exit 1
|
||||
fi
|
||||
cd "$PREVDIR"
|
||||
I18N_DIR="$BINDIR"/spec/i18n
|
||||
else
|
||||
# We are not in a repo and local translations were not found, abort!
|
||||
echo "ERROR: could not find translations. Maybe you need to run the setup.sh script?"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# TODO: add debug message about where translations are loaded from
|
||||
|
||||
# Initialize translations
|
||||
[ -f $I18N_DIR/$locale.json ] && locale_strings="$(cat $I18N_DIR/$locale.json)" || locale_strings="$(cat $I18N_DIR/en.json)"
|
||||
|
|
Loading…
Reference in New Issue