@@ -161,6 +161,14 @@ public static function addInitScript(string $application, string $file): void {
161161 $ path = "js/ $ file " ;
162162 }
163163
164+ // We need to handle the translation BEFORE the init script
165+ // is loaded, as the init script might use translations
166+ if ($ application !== 'core '
167+ && $ file !== null
168+ && !str_contains ($ file , 'l10n ' )) {
169+ self ::addTranslations ($ application , null , true );
170+ }
171+
164172 self ::$ scriptsInit [] = $ path ;
165173 }
166174
@@ -235,7 +243,7 @@ public static function getScripts(): array {
235243 * @param string $languageCode language code, defaults to the current locale
236244 * @since 8.0.0
237245 */
238- public static function addTranslations ($ application , $ languageCode = null ) {
246+ public static function addTranslations ($ application , $ languageCode = null , $ init = false ) {
239247 if (is_null ($ languageCode )) {
240248 $ languageCode = \OC ::$ server ->getL10NFactory ()->findLanguage ($ application );
241249 }
@@ -244,7 +252,12 @@ public static function addTranslations($application, $languageCode = null) {
244252 } else {
245253 $ path = "l10n/ $ languageCode " ;
246254 }
247- self ::$ scripts [$ application ][] = $ path ;
255+
256+ if ($ init ) {
257+ self ::$ scriptsInit [] = $ path ;
258+ } else {
259+ self ::$ scripts [$ application ][] = $ path ;
260+ }
248261 }
249262
250263 /**
0 commit comments