Translation management engine for Rails applications.
$ gem 'i18nline-rails'
1b. Optionally install rails-i18n for some nice default translations: $ gem 'rails-i18n'
jj$ bundle
$ rake i18nline:install:migrations
$ rails generate i18nline:install
$ rake db:migrate
config/initializers/i18nline.rb
<%= i18nline_assets_inclusion_tag %>
mount I18nline::Engine => "/i18nline"
config.i18n.fallbacks = false
If everything is right, users who can translate as specified in the initilizer file will see red inline marks on missing translations on views.
Right clicking an inline mark will open a translation management view for that specific key.
A translation dashboard will be available to translators at /i18nline
.
Your application should keep track of the locale that is asked by the user. A basic implementation of this in you application controller could look like this:
before_action :set_locale
def set_locale
previous_locale = session[:locale] || I18n.locale.to_s
I18n.locale = params[:locale] || session[:locale] || locale_from_browser || default_language
if I18n.locale.to_s != session[:locale].to_s
logger.debug "Locale changed from -#{session[:locale].to_s}- to -#{I18n.locale.to_s}-."
unless I18n.available_locales.include? I18n.locale.to_s
logger.debug "-#{I18n.locale.to_s}- is not included in available locales. Changing back to locale -#{previous_locale}-."
I18n.locale = previous_locale
end
end
session[:locale] = I18n.locale.to_s
end
private
def locale_from_browser
request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
end
You can learn more about it here: http://guides.rubyonrails.org/i18n.html#setting-and-passing-the-locale
You need to provide some configuration options so i18nline can work. They configuration file is located at your_app_root/config/initializers/i18nline.rb
.
Fallbacks are already done by I18n, but show how to use them here.
Cache abilitation already done by i18n, but show how to set it here.
Make your best effort to follow this guidelines:
Fork this repo.
Create feature branch with a meaningful name in your fork.
Make sure it works before starting your changes:
$ bundle
$ rake db:setup
$ rake db:migrate
$ rake
$ cd test/dummy
$ rails server
Make your changes.
Add tests to /i18nline_root/spec/*
Add tests to /i18nline_root/test/dummy/spec/* to make a point for your changes when we review the pull request.
Make sure all tests pass.
Make your pull request.
https://github.com/Chipairon/i18nline/graphs/contributors
This project rocks and uses MIT-LICENSE.