Skip to content

Instantly share code, notes, and snippets.

@biow0lf
Created December 16, 2011 14:53
Show Gist options
  • Save biow0lf/1486342 to your computer and use it in GitHub Desktop.
Save biow0lf/1486342 to your computer and use it in GitHub Desktop.
liquid + i18n from rails
# lib/liquid_i18n_rails.rb
module LiquidI18nRails
def t(string)
I18n.t(string.to_sym)
end
end
# config/initializers/liquid.rb
require 'liquid_i18n_rails'
Liquid::Template.register_filter LiquidI18nRails
# and then:
{{ 'string' | t }}
# where 'string' is name of sym for I18n.t
# it will do .to_sym automatically
@saadbinakhlaq
Copy link

saadbinakhlaq commented Jun 21, 2017

I couldn't find anything on liquid for translations with arguments so I did something like this

module LiquidI18nRails
  def t(string, arguments = nil)
    I18n.t(string.to_sym, arguments.with_indifferent_access)
  end
end

now can translate it like this

{{ 'hello.world' | t: data: 'yourname' }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment