
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
R18n-rails is a gem to add out-of-box R18n support to Rails I18n.
It is a wrapper for R18n Rails API and R18n core libraries. See R18n core documentation for more information.
R18n for Rails is fully compatible with Rails I18n, and add extra features:
See full features in main README.
Add r18n-rails
gem to your Gemfile
:
gem 'r18n-rails'
Now R18n will auto-detect user locales.
Define your way to set locale manually. R18n will find it in
params[:locale]
or session[:locale]
. Best way is a put optional
locale prefix to URLs:
match ':controller/:action'
match ':locale/:controller/:action'
Print available translations, to choose from them manually (and to help search engines):
%ul
- r18n.available_locales.each do |locale|
%li
%a( href="/#{locale.code}/" )= locale.title
Translations in I18n format are stored in
config/locales/%{locale}.yml
:
en:
user:
name: "User name is %{name}"
count:
zero: "No users"
one: "One user"
many: "%{count} users"
Translations in R18n format go to app/i18n/%{locale}.yml
:
user:
name: User name is %1
count: !!pl
0: No users
1: 1 user
n: '%1 users'
Use translated messages in views. You can use Rails I18n syntax:
t 'user.name', name: 'John'
t 'user.count', count: 5
or R18n syntax:
t.user.name(name: 'John') # for Rails I18n named variables
t.user.name('John') # for R18n variables
t.user.count(5)
Print dates and numbers in user's tradition:
l Date.today, :standard #=> "2009-12-20"
l Time.now, :full #=> "20th of December, 2009 12:00"
l 1234.5 #=> "1,234.5"
Translate models. You can use R18n::Translated
mixin for any Ruby class,
not only for ActiveRecord models
Add to migration columns for each of the supported locales, named as
%{name}_%{locale}
:
t.string :title_en
t.string :title_ru
t.string :text_en
t.string :text_ru
Add R18n::Translated
mixin to model:
class Post < ActiveRecord::Base
include R18n::Translated
Call translations
method in model with all columns to be translated:
translations :title, :text
Now model will have virtual methods title
, text
, title=
and text=
, which will call title_ru
or title_en
and etc based
on current user locales.
Download translations for Rails system messages (validation, etc) from
svenfuchs/rails-i18n
and put them to config/locales/
(because them use Rails I18n format).
Add your own translations filters to app/i18n/filters.rb
:
R18n::Filters.add('gender') do |translation, config, user|
translation[user.gender]
end
And use in translations:
log:
signup: !!gender
male: Он зарегистрировался
female: Она зарегистрировалась
and application:
t.log.signup(user)
R18n is licensed under the GNU Lesser General Public License version 3. You can read it in LICENSE file or in www.gnu.org/licenses/lgpl-3.0.html.
Andrey “A.I.” Sitnik andrey@sitnik.ru
FAQs
Unknown package
We found that r18n-rails demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.