-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add language toggle and hook up some translations
- Loading branch information
1 parent
89fffea
commit b4c4ba9
Showing
10 changed files
with
121 additions
and
11 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 |
---|---|---|
@@ -1 +1,9 @@ | ||
{} | ||
{ | ||
"Index": { | ||
"accounts": "Accounts", | ||
"contacts": "Contacts", | ||
"settings": "Settings", | ||
"transactions": "Transactions", | ||
"wallet": "Wallet" | ||
} | ||
} |
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 +1,9 @@ | ||
{} | ||
{ | ||
"Index": { | ||
"accounts": "Cuentas", | ||
"contacts": "Contactos", | ||
"settings": "Configuración", | ||
"transactions": "Transacciones", | ||
"wallet": "Billetera" | ||
} | ||
} |
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,76 @@ | ||
'use client'; | ||
|
||
import { Check, Languages } from 'lucide-react'; | ||
import { useRouter } from 'next/navigation'; | ||
import * as React from 'react'; | ||
import { useState } from 'react'; | ||
|
||
import { Button } from '@/components/ui/button'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu'; | ||
import { SupportedLanguage } from '@/i18n'; | ||
|
||
const setCookie = (locale: SupportedLanguage) => | ||
(document.cookie = `locale=${locale}; max-age=31536000; path=/;`); | ||
|
||
const deleteCookie = () => | ||
(document.cookie = 'locale=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'); | ||
|
||
export function LanguageToggle() { | ||
const { refresh } = useRouter(); | ||
|
||
const [language, setLanguage] = useState<SupportedLanguage | undefined>( | ||
() => { | ||
const localeCookie = document.cookie | ||
.split('; ') | ||
.find(c => c.startsWith('locale=')) | ||
?.split('=')[1] as SupportedLanguage | undefined; | ||
|
||
return localeCookie; | ||
} | ||
); | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline" size="icon"> | ||
<Languages className="h-[1.2rem] w-[1.2rem]" /> | ||
<span className="sr-only">Toggle theme</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end"> | ||
<DropdownMenuItem | ||
onClick={() => { | ||
setCookie('en'); | ||
setLanguage('en'); | ||
refresh(); | ||
}} | ||
> | ||
English {language === 'en' && <Check size={14} className="ml-1" />} | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
onClick={() => { | ||
setCookie('es'); | ||
setLanguage('es'); | ||
refresh(); | ||
}} | ||
> | ||
Español {language === 'es' && <Check size={14} className="ml-1" />} | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
onClick={() => { | ||
deleteCookie(); | ||
setLanguage(undefined); | ||
refresh(); | ||
}} | ||
> | ||
System {!language && <Check size={14} className="ml-1" />} | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
} |
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
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