From 711a04d3782a40eff227f2b56e86e0d2a15f5980 Mon Sep 17 00:00:00 2001 From: southerntofu Date: Tue, 1 Dec 2020 17:36:12 +0100 Subject: [PATCH] Load translations from file, but disable color output --- forgebuild.sh | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/forgebuild.sh b/forgebuild.sh index c85cc46..5f3fd3d 100755 --- a/forgebuild.sh +++ b/forgebuild.sh @@ -22,25 +22,29 @@ fi # - we load the requested language if it exists, fail otherwise # - when no language is requested, default to something (TODO) if [[ "$LANG" != "NONE" ]]; then - # Enable colors (escape codes) as echo option - COLORS=1 - - # Extract two letters from $LANG - locale="${LANG:0:2}" - - # Ensure translations have been setup - 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 + # If LANG is a file, load it directly + if [ -f "$LANG" ]; then + locale_strings="$(cat $LANG)" else - echo "ERROR: could not find translations. Maybe you need to run the setup.sh script?" - exit 1 + # Enable colors (escape codes) as echo option + COLORS=1 + + # Extract two letters from $LANG + locale="${LANG:0:2}" + + # Ensure translations have been setup + 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 + else + echo "ERROR: could not find translations. Maybe you need to run the setup.sh script?" + exit 1 + fi + + # Initialize translations + [ -f $I18N_DIR/$locale.json ] && locale_strings="$(cat $I18N_DIR/$locale.json)" || locale_strings="$(cat $I18N_DIR/en.json)" fi - - # Initialize translations - [ -f $I18N_DIR/$locale.json ] && locale_strings="$(cat $I18N_DIR/$locale.json)" || locale_strings="$(cat $I18N_DIR/en.json)" - fi # End translations initialization # Takes one argument, looks up translation @@ -305,7 +309,7 @@ done # Error when the requested basedir (or the default ~/.forgebuild) does not exist if [ ! -d $BASEDIR ]; then - i18n_basedir="$BASEDIR" + export i18n_basedir="$BASEDIR" error "missing_basedir" exit 1 fi