Remove smart button locale, validate bcp47, add en as default fallback

This commit is contained in:
dinamiko 2021-05-13 16:41:38 +02:00
parent 845a83acb4
commit 33022f3c47
4 changed files with 9 additions and 55 deletions

View file

@ -67,12 +67,16 @@ class ApplicationContextRepository {
*/
protected function valid_bcp47_code() {
$locale = str_replace( '_', '-', get_user_locale() );
$parts = explode( '-', $locale );
if ( count( $parts ) < 3 ) {
if ( preg_match( '/^[a-z]{2}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}))?$/', $locale ) ) {
return $locale;
}
return substr( $locale, 0, strrpos( $locale, '-' ) );
$parts = explode( '-', $locale );
if ( count( $parts ) === 3 ) {
return substr( $locale, 0, strrpos( $locale, '-' ) );
}
return 'en';
}
}