aboutsummaryrefslogtreecommitdiff
path: root/lib/models/ModuleManagementModel.php
diff options
context:
space:
mode:
authorPeter Thienel <thienel@data-quest.de>2024-12-20 14:20:33 +0000
committerPeter Thienel <thienel@data-quest.de>2024-12-20 14:20:33 +0000
commit5f8c492f51f3e0eda579157312b4ed5f7fa024e1 (patch)
tree93c1abfd248bdc23f29f3eec07306b190b0a702d /lib/models/ModuleManagementModel.php
parenta8298beda0487fd5e5a4a286f90ba549dbd101fd (diff)
Resolve "Sprachauswahl für Originalfassung der Modul(teil)-Deskriptoren", fixes #4261
Closes #4261 Merge request studip/studip!3729
Diffstat (limited to 'lib/models/ModuleManagementModel.php')
-rw-r--r--lib/models/ModuleManagementModel.php49
1 files changed, 17 insertions, 32 deletions
diff --git a/lib/models/ModuleManagementModel.php b/lib/models/ModuleManagementModel.php
index 608a088..e8f684d 100644
--- a/lib/models/ModuleManagementModel.php
+++ b/lib/models/ModuleManagementModel.php
@@ -699,57 +699,42 @@ abstract class ModuleManagementModel extends SimpleORMap implements ModuleManage
/**
* Sets the language for localized fields and the locale environment
* globally.
- * Possible values are configured in mvv_config.php.
+ * See configuration of CONTENT_LANGUAGES.
*
* @see mvv_config.php
- * @param string $language The language.
+ * @param string $language The language code.
*/
- public static final function setLanguage($language)
+ public static final function setContentLanguage($language)
{
- $language = mb_strtoupper(mb_strstr($language . '_', '_', true));
- if (isset($GLOBALS['MVV_LANGUAGES']['values'][$language])) {
- $locale = $GLOBALS['MVV_LANGUAGES']['values'][$language]['locale'];
- setLocaleEnv($locale);
- self::setContentLanguage($language);
- // load config file again
- require $GLOBALS['STUDIP_BASE_PATH'] . '/config/mvv_config.php';
- }
- }
-
- /**
- * Switches the content to the given language.
- * Compared to ModuleManagementModel::setLanguage() strings translated with
- * gettext are always in the prefered language selected by the user.
- *
- * @param string $language The language code (see mvv_config.php)
- */
- public static function setContentLanguage($language)
- {
- if (!is_array($GLOBALS['MVV_LANGUAGES']['values'][$language])) {
+ $content_languages = Config::get()->CONTENT_LANGUAGES;
+ if (empty($content_languages[$language])) {
throw new InvalidArgumentException();
}
- $locale = $GLOBALS['MVV_LANGUAGES']['values'][$language]['locale'];
- I18NString::setContentLanguage($locale);
+ setLocaleEnv($language);
+ I18NString::setContentLanguage($language);
self::$language = $language;
+ // load config file again
+ require $GLOBALS['STUDIP_BASE_PATH'] . '/config/mvv_config.php';
}
- public function getAvailableTranslations()
+ public function getAvailableTranslations(string $original_language): array
{
- $translations[] = $GLOBALS['MVV_LANGUAGES']['default'];
+ $translations = [];
$stmt = DBManager::get()->prepare('SELECT DISTINCT `lang` '
. 'FROM i18n '
. 'WHERE `object_id` = ? AND `table` = ?');
$stmt->execute([$this->id, $this->db_table()]);
- foreach ($stmt->fetchAll() as $locale) {
- $language = mb_strtoupper(mb_strstr($locale['lang'], '_', true));
- if (is_array($GLOBALS['MVV_LANGUAGES']['values'][$language])) {
- $translations[] = $language;
+ $languages = array_merge([$original_language],
+ $stmt->fetchAll(PDO::FETCH_COLUMN));
+ $content_languages = $GLOBALS['CONTENT_LANGUAGES'];
+ foreach ($languages as $code) {
+ if (!empty($content_languages[$code])) {
+ $translations[] = $code;
}
}
return $translations;
}
-
/**
* Returns the currently selected language.
*