module Jekyll::I18nFilter
i18n filter for jekyll
Public Instance Methods
current_locale(locale)
click to toggle source
# File lib/starter_web/_plugins/date-i18n.rb, line 54 def current_locale(locale) l = locale || @context.registers[:page]['language'] || @context.registers[:site].config['language'] if l && I18n.config.available_locales.include?(l.to_sym) l else false end end
load_translations()
click to toggle source
# File lib/starter_web/_plugins/date-i18n.rb, line 48 def load_translations return false unless I18n.backend.send(:translations).empty? filename = File.join(File.dirname(__FILE__), '../_data/locales/*.yml') I18n.backend.load_translations Dir[filename] end
localize(input, format = nil, locale = nil)
click to toggle source
Example:
{{ post.date | localize: "%d.%m.%Y" }} {{ post.date | localize: ":short" }}
# File lib/starter_web/_plugins/date-i18n.rb, line 30 def localize(input, format = nil, locale = nil) # Side effects: changes I18n.config, must run before current_locale is set load_translations input = Time.at(input) if input.class == Integer format = format =~ /^:(\w+)/ ? Regexp.last_match(1).to_sym : format if input && locale = current_locale(locale) I18n.locale = locale I18n.l(input, format: format) else input end end