Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Sinatra extension which provides i18n support to translate your web application.
It is a wrapper for R18n core library. See R18n documentation for more information.
Create translations dir ./i18n/
.
Add file with translation to ./i18n/
with language code in file name
(for example, en.yml
for English or en-us.yml
USA English dialect).
For example, ./i18n/en.yml
:
post:
friends: Post only for friends
tags: Post tags are %1
comments: !!pl
0: No comments
1: One comment
n: '%1 comments'
html: !!html
<b>Don't escape HTML</b>
Add R18n to your Sinatra application:
require 'sinatra/r18n'
If your application inherits from Sinatra::Base
also add:
class YourApp < Sinatra::Base
register Sinatra::R18n
set :root, __dir__
Add locale to your URLs. For example:
get '/:locale/posts/:id' do
@post = Post.find(params[:id])
haml :post
end
Or save locale in session, when user change it:
before do
session[:locale] = params[:locale] if params[:locale]
end
Warning: such hooks have to be before register Sinatra::R18n
since R18n version 5
has no more lazy evaluation and initializes immediately. See #3 or specs / test application.
Use translation messages in views. For example in HAML:
%p= t.post.friends
%p= t.post.tags(@post.tags.join(', '))
%h2= t.comments(@post.comments.size)
Print localized time and numbers. For example:
l @post.created_at, :human
Print available translations. For example in HAML:
%ul
- r18n.available_locales.each do |locale|
%li
%a( href="/#{locale.code}/" )= locale.title
You can change default locale and translations dir:
R18n::I18n.default = 'ru'
R18n.default_places { './translations' }
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 sinatra-r18n 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.