Skip to content

Commit

Permalink
change handling of locales with option -L
Browse files Browse the repository at this point in the history
1- If the user provides something that "looks" like a locale
   ([a-z][a-v]_[A-Z][A-Z]*), I set LANGUAGE and LC_MESSAGES.
2- If the user provides something that looks like a language code
   ([a-z][a-v]), I set LANGUAGE.
3- Otherwise, I print an error message.
  • Loading branch information
phyver committed Jun 21, 2021
1 parent 532b460 commit 9503f32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
2 changes: 2 additions & 0 deletions i18n/start-help/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ options:
-R reset game

-L ... set LANGUAGE variable (ex: -L fr:it:en)
On non GNU systems, set the variable LC_MESSAGES
to a valid locale.

-q quiet: don't show information messages
-n black and white: don't use ANSI escape codes for color
Expand Down
2 changes: 2 additions & 0 deletions i18n/start-help/fr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ options :
-R recommence une partie du début

-L initialise la variable LANGUAGE (ex : -L fr:it:en)
Pour les système non GNU, initialisez la variable LC_MESSAGES
avec une locale valide.

-q mode silencieux : n'affiche pas les messages d'information
-n mode noir et blanc : n'utilise pas les séquences ANSI
Expand Down
15 changes: 1 addition & 14 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,7 @@ do
RESET="TRUE"
;;
L)
if locale | grep "LANGUAGE" >/dev/null
then
export LANGUAGE=$OPTARG
else
if locale -a | grep -qx "$OPTARG"
then
export LC_MESSAGES=$OPTARG
else
echo "Unknown locale: '$OPTARG'." >&2
echo "You can run 'locale -a' to get a list of all locales installed on your system." >&2
locale -a | grep "$OPTARG" && echo "The above locales might be relevant..." >&2
exit 1
fi
fi
export LANGUAGE="$OPTARG" # only works on GNU systems
;;
X)
echo "$(gettext "Error: this option is only available from an executable archive!")" >&2
Expand Down

0 comments on commit 9503f32

Please sign in to comment.