File tree Expand file tree Collapse file tree 4 files changed +18
-6
lines changed Expand file tree Collapse file tree 4 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ function setLocale(locale) {
227227function getLocale ( ) {
228228 return ( _locale ||
229229 document . documentElement . getAttribute ( 'data-symfony-ux-translator-locale' ) ||
230- document . documentElement . lang ||
230+ ( document . documentElement . lang ? document . documentElement . lang . replace ( '-' , '_' ) : null ) ||
231231 'en' ) ;
232232}
233233function throwWhenNotFound ( enabled ) {
Original file line number Diff line number Diff line change @@ -47,8 +47,8 @@ export function setLocale(locale: LocaleType | null) {
4747export function getLocale ( ) : LocaleType {
4848 return (
4949 _locale ||
50- document . documentElement . getAttribute ( 'data-symfony-ux-translator-locale' ) || // <html data-symfony-ux-translator-locale="en ">
51- document . documentElement . lang || // <html lang="en">
50+ document . documentElement . getAttribute ( 'data-symfony-ux-translator-locale' ) || // <html data-symfony-ux-translator-locale="en_US ">
51+ ( document . documentElement . lang ? document . documentElement . lang . replace ( '-' , '_' ) : null ) || // <html lang="en-US ">
5252 'en'
5353 ) ;
5454}
Original file line number Diff line number Diff line change @@ -35,6 +35,18 @@ describe('Translator', () => {
3535 } ) ;
3636 } ) ;
3737
38+ describe ( 'getLocale' , ( ) => {
39+ test ( 'with subcode' , ( ) => {
40+ // allow format according to W3
41+ document . documentElement . lang = 'de-AT' ;
42+ expect ( getLocale ( ) ) . toEqual ( 'de_AT' ) ;
43+
44+ // or "incorrect" Symfony locale format
45+ document . documentElement . lang = 'de_AT' ;
46+ expect ( getLocale ( ) ) . toEqual ( 'de_AT' ) ;
47+ } ) ;
48+ } ) ;
49+
3850 describe ( 'setLocale' , ( ) => {
3951 test ( 'custom locale' , ( ) => {
4052 setLocale ( 'fr' ) ;
Original file line number Diff line number Diff line change @@ -90,9 +90,9 @@ Configuring the default locale
9090
9191By default, the default locale is ``en `` (English) that you can configure through many ways (in order of priority):
9292
93- #. With ``setLocale('your-locale ') `` from ``@symfony/ux-translator `` package
94- #. Or with ``<html data-symfony-ux-translator-locale="your- locale"> `` attribute
95- #. Or with ``<html lang="your- locale"> `` attribute
93+ #. With ``setLocale('de') `` or `` setLocale('de_AT ') `` from ``@symfony/ux-translator `` package
94+ #. Or with ``<html data-symfony-ux-translator-locale="{{ app.request. locale }} "> `` attribute (e.g., ` de_AT ` or ` de ` for Symfony locale format)
95+ #. Or with ``<html lang="{{ app.request. locale|replace({ '_': '-' }) }} "> `` attribute (e.g., ` de-AT ` or ` de ` for W3C spec compliant format)
9696
9797Detecting missing translations
9898~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can’t perform that action at this time.
0 commit comments