Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion doc/help.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions src/options/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
Loading