react-i18next icon indicating copy to clipboard operation
react-i18next copied to clipboard

Translated components not rendering at all after upgrade to 2.0.0

Open JesperWe opened this issue 9 years ago • 16 comments

componentWillMount() of translated components is not called, and the React devtools show the components as null.

Downgrading just react-i18next to 1.10.1 fixes the problem.

There are no error messages in the console and no errors from babel either.

image

JesperWe avatar Jan 21 '17 09:01 JesperWe

did you upgrade i18next https://github.com/i18next/react-i18next/blob/master/CHANGELOG.md#200 ?

jamuhl avatar Jan 21 '17 09:01 jamuhl

  "dependencies": {
    "antd": "^2.4.0",
    "apollo-client": "^0.7.3",
    "aws-sdk": "^2.7.19",
    "axios": "^0.15.3",
    "browser-cookies": "^1.0.8",
    "buffer": "^5.0.2",
    "card-react": "^1.2.5",
    "crypto": "0.0.3",
    "graphql-tag": "^1.1.2",
    "i18next": "^5.0.0",
    "i18next-browser-languagedetector": "^1.0.1",
    "i18next-xhr-backend": "^1.2.1",
    "immutability-helper": "^2.0.0",
    "jsonpipe": "^2.1.1",
    "react": "^15.4.2",
    "react-addons-css-transition-group": "^15.4.2",
    "react-apollo": "^0.8.1",
    "react-async-script-loader": "^0.2.2",
    "react-big-calendar": "^0.12.3",
    "react-click-outside": "^2.2.0",
    "react-datepicker": "^0.39.0",
    "react-dom": "^15.4.2",
    "react-draft-wysiwyg": "^1.5.4",
    "react-google-maps": "^6.0.1",
    "react-hammerjs": "^0.5.0",
    "react-i18next": "^2.0.0",
    "react-notification-badge": "^1.3.0",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.0",
    "react-svg-popover": "^1.0.10",
    "react-toastr": "^2.8.2",
    "redux": "^3.6.0",
    "wkx": "^0.4.1"
  },

JesperWe avatar Jan 21 '17 10:01 JesperWe

let me check the code...

jamuhl avatar Jan 21 '17 17:01 jamuhl

did check...extended even the sample to have a second component loading delayed: https://github.com/i18next/react-i18next/commit/3484936ec5276287adc46cb9815b5109ff0dc339

all working as expected...are you sure your i18next version was updated (not some old version from cache)?!?

jamuhl avatar Jan 21 '17 18:01 jamuhl

treat@vps29:~/foobar/tyc$ rm -rf node_modules
treat@vps29:~/foobar/tyc$ npm -v
3.10.10
treat@vps29:~/foobar/tyc$ npm i
npm WARN prefer global [email protected] should be installed with -g
[email protected] /home/treat/foobar/tyc

....

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] requires a peer of apollo-client@^0.6.0 but none was installed.
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^2.2.3 but none was installed.
treat@vps29:~/foobar/tyc$ tail -3 node_modules/react-i18next/package.json 
  },
  "version": "1.10.1"
}
treat@vps29:~/foobar/tyc$ tail -3 node_modules/i18next/package.json 
  },
  "version": "5.0.0"
}
treat@vps29:~/foobar/tyc$ npm start 
Compiled successfully!

The app is running at:

  http://localhost:3000/

Note that the development build is not optimized.
To create a production build, use npm run build.

image

Result: App is fine

^C
treat@vps29:~/foobar/tyc$ npm r react-i18next
- [email protected] node_modules/react-i18next
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^2.2.3 but none was installed.
npm WARN [email protected] requires a peer of apollo-client@^0.6.0 but none was installed.
treat@vps29:~/foobar/tyc$ npm i -S [email protected]
[email protected] /home/treat/foobar/tyc
├── UNMET PEER DEPENDENCY [email protected]
├── UNMET PEER DEPENDENCY [email protected]
└── [email protected] 

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] requires a peer of eslint-plugin-jsx-a11y@^2.2.3 but none was installed.
npm WARN [email protected] requires a peer of apollo-client@^0.6.0 but none was installed.
treat@vps29:~/foobar/tyc$ npm start 
Compiled successfully!

The app is running at:

  http://localhost:3000/

Note that the development build is not optimized.
To create a production build, use npm run build.

Another hard reload.

Result: Several (although not all) translated components are broken

image

The weird thing is that there are no error messages. Are you perhaps catch()-ing somewhere and not logging or propagating?

JesperWe avatar Jan 21 '17 20:01 JesperWe

seems it's not calling ready here: https://github.com/i18next/react-i18next/blob/master/src/translate.js#L43

just i can't say way...could you debug and look if it is:

a) initialized here: https://github.com/i18next/react-i18next/blob/master/src/translate.js#L48 b) lands in that function if not initialized: https://github.com/i18next/react-i18next/blob/master/src/translate.js#L51

thank you for your effort

jamuhl avatar Jan 21 '17 20:01 jamuhl

When breaking here:

image

I only hit three times (the brk@100 first, then brk@93) on App home screen reload. I guess there are around 3-4 components that are translated which doesn't hit. All components use the same translations file:

import i18n from 'i18next';
import XHR from 'i18next-xhr-backend';
import LanguageDetector from 'i18next-browser-languagedetector';

i18n
		.use(XHR)
		.use(LanguageDetector)
		.init( {
			detection: {
				// order and from where user language should be detected
				order: ['querystring', 'cookie', 'navigator', 'localStorage', 'htmlTag'],

				// keys or params to lookup language from
				lookupQuerystring: 'language',
				lookupCookie: 'language',
				lookupLocalStorage: 'language',

				// cache user language on
				caches: ['cookie'],

				// optional expire and domain for set cookie
				cookieMinutes: 60*24*365,
				//cookieDomain: 'myDomain',

				// optional htmlTag with lang attribute, the default is:
				//	htmlTag: document.documentElement
			},

			fallbackLng: 'en',
			nsSeparator: false,
			keySeparator: false,
			debug: false,

			ns: [ 'common' ],
			defaultNS: 'common',

			interpolation: {
				escapeValue: false // not needed for react!!
			},

			backend: {
				loadPath: "/locales/{{lng}}/{{ns}}.json"
			}
		} );

export default i18n;

components:

export default graphql( gqlFindSuppliers, findSuppliersOptions )(
		translate( [ 'common' ], { wait: true } )( Browser )
);

JesperWe avatar Jan 21 '17 20:01 JesperWe

what is _this2.i18n.isInitialized (be97) in the cases?!?

jamuhl avatar Jan 21 '17 20:01 jamuhl

Going afk. Tomorrow.

JesperWe avatar Jan 21 '17 20:01 JesperWe

great...lokking forward to get this solved

jamuhl avatar Jan 21 '17 20:01 jamuhl

I'm having the exact same problem using [email protected] and [email protected].

In my case both components have wait: true but only the first is loading. Setting wait: false does render both components but of course you can see translations being replaced.

image

image

st3phan avatar Jan 22 '17 13:01 st3phan

So apparently I have 5 translated components on my landing page. var initialized = function initialized() ... is called 5 times with _this2.i18n.isInitialized always undefined, but the initialized function (line 100) is only called 3 times.

JesperWe avatar Jan 22 '17 14:01 JesperWe

think i found the issue...it's related to the eventemitter code in i18next. will publish a fix in a minute.

jamuhl avatar Jan 22 '17 14:01 jamuhl

could you try with [email protected]

jamuhl avatar Jan 22 '17 14:01 jamuhl

Yes. Working now! Thank you!

st3phan avatar Jan 22 '17 14:01 st3phan

great will add a 2.0.1 patch...which also solves it in react-i18next. thanks for your time aand help solving this.

jamuhl avatar Jan 22 '17 15:01 jamuhl