Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sshaw/i18n-env-config
Set I18n.locale based on the environment variables that control the locale.
https://github.com/sshaw/i18n-env-config
environment-variables i18n locale ruby
Last synced: 16 days ago
JSON representation
Set I18n.locale based on the environment variables that control the locale.
- Host: GitHub
- URL: https://github.com/sshaw/i18n-env-config
- Owner: sshaw
- License: mit
- Created: 2016-09-17T23:37:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-18T02:27:50.000Z (about 8 years ago)
- Last Synced: 2024-04-25T03:43:34.828Z (7 months ago)
- Topics: environment-variables, i18n, locale, ruby
- Language: Ruby
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# I18n::Env::Config
[![Build Status](https://secure.travis-ci.org/sshaw/i18n-env-config.svg)](https://secure.travis-ci.org/sshaw/i18n-env-config)
Set `I18n.locale` based on the environment variables that control the locale.
This is for Desktop applications only.
For web application see [http_accept_languge](https://github.com/iain/http_accept_language) or [http-accept](https://github.com/ioquatix/http-accept).## Usage
```ruby
require "i18n"
require "i18n/env/config"I18n.config = I18n::Env::Config.new
```Now `I18n.locale` will be derived from the user's environment.
## Environment Variables
The following environment variables are searched, in order:
1. `LANGUAGE`
1. `LC_ALL`
1. `LC_MESSAGES`
1. `LANG`(Just like [gettext](https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables)).
If an exact match is not found, the list is reevaluated using the locale's parent(s).
E.g., if `en_US` is not found, we see if `en` is available.## Installation
Add this line to your application's Gemfile:
```ruby
gem "i18n-env-config"
```And then execute:
$ bundle
Or install it yourself as:
$ gem install i18n-env-config
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).