@@ -67,21 +67,44 @@ public static function getDefaultFallback()
6767 */
6868 public static function getFallback ($ locale )
6969 {
70- if (false === $ pos = strrpos ($ locale , '_ ' )) {
71- if (self ::$ defaultFallback === $ locale ) {
72- return 'root ' ;
73- }
70+ if (function_exists ('locale_parse ' )) {
71+ $ localeSubTags = locale_parse ($ locale );
72+ if (1 === count ($ localeSubTags )) {
73+ if (self ::$ defaultFallback === $ localeSubTags ['language ' ]) {
74+ return 'root ' ;
75+ }
76+
77+ // Don't return default fallback for "root", "meta" or others
78+ // Normal locales have two or three letters
79+ if (strlen ($ locale ) < 4 ) {
80+ return self ::$ defaultFallback ;
81+ }
7482
75- // Don't return default fallback for "root", "meta" or others
76- // Normal locales have two or three letters
77- if (strlen ($ locale ) < 4 ) {
78- return self ::$ defaultFallback ;
83+ return null ;
7984 }
8085
81- return ;
86+ array_pop ($ localeSubTags );
87+
88+ return locale_compose ($ localeSubTags );
89+ }
90+
91+ if (false !== $ pos = strrpos ($ locale , '_ ' )) {
92+ return substr ($ locale , 0 , $ pos );
8293 }
8394
84- return substr ($ locale , 0 , $ pos );
95+ if (false !== $ pos = strrpos ($ locale , '- ' )) {
96+ return substr ($ locale , 0 , $ pos );
97+ }
98+
99+ if (self ::$ defaultFallback === $ locale ) {
100+ return 'root ' ;
101+ }
102+
103+ // Don't return default fallback for "root", "meta" or others
104+ // Normal locales have two or three letters
105+ if (strlen ($ locale ) < 4 ) {
106+ return self ::$ defaultFallback ;
107+ }
85108 }
86109
87110 /**
0 commit comments