New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

handlebars_assets_i18n

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handlebars_assets_i18n

  • 0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

HandlebarsAssetsI18n

Very simple handlebars_assets internationalization for .hamlbars and .slimbars that allows your to have precompiled translated templates for each desired locale. So that you don't need translate it on client side on the fly.

Installation

Add this line to your application's Gemfile:

gem 'handlebars_assets_i18n'

Configuration

By default templates will be precompiled with all available locales. You can restrict it using locales configuration option:

HandlebarsAssets::Config.locales = [:en, :de]

How it works

If you file is app/javascripts/templates/shared/errors.hamlbars or app/javascripts/templates/shared/errors.slimbars and your locales are :en and :de then the assets pipeline will compile code for each locale and store it under corresponding names HandlebarsAssets['shared/errors_en'] and HandlebarsAssets['shared/errors_de'].

Using with Marionette

Export current locale in your layouts/application.html.haml to client side:

...
:javascript
  MyApp.locale = '#{I18n.locale}'
...

Internationalize your Marionette renderer:


Marionette.Renderer.render = (template, context) ->
  template = "#{template}_#{MyApp.locale}"

  unless HandlebarsTemplates[template]
    throw "Template '#{template}' not found!"

  HandlebarsTemplates[template](data)

That's all.

Now you can use I18n.translate and I18n.localize helpers in .hamlbars or .slimbars. Also if you use this gem with rails then you can use rails t and l helpers`:

%h2
  =t 'title.errors'

%ul
  {{#each errors}}
  %li {{.}
  {{/each}}

Benefits

  • Easy to plug in.
  • Fast due to precompiled templates with translations.
  • No I18n javascript code required.
  • Translation keys are not exported to client side.

Penalty of Simplicity

  • Please remember that translation is performed on precompilation phase. Not at runtime.
  • You must recompile templates if you changed translations in config/locales.
  • You can't use interpolation features.

Author

Andriy Yanko

License

FAQs

Package last updated on 15 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc