-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use proper way to require express-handlebars
import Fragment from react (#3133) Switched twitch iframe from `twitch.tv` to `player.twitch.tv` (#3023) added next-i18next fixed errors to run i18next added more translations added next-i18next fixed errors to run i18next added more translations removed de language fixed translation attempting to use i18 without next added language routing prettier fix renamed component fixed typo revert formatting in package.json revert formatting in package.json removed extra css Update type Co-authored-by: Josue <[email protected]> cleaned code updated pnpm-lock.yaml added language array for rendering list of languages coding fixes added key Revert "fix: use proper way to require express-handlebars" This reverts commit 83b9631. fix: use proper way to require express-handlebars import Fragment from react (#3133) Switched twitch iframe from `twitch.tv` to `player.twitch.tv` (#3023) added next-i18next fixed errors to run i18next added more translations added next-i18next fixed errors to run i18next added more translations removed de language fixed translation attempting to use i18 without next added language routing prettier fix renamed component fixed typo revert formatting in package.json revert formatting in package.json removed extra css Update type Co-authored-by: Josue <[email protected]> cleaned code updated pnpm-lock.yaml added language array for rendering list of languages coding fixes added key added getlang fn moved translation to about page revert capital added CSS to selectbox new pnpm-lock restored bannerbuttons file
- Loading branch information
1 parent
8adb138
commit b42ab12
Showing
7 changed files
with
913 additions
and
648 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,67 @@ | ||
import { createContext, ChangeEvent, useState } from 'react'; | ||
import { FormControl, Grid, InputLabel, MenuItem, Select } from '@material-ui/core'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
import { setLang, getLang } from '../translations/i18n'; | ||
|
||
export interface TranslationInterface { | ||
currentLanguage: string; | ||
} | ||
|
||
export const translationInterface = createContext<TranslationInterface>({ | ||
currentLanguage: 'en', | ||
}); | ||
|
||
const languages: Array<{ name: string; code: string }> = [ | ||
{ name: 'English', code: 'en' }, | ||
{ name: 'Español', code: 'es' }, | ||
]; | ||
|
||
const useStyles = makeStyles((theme) => { | ||
return { | ||
selectBox: { | ||
width: '10rem', | ||
fontFamily: 'sans-serif', | ||
}, | ||
}; | ||
}); | ||
|
||
const LanguageSelector = () => { | ||
const classes = useStyles(); | ||
|
||
// sets the state to use the current i18 language. i18 remembers the language for the page, | ||
// and is not effected by rendering. | ||
const [language, setLanguage] = useState(getLang()); | ||
|
||
const changeLanguage = ( | ||
e: ChangeEvent<{ name?: string | undefined; value: string | unknown }> | ||
) => { | ||
e.preventDefault(); | ||
setLanguage(e.target.value as string); | ||
setLang(e.target.value); | ||
}; | ||
|
||
return ( | ||
<Grid container> | ||
<FormControl> | ||
<InputLabel>Language</InputLabel> | ||
<Select | ||
className={classes.selectBox} | ||
value={language} | ||
label="Language" | ||
onChange={changeLanguage} | ||
> | ||
{languages.map((lang) => { | ||
return ( | ||
<MenuItem key={lang.code} value={lang.code}> | ||
{lang.name} | ||
</MenuItem> | ||
); | ||
})} | ||
</Select> | ||
</FormControl> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default LanguageSelector; |
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 @@ | ||
const TRANSLATIONS_EN = { | ||
about: 'About', | ||
aboutUs: 'About Us', | ||
signIn: 'Sign In', | ||
signOut: 'Sign out', | ||
}; | ||
|
||
export default TRANSLATIONS_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,8 @@ | ||
const TRANSLATIONS_ES = { | ||
about: 'Acerca de', | ||
aboutUs: 'Sobre nosotros', | ||
signIn: 'Iniciar sesión', | ||
signOut: 'Cerrar sesión', | ||
}; | ||
|
||
export default TRANSLATIONS_ES; |
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,30 @@ | ||
import i18n from 'i18next'; | ||
import { initReactI18next } from 'react-i18next'; | ||
import LanguageDetector from 'i18next-browser-languagedetector'; | ||
|
||
import TRANSLATIONS_ES from './es/translations'; | ||
import TRANSLATIONS_EN from './en/translations'; | ||
|
||
i18n | ||
.use(LanguageDetector) | ||
.use(initReactI18next) | ||
.init({ | ||
resources: { | ||
en: { | ||
translation: TRANSLATIONS_EN, | ||
}, | ||
es: { | ||
translation: TRANSLATIONS_ES, | ||
}, | ||
}, | ||
}); | ||
|
||
// function to set the language for i18n | ||
export const setLang = (language) => { | ||
i18n.changeLanguage(language); | ||
}; | ||
|
||
// function to return the current language selected for i18n | ||
export function getLang() { | ||
return i18n.language || 'en'; | ||
} |