Add a plugin for Russian localization, make it be loaded first.
This commit is contained in:
27
_plugins/1-i18n_filter.rb
Normal file
27
_plugins/1-i18n_filter.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'i18n'
|
||||
|
||||
LOCALE = :ru # set your locale
|
||||
|
||||
# Create folder "_locales" and put some locale file from
|
||||
# https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
|
||||
module Jekyll
|
||||
module I18nFilter
|
||||
# Example:
|
||||
# {{ post.date | localize: "%d.%m.%Y" }}
|
||||
# {{ post.date | localize: ":short" }}
|
||||
def localize(input, format=nil)
|
||||
load_translations
|
||||
format = (format =~ /^:(\w+)/) ? $1.to_sym : format
|
||||
I18n.l input, :format => format
|
||||
end
|
||||
|
||||
def load_translations
|
||||
unless I18n::backend.instance_variable_get(:@translations)
|
||||
I18n.backend.load_translations Dir[File.join(File.dirname(__FILE__), '../_locales/*.yml')]
|
||||
I18n.locale = LOCALE
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_filter(Jekyll::I18nFilter)
|
Reference in New Issue
Block a user