Skip to content

Commit a6e0b90

Browse files
committed
L10N patch.
1 parent cdc2ee3 commit a6e0b90

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

assets/config.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# License: GNU/GPLv2
88
# @see LICENSE.txt
99
#
10-
# This file: Configuration defaults file (last modified: 2023.09.01).
10+
# This file: Configuration defaults file (last modified: 2023.09.05).
1111
##/
1212

1313
core:
@@ -182,15 +182,12 @@ core:
182182
zh-TW: "中文(傳統)"
183183
choice_filter: "filterL10N"
184184
defer:
185-
bn-IN: "bn-BD"
186-
en-GB: "en-AU"
187-
en-NZ: "en-AU"
188-
en-SG: "en-AU"
189-
en-ZA: "en-AU"
185+
mo: "ro"
186+
nb: "no"
190187
zh-HK: "zh-TW"
191188
zh-MO: "zh-TW"
192-
zh-SG: "zh-CN"
193189
assume:
190+
af: "af-ZA"
194191
bg: "bg-BG"
195192
bn: "bn-BD"
196193
cs: "cs-CZ"
@@ -206,12 +203,15 @@ core:
206203
ja: "ja-JP"
207204
ko: "ko-KR"
208205
lv: "lv-LV"
206+
mo: "ro-MO"
209207
ms: "ms-MY"
208+
nb: "nb-NO"
210209
nl: "nl-NL"
211-
no: "no-NO"
210+
no: "nb-NO"
212211
pa: "pa-IN"
213212
pl: "pl-PL"
214213
pt: "pt-BR"
214+
ro: "ro-RO"
215215
ru: "ru-RU"
216216
sv: "sv-SE"
217217
ta: "ta-IN"

src/Loader.php

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2023.09.04).
11+
* This file: The loader (last modified: 2023.09.05).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -611,7 +611,11 @@ public function loadL10N(string $Path = ''): void
611611
}
612612
if ($Primary === '') {
613613
$Try = preg_replace('~-.*$~', '', $this->Configuration['core']['lang']);
614-
$Primary = $this->readFile($Path . $Try . '.yml');
614+
if (($Primary = $this->readFile($Path . $Try . '.yml')) === '') {
615+
if (isset($this->ConfigurationDefaults['core']['lang']['defer'][$Try])) {
616+
$Primary = $this->readFile($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Try] . '.yml');
617+
}
618+
}
615619
}
616620
}
617621
$Fallback = $this->readFile($Path . 'en.yml');
@@ -660,44 +664,35 @@ public function loadL10N(string $Path = ''): void
660664
}
661665
} else {
662666
$Try = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE'], 20);
667+
$Accepted = '';
663668
foreach ($Try as $Accepted) {
664669
$Accepted = preg_replace(['~;.*$~', '~[^-A-Za-z]~'], '', $Accepted);
665-
$ForAutoAssign = $Accepted;
666670
$Primary = '';
667671
$IsSameAs = false;
668-
if ($this->L10NAccepted === $Accepted) {
669-
$IsSameAs = true;
670-
break;
671-
}
672-
if (isset($this->ConfigurationDefaults['core']['lang']['defer'][$Accepted])) {
673-
if ($this->L10NAccepted === $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted]) {
672+
foreach ([$Accepted, strtolower(preg_replace('~-.*$~', '', $Accepted))] as $Accepted) {
673+
if ($this->L10NAccepted === $Accepted) {
674674
$IsSameAs = true;
675-
break;
675+
break 2;
676676
}
677-
if (is_readable($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted] . '.yml')) {
678-
$Primary = $this->readFile($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted] . '.yml');
679-
break;
677+
if (is_readable($Path . $Accepted . '.yml')) {
678+
$Primary = $this->readFile($Path . $Accepted . '.yml');
679+
break 2;
680680
}
681-
}
682-
if (is_readable($Path . $Accepted . '.yml')) {
683-
$Primary = $this->readFile($Path . $Accepted . '.yml');
684-
break;
685-
}
686-
$Accepted = strtolower(preg_replace('~-.*$~', '', $Accepted));
687-
if ($this->Configuration['core']['lang'] === $Accepted) {
688-
$Accepted = $this->L10NAccepted;
689-
$IsSameAs = true;
690-
break;
691-
}
692-
if (is_readable($Path . $Accepted . '.yml')) {
693-
if (isset($this->ConfigurationDefaults['core']['lang']['assume'][$Accepted])) {
694-
$Accepted = $this->ConfigurationDefaults['core']['lang']['assume'][$Accepted];
695-
$ForAutoAssign = $Accepted;
681+
if (isset($this->ConfigurationDefaults['core']['lang']['defer'][$Accepted])) {
682+
if ($this->L10NAccepted === $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted]) {
683+
$IsSameAs = true;
684+
break 2;
685+
}
686+
if (is_readable($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted] . '.yml')) {
687+
$Primary = $this->readFile($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted] . '.yml');
688+
break 2;
689+
}
696690
}
697-
$Primary = $this->readFile($Path . $Accepted . '.yml');
698-
break;
699691
}
700692
}
693+
if ($Primary !== '') {
694+
$Accepted = $this->ConfigurationDefaults['core']['lang']['assume'][$Accepted] ?? $Accepted;
695+
}
701696

702697
/** Process client-specified L10N data. */
703698
if ($IsSameAs) {
@@ -714,11 +709,11 @@ public function loadL10N(string $Path = ''): void
714709
$this->ClientL10N->Data = array_merge($this->ClientL10N->Data, $Arr);
715710
} else {
716711
$this->ClientL10N = new \Maikuolan\Common\L10N($Arr, $this->L10N);
717-
$this->ClientL10N->autoAssignRules($ForAutoAssign);
712+
$this->ClientL10N->autoAssignRules($Accepted);
718713
}
719714
} elseif (!($this->ClientL10N instanceof \Maikuolan\Common\L10N)) {
720715
$this->ClientL10N = new \Maikuolan\Common\L10N([], $this->L10N);
721-
$this->ClientL10N->autoAssignRules($ForAutoAssign);
716+
$this->ClientL10N->autoAssignRules($Accepted);
722717
}
723718
}
724719

0 commit comments

Comments
 (0)