You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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).
Abandon moment.js and rely on transifex for timeAgo (not sure this is possible)
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.
Create a fallthrough to revert to numeric dates in local format instead of using human-friendly timeAgo strings.
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)
ormoment.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.
Aha! Link: https://ushahiditeam.aha.io/features/PROD-517
The text was updated successfully, but these errors were encountered: