Giter Club home page Giter Club logo

i18n-coffee's Introduction

#i18n-coffee

Client Side Localisation for Rails

Gem Version

##Usage

In your Gemfile add

gem 'i18n-coffee', '~> 0.1.3'

##Setup locale translations

By default, it looks for javascripts node in your {locale}.yml.

# config/locales/en.yml
en:
  javascripts:
    hello: "Hello"

##On the client-side

In your app/asssets/javascripts/application.js file include i18n

//= require i18n

You can now try use window.translate or window.t for translation lookup.

window.t('javascripts.hello'); // "Hello"

Based on I18n.locale in Rails, it will load the corresponding translations from your locale files.

###Passing variables to translation

You can use variables to generate dynamic content in the client-side translations the same way that Rails does.

window.t('javascripts.greeting', { name: "Mann" });
# config/locales/en.yml
en:
  javascripts:
    greeting: "Hello %{name}!"

##Change javascript translations root

You can choose a different root node as the translations.

# config/locales/en.yml
en:
  views:
    home:
      title: "Hello world!"

To select views.home as translation root:

# config/application.rb
config.i18n_translations_root = 'views.home'

The translation root setting = views.home in config/application.rb will become views_home in client-side lookup key.

window.t('views_home.title'); // "Hello world!"

i18n-coffee's People

Contributors

lchanmann avatar

Watchers

 avatar

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.