Skip to content

Commit

Permalink
feat: improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Oct 25, 2024
1 parent 69912cc commit 528bd29
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 3 additions & 5 deletions testapps/next-internal/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextPage } from 'next';
import Head from 'next/head';
import { useEffect, useState } from 'react';
import { T, Tolgee, TolgeeProvider, useTolgeeSSR } from '@tolgee/react';
import { T, Tolgee, TolgeeProvider } from '@tolgee/react';
import { InContextTools } from '@tolgee/web/tools';
import { useRouter } from 'next/router';

Expand All @@ -26,19 +26,17 @@ const Home: NextPage = () => {

const [ready, setReady] = useState(false);

const tolgeeSSR = useTolgeeSSR(tolgee, router.locale);

useEffect(() => {
const queryParams = new URLSearchParams(window.location.search);
const apiKey =
queryParams.get('api_key') || process.env.NEXT_PUBLIC_TOLGEE_API_KEY;

tolgeeSSR.updateOptions({ apiKey });
tolgee.updateOptions({ apiKey });
setReady(true);
}, []);

return ready ? (
<TolgeeProvider tolgee={tolgeeSSR}>
<TolgeeProvider tolgee={tolgee} language={router.locale}>
<div className={styles.container}>
<Head>
<title>Create Next App</title>
Expand Down
6 changes: 3 additions & 3 deletions testapps/next/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Todos } from '../views/Todos';
export const getStaticProps: GetStaticProps = async (context) => {
return {
props: {
locales: await getServerLocales(context.locale),
staticData: await getServerLocales(context.locale),
},
};
};

const Home: NextPage<{ locales: any }> = ({ locales }) => {
const Home: NextPage<{ staticData: any }> = ({ staticData }) => {
return (
<TolgeeNextProvider locales={locales}>
<TolgeeNextProvider staticData={staticData}>
<Todos />
</TolgeeNextProvider>
);
Expand Down
6 changes: 3 additions & 3 deletions testapps/next/src/pages/translation-methods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { TranslationMethods } from '../views/TranslationMethods';
export const getStaticProps: GetStaticProps = async (context) => {
return {
props: {
locales: await getServerLocales(context.locale, ['', 'namespaced']),
staticData: await getServerLocales(context.locale, ['', 'namespaced']),
},
};
};

const Home: NextPage<{ locales: any }> = ({ locales }) => {
const Home: NextPage<{ staticData: any }> = ({ staticData }) => {
return (
<TolgeeNextProvider locales={locales}>
<TolgeeNextProvider staticData={staticData}>
<TranslationMethods />
</TolgeeNextProvider>
);
Expand Down
11 changes: 6 additions & 5 deletions testapps/next/src/tolgeeNext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TolgeeProvider,
getFallbackArray,
DevTools,
useTolgeeSSR,
TolgeeStaticData,
} from '@tolgee/react';

const apiKey = process.env.NEXT_PUBLIC_TOLGEE_API_KEY;
Expand Down Expand Up @@ -37,7 +37,7 @@ export const getServerLocales = async (
};

type Props = {
locales: any;
staticData: TolgeeStaticData;
};

const tolgee = Tolgee()
Expand All @@ -51,15 +51,16 @@ const tolgee = Tolgee()
});

export const TolgeeNextProvider = ({
locales,
staticData,
children,
}: React.PropsWithChildren<Props>) => {
const router = useRouter();
const tolgeeSSR = useTolgeeSSR(tolgee, router.locale, locales);

return (
<TolgeeProvider
tolgee={tolgeeSSR}
tolgee={tolgee}
language={router.locale}
staticData={staticData}
fallback="Loading..."
options={{ useSuspense: true }}
>
Expand Down
1 change: 1 addition & 0 deletions testapps/vue-ssr/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

0 comments on commit 528bd29

Please sign in to comment.