-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make locale toggle * i18n next setup * cleanup dependencies
- Loading branch information
1 parent
e80a645
commit 1616fdd
Showing
15 changed files
with
173 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 @@ | ||
import { resources, defaultNS } from './i18n'; | ||
|
||
declare module 'i18next' { | ||
interface CustomTypeOptions { | ||
defaultNS: typeof defaultNS; | ||
resources: typeof resources['en']; | ||
} | ||
} |
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,31 @@ | ||
import { FC, useState } from 'react' | ||
import ToggleButton from '@mui/material/ToggleButton' | ||
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup' | ||
import { useTranslation } from 'react-i18next'; | ||
import Locale from '@/i18n/locales' | ||
|
||
const LocaleToggle: FC = () => { | ||
const [locale, setLocale] = useState(Locale.EN); | ||
const { i18n } = useTranslation(); | ||
|
||
const handleChange = (_: React.MouseEvent<HTMLElement>, nextLocale: Locale) => { | ||
const changeLanguage = async () => { | ||
await i18n.changeLanguage(nextLocale).then(() => | ||
setLocale(nextLocale) | ||
) | ||
} | ||
changeLanguage().catch((e: Error) => { | ||
console.error(e) | ||
}) | ||
} | ||
|
||
return <ToggleButtonGroup | ||
exclusive | ||
value={locale} | ||
onChange={handleChange}> | ||
<ToggleButton value={Locale.EN}>English</ToggleButton> | ||
<ToggleButton value={Locale.JA}>日本語</ToggleButton> | ||
</ToggleButtonGroup> | ||
} | ||
|
||
export default LocaleToggle |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import i18next from 'i18next' | ||
import { initReactI18next } from 'react-i18next' | ||
import english from './en/translation.json' | ||
import japanese from './ja/translation.json' | ||
import Locale from './locales' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
i18next.use(initReactI18next).init({ | ||
lng: Locale.EN, // if you're using a language detector, do not define the lng option | ||
debug: true, | ||
resources: { | ||
en: { | ||
translation: english | ||
}, | ||
ja: { | ||
translation: japanese | ||
} | ||
|
||
}, | ||
// if you see an error like: "Argument of type 'DefaultTFuncReturn' is not assignable to parameter of type xyz" | ||
// set returnNull to false (and also in the i18next.d.ts options) | ||
// returnNull: false, | ||
}); |
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,5 @@ | ||
{ | ||
"codeOfConduct": "Code of Conduct", | ||
"helloWorld": "✨ Hello World ✨", | ||
"joinUs": "✨ Join us on Slack ✨" | ||
} |
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,5 @@ | ||
{ | ||
"codeOfConduct": "行動規範", | ||
"helloWorld": "✨ Hello 世界 ✨", | ||
"joinUs": "✨ スラックに参加する ✨" | ||
} |
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,6 @@ | ||
enum Locale { | ||
EN = 'en', | ||
JA = 'ja' | ||
} | ||
|
||
export default Locale |
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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
import { FC } from 'react' | ||
import { FC, Suspense } from 'react' | ||
import Header from '@/components/Header/Header' | ||
import Footer from '@/components/Footer/Footer' | ||
import { | ||
Outlet, | ||
} from 'react-router-dom' | ||
|
||
// loading component for suspense fallback | ||
const Loader = () => ( | ||
<div> | ||
<div>Loading...</div> | ||
</div> | ||
); | ||
|
||
const BaseLayout: FC = () => { | ||
return <> | ||
return <Suspense fallback={<Loader />}> | ||
<Header /> | ||
<Outlet /> | ||
<Footer /> | ||
</> | ||
</Suspense> | ||
} | ||
|
||
export default BaseLayout |
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