Skip to content

Commit 1267427

Browse files
committed
i18n: allow a theme and module to work together (#2172)
* i18n: allow a theme and module to work together * style A slight update to header includes during the cherry pick
1 parent c0c3765 commit 1267427

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/SimpleSAML/Locale/Localization.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Gettext\{Translations, Translator, TranslatorFunctions};
1717
use SimpleSAML\{Configuration, Logger};
1818
use Symfony\Component\HttpFoundation\File\File;
19+
use SimpleSAML\Locale\Translate;
1920

2021
use function explode;
2122
use function is_dir;
@@ -141,6 +142,7 @@ public function addModuleDomain(string $module, string $localeDir = null, string
141142
public function defaultDomain(string $domain): self
142143
{
143144
$this->translator->defaultDomain($domain);
145+
Translate::addDefaultDomain($domain);
144146
return $this;
145147
}
146148

src/SimpleSAML/Locale/Translate.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class Translate
3030
*/
3131
private Language $language;
3232

33+
/**
34+
* A theme and module may exist together as dual default translation domains
35+
*/
36+
private static array $defaultDomains = [];
3337

3438
/**
3539
* Constructor
@@ -66,6 +70,10 @@ public static function noop(string $tag): string
6670
return $tag;
6771
}
6872

73+
public static function addDefaultDomain(string $domain): void
74+
{
75+
array_push(self::$defaultDomains, $domain);
76+
}
6977

7078
/**
7179
* Translate a singular text.
@@ -84,9 +92,18 @@ public static function translateSingularGettext(?string $original): string
8492
$text = TranslatorFunctions::getTranslator()->dgettext("core", $original);
8593
if ($text === $original) {
8694
$text = TranslatorFunctions::getTranslator()->dgettext("messages", $original);
87-
// try attributes.po
8895
if ($text === $original) {
89-
$text = TranslatorFunctions::getTranslator()->dgettext("", $original);
96+
foreach (self::$defaultDomains as $d) {
97+
$text = TranslatorFunctions::getTranslator()->dgettext($d, $original);
98+
if ($text != $original) {
99+
return $text;
100+
}
101+
}
102+
103+
// try attributes.po
104+
if ($text === $original) {
105+
$text = TranslatorFunctions::getTranslator()->dgettext("", $original);
106+
}
90107
}
91108
}
92109
}

0 commit comments

Comments
 (0)