Skip to content

Commit

Permalink
chore: Adjusting the interceptor and correcting sideWrapper translations
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed May 30, 2024
1 parent 1078b7c commit 0c1db8e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 36 deletions.
4 changes: 3 additions & 1 deletion docs/src/app/[locale]/(doc-session)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "react-modern-drawer/dist/index.css";
import type { Metadata } from "next";
import { setStaticParamsLocale } from "next-international/server";

import { I18nProviderClient } from "@/locales/client";
import { getScopedI18n } from "@/locales/server";

import { LocaleParams } from "../types/locale";
Expand Down Expand Up @@ -30,6 +31,7 @@ type DocumentationLayoutProps = Readonly<{

export default function DocumentationLayout({
children,
params: { locale },
}: DocumentationLayoutProps) {
return <>{children}</>;
return <I18nProviderClient locale={locale}>{children}</I18nProviderClient>;
}
2 changes: 1 addition & 1 deletion docs/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Image from "next/image";
import Link from "next/link";

import Intercepter from "@/components/Intercepter";
import Intercepter from "@/components/Interceptor";
import translation from "@/components/Internationalization";
import MainBg from "@/components/MainBg";
import { merriweather, oswald, playfair, roboto100, sofiaPro } from "@/fonts";
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { FaYoutube, FaInstagram, FaGithub, FaLinkedin } from "react-icons/fa";

import { playfair, sofiaPro } from "@/fonts";

import translation, { getBrowserLang } from "../Internationalization";
import translation, { Langs, getBrowserLang } from "../Internationalization";

export default function Footer() {
const [isClient, setIsClient] = useState(false);

const browserLang = getBrowserLang();
const browserLang = getBrowserLang() as unknown as (Langs | undefined)[];

const t = (text: string) =>
translation({ text, subject: "Footer", language: browserLang });
Expand Down
4 changes: 2 additions & 2 deletions docs/src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { FaCaretDown } from "react-icons/fa";

import { roboto700 } from "@/fonts";

import translation, { getBrowserLang } from "../Internationalization";
import translation, { Langs, getBrowserLang } from "../Internationalization";

export default function Header() {
const [isClient, setIsClient] = useState(false);

const browserLang = getBrowserLang();
const browserLang = getBrowserLang() as unknown as (Langs | undefined)[];

const t = (text: string) =>
translation({ text, subject: "Header", language: browserLang });
Expand Down
24 changes: 0 additions & 24 deletions docs/src/components/Intercepter/index.tsx

This file was deleted.

36 changes: 36 additions & 0 deletions docs/src/components/Interceptor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use client";

import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";

import { getBrowserLang } from "../Internationalization";
import MainBg from "../MainBg";

export default function Intercepter() {
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();

useEffect(() => {
const browserLang = getBrowserLang();

const verify = (browserLang &&
(browserLang[0] === "pt" || browserLang[0] === "pt-BR")) as boolean;

if (verify) {
document.documentElement.lang = "pt";
setIsLoading(true);
router.push("/pt");
setIsLoading(false);
}
}, []);

if (isLoading) {
return (
<MainBg>
<></>
</MainBg>
);
}

return null;
}
10 changes: 5 additions & 5 deletions docs/src/components/Internationalization/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import enJson from "@/locales/en/en.json";
import ptJson from "@/locales/pt/pt.json";

export type Langs = "en" | "pt" | "";
export type Langs = "en" | "pt";

interface TranslationProps {
text: string;
subject?: keyof typeof enJson | "";
language?: Langs;
language?: (Langs | undefined)[];
}

interface Locale {
Expand All @@ -15,15 +15,15 @@ interface Locale {

function translation({
text,
language = "",
language = [],
subject = "",
}: TranslationProps): string {
if (language) {
for (const lang of language) {
if (lang.includes("pt")) {
if (lang?.includes("pt")) {
return portugueseTreatment({ text, subject });
}
if (lang.includes("en")) {
if (lang?.includes("en")) {
return englishTreatment({ text, subject });
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/SidebarWrapper/js/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import translation, { Langs } from "@/components/Internationalization";

export default function SidebarWrapper({ locale }: { locale?: Langs }) {
const t = (text: string) =>
translation({ text, subject: "SidebarWrapperJs", language: locale });
translation({ text, subject: "SidebarWrapperJs", language: [locale] });

const route = locale === "pt" ? "/pt/" : "/";

Expand Down

0 comments on commit 0c1db8e

Please sign in to comment.