How to properly display jalali dates for Persian language


(Mahdi Hosseini) #1

I’m a new rails/discourse developer. I’m wondering if someone could tell me about discourse structure.
I wanted to edit some view files so I edited discourse/app/views/[view-folder]/[*.html.erb] files and nothing changed, even static text like ‘test’ didn’t show up in website.
could you tell me which files can change things on website template?


(Jay Pfaffman) #2

Did you set up a development server? Also, if you are going to make changes and ever want to upgrade Discourse, you should develop plugins.


(Mahdi Hosseini) #3

I have installed discourse on Ubuntu and docker.
I want to change template dates to jalali dates and I don’t know where to start.


(Mahdi Hosseini) #4

I’m trying to make a plugin to convert gregorian dates to jalali date.
this is what I’ve done so far :
plugin.rb file :

# name: تاریخ شمسی
# about: تاریخ شمسی Discourse
# version: 1.0
# authors: l3est

# javascript
register_asset "javascripts/moment-jalaali.js", :server_side

this is moment-jalaali.js file :

and added translated date formats:
YYYY MM changes to jYYYY jMM

and there is assets\javascripts folder in plugin main folder, this is the plugin structure:
jalaali-date
plugin.rb
-assets
–javascripts
—moment-jalaali.js


(Jay Pfaffman) #5

Hey @erlend_sh. Is this the kind of translation that should be in core?


(Mahdi Hosseini) #6

I think it should be for persian language files (client.fa_IR.yml and server.fa_IR.yml) . but no others.

Does anyone know how can I change formatter.js.es6 dates to jajali with plugin ?
the moment-jalali library works on chrome console when website loads.


(Christoph) #7

In case you haven’t seen it yet, this might be useful:


(Mahdi Hosseini) #8

thanks for the link. I’ve seen this before.
I know how to make plugins. I just don’t know where I can edit dates before it gets to user browser.


(Dean Taylor) #9

You don’t…

I believe (hopefully someone will correct me if I’m wrong)…

…for the most part dates and times are stored in UTC/GMT server side and translated to the local user’s time zone in the browser (client side).


(Mahdi Hosseini) #10

I think I’m not explaining well.

I’m looking for specific files that format dates before sending it to browser, so I’ll be able to add moment-jalali or other jalali date converters to it to get jalali date in browser.


(Mahdi Hosseini) #11

I found this file:
discourse/app/assets/javascripts/discourse/lib/formatter.js.es6

this is the file that returns date to web browser. the question is how can I add the moment-jalali.js file to this? then everything will be ok.
client.fa_IR.yml file has ‘jYYYY jMM jD’ format instead of ‘YYYY MM D’ (for fa_IR language only)
here’s an example how moment-jalali works:
m.format('jYYYY/jM/jD [is] YYYY/M/D') // 1360/5/26 is 1981/8/17


(Dean Taylor) #12

I haven’t done translations before, however - my understanding is that…

All translations are supplied via Discourse localization

This at some point then is migrated into client and server files in the Discourse repo where the English versions are these:
discourse/client.en.yml at master · discourse/discourse · GitHub
discourse/server.en.yml at master · discourse/discourse · GitHub

This topic covers this in more detail:

Note that there is a whole dates section in each of these files which comes from Transiflex:


Again hopefully someone with more knowledge will correct me if wrong…

As I see it you should submit the "jYYYY etc translations to Discourse localization

Moment.js will then be called with the right “jYYYY” etc instead of “YYYY”

Then you need to submit two extra code patches / Pull Requests to Discourse to add and call the extra libraries as needed:

  1. One Pull Request to add and load moment-jalaali if, an only if “jYYYY” etc are used.
  2. 2nd Pull Request for handling any dates etc which are handled via Ruby.

Following the translation and then first pull request should get you most of the way there.

One of the Discourse team will read this at some point (they read everything here) and may comment on if this is acceptable or if they have a better idea for a way forward.


(Mahdi Hosseini) #13

Thanks for all the information. I think plugin would be better for this problem.
if I add the jYYYY to translation files, it won’t parse correctly.
jYYYY jMM jD will turn into j2017 jMay j7

still and the main question is, how to add moment-jalaali.js to formatter.js.es6 (ECMA Script 6 file) ?


(Jeff Atwood) #16

(Jeff Atwood) #17

This topic was automatically opened after 29 hours.


(Satoshi Download) #18

Hi
How to change the processmaker 3.2 environment to Hijri or Jalali Calendar?
The processmaker has been used by Moment.js , I want to use moment-jalaali.js.
for example : I want use Jalali Calender in “Inbox,Draft,Participation,Last Modified,Due Date,Summeary,…”


(Sam Saffron) #19

@Osama any ideas about what we should offer here?


#20

It looks like there are moment.js plugins for Hijri and Jalali calenders: Moment.js | Docs

To see how easy it’s to use, I cloned the Hijri plugin into vendor folder and changed the dates formats in client.ar.yml according to the plugin documentation and I got it to display Hijri dates in a few places:


(July 2017 is in 1438 Hijri year)

I’m guessing it didn’t display Hijri dates in all places because those were using different core methods for displaying dates and might need to be tweaked a bit to display Hijri dates correctly.

Overall I think Hijri support should be done in a plugin and in a new separate Arabic locale to let people choose between Hijri or Gregorian.


(Gerhard Schlager) #21

The plugin could either create a new locale that falls back to the existing Arabic locale or it could simply override the existing locale. In either case, the locale files in the plugin would only need to contain the new date formats. See: Add a new locale from plugin