Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions i18next-nextjs-react/next-host/components/ReactRemoteContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { type MouseEvent } from 'react';
import i18nService from 'i18next-shared-lib/lib/i18nService';

import useReactRemoteTranslation from '../i18n/useReactRemoteTranslation';

const ReactRemoteContent = () => {
const { t } = useReactRemoteTranslation('react-remote-main');

const switchLanguage = () => {
i18nService.switchLanguage();
};

const handleButtonClick = (event: MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
switchLanguage();
};

return (
<div
style={{
border: 'dashed 5px blue',
}}
>
<header>{t('remoteTitle')}</header>
<aside>
<button onClick={handleButtonClick}>{t('changeLanguageButtonLabel')}</button>
</aside>
<main>{t('remoteContent')}</main>
</div>
);
};

export default ReactRemoteContent;
7 changes: 7 additions & 0 deletions i18next-nextjs-react/next-host/i18n/react-remote/en/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reactRemoteMain from './react-remote-main.json';

const TranslationsEN = {
'react-remote-main': reactRemoteMain,
};

export default TranslationsEN;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"remoteTitle": "React Remote : Title",
"changeLanguageButtonLabel": "React Remote : change language",
"remoteContent": "React Remote : I'm the remote child !"
}
7 changes: 7 additions & 0 deletions i18next-nextjs-react/next-host/i18n/react-remote/fr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reactRemoteMain from './react-remote-main.json';

const TranslationsFR = {
'react-remote-main': reactRemoteMain,
};

export default TranslationsFR;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"remoteTitle": "React Remote : Titre",
"changeLanguageButtonLabel": "React Remote : changer la langue",
"remoteContent": "React Remote : Je suis le remote child"
}
11 changes: 11 additions & 0 deletions i18next-nextjs-react/next-host/i18n/useReactRemoteTranslation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import useInstanceTranslation from 'i18next-shared-lib/lib/useInstanceTranslation';

import TranslationsEN from './react-remote/en';
import TranslationsFR from './react-remote/fr';

const useReactRemoteTranslation = useInstanceTranslation('react-remote', {
en: TranslationsEN,
fr: TranslationsFR,
});

export default useReactRemoteTranslation;
34 changes: 0 additions & 34 deletions i18next-nextjs-react/next-host/next.config.js

This file was deleted.

13 changes: 13 additions & 0 deletions i18next-nextjs-react/next-host/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import '../styles/globals.css';
import type { AppProps } from 'next/app';
import { useEffect } from 'react';

function MyApp({ Component, pageProps }: AppProps) {
useEffect(() => {
const selectors = ['style[data-next-hide-fouc="true"]', 'noscript[data-next-hide-fouc="true"]'];

selectors.forEach((selector) => {
document.querySelectorAll(selector).forEach((element) => element.remove());
});

if (document.body.style.display === 'none') {
document.body.style.removeProperty('display');
}
}, []);

return <Component {...pageProps} />;
}

Expand Down
41 changes: 32 additions & 9 deletions i18next-nextjs-react/next-host/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import type { NextPage } from 'next';
import useNextHostTranslation from '../i18n/useNextHostTranslation';
import dynamic from 'next/dynamic';
const ReactRemoteContent = dynamic(() => import('reactRemote/Content'), { ssr: false });
import { useEffect, useState, type MouseEvent } from 'react';
import i18nService from 'i18next-shared-lib/lib/i18nService';

console.log(__webpack_share_scopes__);
setTimeout(() => console.log(__webpack_share_scopes__), 1000);
import useNextHostTranslation from '../i18n/useNextHostTranslation';

const ReactRemoteContent = dynamic(() => import('../components/ReactRemoteContent'), { ssr: false });

const Home: NextPage = () => {
const { t } = useNextHostTranslation('next-main');
const [isRemoteVisible, setIsRemoteVisible] = useState(false);

useEffect(() => {
setIsRemoteVisible(true);
}, []);

const switchLanguage = () => {
i18nService.switchLanguage();
};

const handleSectionClick = () => {
switchLanguage();
};

const handleButtonClick = (event: MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
switchLanguage();
};
return (
<main
style={{
Expand All @@ -27,16 +42,24 @@ const Home: NextPage = () => {
<h1>Next Host</h1>
</header>
<section
onClick={handleSectionClick}
style={{
marginBottom: 10,
cursor: 'pointer',
}}
>
<p>{t('mainText')}</p>
<button onClick={switchLanguage}>{t('changeLanguageButtonLabel')}</button>
</section>
<section>
<h2>{`${t('remoteChildTitle')} :`}</h2>
<ReactRemoteContent />
<button onClick={handleButtonClick}>{t('changeLanguageButtonLabel')}</button>
{isRemoteVisible && (
<div
style={{
marginTop: 10,
}}
>
<h2>{`${t('remoteChildTitle')} :`}</h2>
<ReactRemoteContent />
</div>
)}
</section>
</main>
);
Expand Down
27 changes: 21 additions & 6 deletions i18next-nextjs-react/react-host/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { type MouseEvent } from 'react';
import { createRoot } from 'react-dom/client';

import './index.css';
Expand All @@ -12,6 +12,15 @@ const App = () => {
const switchLanguage = () => {
i18nService.switchLanguage();
};

const handleSectionClick = () => {
switchLanguage();
};

const handleButtonClick = (event: MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
switchLanguage();
};
return (
<main
style={{
Expand All @@ -27,16 +36,22 @@ const App = () => {
<h1>React Host</h1>
</header>
<section
onClick={handleSectionClick}
style={{
marginBottom: 10,
cursor: 'pointer',
}}
>
<p>{t('mainText')}</p>
<button onClick={switchLanguage}>{t('changeLanguageButtonLabel')}</button>
</section>
<section>
<h2>{`${t('remoteChildTitle')} :`}</h2>
<ReactRemoteContent />
<button onClick={handleButtonClick}>{t('changeLanguageButtonLabel')}</button>
<div
style={{
marginTop: 10,
}}
>
<h2>{`${t('remoteChildTitle')} :`}</h2>
<ReactRemoteContent />
</div>
</section>
</main>
);
Expand Down
9 changes: 7 additions & 2 deletions i18next-nextjs-react/react-remote/src/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { type MouseEvent } from 'react';
import useReactRemoteTranslation from './i18n/useReactRemoteTranslation';
import i18nService from 'i18next-shared-lib/lib/i18nService';

Expand All @@ -9,6 +9,11 @@ export const Content = () => {
i18nService.switchLanguage();
};

const handleButtonClick = (event: MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
switchLanguage();
};

return (
<div
style={{
Expand All @@ -17,7 +22,7 @@ export const Content = () => {
>
<header>{t('remoteTitle')}</header>
<aside>
<button onClick={() => switchLanguage()}>{t('changeLanguageButtonLabel')}</button>
<button onClick={handleButtonClick}>{t('changeLanguageButtonLabel')}</button>
</aside>
<main>{t('remoteContent')}</main>
</div>
Expand Down
Loading