-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
11 changed files
with
121 additions
and
13 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
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,75 @@ | ||
'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 getCookie = () => | ||
document.cookie | ||
.split('; ') | ||
.find(c => c.startsWith('locale=')) | ||
?.split('=')[1] as SupportedLanguage | undefined; | ||
|
||
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>( | ||
getCookie() | ||
); | ||
|
||
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