-
Notifications
You must be signed in to change notification settings - Fork 22
fix: use static language list instead of l10nFactory for translation providers #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bakiburakogun
wants to merge
1
commit into
nextcloud:main
Choose a base branch
from
bakiburakogun:fix/translation-languages-force-language
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\OpenAi\Translation; | ||
|
|
||
| /** | ||
| * Static list of languages supported by AI translation providers. | ||
| * | ||
| * AI models can translate between any language pair regardless of which | ||
| * UI translations are installed on the server. Using l10nFactory->getLanguages() | ||
| * breaks when force_language is set (returns only the forced language). | ||
| * | ||
| * @see https://github.com/nextcloud/integration_openai/issues/357 | ||
| */ | ||
| class LanguageList { | ||
|
|
||
| /** | ||
| * Returns a comprehensive list of common languages with English display names. | ||
| * | ||
| * @return array<array{code: string, name: string}> | ||
| */ | ||
| public static function getLanguages(): array { | ||
| return [ | ||
| ['code' => 'af', 'name' => 'Afrikaans'], | ||
| ['code' => 'sq', 'name' => 'Albanian'], | ||
| ['code' => 'am', 'name' => 'Amharic'], | ||
| ['code' => 'ar', 'name' => 'Arabic'], | ||
| ['code' => 'hy', 'name' => 'Armenian'], | ||
| ['code' => 'az', 'name' => 'Azerbaijani'], | ||
| ['code' => 'eu', 'name' => 'Basque'], | ||
| ['code' => 'be', 'name' => 'Belarusian'], | ||
| ['code' => 'bn', 'name' => 'Bengali'], | ||
| ['code' => 'bs', 'name' => 'Bosnian'], | ||
| ['code' => 'bg', 'name' => 'Bulgarian'], | ||
| ['code' => 'my', 'name' => 'Burmese'], | ||
| ['code' => 'ca', 'name' => 'Catalan'], | ||
| ['code' => 'zh', 'name' => 'Chinese (Simplified)'], | ||
| ['code' => 'zh_TW', 'name' => 'Chinese (Traditional)'], | ||
| ['code' => 'hr', 'name' => 'Croatian'], | ||
| ['code' => 'cs', 'name' => 'Czech'], | ||
| ['code' => 'da', 'name' => 'Danish'], | ||
| ['code' => 'nl', 'name' => 'Dutch'], | ||
| ['code' => 'en', 'name' => 'English'], | ||
| ['code' => 'et', 'name' => 'Estonian'], | ||
| ['code' => 'fi', 'name' => 'Finnish'], | ||
| ['code' => 'fr', 'name' => 'French'], | ||
| ['code' => 'gl', 'name' => 'Galician'], | ||
| ['code' => 'ka', 'name' => 'Georgian'], | ||
| ['code' => 'de', 'name' => 'German'], | ||
| ['code' => 'el', 'name' => 'Greek'], | ||
| ['code' => 'gu', 'name' => 'Gujarati'], | ||
| ['code' => 'ha', 'name' => 'Hausa'], | ||
| ['code' => 'he', 'name' => 'Hebrew'], | ||
| ['code' => 'hi', 'name' => 'Hindi'], | ||
| ['code' => 'hu', 'name' => 'Hungarian'], | ||
| ['code' => 'is', 'name' => 'Icelandic'], | ||
| ['code' => 'id', 'name' => 'Indonesian'], | ||
| ['code' => 'ga', 'name' => 'Irish'], | ||
| ['code' => 'it', 'name' => 'Italian'], | ||
| ['code' => 'ja', 'name' => 'Japanese'], | ||
| ['code' => 'kn', 'name' => 'Kannada'], | ||
| ['code' => 'kk', 'name' => 'Kazakh'], | ||
| ['code' => 'km', 'name' => 'Khmer'], | ||
| ['code' => 'ko', 'name' => 'Korean'], | ||
| ['code' => 'ku', 'name' => 'Kurdish'], | ||
| ['code' => 'ky', 'name' => 'Kyrgyz'], | ||
| ['code' => 'lo', 'name' => 'Lao'], | ||
| ['code' => 'lv', 'name' => 'Latvian'], | ||
| ['code' => 'lt', 'name' => 'Lithuanian'], | ||
| ['code' => 'mk', 'name' => 'Macedonian'], | ||
| ['code' => 'ms', 'name' => 'Malay'], | ||
| ['code' => 'ml', 'name' => 'Malayalam'], | ||
| ['code' => 'mt', 'name' => 'Maltese'], | ||
| ['code' => 'mn', 'name' => 'Mongolian'], | ||
| ['code' => 'ne', 'name' => 'Nepali'], | ||
| ['code' => 'no', 'name' => 'Norwegian'], | ||
| ['code' => 'ps', 'name' => 'Pashto'], | ||
| ['code' => 'fa', 'name' => 'Persian'], | ||
| ['code' => 'pl', 'name' => 'Polish'], | ||
| ['code' => 'pt', 'name' => 'Portuguese'], | ||
| ['code' => 'pt_BR', 'name' => 'Portuguese (Brazil)'], | ||
| ['code' => 'pa', 'name' => 'Punjabi'], | ||
| ['code' => 'ro', 'name' => 'Romanian'], | ||
| ['code' => 'ru', 'name' => 'Russian'], | ||
| ['code' => 'sr', 'name' => 'Serbian'], | ||
| ['code' => 'si', 'name' => 'Sinhala'], | ||
| ['code' => 'sk', 'name' => 'Slovak'], | ||
| ['code' => 'sl', 'name' => 'Slovenian'], | ||
| ['code' => 'so', 'name' => 'Somali'], | ||
| ['code' => 'es', 'name' => 'Spanish'], | ||
| ['code' => 'sw', 'name' => 'Swahili'], | ||
| ['code' => 'sv', 'name' => 'Swedish'], | ||
| ['code' => 'tl', 'name' => 'Tagalog'], | ||
| ['code' => 'ta', 'name' => 'Tamil'], | ||
| ['code' => 'te', 'name' => 'Telugu'], | ||
| ['code' => 'th', 'name' => 'Thai'], | ||
| ['code' => 'tr', 'name' => 'Turkish'], | ||
| ['code' => 'tk', 'name' => 'Turkmen'], | ||
| ['code' => 'uk', 'name' => 'Ukrainian'], | ||
| ['code' => 'ur', 'name' => 'Urdu'], | ||
| ['code' => 'uz', 'name' => 'Uzbek'], | ||
| ['code' => 'vi', 'name' => 'Vietnamese'], | ||
| ['code' => 'cy', 'name' => 'Welsh'], | ||
| ['code' => 'yo', 'name' => 'Yoruba'], | ||
| ['code' => 'zu', 'name' => 'Zulu'], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a code => name map of all supported languages. | ||
| * | ||
| * @return array<string, string> | ||
| */ | ||
| public static function getLanguagesByCode(): array { | ||
| $map = []; | ||
| foreach (self::getLanguages() as $lang) { | ||
| $map[$lang['code']] = $lang['name']; | ||
| } | ||
| return $map; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.