8
8
* License: GNU/GPLv2
9
9
* @see LICENSE.txt
10
10
*
11
- * This file: The loader (last modified: 2022.12.26 ).
11
+ * This file: The loader (last modified: 2023.02.14 ).
12
12
*/
13
13
14
14
namespace phpMussel \Core ;
@@ -638,19 +638,28 @@ public function loadL10N(string $Path = ''): void
638
638
$ this ->ClientL10N = &$ this ->L10N ;
639
639
}
640
640
} else {
641
- $ Accepted = preg_replace (['~^([^,]*).*$~ ' , '~[^-A-Za-z]~ ' ], ['\1 ' , '' ], $ _SERVER ['HTTP_ACCEPT_LANGUAGE ' ]);
642
- $ Primary = '' ;
643
- $ IsSameAs = false ;
644
- if ($ this ->Configuration ['core ' ]['lang ' ] === $ Accepted ) {
645
- $ IsSameAs = true ;
646
- } elseif (is_readable ($ Path . $ Accepted . '.yml ' )) {
647
- $ Primary = $ this ->readFile ($ Path . $ Accepted . '.yml ' );
648
- } else {
649
- $ Accepted = strtolower (preg_replace ('~^([^-]*).*$~ ' , '\1 ' , $ Accepted ));
641
+ $ Try = explode (', ' , $ _SERVER ['HTTP_ACCEPT_LANGUAGE ' ]);
642
+ foreach ($ Try as $ Accepted ) {
643
+ $ Accepted = preg_replace (['~;.*$~ ' , '~[^-A-Za-z]~ ' ], '' , $ Accepted );
644
+ $ ForAutoAssign = $ Accepted ;
645
+ $ Primary = '' ;
646
+ $ IsSameAs = false ;
650
647
if ($ this ->Configuration ['core ' ]['lang ' ] === $ Accepted ) {
651
648
$ IsSameAs = true ;
652
- } elseif (is_readable ($ Path . $ Accepted . '.yml ' )) {
649
+ break ;
650
+ }
651
+ if (is_readable ($ Path . $ Accepted . '.yml ' )) {
653
652
$ Primary = $ this ->readFile ($ Path . $ Accepted . '.yml ' );
653
+ break ;
654
+ }
655
+ $ Accepted = strtolower (preg_replace ('~-.*$~ ' , '' , $ Accepted ));
656
+ if ($ this ->Configuration ['core ' ]['lang ' ] === $ Accepted ) {
657
+ $ IsSameAs = true ;
658
+ break ;
659
+ }
660
+ if (is_readable ($ Path . $ Accepted . '.yml ' )) {
661
+ $ Primary = $ this ->readFile ($ Path . $ Accepted . '.yml ' );
662
+ break ;
654
663
}
655
664
}
656
665
@@ -659,25 +668,25 @@ public function loadL10N(string $Path = ''): void
659
668
if (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
660
669
$ this ->ClientL10N = &$ this ->L10N ;
661
670
}
662
- } elseif ($ Primary ) {
671
+ } elseif ($ Primary !== '' ) {
663
672
$ Arr = [];
664
- if (! $ this ->ClientL10NAccepted ) {
673
+ if ($ this ->ClientL10NAccepted === '' ) {
665
674
$ this ->ClientL10NAccepted = $ Accepted ;
666
675
}
667
676
$ this ->YAML ->process ($ Primary , $ Arr );
668
677
if ($ this ->ClientL10N instanceof \Maikuolan \Common \L10N && is_array ($ this ->ClientL10N ->Data )) {
669
678
$ this ->ClientL10N ->Data = array_merge ($ this ->ClientL10N ->Data , $ Arr );
670
679
} else {
671
680
$ this ->ClientL10N = new \Maikuolan \Common \L10N ($ Arr , $ this ->L10N );
672
- $ this ->ClientL10N ->autoAssignRules ($ Accepted );
681
+ $ this ->ClientL10N ->autoAssignRules ($ ForAutoAssign );
673
682
}
674
683
} elseif (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
675
684
$ this ->ClientL10N = new \Maikuolan \Common \L10N ([], $ this ->L10N );
676
685
}
677
686
}
678
687
679
688
/** Fallback for missing accepted client L10N choice. */
680
- if (!$ this ->ClientL10NAccepted ) {
689
+ if (!$ this ->ClientL10NAccepted === '' ) {
681
690
$ this ->ClientL10NAccepted = $ this ->Configuration ['core ' ]['lang ' ];
682
691
}
683
692
}
0 commit comments