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

Is there a way to turn off warnings for non-defined keys? #45

Closed
spherop opened this issue Jan 25, 2018 · 5 comments
Closed

Is there a way to turn off warnings for non-defined keys? #45

spherop opened this issue Jan 25, 2018 · 5 comments

Comments

@spherop
Copy link

spherop commented Jan 25, 2018

I am wondering if it's possible to turn off the browser console warnings for missing keys in a locale file?

eg in chrome console:

react-intl-universal key "ZIP_CODE" not defined in en-US
tracker.js:13 react-intl-universal key "REDEEM_PROMO_CODE" not defined in en-US
etc.

This is causing a lot of log pollution.

Thanks.

@cwtuan
Copy link
Collaborator

cwtuan commented Jan 26, 2018

why not just define a key to fix it?

@spherop
Copy link
Author

spherop commented Jan 27, 2018

@cwtuan - good question - here's why:

Since the site is in English, and the developers speak English natively, made sense to write a little helper that creates the translations from the English text - and use the defaultMessage mechanism to fallback.

export const t = (stringToTranslate, defaultString = false, options = null) => {
  if (!stringToTranslate) { return null; }
  defaultString = defaultString || stringToTranslate;
  return intl.get(stringToTranslate.split(' ').join('_').toUpperCase(), options).defaultMessage(defaultString);
};

In render we have:

<span className="titleRow">{t('Thank you')}, {this.props.first_name}!</span>
<span className="titleRow">{t('Your booking is confirmed')}!</span>

Thus t('Thank you') becomes intl.get('THANK_YOU').defaultMessage('Thank you')

Therefore, we don't need English versions of these because we fallback on defaultMessage. Since we have a huge amount to translate, saves us from having English versions of most translations. Also, keeps our views readable with the real text vs harder to grok keys.

Hope this all makes some sense... or maybe I am making an odd move here?

@spherop
Copy link
Author

spherop commented Jan 30, 2018

This pr would resolve: #44

@Panoplos
Copy link

I second this. During development, it is annoying to have so many warnings.

@cwtuan
Copy link
Collaborator

cwtuan commented May 13, 2018

@cwtuan cwtuan closed this as completed May 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants