diff --git a/classes/Conf/PublicationUsage/class.xoctPublicationSubUsageFormGUI.php b/classes/Conf/PublicationUsage/class.xoctPublicationSubUsageFormGUI.php index 99dd0757c..666aa182d 100644 --- a/classes/Conf/PublicationUsage/class.xoctPublicationSubUsageFormGUI.php +++ b/classes/Conf/PublicationUsage/class.xoctPublicationSubUsageFormGUI.php @@ -94,7 +94,7 @@ protected function initForm() // F_DISPLAY_NAME $max_lenght = 20; $display_name = (!empty($this->object->getDisplayName()) ? $this->object->getDisplayName() : '{added display name}'); - $info = sprintf($this->parent_gui->txt(self::F_DISPLAY_NAME . '_info'), $max_lenght, strtolower($display_name)); + $info = sprintf($this->plugin->txt('publication_usage_sub_' . self::F_DISPLAY_NAME . '_info'), $max_lenght, strtolower($display_name)); $te = new ilTextInputGUI($this->parent_gui->txt(self::F_DISPLAY_NAME), self::F_DISPLAY_NAME); $te->setInfo($info); $te->setMaxLength($max_lenght); diff --git a/classes/Event/class.xoctEventRenderer.php b/classes/Event/class.xoctEventRenderer.php index 2e034c464..a72fc0bd9 100644 --- a/classes/Event/class.xoctEventRenderer.php +++ b/classes/Event/class.xoctEventRenderer.php @@ -17,6 +17,7 @@ use srag\Plugins\Opencast\UI\Modal\EventModals; use srag\Plugins\Opencast\Model\DTO\DownloadDto; use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait; +use srag\Plugins\Opencast\Util\Locale\LocaleTrait; /** * Class xoctEventRenderer @@ -26,6 +27,7 @@ class xoctEventRenderer { use TranslatorTrait; + use LocaleTrait; public const LANG_MODULE = 'event'; /** @@ -136,9 +138,10 @@ public function renderDropdowns(&$tpl): void $content['link'] ); } - $display_name = PublicationUsageGroupRepository::getLocalizedDisplayName($group_data['display_name']); + $display_name = $this->getLocaleString(strtolower($group_data['display_name']), + PublicationUsageGroup::DISPLAY_NAME_LANG_MODULE, $group_data['display_name']); if (empty($display_name)) { - $display_name = $this->translate('default', PublicationUsageGroup::DISPLAY_NAME_LANG_MODULE); + $display_name = $this->getLocaleString('default', PublicationUsageGroup::DISPLAY_NAME_LANG_MODULE); } $dropdown = $this->factory->dropdown()->standard( $items diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 86059b610..81196e68f 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -581,7 +581,7 @@ channel_type#:#Serie file#:#Datei link#:#URL subtab_publication_usage#:#Publikationsnutzungen -subtab_publication_sub_usage#:#Unternutzungen +subtab_publication_sub_usage#:#Unternutzungen subtab_publication_groups#:#Unternutzungsgruppen publication_usage_msg_success_sub#:#Unternutzung gespeichert publication_usage_select_sub_usage_id#:#Unternutzungen @@ -593,6 +593,7 @@ publication_usage_no_identifier#:#Keine Unternutzung gefunden! publication_usage_sub#:#Unternutzung publication_usage_display_name#:#Anzeigename publication_usage_display_name_info#:#Anzeigename, der in dem Button angezeigt wird. (Maximal %s Zeichen, kann übersetzt werden, wenn (pu_display_name_%s) in eine(r) Sprachdatei gespeichert wird.) +publication_usage_sub_display_name_info#:#Anzeigename, der in dem Button angezeigt wird. (Maximal %s Zeichen, kann übersetzt werden, wenn (pus_display_name_%s) in eine(r) Sprachdatei gespeichert wird.) publication_usage_group_id#:#Unternutzungsgruppe publication_usage_add_new_sub#:#untergeordnete Nutzung hinzufügen publication_usage_add_new_group#:#Neue Unternutzungsgruppe hinzufügen diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 50466c379..223082922 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -594,6 +594,7 @@ publication_usage_no_identifier#:#No publication usage identifier found! publication_usage_sub#:#Sub publication_usage_display_name#:#Display Name publication_usage_display_name_info#:#The display name (max %s chars) to be shown to the users, and it can be localized by adding a string id (pu_display_name_%s) to the plugin languages. +publication_usage_sub_display_name_info#:#The display name (max %s chars) to be shown to the users, and it can be localized by adding a string id (pus_display_name_%s) to the plugin languages. publication_usage_group_id#:#Publication Group publication_usage_add_new_group#:#Add new group publication_usage_group_name#:#Name diff --git a/src/Model/Publication/Config/PublicationSubUsageRepository.php b/src/Model/Publication/Config/PublicationSubUsageRepository.php index 88a2fd128..01c3e3709 100644 --- a/src/Model/Publication/Config/PublicationSubUsageRepository.php +++ b/src/Model/Publication/Config/PublicationSubUsageRepository.php @@ -2,7 +2,7 @@ namespace srag\Plugins\Opencast\Model\Publication\Config; -use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait; +use srag\Plugins\Opencast\Util\Locale\LocaleTrait; /** * Class PublicationSubUsageRepository @@ -11,7 +11,7 @@ */ class PublicationSubUsageRepository { - use TranslatorTrait; + use LocaleTrait; /** * Returns the display name of the sub-usage but by looking for a record also in localization. * @param int $sub_id @@ -23,10 +23,8 @@ public function getDisplayName(int $sub_id): string $sub_usage = PublicationSubUsage::find($sub_id); if (!empty($sub_usage) && !empty($sub_usage->getDisplayName())) { $display_name = $sub_usage->getDisplayName(); - $translated_display_name = $this->translate(strtolower($display_name), PublicationSubUsage::DISPLAY_NAME_LANG_MODULE); - if (strpos($translated_display_name, 'MISSING') === false) { - $display_name = $translated_display_name; - } + $display_name = $this->getLocaleString(strtolower($display_name), + PublicationSubUsage::DISPLAY_NAME_LANG_MODULE, $display_name); } return trim($display_name); } @@ -40,7 +38,7 @@ public function getDisplayName(int $sub_id): string public function generateTitle(string $parent_usage_id, string $title_text): string { $count_subs = PublicationSubUsage::where(['parent_usage_id' => $parent_usage_id])->count(); - return $title_text . " (" . $this->translate('publication_usage_sub') . "-" . ($count_subs + 1) . ")"; + return $title_text . " (" . $this->getLocaleString('publication_usage_sub') . "-" . ($count_subs + 1) . ")"; } /** diff --git a/src/Model/Publication/Config/PublicationUsageGroupRepository.php b/src/Model/Publication/Config/PublicationUsageGroupRepository.php index 5c1dd1235..1bba01bca 100644 --- a/src/Model/Publication/Config/PublicationUsageGroupRepository.php +++ b/src/Model/Publication/Config/PublicationUsageGroupRepository.php @@ -2,8 +2,6 @@ namespace srag\Plugins\Opencast\Model\Publication\Config; -use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait; - /** * Class PublicationUsageGroupRepository * @@ -11,36 +9,6 @@ */ class PublicationUsageGroupRepository { - use TranslatorTrait; - /** - * Returns the display name of the group but by looking for a record also in localization. - * @param int $group_id - * @return string - */ - public static function getDisplayName(int $group_id): string - { - $display_name = ''; - $group = PublicationUsageGroup::find($group_id); - if (!empty($group) && !empty($group->getDisplayName())) { - $display_name = $group->getDisplayName(); - $display_name = self::getLocalizedDisplayName($display_name); - } - return trim($display_name); - } - - /** - * @param string $group_display_name - * @return string - */ - public static function getLocalizedDisplayName($group_display_name): string - { - $localized_display_name = self::translate(strtolower($group_display_name), PublicationUsageGroup::DISPLAY_NAME_LANG_MODULE); - if (strpos($localized_display_name, 'MISSING') === false) { - $group_display_name = $localized_display_name; - } - return trim($group_display_name); - } - /** * @param array $sub_ids * @return array diff --git a/src/Model/Publication/Config/PublicationUsageRepository.php b/src/Model/Publication/Config/PublicationUsageRepository.php index 422ae3d98..bf1814e13 100644 --- a/src/Model/Publication/Config/PublicationUsageRepository.php +++ b/src/Model/Publication/Config/PublicationUsageRepository.php @@ -2,7 +2,7 @@ namespace srag\Plugins\Opencast\Model\Publication\Config; -use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait; +use srag\Plugins\Opencast\Util\Locale\LocaleTrait; /** * Class PublicationUsageRepository @@ -13,7 +13,7 @@ */ class PublicationUsageRepository { - use TranslatorTrait; + use LocaleTrait; public function exists(string $usage): bool { return !is_null(PublicationUsage::find($usage)); @@ -104,14 +104,11 @@ public function store( */ public function getDisplayName(string $usage): string { - $display_name = ''; $usage = $this->getUsage($usage); - if (!empty($usage->getDisplayName())) { - $display_name = $usage->getDisplayName(); - $translated_display_name = $this->translate(strtolower($display_name), PublicationUsage::DISPLAY_NAME_LANG_MODULE); - if (strpos($translated_display_name, 'MISSING') === false) { - $display_name = $translated_display_name; - } + $display_name = $usage->getDisplayName() ?? ''; + if (!empty($display_name)) { + $display_name = $this->getLocaleString(strtolower($display_name), + PublicationUsage::DISPLAY_NAME_LANG_MODULE, $display_name); } return trim($display_name); } diff --git a/src/Util/Locale/LocaleTraits.php b/src/Util/Locale/LocaleTraits.php new file mode 100644 index 000000000..fc5b717c0 --- /dev/null +++ b/src/Util/Locale/LocaleTraits.php @@ -0,0 +1,47 @@ + + */ +trait LocaleTrait +{ + /** + * A translator function, which makes sure that strings go through pluign->txt method to get translated. + * It uses the plugin property of the class or gets it from global container. + * @param string $string string to translate + * @param string $module + * @param ?string $fallback the fallback string in case the translataion does not exist. + * + * @return string + */ + public function getLocaleString(string $string, ?string $module = '', ?string $fallback = null): string + { + $locale_string = $string; + // Attaching module if any! + if (!empty($module)) { + $locale_string = $module . "_" . $string; + } + + // Make sure plugin object is there! + global $opencastContainer; + $plugin = property_exists($this, 'plugin') ? $this->plugin : $opencastContainer[\ilOpenCastPlugin::class]; + + // Performing the regular txt translation. + $translation = $plugin->txt($locale_string); + + // If a fallback string is provided, we check for every scenario in which the txt method might return a value in case of not finding the original string. (backwards compatibility with ILIAS < 8) + $start = substr($translation, 0, 1); + $end = substr($translation, -1); + if (((empty($translation) || $translation === "MISSING" || strpos($translation, "MISSING ") === 0) || + ($start == '-' && $end == '-' && strpos($translation, $locale_string) !== false)) && !empty($fallback)) { + return $fallback; + } + + return $translation; + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index b6a823c7f..18e3228a0 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -309,6 +309,7 @@ 'srag\\Plugins\\Opencast\\Util\\FileTransfer\\OpencastIngestService' => $baseDir . '/src/Util/FileTransfer/OpencastIngestService.php', 'srag\\Plugins\\Opencast\\Util\\FileTransfer\\PaellaConfigStorageService' => $baseDir . '/src/Util/FileTransfer/PaellaConfigStorageService.php', 'srag\\Plugins\\Opencast\\Util\\FileTransfer\\UploadStorageService' => $baseDir . '/src/Util/FileTransfer/UploadStorageService.php', + 'srag\\Plugins\\Opencast\\Util\\Locale\\LocaleTrait' => $baseDir . '/src/Util/Locale/LocaleTraits.php', 'srag\\Plugins\\Opencast\\Util\\Player\\LivePlayerDataBuilder' => $baseDir . '/src/Util/Player/LivePlayerDataBuilder.php', 'srag\\Plugins\\Opencast\\Util\\Player\\PaellaConfigService' => $baseDir . '/src/Util/Player/PaellaConfigService.php', 'srag\\Plugins\\Opencast\\Util\\Player\\PaellaConfigServiceFactory' => $baseDir . '/src/Util/Player/PaellaConfigServiceFactory.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index d3acda9ed..ae13e0917 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -14,7 +14,7 @@ class ComposerStaticInitf618280b835f1c6e99e4eb8d8a3e04f0 ); public static $prefixLengthsPsr4 = array ( - 's' => + 's' => array ( 'srag\\LibraryLanguageInstaller\\OpenCast\\' => 39, 'srag\\LibrariesNamespaceChanger\\' => 31, @@ -22,18 +22,18 @@ class ComposerStaticInitf618280b835f1c6e99e4eb8d8a3e04f0 'srag\\DIC\\OpenCast\\' => 18, 'srag\\CustomInputGUIs\\OpenCast\\' => 30, ), - 'P' => + 'P' => array ( 'Psr\\Http\\Message\\' => 17, 'Psr\\Http\\Client\\' => 16, ), - 'O' => + 'O' => array ( 'OpencastApi\\Rest\\' => 17, 'OpencastApi\\Mock\\' => 17, 'OpencastApi\\' => 12, ), - 'G' => + 'G' => array ( 'GuzzleHttp\\Psr7\\' => 16, 'GuzzleHttp\\Promise\\' => 19, @@ -42,56 +42,56 @@ class ComposerStaticInitf618280b835f1c6e99e4eb8d8a3e04f0 ); public static $prefixDirsPsr4 = array ( - 'srag\\LibraryLanguageInstaller\\OpenCast\\' => + 'srag\\LibraryLanguageInstaller\\OpenCast\\' => array ( 0 => __DIR__ . '/..' . '/srag/librarylanguageinstaller/src', ), - 'srag\\LibrariesNamespaceChanger\\' => + 'srag\\LibrariesNamespaceChanger\\' => array ( 0 => __DIR__ . '/..' . '/srag/librariesnamespacechanger/src', ), - 'srag\\DataTableUI\\OpenCast\\' => + 'srag\\DataTableUI\\OpenCast\\' => array ( 0 => __DIR__ . '/..' . '/srag/datatable/src', ), - 'srag\\DIC\\OpenCast\\' => + 'srag\\DIC\\OpenCast\\' => array ( 0 => __DIR__ . '/..' . '/srag/dic/src', ), - 'srag\\CustomInputGUIs\\OpenCast\\' => + 'srag\\CustomInputGUIs\\OpenCast\\' => array ( 0 => __DIR__ . '/..' . '/srag/custominputguis/src', ), - 'Psr\\Http\\Message\\' => + 'Psr\\Http\\Message\\' => array ( 0 => __DIR__ . '/..' . '/psr/http-factory/src', 1 => __DIR__ . '/..' . '/psr/http-message/src', ), - 'Psr\\Http\\Client\\' => + 'Psr\\Http\\Client\\' => array ( 0 => __DIR__ . '/..' . '/psr/http-client/src', ), - 'OpencastApi\\Rest\\' => + 'OpencastApi\\Rest\\' => array ( 0 => __DIR__ . '/..' . '/elan-ev/opencast-api/src/OpencastApi/Rest', ), - 'OpencastApi\\Mock\\' => + 'OpencastApi\\Mock\\' => array ( 0 => __DIR__ . '/..' . '/elan-ev/opencast-api/src/OpencastApi/Mock', ), - 'OpencastApi\\' => + 'OpencastApi\\' => array ( 0 => __DIR__ . '/..' . '/elan-ev/opencast-api/src/OpencastApi', ), - 'GuzzleHttp\\Psr7\\' => + 'GuzzleHttp\\Psr7\\' => array ( 0 => __DIR__ . '/..' . '/guzzlehttp/psr7/src', ), - 'GuzzleHttp\\Promise\\' => + 'GuzzleHttp\\Promise\\' => array ( 0 => __DIR__ . '/..' . '/guzzlehttp/promises/src', ), - 'GuzzleHttp\\' => + 'GuzzleHttp\\' => array ( 0 => __DIR__ . '/..' . '/guzzlehttp/guzzle/src', ), @@ -401,6 +401,7 @@ class ComposerStaticInitf618280b835f1c6e99e4eb8d8a3e04f0 'srag\\Plugins\\Opencast\\Util\\FileTransfer\\OpencastIngestService' => __DIR__ . '/../..' . '/src/Util/FileTransfer/OpencastIngestService.php', 'srag\\Plugins\\Opencast\\Util\\FileTransfer\\PaellaConfigStorageService' => __DIR__ . '/../..' . '/src/Util/FileTransfer/PaellaConfigStorageService.php', 'srag\\Plugins\\Opencast\\Util\\FileTransfer\\UploadStorageService' => __DIR__ . '/../..' . '/src/Util/FileTransfer/UploadStorageService.php', + 'srag\\Plugins\\Opencast\\Util\\Locale\\LocaleTrait' => __DIR__ . '/../..' . '/src/Util/Locale/LocaleTraits.php', 'srag\\Plugins\\Opencast\\Util\\Player\\LivePlayerDataBuilder' => __DIR__ . '/../..' . '/src/Util/Player/LivePlayerDataBuilder.php', 'srag\\Plugins\\Opencast\\Util\\Player\\PaellaConfigService' => __DIR__ . '/../..' . '/src/Util/Player/PaellaConfigService.php', 'srag\\Plugins\\Opencast\\Util\\Player\\PaellaConfigServiceFactory' => __DIR__ . '/../..' . '/src/Util/Player/PaellaConfigServiceFactory.php',