Skip to content

Instantly share code, notes, and snippets.

@WebiSamurai
Created July 17, 2019 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebiSamurai/700a7f663a5eaa6fda63686ce5785a90 to your computer and use it in GitHub Desktop.
Save WebiSamurai/700a7f663a5eaa6fda63686ce5785a90 to your computer and use it in GitHub Desktop.
require 'i18n'
LOCALE = 'ru'
module Jekyll
module I18nFilter
def localize(input, format=nil)
load_translations
format = (format =~ /^:(\w+)/) ? $1.to_sym : format
I18n.l input, :format => format, :locale => LOCALE
end
def load_translations
unless I18n::backend.instance_variable_get(:@translations) and locale_file_exists
I18n.backend.load_translations Dir[File.join(File.dirname(__FILE__),'../_locales/*.yml')]
end
end
def locale_file_exists
file_name = File.join(LOCALE,'.yml')
return (locale_file_exists_in_current_dir(file_name) and locale_exists_in_locales_dir(file_name))
end
def locale_file_exists_in_current_dir(file_name)
return File.exists?(File.join(File.dirname(__FILE__),file_name))
end
def locale_exists_in_locales_dir(file_name)
return File.exists?(File.join('../_locales/',file_name))
end
end
end
Liquid::Template.register_filter(Jekyll::I18nFilter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment