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.
rails_locale_detection
Advanced tools
Sets the current locale of a request using a combination of params, cookies, http headers, and an optional user object.
In turn, it checks the value of params[:locale]
, cookies[:locale]
and HTTP_ACCEPT_LANGUAGE
headers to find a locale that
corresponds to the available locales, then stores the locale in a cookie for future requests. If a user_locale
method
is provided, any valid return value will be used, with preference over the other locale detection methods except for params[:locale]
.
Include the gem in your Gemfile
gem 'rails_locale_detection'
Set your default and available locales
I18n.default_locale = :en
I18n.available_locales = [:en, :fr]
To support user locales, add a user_locale
method
class ApplicationController < ActionController::Base
def user_locale
current_user.locale if current_user
end
end
Methods for accessing current_locale
, available_locales
, and alternate_locales
are available in controller and views
Configuration is done via a block that can be added as an initializer:
RailsLocaleDetection.config do |config|
config.locale_expiry = 3.months
config.set_default_url_option = :always # valid values are true, false, :always, :never and :explicity
config.detection_order = [:param, :user, :cookie, :request]
config.automatically_detect = true
config.locale_key = :locale
end
The configuration options:
locale_expiry
sets how long the locale cookie lasts.set_default_url_option
determines under which conditions the default_url_option
is set
true
or :always
sets the option on all requestsfalse
or :never
never sets the option:explicity
sets the option only when a param[:locale] is presentdetection_order
set the order in which locale detection occurs. Omit values to skip those sourcesautomatically_detect
configures automatic inclusion of the detection callback.
You can set this to false and include the callback yourself by calling detect_locale
in your controller as required.locale_key
configures the key used for param
and cookie
param
first, as this make more sense in most contexts.Copyright (c) 2012-present Mateo Murphy. See LICENSE.txt for further details.
FAQs
Unknown package
We found that rails_locale_detection 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.