Skip to content

fix(l10n): make translation factory caches app- and locale-aware#61037

Draft
joshtrichards wants to merge 8 commits into
masterfrom
jtr/fix-L10N-Factory-caching
Draft

fix(l10n): make translation factory caches app- and locale-aware#61037
joshtrichards wants to merge 8 commits into
masterfrom
jtr/fix-L10N-Factory-caching

Conversation

@joshtrichards
Copy link
Copy Markdown
Member

@joshtrichards joshtrichards commented Jun 6, 2026

  • Resolves: # (possibly some weird language/locale mismatch bugs)

Summary

Don't let the number of changed lines scare you; the bulk are either mechanical variable name changes or comment updates/removals.

Improve OC\L10N\Factory caching and clean up related internals.

Changes

  • cache resolved request language per app context
  • cache L10N instances per app, language, and locale
  • deduplicate discovered languages before caching
  • lazily build the language membership map used by languageExists()
  • harden findLanguageFromLocale() for null / empty input
  • clean up internal naming, comments, code duplication, and docblocks

Why

Factory::get() previously cached L10N instances only by app and language, which could reuse the same instance across different locales.

This also makes language lookup caching more explicit and avoids duplicate language entries when app and theme translations overlap.

Testing

  • see TODO

TODO

  • Updated / added tests that cover:
    • locale-specific L10N instance caching
    • lazy language membership-map construction
    • rebuilding the membership map from cached available languages
    • null / empty input handling in findLanguageFromLocale()

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

…instance cache

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Reuse the already resolved l10n directory instead, preventing an unnecessary exception path for unknown apps

Signed-off-by: Josh <josh.t.richards@gmail.com>
Stop populating availableLanguageMap in the cache-hit path and make it lazy in languageExists().

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards added this to the Nextcloud 35 milestone Jun 6, 2026
@joshtrichards joshtrichards added bug 2. developing Work in progress technical debt 🧱 🤔🚀 feature: language/translations (l10n/i18n) Localization and translation matters ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) labels Jun 6, 2026
Signed-off-by: Josh <josh.t.richards@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress bug feature: language/translations (l10n/i18n) Localization and translation matters ♻️ refactor Refactor code (not a bug fix, not a feature just refactoring) technical debt 🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant