Skip to content

Commit

Permalink
fix(l10n): fix translations for init scripts
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Dec 7, 2023
1 parent 5cf42ff commit 7ce91c9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ public static function addInitScript(string $application, string $file): void {
$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'

Check failure on line 166 in lib/public/Util.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

lib/public/Util.php:166:7: RedundantCondition: Type string for $file is never null (see https://psalm.dev/122)

Check failure on line 166 in lib/public/Util.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

RedundantCondition

lib/public/Util.php:166:7: RedundantCondition: Type string for $file is never null (see https://psalm.dev/122)
&& $file !== null

Check failure on line 167 in lib/public/Util.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

lib/public/Util.php:167:7: RedundantCondition: string can never contain null (see https://psalm.dev/122)

Check failure on line 167 in lib/public/Util.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

RedundantCondition

lib/public/Util.php:167:7: RedundantCondition: string can never contain null (see https://psalm.dev/122)

Check failure

Code scanning / Psalm

RedundantCondition Error

Type string for $file is never null

Check failure

Code scanning / Psalm

RedundantCondition Error

string can never contain null
&& !str_contains($file, 'l10n')) {
self::addTranslations($application, null, true);
}

self::$scriptsInit[] = $path;
}

Expand Down Expand Up @@ -235,7 +243,7 @@ public static function getScripts(): array {
* @param string $languageCode language code, defaults to the current locale
* @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);
}
Expand All @@ -244,7 +252,12 @@ public static function addTranslations($application, $languageCode = null) {
} else {
$path = "l10n/$languageCode";
}
self::$scripts[$application][] = $path;

if ($init) {
self::$scriptsInit[] = $path;
} else {
self::$scripts[$application][] = $path;
}
}

/**
Expand Down

0 comments on commit 7ce91c9

Please sign in to comment.