-
Notifications
You must be signed in to change notification settings - Fork 0
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
22 changed files
with
528 additions
and
82 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,3 +1,6 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
"extends": "next/core-web-vitals", | ||
"rules": { | ||
"react-hooks/rules-of-hooks": "off" // Checks rules of Hooks | ||
} | ||
} |
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
File renamed without changes.
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,39 @@ | ||
import { dir } from "i18next"; | ||
import { Inter } from "next/font/google"; | ||
import { ReactNode } from "react"; | ||
import "./globals.css"; | ||
|
||
import Container from "@/components/Container"; | ||
import Footer from "@/components/Footer"; | ||
import Header from "@/components/Header"; | ||
import { ThemeProvider } from "@/context/ThemeContext"; | ||
import { languages } from "@/app/i18n/settings"; | ||
|
||
export async function generateStaticParams() { | ||
return languages.map((lng) => ({ lng })); | ||
} | ||
|
||
const inter = Inter({ subsets: ["latin"] }); | ||
|
||
type Props = { | ||
children: ReactNode; | ||
params: { lang: string }; | ||
}; | ||
|
||
async function RootLayout({ children, params: { lang } }: Props) { | ||
return ( | ||
<html lang={lang} dir={dir(lang)}> | ||
<body | ||
className={`bg-white dark:bg-slate-900 text-gray-700 dark:text-gray-200 antialiased" ${inter.className}`} | ||
> | ||
<ThemeProvider> | ||
<Header lang={lang} /> | ||
<Container>{children}</Container> | ||
<Footer lang={lang} /> | ||
</ThemeProvider> | ||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
export default RootLayout; |
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 { Metadata } from "next"; | ||
|
||
import Container from "@/components/Container"; | ||
import { useTranslation } from "../i18n"; | ||
|
||
type Props = { | ||
params: { lang: string }; | ||
}; | ||
|
||
export default async function Home({ params: { lang } }: Props) { | ||
const { t } = await useTranslation(lang); | ||
|
||
return ( | ||
<> | ||
<Container> | ||
<div className="space-y-6"> | ||
<h1 className="text-2xl font-bold">{t("title")}</h1> | ||
<p>{t("description")}</p> | ||
<p>{t("phrase")}</p> | ||
</div> | ||
</Container> | ||
</> | ||
); | ||
} | ||
|
||
export const metadata: Metadata = { | ||
title: "Andres Parra - Software Engineer | @byandrev", | ||
description: | ||
"Desarrollador de software apasionado por la tecnología y el desarrollo web. | Andres Parra - Software Engineer | @byandrev", | ||
}; |
File renamed without changes.
File renamed without changes.
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,59 @@ | ||
"use client"; | ||
|
||
import i18next from "i18next"; | ||
import LanguageDetector from "i18next-browser-languagedetector"; | ||
import resourcesToBackend from "i18next-resources-to-backend"; | ||
import { useEffect, useState } from "react"; | ||
import { | ||
initReactI18next, | ||
useTranslation as useTranslationOrg, | ||
} from "react-i18next"; | ||
|
||
import { getOptions, languages } from "./settings"; | ||
|
||
const runsOnServerSide = typeof window === "undefined"; | ||
|
||
// | ||
i18next | ||
.use(initReactI18next) | ||
.use(LanguageDetector) | ||
.use( | ||
resourcesToBackend( | ||
(language: string, namespace: string) => | ||
import(`./locales/${language}/${namespace}.json`) | ||
) | ||
) | ||
.init({ | ||
...getOptions(), | ||
lng: undefined, // let detect the language on client side | ||
detection: { | ||
order: ["path", "htmlTag", "cookie", "navigator"], | ||
}, | ||
preload: runsOnServerSide ? languages : [], | ||
}); | ||
|
||
export function useTranslation( | ||
lng: string, | ||
ns: string = "translation", | ||
options: any = {} | ||
) { | ||
const ret = useTranslationOrg(ns, options); | ||
const { i18n } = ret; | ||
if (runsOnServerSide && lng && i18n.resolvedLanguage !== lng) { | ||
i18n.changeLanguage(lng); | ||
} else { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const [activeLng, setActiveLng] = useState(i18n.resolvedLanguage); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useEffect(() => { | ||
if (activeLng === i18n.resolvedLanguage) return; | ||
setActiveLng(i18n.resolvedLanguage); | ||
}, [activeLng, i18n.resolvedLanguage]); | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useEffect(() => { | ||
if (!lng || i18n.resolvedLanguage === lng) return; | ||
i18n.changeLanguage(lng); | ||
}, [lng, i18n]); | ||
} | ||
return ret; | ||
} |
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,37 @@ | ||
import { createInstance, i18n } from "i18next"; | ||
import resourcesToBackend from "i18next-resources-to-backend"; | ||
import { TFunction } from "next-i18next"; | ||
import { initReactI18next } from "react-i18next/initReactI18next"; | ||
|
||
import { getOptions } from "./settings"; | ||
|
||
const initI18next = async (lng: string, ns: string) => { | ||
const i18nInstance = createInstance(); | ||
await i18nInstance | ||
.use(initReactI18next) | ||
.use( | ||
resourcesToBackend( | ||
(language: string, namespace: string) => | ||
import(`./locales/${language}/${namespace}.json`) | ||
) | ||
) | ||
.init(getOptions(lng, ns)); | ||
return i18nInstance; | ||
}; | ||
|
||
export async function useTranslation( | ||
lng: string, | ||
ns: string = "translation", | ||
options: any = {} | ||
): Promise<{ t: TFunction; i18n: i18n }> { | ||
const i18nextInstance = await initI18next(lng, ns); | ||
|
||
return { | ||
t: i18nextInstance.getFixedT( | ||
lng, | ||
Array.isArray(ns) ? ns[0] : ns, | ||
options.keyPrefix | ||
), | ||
i18n: i18nextInstance, | ||
}; | ||
} |
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,15 @@ | ||
{ | ||
"title": "Hi, I'm Andres Parra, Softwart Engineer", | ||
"description": "I am a software developer passionate about technology and web development. I like to always be learning and sharing my knowledge, that's why this blog exists. Fan of open source and coffee ☕.", | ||
"phrase": "Every line of code is an opportunity to create magic and bring innovative ideas to life. innovative ideas to life.", | ||
|
||
"spanish": "Spanish", | ||
"english": "English", | ||
|
||
"menu": { | ||
"about-me": "About me", | ||
"posts": "Posts" | ||
}, | ||
|
||
"footer": { "text": "Developed with 💙" } | ||
} |
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,15 @@ | ||
{ | ||
"title": "Hola, soy Andres Parra, Softwart Engineer", | ||
"description": "Soy un desarrollador de software apasionado por la tecnología y el desarrollo web. Me gusta siempre estar aprendiendo y compartiendo mis conocimientos, por eso existe este blog. Fan del open source y del café ☕.", | ||
"phrase": "Cada línea de código es una oportunidad para crear magia y dar vida a ideas innovadoras.", | ||
|
||
"spanish": "Español", | ||
"english": "Ingles", | ||
|
||
"menu": { | ||
"about-me": "Sobre mí", | ||
"posts": "Artículos" | ||
}, | ||
|
||
"footer": { "text": "Desarrollado con 💙" } | ||
} |
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,15 @@ | ||
export const fallbackLng = "es"; | ||
export const languages = [fallbackLng, "en"]; | ||
export const defaultNS = "translation"; | ||
|
||
export function getOptions(lng = fallbackLng, ns = defaultNS) { | ||
return { | ||
// debug: true, | ||
supportedLngs: languages, | ||
fallbackLng, | ||
lng, | ||
fallbackNS: defaultNS, | ||
defaultNS, | ||
ns, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Oops, something went wrong.