• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Replaces plain text strings in your views and replaces them with I18n message strings so you only have to provide the translations (i15r = internationalizer)

I15r Build Status Code Climate

Goal

You prefer polishing your views to manually replacing strings in them to make them i18n compatible. If I got that one right, i15r is for you. It automates the process that would otherwise drive most of us nuts.

Summary

I15r (Internationalizer) searches for all the non-i18n texts in your erb and haml templates in the given file/directory and replaces them with I18n messages.

The message string is based on the path of the file in which the text was found and the text itself that was replaced.

E.g

(in file app/views/users/new.html.erb)
<label for="user-name">Name</label>
<input type="text" id="user-name" name="user[name]" />

will be replaced by:

(in file app/views/users/new.html.erb)
<label for="user-name"><%= I18n.t("users.new.name") %></label>
<input type="text" id="user-name" name="user[name]" />

and

(in file app/views/member/users/edit.html.erb)
<label for="user-name">Name</label>
<input type="text" id="user-name" name="user[name]" />

will be replaced by

(in file app/views/member/users/edit.html.erb)
<label for="user-name"><%= I18n.t("member.users.edit.name") %></label>
<input type="text" id="user-name" name="user[name]" />

Installation

Standalone

gem install i15r

In-app

Put the following in your Gemfile:

gem 'i15r', '~> 0.5.1'

Usage

Convert a single file

i15r path/leading/to/template

Convert all files in a directory (deep search)

i15r path/leading/to/directory

All files with an erb or haml suffix in that directory or somewhere in the hierarchy below will be converted.

Dry run

By default, i15r overwrites all the source files with the i18n message strings it generates. If you first want to see what would be replaced, you should do:

i15r app/views/users -n

or

i15r app/views/users --dry-run

Custom prefix

If you don't want the file path to appear in the i18n message string, you can pass a prefix parameter that will be used to generate the message strings. For example if you have the following in a file called app/views/users/new.html.erb:

<label for="user-name">Name</label>
<input type="text" id="user-name" name="user[name]" />

And then call:

i15r app/views/users/new.html.erb --prefix my_project

The file will then contain:

<label for="user-name"><%= I18n.t("my_project.name") %></label>
<input type="text" id="user-name" name="user[name]" />

If you want the a prefix plus the file path to appear in the i18n message string, you can pass a prefix_with_path parameter:

i15r app/views/users/new.html.erb --prefix_with_path my_project

The above file will then contain:

<label for="user-name"><%= I18n.t("my_project.users.new.name") %></label>
<input type="text" id="user-name" name="user[name]" />

Override I18n.t function name

If you don't want to use the full I18n.t name, use the override_i18n_method parameter:

i15r app/views/users/new.html.erb --override_i18n_method t

This will cause output that normally results in:

<label for="user-name"><%= I18n.t("users.new.name") %></label>

to result in

<label for="user-name"><%= t("users.new.name") %></label>

No default translation

If you want to skip the default translation, you must add the --no-default flag

For example, if calling

i15r app/views/users/new.html.erb

results in

<label for="user-name"><%= I18n.t("users.new.name", :default => 'Name') %></label>

Adding the --no-default flag

i15r app/views/users/new.html.erb --no-default

results in

<label for="user-name"><%= I18n.t("users.new.name") %></label>

Design principles & suggested use

I15R takes the 80-20 approach. It focuses on finding most of the text that needs to be replaced in your templates and replacing them with the correct i18n strings. It forgoes the 100% hit rate in favor of getting the 80% right and keeping the code (relatively) simple. Consequently, please report any bug that concerns strings that should not have been replaced or ones that have been replaced incorrectly.

A good practice is to first run i15r with the --dry-run option to see what would be replaced and then run it for real, without the --dry-run option. You can also run it on files that have already been "internationalized" since i15r will just skip those rows.

See also

Your next step is probably to create a YML locale file containing all the strings i15r generated. You're in luck! missing_t is a gem that can do this for you.

Contributing

Please submit any bugs or feature requests to the issue tracker.

If you'd like to contibute, please see Contributing.

License

Copyright (c) 2009 Balint Erdi

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

rarwe-demo

An example Ember.js app, a demo version of Rock and Roll with Ember.js
HTML
179
star
2

missing_t

See all the missing I18n translations in your Rails project
Ruby
27
star
3

ember-cli-star-rating

An Ember CLI addon for using stars to manage ratings
JavaScript
26
star
4

ember-data-patterns

Different data loading patterns in Ember with a json:api compliant API
JavaScript
17
star
5

ideavote-emberfire

My ideavote project built with emberFire
JavaScript
14
star
6

balinterdi.github.com

My tech blog
HTML
12
star
7

tale-of-two-bindings

JavaScript
10
star
8

ember-cancelable-button

A button with a built-in cancel feature, see examples at
JavaScript
9
star
9

ember-cli-autocomplete

A widely customizable autocomplete component, very much based on ic-autocomplete.
JavaScript
8
star
10

todo-list

A very simple todolist (a la tadalist.com) in Sinatra
JavaScript
7
star
11

rock-and-roll-api

REST API for my Ember.js “Build an Ember app” screencast series
Ruby
6
star
12

twuckoo

Need to tweet periodically in an automated fashion? Then Twuckoo is for you!
Ruby
6
star
13

photo-uploader

easy way to upload photos (first only through ftp) for development (as requested by fotomarket.hu)
Ruby
4
star
14

rsvp-promises-sandbox

A small playground to get an insight into (RSVP.js) promises, with a half-decent html interface
JavaScript
4
star
15

ember-twitter

An Ember.js twitter client
CSS
4
star
16

ideavote

JavaScript
4
star
17

clojure-exercises

My road to Clojure wisdom :)
Clojure
4
star
18

console-navigator

a general console-browser written in ruby (under development)
Ruby
4
star
19

myvocab

a pet project to learn RoR
Ruby
4
star
20

thrifty

JavaScript
4
star
21

rails_app_templates

Rails app templates I use for my projects
Ruby
3
star
22

codekata

Ruby
3
star
23

emberconf2017-resources

Working materials, guides, presentation
3
star
24

working_with_merb

A project to learn merb that copies the concept of the Working with Rails site
Ruby
3
star
25

philotes

A merb-slice for providing social networking functionality
Ruby
3
star
26

component-flavors

A tutorial app & playground for component types, modifiers, call syntaxes, etc. (“flavors“) in Ember.js
JavaScript
3
star
27

only_owner

A Rails plugin to facilitate access management of owner-type controller actions
Ruby
3
star
28

acts_as_trivia

Because everybody loves to play games
Ruby
3
star
29

chart-maker-dsl

A simple DSL that generates HTML charts from an input DSL file
2
star
30

learn_git

just to learn git. I can freely try sophisticated things here
2
star
31

torii-spotify

Torii providers for authentication against Spotify
JavaScript
2
star
32

asset-import-embroider

JavaScript
1
star
33

bluff_it

JavaScript
1
star
34

Game-Of-Life

My obligatory Game of Life in Clojure
JavaScript
1
star
35

ember-tailwind-template

A template to give a head start for an Ember app with Tailwindcss
JavaScript
1
star
36

javascript_5_slideban

Ruby
1
star
37

vapor

a lightweight (html) cloud generator
Ruby
1
star
38

something-blue

Helps to keep track of your lent items. A pet project to get acquainted with CouchDB (using RelaxDB as a Ruby library)
Ruby
1
star
39

par_avion

a demo application I put together for a presentation on Rails
Ruby
1
star