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) {
227
227
function getLocale ( ) {
228
228
return ( _locale ||
229
229
document . documentElement . getAttribute ( 'data-symfony-ux-translator-locale' ) ||
230
- document . documentElement . lang ||
230
+ ( document . documentElement . lang ? document . documentElement . lang . replace ( '-' , '_' ) : null ) ||
231
231
'en' ) ;
232
232
}
233
233
function throwWhenNotFound ( enabled ) {
Original file line number Diff line number Diff line change @@ -47,8 +47,8 @@ export function setLocale(locale: LocaleType | null) {
47
47
export function getLocale ( ) : LocaleType {
48
48
return (
49
49
_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 ">
52
52
'en'
53
53
) ;
54
54
}
Original file line number Diff line number Diff line change @@ -35,6 +35,18 @@ describe('Translator', () => {
35
35
} ) ;
36
36
} ) ;
37
37
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
+
38
50
describe ( 'setLocale' , ( ) => {
39
51
test ( 'custom locale' , ( ) => {
40
52
setLocale ( 'fr' ) ;
Original file line number Diff line number Diff line change @@ -90,9 +90,9 @@ Configuring the default locale
90
90
91
91
By default, the default locale is ``en `` (English) that you can configure through many ways (in order of priority):
92
92
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)
96
96
97
97
Detecting missing translations
98
98
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can’t perform that action at this time.
0 commit comments