Project

i18n_utils

0.0
No commit activity in last 3 years
No release in over 3 years
I18n utilities for Ruby on Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

I18nUtils

I18n utilities for Ruby on Rails.

Usage

Just include I18nUtils::Helper in e.g. your ApplicationHelper to get all the things.

Or see under each section to only get that part.

t_model, t_attribute

Get this part with include I18nUtils::Model in e.g. your ApplicationHelper.

I think the Rails way to translate attributes and models is ugly and on the wrong object.

With this, your views can do t_model(User) instead of User.model_name.human. Or pass an instance: t_model(some_user)

Also t_attribute(User, :email) instead of User.human_attribute_name(:email).

Want to use them outside views? Feel free to include the module anywhere you like, or call them via the I18nUtils object, e.g. I18nUtils.t_model(User).

You could even do I18n.extend(I18nUtils::Model) to get e.g. I18n.t_model(User).

t_scope

Get this part with include I18nUtils::Scope in e.g. your ApplicationHelper.

Links or other markup in the middle of a translation is tricky. Either you put the HTML straight in the translation and risk the translator messing it up, or it becomes a mess:

= t("welcome.sign_in_now.text",
  sign_in: link_to(t("welcome.sign_in_now.sign_in"), sign_in_url))

The t_scope helper lets you use blocks for interpolated values, in your regular template:

= t_scope("welcome.sign_in_now.text") do |scope|
  - scope.sign_in do
    = link_to(scope.t(:sign_in), sign_in_url)

Installation

Add this line to your application's Gemfile:

gem 'i18n_utils'

And then execute:

$ bundle

Or install it yourself as:

$ gem install i18n_utils