diff --git a/example/nextjs/pages/_app.js b/example/nextjs/pages/_app.js index 8eb5f0e1..49429f00 100644 --- a/example/nextjs/pages/_app.js +++ b/example/nextjs/pages/_app.js @@ -31,8 +31,16 @@ if (enableSubpaths) { // Warning: Did not expect server HTML to contain a

in
. // not sure - did neither find something wrong - nor seems the warning to make sense export default class MyApp extends App { + + static async getInitialProps({ ctx }) { + return { + initialLanguage: ctx.req.language ? + ctx.req.language : translation.defaultLanguage + }; + }; + render() { - const { Component, pageProps } = this.props; + const { Component, pageProps, initialLanguage } = this.props; return ( @@ -41,6 +49,7 @@ export default class MyApp extends App { ns="common" i18n={(pageProps && pageProps.i18n) || i18n} wait={process.browser} + initialLanguage={initialLanguage} > {t => ( diff --git a/example/nextjs/pages/index.js b/example/nextjs/pages/index.js index 6d772b4c..88f31bdd 100644 --- a/example/nextjs/pages/index.js +++ b/example/nextjs/pages/index.js @@ -22,5 +22,9 @@ export default withI18next(['home', 'common'])(({ t, initialI18nStore, ...rest } {t('link.gotoPage2')} +
+ + {t('link.gotoPage3')} +
)); diff --git a/example/nextjs/pages/page3.js b/example/nextjs/pages/page3.js new file mode 100644 index 00000000..13baaee9 --- /dev/null +++ b/example/nextjs/pages/page3.js @@ -0,0 +1,12 @@ +// a page not using i18next - no hoc - not t function +import React from 'react'; +import Link from 'next/link'; + +export default () => ( +
+

Hello Page 3

+ + back + +
+);