Skip to content

Commit

Permalink
feat(i18n): Widget pra trocar de línguagem 🌐
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1t3h47 committed Nov 19, 2023
1 parent 32ca42c commit e70dd57
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import LanguageSelect from "@/components/molecules/LanguageSelect";
import { useI18n } from "@/utils/i18n/hooks/useI18n";
import { useLinks } from "@/utils/i18n/hooks/useLinks";
import { useNeutral } from "@/utils/i18n/hooks/useNeutral";
Expand Down Expand Up @@ -457,6 +458,7 @@ const Curriculum: React.FC = () => {
</li>
</ul>
</section>
<LanguageSelect />
</div>
</div>
</>
Expand Down
30 changes: 30 additions & 0 deletions src/components/molecules/LanguageSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// LanguageSelect.tsx
import React from "react";
import { useToggleLanguage } from "./useToggleLanguage";

const LanguageSelect: React.FC = () => {
const { currentLanguage, toggleLanguage, languages } = useToggleLanguage();

return (
<div className="fixed bottom-0 right-0 p-4 flex flex-col print:hidden">
{languages.map((language) => (
<button
key={language.code}
onClick={() => toggleLanguage(language.code)}
className={`px-2 py-1 bg-gray-200 rounded cursor-pointer hover:bg-gray-300 ${
currentLanguage === language.code && "font-bold"
}`}
>
<span className="flex items-center">
<span role="img" aria-label="Flag" className="text-2xl mr-1">
{language.emoji}
</span>
{language.label}
</span>
</button>
))}
</div>
);
};

export default LanguageSelect;
20 changes: 20 additions & 0 deletions src/components/molecules/LanguageSelect/useToggleLanguage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// useLanguage.ts
import { languages } from "@/utils/i18n/languages";
import { useEffect, useState } from "react";
import { useT } from "talkr";

export const useToggleLanguage = () => {
const { setLocale, locale } = useT();

const [currentLanguage, setCurrentLanguage] = useState<string>(locale);

useEffect(() => {
setCurrentLanguage(locale);
}, [locale]);

const toggleLanguage = (languageCode: string) => {
setLocale(languageCode);
};

return { currentLanguage, toggleLanguage, languages };
};
2 changes: 1 addition & 1 deletion src/utils/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"address": "Curitiba - PR - Brazil",
"profession": "Full-Stack Developer Specialist in React and Next.js",
"profession": "Full-Stack Developer Specialist in React and Next",
"description": "Solid experience in projects involving Frontend Development and SEO, currently in search of new challenges",
"certs_title": "Certifications",
"sololearn": "SoloLearn (USA):",
Expand Down
10 changes: 10 additions & 0 deletions src/utils/i18n/languages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface Language {
code: string;
emoji: string;
label: string;
}

export const languages: Language[] = [
{ code: "en", emoji: "🇺🇸", label: "EN" },
{ code: "pt", emoji: "🇧🇷", label: "PT" },
];

0 comments on commit e70dd57

Please sign in to comment.