-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6ccc35
commit 8ff4b4e
Showing
12 changed files
with
118 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
i18n: { | ||
locales: [ | ||
"en", | ||
"en-US", | ||
"en-GB", | ||
"es", | ||
"es-AR", | ||
"es-ES", | ||
"pl", | ||
"pl-PL", | ||
"fr", | ||
"fr-BE", | ||
"fr-CA", | ||
], | ||
defaultLocale: "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
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,10 @@ | ||
{ | ||
"index": {}, | ||
"search": { | ||
"title": "Search", | ||
"placeholder": "Type something ..." | ||
}, | ||
"player": { | ||
"error": "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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"index": {}, | ||
"search": { | ||
"title": "Buscar", | ||
"placeholder": "Escribe algo ..." | ||
}, | ||
"player": { | ||
"error": "Oh oh, algo salió mal :(" | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"index": {}, | ||
"search": { | ||
"title": "Chercher", | ||
"placeholder": "Tapez quelque chose ..." | ||
}, | ||
"player": { | ||
"error": "Quelque chose s'est mal passé :(" | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"index": {}, | ||
"search": { | ||
"title": "Szukać", | ||
"placeholder": "Napisz coś ..." | ||
}, | ||
"player": { | ||
"error": "Ojojoj, coś poszło nie tak :(" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useRouter } from "next/router"; | ||
import { useState, useEffect } from "react"; | ||
import en from "../../../public/i18n/en.json"; | ||
|
||
export const useTranslation = createUseTranslation("en", en); | ||
|
||
export function createUseTranslation<T>(defaultLocale: string, translation: T) { | ||
const cache = new Map(); | ||
cache.set(defaultLocale, translation); | ||
|
||
return function useTranslation() { | ||
const { locale } = useRouter(); | ||
const [lang] = locale.split("-"); | ||
const [t, setTranslation] = useState(translation); | ||
|
||
useEffect(() => { | ||
if (cache.has(lang)) { | ||
return setTranslation(cache.get(lang)); | ||
} | ||
|
||
fetch(`/i18n/${lang}.json`) | ||
.then((r) => r.json()) | ||
.then((translation) => { | ||
cache.set(lang, translation); | ||
setTranslation(translation); | ||
}); | ||
}, [lang]); | ||
|
||
return { t }; | ||
}; | ||
} |
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