Habitica: timestamp durations are not localized to the user's language in chat/inbox messages and due dates for To-Do tasks

Created on 15 Jul 2018  Â·  6Comments  Â·  Source: HabitRPG/habitica

For any player using a language other than English, the timestamps are not converted to their language in dated To-Dos or in chat messages in the Inbox or Guilds/Parties/Tavern. This results in a poor experience for the user as they see text that's partially translated and partially in English:

image

For To-Dos, the relevant code is:
https://github.com/HabitRPG/habitica/blob/f810fff6fc7ac4c0bb263e552d5892ab7b0ddcab/website/client/components/tasks/task.vue#L618-L635

For messages, it's:
https://github.com/HabitRPG/habitica/blob/f810fff6fc7ac4c0bb263e552d5892ab7b0ddcab/website/client/components/chat/chatCard.vue#L164-L166

I.e., the moment.js humanize and fromNow functions aren't being called in a way that allows the user's preferences.language setting to be considered.

moment.js has support for internationalization (i18n). From a brief reading of the docs, it looks like we'd need to load the locale for the user's language setting.

~If it turns out to not be possible for us to do that (e.g., if it the locale data would put too much load on the website), then it would be better for us to replace humanize/fromNow with exact timestamps as they won't require text strings and so won't put non-English speakers at a disadvantage. If the humanize/fromNow text is considered highly desirable but it's not possible to allow for it to be translated, then we could use humanize/fromNow if the user's preferences.language is en and date/timestamps otherwise.~

~I'm going to leave this as suggestion/discussion for a few days for the staff to comment if desired, and then if there's no objections, I'll mark this as help wanted for loading the user's preferred locale (i.e., the bolded part above, not the italicised part).~

_(Thanks to Rodrigo Nasc (72f5b24b-e2b8-4168-99a7-4dbf978faf64) for reporting this and providing the screenshot.)_

help wanted Guilds Party Page Task Page Tavern Chat medium level coding

All 6 comments

I'm pretty sure we include moment's localization in the client side https://github.com/HabitRPG/habitica/blob/develop/website/server/controllers/api-v3/i18n.js#L19 and https://github.com/HabitRPG/habitica/blob/develop/website/client/libs/i18n.js#L16, it used to work so I'm not sure if it just stopped working in some areas or in general

Hi! Can I try working on this?

sure!

Got it!

So I was looking into the different language settings and as far as I can tell, this problem only happens in the following languages: Brazilian Portuguese (like in the bug report) as well as Simplified and Traditional Chinese. They were all missing their moment.js locale configuration, which was why moment.locale was defaulting to English in these cases.

As @paglias pointed out (thanks!), this is the code that handles that:
https://github.com/HabitRPG/habitica/blob/d2a39a5124a60a04e56f60f9d498e4ff54cd6fdb/website/server/controllers/api-v3/i18n.js#L19

But as seen here, language.momentLangCode doesn't correspond to the configuration—language.code does:

momentlang

Now the due dates and chat timestamps are fixed:

br_fixed br_fixed_chat

The only exception is Traditional Chinese, code zh_TW, which is not present in the momentLangs array. What do you think is the best way to handle this case?

The reason why we had that code was because the language code used in our translations don't match the ones used by moment.js For example for brazilian portuguese moment uses pt-br while we use pt_BR, so we had a mapping between our codes and theirs. https://github.com/HabitRPG/habitica/blob/develop/website/server/libs/i18n.js#L14

So in this case zh_TW should load moment zh-tw. I think if you had this new mapping to the momentLangsMapping object that i linked about it should work

Oh okay, works now!

Was this page helpful?
0 / 5 - 0 ratings