88 * License: GNU/GPLv2
99 * @see LICENSE.txt
1010 *
11- * This file: The loader (last modified: 2022.12.26 ).
11+ * This file: The loader (last modified: 2023.02.14 ).
1212 */
1313
1414namespace phpMussel \Core ;
@@ -638,19 +638,28 @@ public function loadL10N(string $Path = ''): void
638638 $ this ->ClientL10N = &$ this ->L10N ;
639639 }
640640 } 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 ;
650647 if ($ this ->Configuration ['core ' ]['lang ' ] === $ Accepted ) {
651648 $ IsSameAs = true ;
652- } elseif (is_readable ($ Path . $ Accepted . '.yml ' )) {
649+ break ;
650+ }
651+ if (is_readable ($ Path . $ Accepted . '.yml ' )) {
653652 $ 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 ;
654663 }
655664 }
656665
@@ -659,25 +668,25 @@ public function loadL10N(string $Path = ''): void
659668 if (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
660669 $ this ->ClientL10N = &$ this ->L10N ;
661670 }
662- } elseif ($ Primary ) {
671+ } elseif ($ Primary !== '' ) {
663672 $ Arr = [];
664- if (! $ this ->ClientL10NAccepted ) {
673+ if ($ this ->ClientL10NAccepted === '' ) {
665674 $ this ->ClientL10NAccepted = $ Accepted ;
666675 }
667676 $ this ->YAML ->process ($ Primary , $ Arr );
668677 if ($ this ->ClientL10N instanceof \Maikuolan \Common \L10N && is_array ($ this ->ClientL10N ->Data )) {
669678 $ this ->ClientL10N ->Data = array_merge ($ this ->ClientL10N ->Data , $ Arr );
670679 } else {
671680 $ this ->ClientL10N = new \Maikuolan \Common \L10N ($ Arr , $ this ->L10N );
672- $ this ->ClientL10N ->autoAssignRules ($ Accepted );
681+ $ this ->ClientL10N ->autoAssignRules ($ ForAutoAssign );
673682 }
674683 } elseif (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
675684 $ this ->ClientL10N = new \Maikuolan \Common \L10N ([], $ this ->L10N );
676685 }
677686 }
678687
679688 /** Fallback for missing accepted client L10N choice. */
680- if (!$ this ->ClientL10NAccepted ) {
689+ if (!$ this ->ClientL10NAccepted === '' ) {
681690 $ this ->ClientL10NAccepted = $ this ->Configuration ['core ' ]['lang ' ];
682691 }
683692 }
0 commit comments