Code Monkey home page Code Monkey logo

vim-i18n's Introduction

vim-i18n

Automated translation of Ruby/Rails projects

Introduction

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.

Examples

Extracting translations in .html.erb files

# app/views/users/show.html.erb
<dt>Name</dt>
    ^^^^
    -> 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

en:
  users:
    show:
      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
---
en:
  homepage:
    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>

Installation

Install via pathogen.vim, simply copy and paste:

cd ~/.vim/bundle
git clone git://github.com/stefanoverna/vim-i18n.git

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.