-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(lang): promise results in switch language
- Loading branch information
Showing
8 changed files
with
54 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ export * as enUS from './en-US' | |
export * as ptBR from './pt-BR' | ||
|
||
export * from './locates' | ||
export * from './set' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { LanguageRaw, LanguageI18N } from 'better-write-types' | ||
|
||
export const localeToRaw = (lang: LanguageRaw) => { | ||
return ( | ||
{ | ||
'Português do Brasil': 'br', | ||
English: 'en', | ||
}[lang] || 'en' | ||
) | ||
} | ||
|
||
export const onSwitchLanguage = (lang: LanguageRaw): Promise<LanguageI18N> => { | ||
return new Promise((res) => { | ||
const set = | ||
{ | ||
'Português do Brasil': 'br', | ||
English: 'en', | ||
}[lang] || 'en' | ||
|
||
localStorage.setItem('lang', set) | ||
|
||
const iso = | ||
{ | ||
en: 'en-US', | ||
br: 'pt-BR', | ||
}[set] || 'en-US' | ||
|
||
;(document.querySelector('html') as HTMLElement).lang = iso | ||
|
||
res(set as LanguageI18N) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type LanguageI18N = 'br' | 'en' | ||
export type LanguageRaw = 'Português do Brasil' | 'English' |