Add portuguese translation

This commit is contained in:
AkiraFukushima 2024-02-05 21:52:13 +09:00
parent effc6a4453
commit a558bcb265
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
2 changed files with 14 additions and 3 deletions

View File

@ -17,6 +17,10 @@ const languages = [
{
label: '日本語',
value: 'ja'
},
{
label: 'Português',
value: 'pt-PT'
}
]
@ -27,11 +31,16 @@ export default function Settings(props: Props) {
useEffect(() => {
if (typeof localStorage !== 'undefined') {
const lang = localStorage.getItem('language')
setLanguage(lang as localeType)
if (lang) {
setLanguage(lang as localeType)
} else {
setLanguage('en')
}
}
}, [])
const languageChanged = (e: string) => {
setLanguage(e as localeType)
if (typeof localStorage !== 'undefined') {
localStorage.setItem('language', e)
}

View File

@ -1,10 +1,11 @@
import en from '../../locales/en/translation.json'
import ja from '../../locales/ja/translation.json'
import pt_pt from '../../locales/pt_pt/translation.json'
import { flattenMessages } from '../utils/flattenMessage'
import { createContext, useState } from 'react'
import { IntlProvider } from 'react-intl'
export type localeType = 'en' | 'ja'
export type localeType = 'en' | 'ja' | 'pt-PT'
type Props = {
children: React.ReactNode
@ -19,7 +20,8 @@ export const Context = createContext<Lang>({} as Lang)
export const IntlProviderWrapper: React.FC<Props> = props => {
const langs = [
{ locale: 'en', messages: flattenMessages(en) },
{ locale: 'ja', messages: flattenMessages(ja) }
{ locale: 'ja', messages: flattenMessages(ja) },
{ locale: 'pt-PT', messages: flattenMessages(pt_pt) }
]
const [lang, setLang] = useState(langs[0])