Skip to content

fix: use static language list instead of l10nFactory for translation providers#358

Merged
lukasdotcom merged 1 commit intonextcloud:mainfrom
bakiburakogun:fix/translation-languages-force-language
Apr 22, 2026
Merged

fix: use static language list instead of l10nFactory for translation providers#358
lukasdotcom merged 1 commit intonextcloud:mainfrom
bakiburakogun:fix/translation-languages-force-language

Conversation

@bakiburakogun
Copy link
Copy Markdown
Contributor

Summary

When force_language is set in config.php, l10nFactory->getLanguages() returns only the forced language (or a very limited set), causing both OldTranslationProvider and TranslateProvider to offer an empty or single-language list to consumers like Spreed's message translation dialog.

AI translation services (OpenAI, LocalAI, etc.) can translate between any languages regardless of which Nextcloud UI languages are installed. The available translation language list should therefore not depend on l10nFactory.

Changes

  • New lib/Translation/LanguageList.php: A shared static helper class providing ~80 common ISO 639 languages with English names. Exposes getLanguages() (array of ['code' => ..., 'name' => ...]) and getLanguagesByCode() (code => name map).
  • OldTranslationProvider: getAvailableLanguages() and getCoreLanguagesByCode() now use LanguageList instead of l10nFactory->getLanguages().
  • TranslateProvider: getInputShapeEnumValues() and getCoreLanguagesByCode() now use LanguageList instead of l10nFactory->getLanguages().

How to reproduce

  1. Set 'force_language' => 'tr' (or any single language) in config.php
  2. Open Spreed → select a message → click Translate
  3. The source/target language dropdowns are empty or show only one language

With this fix, all ~80 common languages are always available.

Fixes #357

Copy link
Copy Markdown
Member

@lukasdotcom lukasdotcom left a comment

Choose a reason for hiding this comment

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

Thanks. It looks good I have a little bit of feedback, and to fix the DCO check you need to sign your commits. The instructions for that are at https://github.com/nextcloud/integration_openai/pull/358/checks?check_run_id=70509628723

Comment thread lib/Translation/LanguageList.php Outdated
* @return array<array{code: string, name: string}>
*/
public static function getLanguages(): array {
return [
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.

The languages should be internationalized. I would just use the endonyms (https://en.wikipedia.org/wiki/Endonym_and_exonym) for them. Also could you merge it with the list in https://github.com/nextcloud/integration_openai/blob/main/lib/AppInfo/Application.php#L83 and use your getLanguages for where that constant is being used so there is only one list.

@lukasdotcom
Copy link
Copy Markdown
Member

Hey @bakiburakogun, are you still interested in implementing the review changes yourself or do you want me to?

@lukasdotcom lukasdotcom force-pushed the fix/translation-languages-force-language branch 2 times, most recently from 64b4c9c to 2e81fee Compare April 22, 2026 16:22
@lukasdotcom lukasdotcom enabled auto-merge April 22, 2026 16:23
@lukasdotcom lukasdotcom force-pushed the fix/translation-languages-force-language branch from 2e81fee to 5deda8b Compare April 22, 2026 16:53
…providers

When force_language is set in config.php, l10nFactory->getLanguages()
returns only the forced language, causing translation providers to offer
an empty or single-language list. AI translation services can translate
any language regardless of installed Nextcloud UI languages.

Introduce a shared LanguageList helper class with common ISO 639
languages. Both OldTranslationProvider and TranslateProvider now use
this static list instead of depending on l10nFactory for determining
available translation languages.

Fixes nextcloud#357

Signed-off-by: Lukas Schaefer <[email protected]>
@lukasdotcom lukasdotcom force-pushed the fix/translation-languages-force-language branch from 5deda8b to b654d47 Compare April 22, 2026 16:54
@lukasdotcom lukasdotcom merged commit ce2fe7a into nextcloud:main Apr 22, 2026
27 checks passed
@github-actions
Copy link
Copy Markdown

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

public const MODELS_CACHE_TTL = 60 * 30;

public const AUDIO_TO_TEXT_LANGUAGES = [['en', 'English'], ['zh', '中文'], ['de', 'Deutsch'], ['es', 'Español'], ['ru', 'Русский'], ['ko', '한국어'], ['fr', 'Français'], ['ja', '日本語'], ['pt', 'Português'], ['tr', 'Türkçe'], ['pl', 'Polski'], ['ca', 'Català'], ['nl', 'Nederlands'], ['ar', 'العربية'], ['sv', 'Svenska'], ['it', 'Italiano'], ['id', 'Bahasa Indonesia'], ['hi', 'हिन्दी'], ['fi', 'Suomi'], ['vi', 'Tiếng Việt'], ['he', 'עברית'], ['uk', 'Українська'], ['el', 'Ελληνικά'], ['ms', 'Bahasa Melayu'], ['cs', 'Česky'], ['ro', 'Română'], ['da', 'Dansk'], ['hu', 'Magyar'], ['ta', 'தமிழ்'], ['no', 'Norsk (bokmål / riksmål)'], ['th', 'ไทย / Phasa Thai'], ['ur', 'اردو'], ['hr', 'Hrvatski'], ['bg', 'Български'], ['lt', 'Lietuvių'], ['la', 'Latina'], ['mi', 'Māori'], ['ml', 'മലയാളം'], ['cy', 'Cymraeg'], ['sk', 'Slovenčina'], ['te', 'తెలుగు'], ['fa', 'فارسی'], ['lv', 'Latviešu'], ['bn', 'বাংলা'], ['sr', 'Српски'], ['az', 'Azərbaycanca / آذربايجان'], ['sl', 'Slovenščina'], ['kn', 'ಕನ್ನಡ'], ['et', 'Eesti'], ['mk', 'Македонски'], ['br', 'Brezhoneg'], ['eu', 'Euskara'], ['is', 'Íslenska'], ['hy', 'Հայերեն'], ['ne', 'नेपाली'], ['mn', 'Монгол'], ['bs', 'Bosanski'], ['kk', 'Қазақша'], ['sq', 'Shqip'], ['sw', 'Kiswahili'], ['gl', 'Galego'], ['mr', 'मराठी'], ['pa', 'ਪੰਜਾਬੀ / पंजाबी / پنجابي'], ['si', 'සිංහල'], ['km', 'ភាសាខ្មែរ'], ['sn', 'chiShona'], ['yo', 'Yorùbá'], ['so', 'Soomaaliga'], ['af', 'Afrikaans'], ['oc', 'Occitan'], ['ka', 'ქართული'], ['be', 'Беларуская'], ['tg', 'Тоҷикӣ'], ['sd', 'सिनधि'], ['gu', 'ગુજરાતી'], ['am', 'አማርኛ'], ['yi', 'ייִדיש'], ['lo', 'ລາວ / Pha xa lao'], ['uz', 'Ўзбек'], ['fo', 'Føroyskt'], ['ht', 'Krèyol ayisyen'], ['ps', 'پښتو'], ['tk', 'Туркмен / تركمن'], ['nn', 'Norsk (nynorsk)'], ['mt', 'bil-Malti'], ['sa', 'संस्कृतम्'], ['lb', 'Lëtzebuergesch'], ['my', 'Myanmasa'], ['bo', 'བོད་ཡིག / Bod skad'], ['tl', 'Tagalog'], ['mg', 'Malagasy'], ['as', 'অসমীয়া'], ['tt', 'Tatarça'], ['haw', 'ʻŌlelo Hawaiʻi'], ['ln', 'Lingála'], ['ha', 'هَوُسَ'], ['ba', 'Башҡорт'], ['jw', 'ꦧꦱꦗꦮ'], ['su', 'Basa Sunda'], ['yue', '粤语']];
public const LANGUAGE_CODES_AND_ENDONYMS = [['en', 'English'], ['zh', '中文'], ['de', 'Deutsch'], ['es', 'Español'], ['ru', 'Русский'], ['ko', '한국어'], ['fr', 'Français'], ['ja', '日本語'], ['pt', 'Português'], ['tr', 'Türkçe'], ['pl', 'Polski'], ['ca', 'Català'], ['nl', 'Nederlands'], ['ar', 'العربية'], ['sv', 'Svenska'], ['it', 'Italiano'], ['id', 'Bahasa Indonesia'], ['hi', 'हिन्दी'], ['fi', 'Suomi'], ['vi', 'Tiếng Việt'], ['he', 'עברית'], ['uk', 'Українська'], ['el', 'Ελληνικά'], ['ms', 'Bahasa Melayu'], ['cs', 'Česky'], ['ro', 'Română'], ['da', 'Dansk'], ['hu', 'Magyar'], ['ta', 'தமிழ்'], ['no', 'Norsk (bokmål / riksmål)'], ['th', 'ไทย / Phasa Thai'], ['ur', 'اردو'], ['hr', 'Hrvatski'], ['bg', 'Български'], ['lt', 'Lietuvių'], ['la', 'Latina'], ['mi', 'Māori'], ['ml', 'മലയാളം'], ['cy', 'Cymraeg'], ['sk', 'Slovenčina'], ['te', 'తెలుగు'], ['fa', 'فارسی'], ['lv', 'Latviešu'], ['bn', 'বাংলা'], ['sr', 'Српски'], ['az', 'Azərbaycanca / آذربايجان'], ['sl', 'Slovenščina'], ['kn', 'ಕನ್ನಡ'], ['et', 'Eesti'], ['mk', 'Македонски'], ['br', 'Brezhoneg'], ['eu', 'Euskara'], ['is', 'Íslenska'], ['hy', 'Հայերեն'], ['ne', 'नेपाली'], ['mn', 'Монгол'], ['bs', 'Bosanski'], ['kk', 'Қазақша'], ['sq', 'Shqip'], ['sw', 'Kiswahili'], ['gl', 'Galego'], ['mr', 'मराठी'], ['pa', 'ਪੰਜਾਬੀ / पंजाबी / پنجابي'], ['si', 'සිංහල'], ['km', 'ភាសាខ្មែរ'], ['sn', 'chiShona'], ['yo', 'Yorùbá'], ['so', 'Soomaaliga'], ['af', 'Afrikaans'], ['oc', 'Occitan'], ['ka', 'ქართული'], ['be', 'Беларуская'], ['tg', 'Тоҷикӣ'], ['sd', 'सिनधि'], ['gu', 'ગુજરાતી'], ['am', 'አማርኛ'], ['yi', 'ייִדיש'], ['lo', 'ລາວ / Pha xa lao'], ['uz', 'Ўзбек'], ['fo', 'Føroyskt'], ['ht', 'Krèyol ayisyen'], ['ps', 'پښتو'], ['tk', 'Туркмен / تركمن'], ['nn', 'Norsk (nynorsk)'], ['mt', 'bil-Malti'], ['sa', 'संस्कृतम्'], ['lb', 'Lëtzebuergesch'], ['my', 'Myanmasa'], ['bo', 'བོད་ཡིག / Bod skad'], ['tl', 'Tagalog'], ['mg', 'Malagasy'], ['as', 'অসমীয়া'], ['tt', 'Tatarça'], ['haw', 'ʻŌlelo Hawaiʻi'], ['ln', 'Lingála'], ['ha', 'هَوُسَ'], ['ba', 'Башҡорт'], ['jw', 'ꦧꦱꦗꦮ'], ['su', 'Basa Sunda'], ['yue', '粤语']];
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.

While the original L10N Service uses endonyms, I think it makes more sense to use exonyms here and have them translatable into the user's selected language, as the user may not speak the language(s) well enough to know the proper endonym.

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.

(see #269 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OldTranslationProvider returns empty/single language list when force_language is set

3 participants