Skip to content
Vim plugin to easily add I18n translations to your Rails project
Vim script Ruby
Branch: master
Clone or download
stefanoverna Merge pull request #9 from simon2k/master
Add ability to display a translation of a key
Latest commit 925186c May 24, 2015
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc Update i18n.txt May 23, 2015
plugin Update May 23, 2015


Automated translation of Ruby/Rails projects


vim-i18n helps you translate your Ruby/Rails project. It just exposes a single function, I18nTranslateString. This function takes the current visual selection, converts it into a I18n.t() call, and adds the proper key in a specified YAML store.


Extracting translations in .html.erb files

# app/views/users/show.html.erb
    -> Visual select and `:call I18nTranslateString()`

You will be asked for a key. In keeping with Rails translation syntax, if the key begins with . it will be considered a relative key:

# app/views/users/show.html.erb
<dt><%= t('.name') %>

# config/locales/en.yml

      name: Name

Extracting translations in .rb files

Say you have the following line in your codebase:

# app/controllers/static_controller.rb
@some_text = "Hello, %{name}!"
             -> Visual select this text and `:call I18nTranslateString()`

The plugin will first ask you for the I18n key to use (ie. homepage.greeting). Then, if still not specified, the plugin will ask you the location of the YAML store (ie. config/locales/en.yml).

At this point, the plugin will replace the selection, and add the string to the YAML store:

# app/controllers/static_controller.rb
@some_text = I18n.t('homepage.greeting', name: '')
             -> BOOM!

# config/locales/en.yml
    title: "Hello, %{name}!"

Note that the extracted translation included the appropriate interpolation.

Displaying translation for the key

Let say you have the following key within view / model / controller:

# app/controllers/static_controller.rb
@some_text = I18n.t('homepage.greeting', name: '')

After selecting and executing I18nDisplayTranslation(), the plugin will return you value for the translation.

Vim mapping

Add this line or a simliar one to your ~.vimrc:

vmap <Leader>z :call I18nTranslateString()<CR>
vmap <Leader>dt :call I18nDisplayTranslation()<CR>


Install via pathogen.vim, simply copy and paste:

cd ~/.vim/bundle
git clone git://
You can’t perform that action at this time.