L10n: falls back to English when the auto-detected locale is unsupported

--key-language with an empty value (and "language": null in the config)
asks for the system locale, not for a specific language. When that locale
has no translation, fastfetch aborted with exit 477 instead of printing
anything, so the same config broke on every locale outside the twelve
supported ones, and under LC_ALL=C variants such as POSIX.

Auto-detected locales now fall back to English. An explicitly requested
language still errors out, so typos and zh are still reported.
This commit is contained in:
Wehrwolfmann
2026-08-18 02:04:01 +02:00
committed by Carter Li
parent 6cb15885c7
commit e5b6e3612a
2 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -588,7 +588,7 @@
{
"long": "key-language",
"desc": "Specify the language used for module keys",
"remark": "Leave empty for auto-detection based on the system locale",
"remark": "Leave empty for auto-detection based on the system locale. Unsupported locales fall back to English",
"arg": {
"type": "enum",
"default": "en",
+8 -2
View File
@@ -17,7 +17,9 @@
// @returns offsetof(FFModuleDisplayName, <language>)
// @see src/common/option.h
static uint32_t optionParseLanguageString(FFstrbuf* language) {
if (language->length == 0) {
const bool detected = language->length == 0;
if (detected) {
#if !FF_MODULE_DISABLE_LOCALE
const char* error = ffDetectLocale(language);
if (__builtin_expect(error != nullptr, false)) {
@@ -52,7 +54,7 @@ static uint32_t optionParseLanguageString(FFstrbuf* language) {
// The language code is expected to be in the format of "en", "en_US", "de", "de_DE", etc.
// First try to match the full language code, then try to match just the first two characters (the language part).
// If no match is found, report a language not supported error.
// If no match is found, report a language not supported error, unless the language was auto-detected.
// en_US -> offsetof(FFModuleDisplayName, en)
// en -> offsetof(FFModuleDisplayName, en)
// zh_CN -> offsetof(FFModuleDisplayName, zh_CN)
@@ -85,6 +87,10 @@ static uint32_t optionParseLanguageString(FFstrbuf* language) {
#pragma GCC diagnostic pop
error:
// The user asked for the system locale, not for this specific language. Most locales have no
// translation, so falling back to English is friendlier than aborting fastfetch entirely.
if (detected) return offsetof(FFModuleDisplayName, en);
fprintf(stderr, "Error: Language '%s' is not supported\n", language->chars);
exit(477);
}