#!/bin/bash # ------------------------------------------------------------------------------ # Copyright (c) 2013-2022 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 # ------------------------------------------------------------------------------ setlocale() { 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 # ------------------------------------------------------------------------------ setc() { # Locale definitions export LC_ALL=C disp I "Locale changed to standard C (POSIX)." } export -f setc # ------------------------------------------------------------------------------ # Change locale to French # ------------------------------------------------------------------------------ setfr() { # Set fr locale definitions setlocal "fr_FR.UTF-8" } export -f setfr # ------------------------------------------------------------------------------ # Change locale to US (needed by Steam) # ------------------------------------------------------------------------------ setus() { setlocal "en_US.UTF-8" } export -f setus # ------------------------------------------------------------------------------ # EOF