added language switcher
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
import { Main } from "@/app/ui/Main";
|
import { Main } from "@/app/ui/Main";
|
||||||
import { PageFooter } from "@/app/ui/PageFooter";
|
|
||||||
import { PageHeader } from "@/app/ui/PageHeader";
|
|
||||||
|
|
||||||
const ConsentPage = () =>
|
const ConsentPage = () =>
|
||||||
<Main>
|
<Main>
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import { Formats, TranslationValues } from 'next-intl';
|
|||||||
// Can be imported from a shared config
|
// Can be imported from a shared config
|
||||||
export const locales = ['en', 'hr'];
|
export const locales = ['en', 'hr'];
|
||||||
|
|
||||||
|
export const localeNames:Record<string,string> = {
|
||||||
|
en: 'English',
|
||||||
|
hr: 'Hrvatski'
|
||||||
|
};
|
||||||
|
|
||||||
export const defaultLocale = 'en';
|
export const defaultLocale = 'en';
|
||||||
|
|
||||||
/** Templating function type as returned by `useTemplate` and `getTranslations` */
|
/** Templating function type as returned by `useTemplate` and `getTranslations` */
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import React from "react";
|
|||||||
import { formatYearMonth } from "../lib/format";
|
import { formatYearMonth } from "../lib/format";
|
||||||
import { YearMonth } from "../lib/db-types";
|
import { YearMonth } from "../lib/db-types";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useTranslations } from 'next-intl';
|
import { useLocale, useTranslations } from 'next-intl';
|
||||||
|
|
||||||
export interface AddMonthButtonProps {
|
export interface AddMonthButtonProps {
|
||||||
yearMonth: YearMonth;
|
yearMonth: YearMonth;
|
||||||
@@ -12,10 +12,11 @@ export interface AddMonthButtonProps {
|
|||||||
export const AddMonthButton:React.FC<AddMonthButtonProps> = ({ yearMonth }) => {
|
export const AddMonthButton:React.FC<AddMonthButtonProps> = ({ yearMonth }) => {
|
||||||
|
|
||||||
const t = useTranslations("home-page.add-month-button");
|
const t = useTranslations("home-page.add-month-button");
|
||||||
|
const locale = useLocale();
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className="card card-compact shadow-s mb-4">
|
<div className="card card-compact shadow-s mb-4">
|
||||||
<Link href={`/year-month/${formatYearMonth(yearMonth)}/add`} className='grid self-center tooltip' data-tip={t("tooltip")}>
|
<Link href={`/${locale}/year-month/${formatYearMonth(yearMonth)}/add`} className='grid self-center tooltip' data-tip={t("tooltip")}>
|
||||||
<span className='flex self-center mr-[-3em]'>
|
<span className='flex self-center mr-[-3em]'>
|
||||||
<CalendarDaysIcon className="h-[1em] w-[1em] cursor-pointer text-4xl" />
|
<CalendarDaysIcon className="h-[1em] w-[1em] cursor-pointer text-4xl" />
|
||||||
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-xl text-green-500 ml-[-.4em] mt-[-.4em]" />
|
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-xl text-green-500 ml-[-.4em] mt-[-.4em]" />
|
||||||
|
|||||||
@@ -1,16 +1,25 @@
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { PageHeader } from "./PageHeader";
|
import { PageHeader } from "./PageHeader";
|
||||||
import { PageFooter } from "./PageFooter";
|
import { PageFooter } from "./PageFooter";
|
||||||
|
import { NextIntlClientProvider, useMessages } from "next-intl";
|
||||||
|
|
||||||
export interface MainProps {
|
export interface MainProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Main:FC<MainProps> = ({ children }) =>
|
export const Main:FC<MainProps> = ({ children }) => {
|
||||||
<main className="flex min-h-screen flex-col bg-base-300">
|
|
||||||
<PageHeader />
|
const message = useMessages();
|
||||||
<div className="sm:mx-auto px-4">
|
|
||||||
{children}
|
return(
|
||||||
</div>
|
<NextIntlClientProvider messages={message}>
|
||||||
<PageFooter />
|
<main className="flex min-h-screen flex-col bg-base-300">
|
||||||
</main>
|
<PageHeader />
|
||||||
|
<div className="sm:mx-auto px-4">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
<PageFooter />
|
||||||
|
</main>
|
||||||
|
</NextIntlClientProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { SelectLanguage } from "./SelectLanguage";
|
||||||
|
|
||||||
export const PageHeader = () =>
|
export const PageHeader = () =>
|
||||||
<div className="navbar bg-base-100 mb-6">
|
<div className="navbar bg-base-100 mb-6">
|
||||||
<Link className="btn btn-ghost text-xl" href="/"><Image src="/icon3.png" alt="logo" width={48} height={48} /> Režije</Link>
|
<Link className="btn btn-ghost text-xl" href="/"><Image src="/icon3.png" alt="logo" width={48} height={48} /> Režije</Link>
|
||||||
</div>
|
<span className="grow"> </span>
|
||||||
|
<SelectLanguage />
|
||||||
|
</div>
|
||||||
16
app/ui/SelectLanguage.tsx
Normal file
16
app/ui/SelectLanguage.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useLocale } from "next-intl";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { usePathname } from "next/navigation";
|
||||||
|
import { defaultLocale, localeNames, locales } from "../i18n";
|
||||||
|
|
||||||
|
export const SelectLanguage: React.FC = () => {
|
||||||
|
const currentPathname = usePathname();
|
||||||
|
|
||||||
|
const locale = useLocale();
|
||||||
|
const secondLocale = locales.find((l) => l !== locale) as string;
|
||||||
|
const secondLocalePathname = defaultLocale === locale ? `/${secondLocale}${currentPathname}` : currentPathname.replace(`/${locale}/`, `/${secondLocale}/`);
|
||||||
|
|
||||||
|
return (<Link className="btn btn-ghost text-xl self-end" href={secondLocalePathname}>{localeNames[secondLocale]}</Link>);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user