]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(l10n): fix translations for init scripts 42093/head
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Thu, 7 Dec 2023 10:51:33 +0000 (11:51 +0100)
committerJohn Molakvoæ <skjnldsv@protonmail.com>
Fri, 8 Dec 2023 11:36:39 +0000 (12:36 +0100)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
lib/public/Util.php

index 488eddbaf4b9528d5e99efc2af7ec5099736f362..6322ab56a8878c91790be7c71ae4574173dbd832 100644 (file)
@@ -161,6 +161,12 @@ class Util {
                        $path = "js/$file";
                }
 
+               // We need to handle the translation BEFORE the init script
+               // is loaded, as the init script might use translations
+               if ($application !== 'core' && !str_contains($file, 'l10n')) {
+                       self::addTranslations($application, null, true);
+               }
+
                self::$scriptsInit[] = $path;
        }
 
@@ -233,9 +239,10 @@ class Util {
         * Add a translation JS file
         * @param string $application application id
         * @param string $languageCode language code, defaults to the current locale
+        * @param bool $init whether the translations should be loaded early or not
         * @since 8.0.0
         */
-       public static function addTranslations($application, $languageCode = null) {
+       public static function addTranslations($application, $languageCode = null, $init = false) {
                if (is_null($languageCode)) {
                        $languageCode = \OC::$server->getL10NFactory()->findLanguage($application);
                }
@@ -244,7 +251,12 @@ class Util {
                } else {
                        $path = "l10n/$languageCode";
                }
-               self::$scripts[$application][] = $path;
+
+               if ($init) {
+                       self::$scriptsInit[] = $path;
+               } else {
+                       self::$scripts[$application][] = $path;
+               }
        }
 
        /**