Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Store translations in your PG database as HSTORE, JSON or JSONB.
To use this gem in your rails app simply add the following to your Gemfile
:
gem 'pg_translatable'
To translate your model's fields you must call the translate
method:
# app/models/post.rb
class Post < ActiveRecord::Base
translate :title, :content
...
end
These fields will be translated to all locales that you have defined in
config.i18n.available_locales
.
E.g. the following configuration would store translations for english, german, french and spanish:
# config/application.rb
module TestApp
class Application < Rails::Application
config.i18n.default_locale = :en
config.i18n.available_locales = [:en, :de, :fr, :es]
end
end
When you call the field's name in singular it will return the value for the
current locale, that is the locale defined in I18n.locale
. So for the above
example, if my current locale was set to :fr
calling title
would return the
title in french.
When you call the field's name in plural it will return a hash containing all
translations. For the above example, calling titles
would return a hash
containing all translations.
Additionally a per locale getter and setter will be defined for each field.
For the above example the following getters and setters would be generated:
title_en
, title_de
, title_fr
, title_es
,
content_en
, content_de
, content_fr
, content_es
NOTE: If it happens that the singular and plural of a given field are the
same then the plural will get suffixed with _translations
.
E.g. If there was a field called news
it's getters and setters would be
news
for the current translation and news_translations
for the
translations hash.
If you want to format the output of a getter method then you can just redefine the formatter method for any field.
E.g. if you wanted your content's translations to be returned in reverse:
# app/models/post.rb
class Post < ActiveRecord::Base
translate :title, :content, :price
private
def content_formatter(value)
value.to_s.reverse
end
end
NOTE: Only getters pass data through formatters, setters save data given to them as is.
To better integrate translations with strong parameters a convenience method
will be defined for each field, it will just be suffixed with _fields
.
For the above example you could do the following:
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
...
private
def post_params
params.require(:post).permit(
*Post.title_fields,
*Post.content_fields
)
end
...
end
There is no practical solution for validating this kind of data. My suggestion is to write custom validator classes.
After checking out the repo, make sure you have a Postgres database server
running on your machine then move to the spec/test_app
directory and run the
following commands:
rake db:create
rake db:migrate
Open an issue here or do the following:
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that pg_translatable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.