Skip to content

enhance: locale matching distance, fallback - #1043

Merged
cosven merged 6 commits into
feeluown:masterfrom
mokurin000:patch-2
May 28, 2026
Merged

enhance: locale matching distance, fallback#1043
cosven merged 6 commits into
feeluown:masterfrom
mokurin000:patch-2

Conversation

@mokurin000

@mokurin000 mokurin000 commented May 27, 2026

Copy link
Copy Markdown
Contributor

The default max_distance of langcodes.closest_supported_match 25 is insufficient to match various languages.

=== langcodes ===
max_distance: 25
zh-Hant    -> None
zh-TW      -> None
zh-SG      -> zh-Hans
ja         -> ja
ja-JP      -> ja
ko         -> None
ru         -> None
de         -> None
fr-FR      -> None
it         -> None
en-GB      -> en-US
ms-MY      -> None

max_distance: 100
zh-Hant    -> zh-Hans
zh-TW      -> zh-Hans
zh-SG      -> zh-Hans
ja         -> ja
ja-JP      -> ja
ko         -> None
ru         -> None
de         -> en-US
fr-FR      -> en-US
it         -> en-US
en-GB      -> en-US
ms-MY      -> en-US

max_distance: 200
zh-Hant    -> zh-Hans
zh-TW      -> zh-Hans
zh-SG      -> zh-Hans
ja         -> ja
ja-JP      -> ja
ko         -> en-US
ru         -> en-US
de         -> en-US
fr-FR      -> en-US
it         -> en-US
en-GB      -> en-US
ms-MY      -> en-US

This PR also added a fallback method to make langcodes an optional dependency.

It's now gated behind the i18n-match optional group.

@mokurin000 mokurin000 changed the title enhance: increase max_distance for locale matching enhance: locale matching distance, fallback May 27, 2026
@mokurin000

Copy link
Copy Markdown
Contributor Author

@cosven 我重写了一份新的 fallback 逻辑,并且适当调整了 distance 阈值

Comment thread feeluown/i18n/__init__.py
Comment on lines +31 to +35
return langcodes.closest_supported_match(
desired_language=locale,
supported_languages=supported_lang,
max_distance=200,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With max_distance=200, unrelated languages tie against the supported set and langcodes picks the first directory returned by os.listdir. In this PR worktree, supported locales are ["ja-JP", "zh-CN", "en-US"], so t("playlist", locale="ko-KR") and locale="ru" return Japanese instead of falling back to English. The old behavior returned None from closest_supported_match, then loaded the fallback chain. This needs an explicit fallback policy for unrelated languages, or a lower/conditional threshold, before enabling the optional langcodes path.

@cosven
cosven merged commit 4f3f64a into feeluown:master May 28, 2026
6 checks passed
@mokurin000
mokurin000 deleted the patch-2 branch May 28, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants