Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with-react-i18next doesn't load translations for nested components from namespace not specified in parent page component #5324

Closed
Yankovsky opened this issue Sep 28, 2018 · 8 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@Yankovsky
Copy link

Yankovsky commented Sep 28, 2018

Examples bug report

Example name

with-react-i18next

Describe the bug

If nested component uses namespace that is not specified in parent page component, than translation is not loaded on server side.
I've pushed code with bug reproduction here Yankovsky@d0d5f18

Also, I've recorded videos:

En language http://s.csssr.ru/U02D248T6/2018-09-28-1757-3wa83v4ypq.mp4
Notice how it works correctly if I start navigation from home page, but translations for home namespace don't load if I start from page2.

For de language slightly different situation. For this example I've changed links so they include ?lng=de param. From home page to page2 http://s.csssr.ru/U02D248T6/2018-09-28-1804-c1hs5sucpa.mp4 Notice, that for some reason en language for page2 was downloaded.
From page2 to home http://s.csssr.ru/U02D248T6/2018-09-28-1805-1zvklg3at4.mp4 Notice flickering and downloading of home.json.

To Reproduce

Check the code above.
Or you can just change ExtendedComponent from example to:

import React from 'react'
import { translate } from 'react-i18next'

function MyComponent ({ t }) {
  return <p>{t('home:sample_button')}</p>
}

const Extended = translate('home')(MyComponent)

export default Extended

Here I changed translation from using common namespace to home namespace. Now try to open page2, translations don't work.

Expected behavior

Provide translations for all namespaces for all components on the page. Side bugs like flickering or unnecessary json download are fixed.

System information

  • OS: macOS
  • Browser: chrome
  • Version of Next.js: 7.0.0
@Yankovsky
Copy link
Author

Please tell me if you need more information.

@timneutkens timneutkens added help wanted good first issue Easy to fix issues, good for newcomers labels Sep 28, 2018
@Yankovsky
Copy link
Author

@jamuhl ^

@jamuhl
Copy link
Contributor

jamuhl commented Sep 28, 2018

@Yankovsky thank you for providing all this for reproduction - just my time is limited too - and as I do not use next.js personally my know-how and personal interest to sink additional time into it is limited.

@jamuhl
Copy link
Contributor

jamuhl commented Sep 28, 2018

if i see it right only the outer page level withI18next using page defines which namespaces get passed down to clients. => https://github.com/Yankovsky/next.js/blob/d0d5f180227ec8a12476aefdbd79c476cf820914/examples/with-react-i18next/lib/withI18next.js#L15

if you need more control (adding namespaces from inner components) you might need to write some extra glueing code using the reportNS function: i18next/react-i18next#500

so i guess this is not an issue - just a limitation / simplification of the sample needing all namespaces defined on the most outer page level component

@jamuhl
Copy link
Contributor

jamuhl commented Oct 3, 2018

beside that...https://github.com/i18next/react-i18next/tree/master/example/nextjs just updated the code to use react-i18next v8.0.6

@jamuhl
Copy link
Contributor

jamuhl commented Oct 17, 2018

that is now added in the react-i18next sample here:

https://github.com/i18next/react-i18next/tree/master/example/nextjs

for details: i18next/react-i18next@798a57c#diff-9602e74119895f686d6b8ce306ef5488R20

@jamuhl
Copy link
Contributor

jamuhl commented Oct 17, 2018

@timneutkens i will merge the sample in the react-i18next repository back as soon i got some feedback it runs stable with the new features:

guess this could be closed for now.

@timneutkens
Copy link
Member

Okay let's close it 👍

@lock lock bot locked as resolved and limited conversation to collaborators Oct 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants