File tree Expand file tree Collapse file tree 2 files changed +39
-10
lines changed
packages/better-write-app/src/use Expand file tree Collapse file tree 2 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,12 @@ import { useUtils } from './utils'
34
34
import i18n from '@/lang'
35
35
import { useI18n } from 'vue-i18n'
36
36
import useEmitter from './emitter'
37
- import { useMouse , usePageLeave , useTextSelection } from '@vueuse/core'
37
+ import {
38
+ useMouse ,
39
+ useNavigatorLanguage ,
40
+ usePageLeave ,
41
+ useTextSelection ,
42
+ } from '@vueuse/core'
38
43
import { watch } from 'vue'
39
44
40
45
export const useStart = ( ) => {
@@ -53,6 +58,7 @@ export const useStart = () => {
53
58
const { x, y } = useMouse ( { type : 'page' } )
54
59
const selection = useTextSelection ( )
55
60
const isLeft = usePageLeave ( )
61
+ const utils = useUtils ( )
56
62
const { t } = i18n . global
57
63
58
64
// set global mouse tracking
@@ -122,19 +128,19 @@ export const useStart = () => {
122
128
123
129
const lang = ( ) => {
124
130
const { locale } = useI18n ( )
125
- const lang = localStorage . getItem ( 'lang' )
131
+
132
+ const lang =
133
+ localStorage . getItem ( 'lang' ) ||
134
+ utils
135
+ . language ( )
136
+ . isoToCode ( useNavigatorLanguage ( ) . language . value as string )
126
137
127
138
if ( ! lang ) return
128
139
129
140
locale . value = lang
130
-
131
- const iso =
132
- {
133
- en : 'en-US' ,
134
- br : 'pt-BR' ,
135
- } [ lang ] || 'en-US'
136
-
137
- ; ( document . querySelector ( 'html' ) as HTMLElement ) . lang = iso
141
+ ; ( document . querySelector ( 'html' ) as HTMLElement ) . lang = utils
142
+ . language ( )
143
+ . codeToIso ( lang )
138
144
}
139
145
140
146
const initial = ( ) => {
Original file line number Diff line number Diff line change @@ -236,6 +236,28 @@ export const useUtils = () => {
236
236
return { assign, getMemorySizeOfObject }
237
237
}
238
238
239
+ const language = ( ) => {
240
+ const isoToCode = ( iso : string ) => {
241
+ return (
242
+ {
243
+ 'pt-BR' : 'br' ,
244
+ 'en-US' : 'en' ,
245
+ } [ iso ] || 'en'
246
+ )
247
+ }
248
+
249
+ const codeToIso = ( code : string ) => {
250
+ return (
251
+ {
252
+ en : 'en-US' ,
253
+ br : 'pt-BR' ,
254
+ } [ code ] || 'en-US'
255
+ )
256
+ }
257
+
258
+ return { isoToCode, codeToIso }
259
+ }
260
+
239
261
return {
240
262
position,
241
263
delay,
@@ -248,5 +270,6 @@ export const useUtils = () => {
248
270
support,
249
271
path,
250
272
object,
273
+ language,
251
274
}
252
275
}
You can’t perform that action at this time.
0 commit comments