8
8
* License: GNU/GPLv2
9
9
* @see LICENSE.txt
10
10
*
11
- * This file: The loader (last modified: 2024.03.21 ).
11
+ * This file: The loader (last modified: 2024.07.01 ).
12
12
*/
13
13
14
14
namespace phpMussel \Core ;
@@ -563,24 +563,20 @@ public function fallback(array $Fallbacks): void
563
563
*/
564
564
public function loadL10N (string $ Path = '' ): void
565
565
{
566
- if ($ this ->Configuration ['core ' ]['lang ' ] === 'en ' ) {
567
- $ Primary = $ this ->readFile ($ Path . 'en.yml ' );
568
- $ Fallback = '' ;
569
- } else {
570
- if (($ Primary = $ this ->readFile ($ Path . $ this ->Configuration ['core ' ]['lang ' ] . '.yml ' )) === '' ) {
571
- if (isset ($ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ this ->Configuration ['core ' ]['lang ' ]])) {
572
- $ Primary = $ this ->readFile ($ Path . $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ this ->Configuration ['core ' ]['lang ' ]] . '.yml ' );
566
+ if (($ Primary = $ this ->readFile ($ Path . $ this ->Configuration ['core ' ]['lang ' ] . '.yml ' )) === '' ) {
567
+ if (isset ($ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ this ->Configuration ['core ' ]['lang ' ]])) {
568
+ if (($ Primary = $ this ->readFile ($ Path . $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ this ->Configuration ['core ' ]['lang ' ]] . '.yml ' )) === '' ) {
569
+ $ Primary = $ this ->readFile ($ Path . preg_replace ('~-.*$~ ' , '' , $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ this ->Configuration ['core ' ]['lang ' ]]) . '.yml ' );
573
570
}
574
- if ( $ Primary === '' ) {
575
- $ Try = preg_replace ( ' ~-.*$~ ' , '' , $ this -> Configuration [ ' core ' ][ ' lang ' ]);
576
- if (( $ Primary = $ this ->readFile ( $ Path . $ Try . ' .yml ' )) === '' ) {
577
- if (isset ( $ this ->ConfigurationDefaults [ ' core ' ][ ' lang ' ][ ' defer ' ][ $ Try ]) ) {
578
- $ Primary = $ this -> readFile ( $ Path . $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Try ] . ' .yml ' );
579
- }
571
+ }
572
+ if ( $ Primary === '' ) {
573
+ $ Try = preg_replace ( ' ~-.*$~ ' , '' , $ this ->Configuration [ ' core ' ][ ' lang ' ]);
574
+ if (( $ Primary = $ this ->readFile ( $ Path . $ Try . ' .yml ' )) === '' ) {
575
+ if ( isset ( $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Try ])) {
576
+ $ Primary = $ this -> readFile ( $ Path . $ this -> ConfigurationDefaults [ ' core ' ][ ' lang ' ][ ' defer ' ][ $ Try ] . ' .yml ' );
580
577
}
581
578
}
582
579
}
583
- $ Fallback = $ this ->readFile ($ Path . 'en.yml ' );
584
580
}
585
581
if ($ Primary !== '' ) {
586
582
$ Accepted = $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['assume ' ][$ this ->Configuration ['core ' ]['lang ' ]] ?? $ this ->Configuration ['core ' ]['lang ' ];
@@ -594,6 +590,7 @@ public function loadL10N(string $Path = ''): void
594
590
if ($ this ->L10NAccepted === '' && $ Accepted !== '' ) {
595
591
$ this ->L10NAccepted = $ Accepted ;
596
592
}
593
+ $ Fallback = substr ($ this ->L10NAccepted , 0 , 3 ) === 'en- ' ? '' : $ this ->readFile ($ Path . 'en.yml ' );
597
594
if ($ Fallback !== '' ) {
598
595
$ Arr = [];
599
596
$ this ->YAML ->process ($ Fallback , $ Arr );
@@ -612,12 +609,12 @@ public function loadL10N(string $Path = ''): void
612
609
}
613
610
} else {
614
611
$ this ->L10N = new \Maikuolan \Common \L10N ($ Primary , $ Fallback );
615
- if ($ this ->Configuration [ ' core ' ][ ' lang ' ] === 'en ' ) {
616
- $ this ->L10N ->autoAssignRules (' en-AU ' );
612
+ if (substr ( $ this ->L10NAccepted , 0 , 3 ) === 'en- ' ) {
613
+ $ this ->L10N ->autoAssignRules ($ this -> L10NAccepted );
617
614
} else {
618
615
$ this ->L10N ->autoAssignRules ($ this ->L10NAccepted , 'en-AU ' );
619
616
}
620
- $ this ->L10N ->PreferredVariant = $ this ->L10NAccepted ;
617
+ $ this ->L10N ->PreferredVariant = $ this ->ConfigurationDefaults [ ' core ' ][ ' lang ' ][ ' defer ' ][ $ this -> L10NAccepted ] ?? $ this -> L10NAccepted ;
621
618
}
622
619
623
620
/** Load client-specified L10N data if possible. */
@@ -637,17 +634,18 @@ public function loadL10N(string $Path = ''): void
637
634
$ IsSameAs = true ;
638
635
break 2 ;
639
636
}
640
- if (is_readable ($ Path . $ Accepted . '.yml ' )) {
641
- $ Primary = $ this ->readFile ($ Path . $ Accepted . '.yml ' );
637
+ if (($ Primary = $ this ->readFile ($ Path . $ Accepted . '.yml ' )) !== '' ) {
642
638
break 2 ;
643
639
}
644
640
if (isset ($ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Accepted ])) {
645
641
if ($ this ->L10NAccepted === $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Accepted ]) {
646
642
$ IsSameAs = true ;
647
643
break 2 ;
648
644
}
649
- if (is_readable ($ Path . $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Accepted ] . '.yml ' )) {
650
- $ Primary = $ this ->readFile ($ Path . $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Accepted ] . '.yml ' );
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
+ ) {
651
649
break 2 ;
652
650
}
653
651
}
@@ -661,6 +659,7 @@ public function loadL10N(string $Path = ''): void
661
659
if ($ IsSameAs ) {
662
660
if (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
663
661
$ this ->ClientL10N = &$ this ->L10N ;
662
+ $ this ->ClientL10NAccepted = &$ this ->L10NAccepted ;
664
663
}
665
664
} elseif ($ Primary !== '' ) {
666
665
$ Arr = [];
@@ -673,6 +672,7 @@ public function loadL10N(string $Path = ''): void
673
672
} else {
674
673
$ this ->ClientL10N = new \Maikuolan \Common \L10N ($ Arr , $ this ->L10N );
675
674
$ this ->ClientL10N ->autoAssignRules ($ Accepted );
675
+ $ this ->ClientL10N ->PreferredVariant = $ this ->ConfigurationDefaults ['core ' ]['lang ' ]['defer ' ][$ Accepted ] ?? $ Accepted ;
676
676
}
677
677
} elseif (!($ this ->ClientL10N instanceof \Maikuolan \Common \L10N )) {
678
678
$ this ->ClientL10N = new \Maikuolan \Common \L10N ([], $ this ->L10N );
@@ -683,7 +683,7 @@ public function loadL10N(string $Path = ''): void
683
683
/** Fallback for missing accepted client L10N choice. */
684
684
if ($ this ->ClientL10NAccepted === '' ) {
685
685
$ this ->ClientL10NAccepted = $ this ->L10NAccepted ;
686
- $ this ->ClientL10N ->PreferredVariant = $ this ->L10NAccepted ;
686
+ $ this ->ClientL10N ->PreferredVariant = $ this ->ConfigurationDefaults [ ' core ' ][ ' lang ' ][ ' defer ' ][ $ this -> L10NAccepted ] ?? $ this -> L10NAccepted ;
687
687
}
688
688
}
689
689
0 commit comments