8
8
* License: GNU/GPLv2
9
9
* @see LICENSE.txt
10
10
*
11
- * This file: The loader (last modified: 2023.09.04 ).
11
+ * This file: The loader (last modified: 2023.09.05 ).
12
12
*/
13
13
14
14
namespace phpMussel \Core ;
@@ -611,7 +611,11 @@ public function loadL10N(string $Path = ''): void
611
611
}
612
612
if ($ Primary === '' ) {
613
613
$ 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
+ }
615
619
}
616
620
}
617
621
$ Fallback = $ this ->readFile ($ Path . 'en.yml ' );
@@ -660,44 +664,35 @@ public function loadL10N(string $Path = ''): void
660
664
}
661
665
} else {
662
666
$ Try = explode (', ' , $ _SERVER ['HTTP_ACCEPT_LANGUAGE ' ], 20 );
667
+ $ Accepted = '' ;
663
668
foreach ($ Try as $ Accepted ) {
664
669
$ Accepted = preg_replace (['~;.*$~ ' , '~[^-A-Za-z]~ ' ], '' , $ Accepted );
665
- $ ForAutoAssign = $ Accepted ;
666
670
$ Primary = '' ;
667
671
$ 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 ) {
674
674
$ IsSameAs = true ;
675
- break ;
675
+ break 2 ;
676
676
}
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 ;
680
680
}
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
+ }
696
690
}
697
- $ Primary = $ this ->readFile ($ Path . $ Accepted . '.yml ' );
698
- break ;
699
691
}
700
692
}
693
+ if ($ Primary !== '' ) {
694
+ $ Accepted = $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['assume ' ][$ Accepted ] ?? $ Accepted ;
695
+ }
701
696
702
697
/** Process client-specified L10N data. */
703
698
if ($ IsSameAs ) {
@@ -714,11 +709,11 @@ public function loadL10N(string $Path = ''): void
714
709
$ this ->ClientL10N ->Data = array_merge ($ this ->ClientL10N ->Data , $ Arr );
715
710
} else {
716
711
$ this ->ClientL10N = new \Maikuolan \Common \L10N ($ Arr , $ this ->L10N );
717
- $ this ->ClientL10N ->autoAssignRules ($ ForAutoAssign );
712
+ $ this ->ClientL10N ->autoAssignRules ($ Accepted );
718
713
}
719
714
} elseif (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
720
715
$ this ->ClientL10N = new \Maikuolan \Common \L10N ([], $ this ->L10N );
721
- $ this ->ClientL10N ->autoAssignRules ($ ForAutoAssign );
716
+ $ this ->ClientL10N ->autoAssignRules ($ Accepted );
722
717
}
723
718
}
724
719
0 commit comments