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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-check namespaces to avoid unnecessary initial `null` render #336

Merged
merged 3 commits into from Nov 2, 2017

Conversation

@andrewbranch
Copy link
Contributor

andrewbranch commented Nov 1, 2017

Fixes #324

I'm adding line notes with questions 馃憤

andrewbranch added 2 commits Nov 1, 2017
src/I18n.js Outdated
@@ -29,9 +29,12 @@ export default class I18n extends Component {
this.options.wait = false;
}

const { language } = this.i18n;

This comment has been minimized.

Copy link
@andrewbranch

andrewbranch Nov 1, 2017

Author Contributor

We only need to check the current language, right?

This comment has been minimized.

Copy link
@jamuhl

jamuhl Nov 2, 2017

Member

i18next loads more than the i18next.language -> i18next.language reflects the detected language - while i18next.languages reflects what get loaded and what will be used to lookup translations (fallbacks, whitelist,...): https://github.com/i18next/i18next/blob/master/src/i18next.js#L135

so check for i18next.languages[0] if that is set (hasResourceBundle) it should have loaded or if like to be very save check all i18next.languages

src/I18n.js Outdated
@@ -29,9 +29,12 @@ export default class I18n extends Component {
this.options.wait = false;
}

const { language } = this.i18n;
const ready = !!language && this.namespaces.every(ns => this.i18n.hasResourceBundle(language, ns));

This comment has been minimized.

Copy link
@andrewbranch

andrewbranch Nov 1, 2017

Author Contributor

In some of the tests, i18n.language was undefined. Under what real-world circumstances is that possible? Does this logic with !!language look ok?

This comment has been minimized.

Copy link
@jamuhl

jamuhl Nov 2, 2017

Member

hm...language should only be empty if not init with resources while initialising or when unable to detect lng

This comment has been minimized.

Copy link
@andrewbranch

andrewbranch Nov 2, 2017

Author Contributor

I'm guessing it's an idiosyncrasy of the tests/mocking, but if language is null, hasResourceBundle throws an error, so I'll keep this check 馃憤

@coveralls

This comment has been minimized.

Copy link

coveralls commented Nov 1, 2017

Coverage Status

Coverage increased (+68.1%) to 83.406% when pulling 5a43e54 on andrewbranch:precheck-namespaces into 0116820 on i18next:master.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Nov 2, 2017

Coverage Status

Coverage increased (+68.1%) to 83.406% when pulling e46173c on andrewbranch:precheck-namespaces into 0116820 on i18next:master.

@coveralls

This comment has been minimized.

Copy link

coveralls commented Nov 2, 2017

Coverage Status

Coverage increased (+68.1%) to 83.406% when pulling 4507759 on andrewbranch:precheck-namespaces into 0116820 on i18next:master.

@jamuhl jamuhl merged commit de4ca34 into i18next:master Nov 2, 2017
3 checks passed
3 checks passed
codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+68.1%) to 83.406%
Details
@jamuhl

This comment has been minimized.

Copy link
Member

jamuhl commented Nov 2, 2017

awesome...published with react-i18next@6.1.0

thanks for adding this to react-i18next

@andrewbranch andrewbranch deleted the andrewbranch:precheck-namespaces branch Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can鈥檛 perform that action at this time.