Skip to content

Use the LANG environment variable on Linux #1308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Sources/FoundationEssentials/Locale/Locale_Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,30 @@ struct LocaleCache : Sendable, ~Copyable {
}
return preferredLocaleID
}
#elseif os(Linux)
func preferences() -> (LocalePreferences, Bool) {
var prefs = LocalePreferences()
// TODO: Fill other preference values from LC_* and LANGUAGE variables: https://github.com/swiftlang/swift-foundation/issues/717
if let lang = ProcessInfo.processInfo.environment["LANG"],
!lang.isEmpty
{
prefs.locale = lang
prefs.languages = [fixed(lang).languageCode ?? "en-001"]
} else {
prefs.locale = "en_001"
prefs.languages = ["en-001"]
}
return (prefs, true)
}

func preferredLanguages(forCurrentUser: Bool) -> [String] {
// TODO: Override with LANGUAGE variable: https://github.com/swiftlang/swift-foundation/issues/717
[Locale.canonicalLanguageIdentifier(from: current.languageCode ?? "en-001")]
}

func preferredLocale() -> String? {
current.identifier
}
#else
func preferences() -> (LocalePreferences, Bool) {
var prefs = LocalePreferences()
Expand Down