Skip to content

Commit 534377c

Browse files
committed
Bug-fix.
Changelog excerpt: - If the client-specified language was the same as the configured language, the client-specified preferred variant would be ignored, even if it wasn't the same as the configured preferred variant; Fixed.
1 parent d43c9b0 commit 534377c

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
155155
### v3.5.2
156156

157157
[2024.07.02; Maikuolan]: Refactored the `loadL10N` method. Merged zh and zh-TW L10N, and dropped region designations (e.g., CN, TW) in favour of script designations (e.g., Hans, Hant).
158+
159+
[2024.07.13; Bug-fix; Maikuolan]: If the client-specified language was the same as the configured language, the client-specified preferred variant would be ignored, even if it wasn't the same as the configured preferred variant; Fixed.

src/Loader.php

Lines changed: 18 additions & 17 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: 2024.07.01).
11+
* This file: The loader (last modified: 2024.07.13).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -629,26 +629,28 @@ public function loadL10N(string $Path = ''): void
629629
$Accepted = preg_replace(['~;.*$~', '~[^-A-Za-z]~'], '', $Accepted);
630630
$Primary = '';
631631
$IsSameAs = false;
632-
foreach ([$Accepted, strtolower(preg_replace('~-.*$~', '', $Accepted))] as $Accepted) {
633-
if ($this->L10NAccepted === $Accepted) {
632+
if ($this->L10NAccepted === $Accepted) {
633+
$IsSameAs = true;
634+
break;
635+
}
636+
$Main = strpos($Accepted, '-') === false ? '' : strtolower(preg_replace('~-.*$~', '', $Accepted));
637+
if (($Primary = $this->readFile($Path . $Accepted . '.yml')) !== '' || ($Primary = $this->readFile($Path . $Main . '.yml')) !== '') {
638+
break;
639+
}
640+
foreach ([$Accepted, $Main] as $Accepted) {
641+
if ($Accepted === '' || !isset($this->ConfigurationDefaults['core']['lang']['defer'][$Accepted])) {
642+
break;
643+
}
644+
if ($this->L10NAccepted === $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted]) {
634645
$IsSameAs = true;
635646
break 2;
636647
}
637-
if (($Primary = $this->readFile($Path . $Accepted . '.yml')) !== '') {
648+
if (
649+
($Primary = $this->readFile($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted] . '.yml')) !== '' ||
650+
($Primary = $this->readFile($Path . preg_replace('~-.*$~', '', $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted]) . '.yml')) !== ''
651+
) {
638652
break 2;
639653
}
640-
if (isset($this->ConfigurationDefaults['core']['lang']['defer'][$Accepted])) {
641-
if ($this->L10NAccepted === $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted]) {
642-
$IsSameAs = true;
643-
break 2;
644-
}
645-
if (
646-
($Primary = $this->readFile($Path . $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted] . '.yml')) !== '' ||
647-
($Primary = $this->readFile($Path . preg_replace('~-.*$~', '', $this->ConfigurationDefaults['core']['lang']['defer'][$Accepted]) . '.yml')) !== ''
648-
) {
649-
break 2;
650-
}
651-
}
652654
}
653655
}
654656
if ($Primary !== '') {
@@ -676,7 +678,6 @@ public function loadL10N(string $Path = ''): void
676678
}
677679
} elseif (!($this->ClientL10N instanceof \Maikuolan\Common\L10N)) {
678680
$this->ClientL10N = new \Maikuolan\Common\L10N([], $this->L10N);
679-
$this->ClientL10N->autoAssignRules($Accepted);
680681
}
681682
}
682683

0 commit comments

Comments
 (0)