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

Moment.js not properly loading locale files needed by platform #2085

Open
kinstella opened this issue Sep 23, 2017 · 0 comments
Open

Moment.js not properly loading locale files needed by platform #2085

kinstella opened this issue Sep 23, 2017 · 0 comments

Comments

@kinstella
Copy link
Contributor

kinstella commented Sep 23, 2017

Throughout platform, it appears Transifex is used as the key to translate known strings, while moment.js is used to translate various dates into a human-friendly local format, particularly the "timeAgo" info in the post metadata directive.

Currently, this appears to be done by sending the ISO 639-1 language code from Transifex to moment, such as 'pt-BR' via a call to something like moment.locale(someLocaleCode) or moment.changeLocale(someLocaleCode) (apparently the latter call is now preferred).

However, moment.js doesn't use the same language codes, nor does it have all files that we might be looking for. This means it will semi-silently fail to change locales, resulting in some dates not being localized.

Furthermore (this needs its own issue, probably), there are a few reported issues in moment.js now, related to loading locale files dynamically (I can add links, if necessary), and this seems to result in moment.js again silently refusing to change locales. Most people seem to suggest loading all needed locales up-front as a workaround, rather than trying to load those files dynamically, as the code has been doing.

A few workarounds I've discussed with a few people, all of which are only partial fixes.

  1. Use string manipulation to approximate the closest match to locale files (change all codes to lowercase, remove or add a dash for region, if necessary).
  2. Abandon moment.js and rely on transifex for timeAgo (not sure this is possible)
  3. Use angular-moment's am-time-ago directive in the HTML, rather than rely on computing timeago in the directives dynamically -- this might be a best practice, anyway.
  4. Create a fallthrough to revert to numeric dates in local format instead of using human-friendly timeAgo strings.

Aha! Link: https://ushahiditeam.aha.io/features/PROD-517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Bug packs
Date and Time
Development

No branches or pull requests

5 participants