22 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
33 * SPDX-License-Identifier: GPL-3.0-or-later
44 */
5- import { afterEach , beforeEach , describe , expect , it , test } from 'vitest'
5+ import { beforeEach , describe , expect , it } from 'vitest'
66import {
77 getCanonicalLocale ,
88 getLanguage ,
@@ -13,54 +13,49 @@ import {
1313const setLocale = ( locale : string ) => document . documentElement . setAttribute ( 'data-locale' , locale )
1414const setLanguage = ( lang : string ) => document . documentElement . setAttribute ( 'lang' , lang )
1515
16- describe ( 'getCanonicalLocale' , ( ) => {
17- afterEach ( ( ) => {
18- setLocale ( '' )
16+ describe ( 'getLanguage' , ( ) => {
17+ it ( 'returns the set language as it is' , ( ) => {
18+ setLanguage ( 'de-DE' )
19+ expect ( getLanguage ( ) ) . toEqual ( 'de-DE' )
1920 } )
2021
21- it ( 'Returns primary locales as is' , ( ) => {
22- setLocale ( 'de' )
23- expect ( getCanonicalLocale ( ) ) . toEqual ( 'de' )
24- setLocale ( 'zu' )
25- expect ( getCanonicalLocale ( ) ) . toEqual ( 'zu' )
22+ it ( 'returns the environment locale if no language is set' , ( ) => {
23+ const environmentLocale = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . locale
24+ setLanguage ( '' )
25+ expect ( getLanguage ( ) ) . toEqual ( environmentLocale )
2626 } )
27+ } )
2728
28- it ( 'Returns extended locales with hyphens' , ( ) => {
29- setLocale ( 'az_Cyrl_AZ' )
30- expect ( getCanonicalLocale ( ) ) . toEqual ( 'az-Cyrl-AZ' )
29+ describe ( 'getLocale' , ( ) => {
30+ it ( 'returns the set locale as it is with underscore' , ( ) => {
3131 setLocale ( 'de_DE' )
32- expect ( getCanonicalLocale ( ) ) . toEqual ( 'de-DE ' )
32+ expect ( getLocale ( ) ) . toEqual ( 'de_DE ' )
3333 } )
34- } )
35-
36- test ( 'getLanguage' , ( ) => {
37- document . documentElement . removeAttribute ( 'lang' )
38- // Expect fallback
39- expect ( getLanguage ( ) ) . toBe ( 'en' )
40- setLanguage ( '' )
41- expect ( getLanguage ( ) ) . toBe ( 'en' )
4234
43- // Expect value
44- setLanguage ( 'zu' )
45- expect ( getLanguage ( ) ) . toBe ( 'zu' )
35+ it ( 'returns the environment locale with underscore if no locale is set' , ( ) => {
36+ const environmentLocale = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . locale
37+ setLocale ( '' )
38+ expect ( getLocale ( ) ) . toEqual ( environmentLocale . replace ( / - / g, '_' ) )
39+ } )
4640} )
4741
48- test ( 'getLocale' , ( ) => {
49- document . documentElement . removeAttribute ( 'data-locale' )
50- // Expect fallback
51- expect ( getLocale ( ) ) . toBe ( 'en' )
52- setLocale ( '' )
53- expect ( getLocale ( ) ) . toBe ( 'en' )
42+ describe ( 'getCanonicalLocale' , ( ) => {
43+ it ( 'returns the set locale with hyphen' , ( ) => {
44+ setLocale ( 'de_DE' )
45+ expect ( getCanonicalLocale ( ) ) . toEqual ( 'de-DE' )
46+ } )
5447
55- // Expect value
56- setLocale ( 'de_DE' )
57- expect ( getLocale ( ) ) . toBe ( 'de_DE' )
48+ it ( 'returns the environment locale with hyphen if no locale is set' , ( ) => {
49+ const environmentLocale = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . locale
50+ setLocale ( '' )
51+ expect ( getCanonicalLocale ( ) ) . toEqual ( environmentLocale )
52+ } )
5853} )
5954
6055describe ( 'isRTL' , ( ) => {
6156 beforeEach ( ( ) => document . documentElement . removeAttribute ( 'data-locale' ) )
6257
63- it ( 'fallsback to English which is LTR' , ( ) => {
58+ it ( 'falls back to English which is LTR' , ( ) => {
6459 // Expect fallback which is English = LTR
6560 expect ( isRTL ( ) ) . toBe ( false )
6661 } )
0 commit comments