mirror of
https://github.com/discourse/discourse.git
synced 2025-09-10 12:04:21 +08:00
automatically updating times for posts on topic
moved moment.js into localization file (we need to localize it) added helpers for date formatting use, moment().shortDate() moment().longDate() moment().shortDateNoYear()
This commit is contained in:
parent
6d85dc1724
commit
c2cfbce9ce
8 changed files with 65 additions and 22 deletions
|
@ -18,11 +18,26 @@ module JsLocaleHelper
|
|||
result = generate_message_format(message_formats, locale_str)
|
||||
|
||||
result << "I18n.translations = #{translations.to_json};\n"
|
||||
result << "I18n.locale = '#{locale_str}'\n"
|
||||
result << "I18n.locale = '#{locale_str}';\n"
|
||||
# loading moment here cause we must customize it
|
||||
result << File.read("#{Rails.root}/lib/javascripts/moment.js")
|
||||
result << moment_locale(locale_str)
|
||||
result << moment_formats
|
||||
result
|
||||
end
|
||||
|
||||
def self.moment_formats
|
||||
result = ""
|
||||
result << moment_format_function('short_date_no_year')
|
||||
result << moment_format_function('short_date')
|
||||
result << moment_format_function('long_date')
|
||||
end
|
||||
|
||||
def self.moment_format_function(name)
|
||||
format = I18n.t("dates." << name)
|
||||
result = "moment.fn.#{name.camelize(:lower)} = function(){ return this.format('#{format}'); };\n"
|
||||
end
|
||||
|
||||
def self.moment_locale(locale_str)
|
||||
filename = Rails.root + "lib/javascript/moment_locale/#{locale_str}.js"
|
||||
if File.exists?(filename)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue