#!/usr/bin/env bash # ------------------------------------------------------------------------------ # Copyright (c) 2013-2026 Geoffray Levasseur # Protected by the BSD3 license. Please read bellow for details. # # * Redistribution and use in source and binary forms, # * with or without modification, are permitted provided # * that the following conditions are met: # * # * Redistributions of source code must retain the above # * copyright notice, this list of conditions and the # * following disclaimer. # * # * Redistributions in binary form must reproduce the above # * copyright notice, this list of conditions and the following # * disclaimer in the documentation and/or other materials # * provided with the distribution. # * # * Neither the name of the copyright holder nor the names # * of any other contributors may be used to endorse or # * promote products derived from this software without # * specific prior written permission. # * # * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND # * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, # * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR # * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # * OF SUCH DAMAGE. # ------------------------------------------------------------------------------ locale_check() { locale -a | grep -qx "$1" || { disp W "Locale '$1' is not installed on this system." return 1 } return 0 } # ------------------------------------------------------------------------------ # Change locale to the given one in parameter # Usage: setlocale setlocale() { local PARSED PARSED=$(getopt -o h --long help -n 'setlocale' -- "$@") if [[ $? -ne 0 ]]; then disp E "Invalid options, use \"setlocale --help\" to display usage." return 1 fi eval set -- "$PARSED" while true; do case "$1" in -h|--help) printf "setlocale: Configure system environment locale variables.\n\n" printf "Usage: setlocale \n\n" printf "Options:\n" printf " -h, --help Display this help screen\n" return 0 ;; --) shift break ;; *) disp E "Invalid options, use \"setlocale --help\" to display usage." return 1 ;; esac done local loc=$1 [[ -z $loc ]] && disp E "No locale specified." && return 1 locale_check "$loc" || return 1 export LANG=$loc export LC_MESSAGES=$loc export LC_TIME=$loc export LC_NUMERIC=$loc export LC_MONETARY=$loc export LC_COLLATE=$loc export LC_CTYPE=$loc disp I "Locale set to $loc." } export -f setlocale # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # Special case : change locale to C standard # Usage: setc setc() { # Locale definitions export LC_ALL=C disp I "Locale changed to standard C (POSIX)." } export -f setc # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # Change locale to French # Usage: setfr setfr() { # Set fr locale definitions setlocale "fr_FR.UTF-8" } export -f setfr # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # Change locale to US (needed by Steam) # Usage: setus setus() { setlocale "en_US.UTF-8" } export -f setus # ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ # EOF