Skip to content

Commit

Permalink
TML-9999 feat: add i18n for link
Browse files Browse the repository at this point in the history
  • Loading branch information
harrytran998 committed Jul 30, 2024
1 parent 3e973ad commit 3ad20f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pages/index/+Page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import './index.scss'
import "./index.scss";
import HomeHero from "#root/pages/index/components/HomeHero";

const IndexPage = () => {
return <>
<HomeHero />
</>;
return (
<>
<HomeHero />
</>
);
};

export default IndexPage;
18 changes: 18 additions & 0 deletions src/shared/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { usePageContext } from "@techmely/vike-react/usePageContext";
import type { AnchorHTMLAttributes, DetailedHTMLProps, FC } from "react";
import { type Locale, baseLocale } from "#root/locales/locales.utils";

type Props = DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> & {
locale?: Locale;
};

const Link: FC<Props> = ({ href, locale, ...props }) => {
const pageContext = usePageContext();
locale = locale || (pageContext.metadata?.locale as Locale);
if (locale !== baseLocale) {
href = `/${locale}${href}`;
}
return <a href={href} {...props} />;
};

export default Link;
6 changes: 6 additions & 0 deletions src/shared/libs/url/tenant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function composeTenantUrl(tenant: string, protocol: string, host: string) {
if (host.startsWith(tenant)) {
return `${protocol}//${host}`;
}
return `${protocol}//${tenant ? `${tenant}.` : ""}${host}`;
}

0 comments on commit 3ad20f7

Please sign in to comment.