github.com/richardwilkes/toolbox@v1.121.0/i18n/localization_other.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  //go:build !windows
    11  
    12  package i18n
    13  
    14  import "os"
    15  
    16  // Locale returns the value of the LC_ALL environment variable, if set. If not, then it falls back to the value of the
    17  // LANG environment variable. If that is also not set, then it returns "en_US.UTF-8".
    18  func Locale() string {
    19  	locale := os.Getenv("LC_ALL")
    20  	if locale == "" {
    21  		locale = os.Getenv("LANG")
    22  		if locale == "" {
    23  			locale = "en_US.UTF-8"
    24  		}
    25  	}
    26  	return locale
    27  }