Skip to content

Commit

Permalink
Merge pull request #184 from cboard-org/feature/LanguagePicker
Browse files Browse the repository at this point in the history
Feature / Language picker
  • Loading branch information
RodriSanchez1 authored Aug 6, 2024
2 parents e0e8799 + 44f7901 commit 25baf01
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
37 changes: 26 additions & 11 deletions src/components/Settings/AppSection.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import React from 'react';
import List from '@mui/material/List';
import ListSubheader from '@mui/material/ListSubheader';
import ListItem from '@mui/material/ListItem';
import ListItemButton from '@mui/material/ListItemButton';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
import Select, { SelectChangeEvent } from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
import ListItemText from '@mui/material/ListItemText';
import ListItemIcon from '@mui/material/ListItemIcon';
import LanguageIcon from '@mui/icons-material/Language';
import { useTranslations } from 'next-intl';
import { useLocale, useTranslations } from 'next-intl';
import { styles } from './styles';
import { supportedLocales } from '@/intl/intl.constants';
import { startTransition } from 'react';
import { useRouter, usePathname } from '@/navigation';

export default function AppSection() {
const router = useRouter();
const pathname = usePathname();
const messages = useTranslations('Settings');
const locale = useLocale();

const handleOnChange = (event: SelectChangeEvent<string>) => {
const nextLocale = event.target.value;

startTransition(() => {
router.replace(pathname, { locale: nextLocale });
});
};

return (
<List
subheader={
Expand All @@ -27,15 +43,14 @@ export default function AppSection() {
<Select
labelId="demo-simple-select-filled-label"
id="demo-simple-select-filled"
// value={age}
// onChange={handleChange}
value={locale}
onChange={handleOnChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
{supportedLocales.map((locale) => (
<MenuItem key={locale} value={locale}>
{locale.slice(0, 2).toUpperCase()}
</MenuItem>
))}
</Select>
</FormControl>
}
Expand All @@ -45,7 +60,7 @@ export default function AppSection() {
<ListItemIcon>
<LanguageIcon />
</ListItemIcon>
<ListItemText id={'labelId'} primary={`Language `} />
<ListItemText id={'labelId'} primary={messages('language')} />
</ListItemButton>
</ListItem>
</List>
Expand Down
2 changes: 1 addition & 1 deletion src/intl/intl.constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const supportedLocales = ['en-US', 'pt-BR', 'pt-PT', 'es-ES'];
export const supportedLocales = ['en-US', 'pt-BR', 'es-ES'];

export const defaultLocale = 'en-US';

Expand Down

0 comments on commit 25baf01

Please sign in to comment.