Skip to content

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

Open
bakiburakogun wants to merge 1 commit intonextcloud:mainfrom
bakiburakogun:fix/translation-languages-force-language
Open

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

Conversation

@bakiburakogun
Copy link
Copy Markdown

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

…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
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

* @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.

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.

OldTranslationProvider returns empty/single language list when force_language is set

2 participants