Page MenuHomePhabricator

Some jQuery.i18n files aren't being imported
Closed, ResolvedPublic1 Estimated Story Points

Description

Repurposing this ticket as requested. I think we've discovered that jquery.i18n.fallbacks.js isn't being imported, and that's why zh-hk doesn't show zh-hans.

It's taken me some time to figure out how to fully get jQuery.i18n to work as intended. I finally ended up importing everything in the src/ directory. I think the order you import them matters, too. You can use their demo as an example (except that demo only shows a few languages, so to be safe, I would include everything in the languages directory).

Also you need CLDRPluralRuleParser.js, which is a submodule of jQuery.i18n and is also on npm.

Upstream

  • Provide a distributed bundle (dist) for consumption #159
  • 'jquery.i18n' is not in the npm registry. #154

Event Timeline

dbarratt subscribed.

Right now we're loading all of the language files at build time. This is probably a bad idea, but it doesn't seem like too much data (right now). So everyone gets all the languages when they load the the main js.

Webpack is configured to load the entire i18n directory:
https://github.com/wikimedia/InteractionTimeline/blob/b6936ff9ac96f36a200e880b03eb95d33413d211/client/webpack.config.js#L41-L44
and
https://github.com/wikimedia/InteractionTimeline/blob/b6936ff9ac96f36a200e880b03eb95d33413d211/client/i18n.dir.js
then we import that directory into the entry point:
https://github.com/wikimedia/InteractionTimeline/blob/b6936ff9ac96f36a200e880b03eb95d33413d211/client/index.js#L13
then we load each file and build a huge JavaScript object:
https://github.com/wikimedia/InteractionTimeline/blob/b6936ff9ac96f36a200e880b03eb95d33413d211/client/index.js#L32-L43
and pass that object to the IntlProvider
https://github.com/wikimedia/InteractionTimeline/blob/b6936ff9ac96f36a200e880b03eb95d33413d211/client/index.js#L63
which then loads it into jQuery.i18n
https://github.com/wikimedia/InteractionTimeline/blob/b6936ff9ac96f36a200e880b03eb95d33413d211/client/src/components/i18n/intl-provider.js#L13

but this is really good to keep in mind when/if we switch to dynamically loading the language(s).

Thanks! :)

@dbarratt I set my browser to zh-HK, but I still see English. I just assumed it was because the zh-hans file wasn't being loaded (because I see German translations for de-de, for instance), but maybe not? Sorry for the assumption, thought I read the code correctly :)

@dbarratt I set my browser to zh-HK, but I still see English. I just assumed it was because the zh-hans file wasn't being loaded (because I see German translations for de-de, for instance), but maybe not? Sorry for the assumption, thought I read the code correctly :)

not a problem, we probably just haven't deployed that language yet (or the fallback). Though we aren't specifying a fallback, so I think the default is English?

I think jQuery.i18n will know to check for zh-hans, if that's what you mean. If nothing can be found it will use English, that much is working fine.

Probably related, it looks like maybe this will pass in zh instead of zh-hk. That still falls back to zh-hans, so you should still see translations, but I think if there were some zh-hk they wouldn't be used?

Probably related, it looks like maybe this will pass in zh instead of zh-hk. That still falls back to zh-hans, so you should still see translations, but I think if there were some zh-hk they wouldn't be used?

Oh that's a bug. :( You're right, I think jQuery.i18n will take whatever navigator.language is.. I'm not sure why I split it... maybe I just forgot to remove it from testing or something.

Maybe it's because you're not importing the jquery.i18n.fallbacks.js file? https://github.com/wikimedia/InteractionTimeline/blob/60b2661a865813f49fb00bd4dd6d2de035c03c2d/client/src/components/i18n/intl-provider.js#L4-L5

At least with other apps, I've found I have to import all of those files for full i18n support (pluralization and such), including CLDRPluralRuleParser.js, which is a submodule of jQuery.i18n. They don't seem to offer a single concatenated build file with everything you need.

Maybe it's because you're not importing the jquery.i18n.fallbacks.js file? https://github.com/wikimedia/InteractionTimeline/blob/60b2661a865813f49fb00bd4dd6d2de035c03c2d/client/src/components/i18n/intl-provider.js#L4-L5

At least with other apps, I've found I have to import all of those files for full i18n support (pluralization and such), including CLDRPluralRuleParser.js, which is a submodule of jQuery.i18n. They don't seem to offer a single concatenated build file with everything you need.

UGH. I figured I'd just go along until I got an error about a dependency. :( Well you're probably right then. sigh

MusikAnimal renamed this task from Load i18n fallback languages to Some jQuery.i18n files aren't being imported.Mar 20 2018, 3:12 AM
MusikAnimal reopened this task as Open.
MusikAnimal updated the task description. (Show Details)
dbarratt moved this task from Review to Done on the Anti-Harassment (AHT Sprint 17) board.

Sorry I was unable to test that PR. Has the code been deployed? Because I still see English with the language set as zh-HK :(

Yeah it's been deployed, you might have to do a hard refresh to get the new JS bundle:
https://tools.wmflabs.org/interaction-timeline/

I tried clearing the cache and also in "Private" browsing, still no dice. Does it work for you? I do see the fallbacks when viewing https://tools.wmflabs.org/interaction-timeline/scripts/main.js