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

Making formatMessage / getIntlMessage crash-safe? #200

Closed
Francoyy opened this issue Nov 3, 2015 · 4 comments
Closed

Making formatMessage / getIntlMessage crash-safe? #200

Francoyy opened this issue Nov 3, 2015 · 4 comments

Comments

@Francoyy
Copy link

Francoyy commented Nov 3, 2015

Hello,

In many FE systems we dynamically apply translation methods to API values. Which means we can not be totally sure if the translation is in our Yala files or not.

For example: Yahoo Local has different providers (Yelp, TripAdvisor, Yahoo). If some day there is a new partner on API side, it will totally crash the FE and this is not appropriate.

Instead of using wrapper functions with try/catch, is it possible that react-intl directly handles such case?

  • getIntlMessage: If translation string missing > return original string
  • formatMessage: If JSON parameters have too many variables, or too few, just do best effort and format what can be formatted, return the original string for the test.

Essentially I would like to understand why those functions currently crash easily, as no FE system wants to show a big stacktrace to the user.
Thanks!

@Francoyy
Copy link
Author

Francoyy commented Nov 3, 2015

I can see mentions of fallbacks in #162 but those seem to be language fallbacks or default string fallbacks?

I understand that we don't like silent errors. But say my translation key/value is "SUMMER_SALE": "Summer Sale". (The key comes from API, my scope is FE, I can not guarantee all the values that API will always return)

Do we:

  • Want to show a huge stracktrace just because there was no translation found?
  • Show the key instead of the value "SUMMER_SALE", which is ugly and deserves someone to create a ticket on my FE property, but at least doesn't crash to the user's face?

Any other suggestions or workarounds?

@ericf
Copy link
Collaborator

ericf commented Nov 3, 2015

React Intl v2 has been rewritten to include graceful translation fallbacks. You can see the algorithm here:
https://github.com/yahoo/react-intl/blob/master/src/format.js#L117-L191

@ericf
Copy link
Collaborator

ericf commented Nov 3, 2015

See: #35, #116, #139

@ericf ericf closed this as completed Nov 3, 2015
@ericf ericf added the duplicate label Nov 3, 2015
@Francoyy
Copy link
Author

Francoyy commented Nov 3, 2015

Got it, will try the v2, thanks!

longlho added a commit that referenced this issue Apr 27, 2020
…eLocale, getLocaleHierarchy fix(@formatjs/intl-utils): dont lowercase locale lookup since we canonicalize it feat(formatjs-extract-cldr-data): Change data format to match with [[LocaleData]] spec feat(@formatjs/intl-relativetimeformat): canonicalize locales, rework to be more spec-compliant, implement internal slot, remove locale negotation proxy, smaller bundle size fix(intl-locales-supported): remove type: modules, fix #200 feat(@formatjs/intl-listformat): canonicalize locales, rework to be more spec-compliant, implement internal slots, remove locale negotiation proxy, smaller bundle size feat(@formatjs/intl-pluralrules): canonicalize locales, rework to be more spec-compliant, implement internal slots, remove locale negotiation proxy, smaller bundle size feat(@formatjs/intl-relativetimeformat): canonicalize locales, rework to be more spec-compliant, implement internal slots, remove locale negotiation proxy, smaller bundle size feat(@formatjs/intl-unified-numberformat): canonicalize locales, rework to be more spec-compliant, implement internal slots, remove locale negotiation proxy, smaller bundle size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants