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.
Rails I18n library for ActiveRecord model/data translation using PostgreSQL's hstore datatype. It provides an interface inspired by Globalize3 but removes the need to maintain separate translation tables.
gem install hstore_translate
When using bundler, put it in your Gemfile:
source 'https://rubygems.org'
gem 'activerecord'
gem 'pg', :platform => :ruby
gem 'hstore_translate'
Model translations allow you to translate your models' attribute values. E.g.
class Post < ActiveRecord::Base
translates :title, :body
end
Allows you to translate the attributes :title and :body per locale:
I18n.locale = :en
post.title # => This database rocks!
I18n.locale = :he
post.title # => אתר זה טוב
You also have locale-specific convenience methods from easy_globalize3_accessors:
I18n.locale = :en
post.title # => This database rocks!
post.title_he # => אתר זה טוב
To find records using translations without constructing hstore queries by hand:
Post.with_title_translation("This database rocks!") # => #<ActiveRecord::Relation ...>
Post.with_title_translation("אתר זה טוב", :he) # => #<ActiveRecord::Relation ...>
In order to make this work, you'll need to define an hstore column for each of your translated attributes, using the suffix "_translations":
class CreatePosts < ActiveRecord::Migration
def up
create_table :posts do |t|
t.column :title_translations, 'hstore'
t.column :body_translations, 'hstore'
t.timestamps
end
end
def down
drop_table :posts
end
end
It is possible to enable fallbacks for missing translations. It will depend on the configuration setting you have set for I18n translations in your Rails config.
You can enable them by adding the next line to config/application.rb
(or
only config/environments/production.rb
if you only want them in production)
config.i18n.fallbacks = true
Sven Fuchs wrote a detailed explanation of the fallback mechanism.
If you've enabled fallbacks for missing translations, you probably want to disable them in the admin interface to display which translations the user still has to fill in.
From:
I18n.locale = :en
post.title # => This database rocks!
post.title_nl # => This database rocks!
To:
I18n.locale = :en
post.title # => This database rocks!
post.disable_fallback
post.title_nl # => nil
You can also call your code into a block that temporarily disable or enable fallbacks.
I18n.locale = :en
post.title_nl # => This database rocks!
post.disable_fallback do
post.title_nl # => nil
end
post.disable_fallback
post.enable_fallback do
post.title_nl # => This database rocks!
end
FAQs
Unknown package
We found that hstore_translate 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.