Skip to content

Treize37/language_engine

 
 

Repository files navigation

language_engine

Build Status

language_engine is a rails engine for language with :

  • a controller
  • a helper

Views and assets are not defined because we think everybody wants to adapt the view in their page.

You can access to a demo on http://appli.chouette.mobi with

Requirements

This code has been run and tested on Travis with :

  • Ruby 1.9.3

Installation

Add gem to your rails app in Gemfile :

gem 'language_engine'

Download gem librairies :

bundle install

Usage (with bootstrap plugin)

First you must set local in your application controller for example :

class ApplicationController < ActionController::Base
  protect_from_forgery
  helper LanguageEngine::Engine.helpers
  before_filter :set_locale
 
  def set_locale
    I18n.locale = session[:language] || I18n.default_locale
  end
  
end  

And then you can use it inline :

 <ul class="nav navbar-nav navbar-right">
   <li class="<%= language_class('fr') %>"><%= link_to_language :fr %></li>
   <li class="<%= language_class('en') %>"><%= link_to_language :en %></li>
 </ul>

Or with dropdown :

<ul class="nav navbar-nav navbar-right">
  <li class="dropdown languages">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
      <%= image_tag("language_engine/#{selected_language}_flag.png", { :'data-locale' => "#{selected_language}" } ) %><b class='caret'></b>
    </a>
    <ul class="dropdown-menu">
      <li><%= link_to_language :fr, { :class => language_class( :fr ) } %></li>
      <li><%= link_to_language :en, { :class => language_class( :en  ) } %></li>
    </ul>
  </li>
</ul>  

Test

bundle exec rake spec

License

This project is licensed under the MIT license, a copy of which can be found in the LICENSE file.

Support

Users looking for support should file an issue on the GitHub issue tracking page, or file a pull request if you have a fix available.

Packages

No packages published

Languages

  • Ruby 77.9%
  • HTML 14.6%
  • JavaScript 4.0%
  • CSS 3.5%