Skip to content

Commit

Permalink
Add default fallback locale (if autodetection fails)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjg committed Aug 9, 2011
1 parent 55fd59d commit ba28e4c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Locale Detector

This Rails gem makes use of the HTTP_ACCEPT_LANGUAGE http header send by the browser with every request, to set the I18n.locale.

If there is no such header it will fall back to the default header.
This Rails gem makes use of the HTTP_ACCEPT_LANGUAGE http header send by web browsers with every request, to set the `I18n.locale` variable.
When this fails (for example if there is no such http header as is the case for Google bot), it will try to determine the locale based on the toplevel domain suffix (so it will set 'de' for the `example.de` domain).
When both fail, it will fall back to the `LocaleDetector.fallback_locale`, which is 'en' by default and can be overriden in `config/initializers/locale_detector.rb`.


## Installation
Expand All @@ -26,4 +26,12 @@ $ bundle
```


You can optionally overwrite the default fallback locale by creating a `config/initializers/locale_detector.rb` file and set the `fallback_locale` to a new string, for example:

```ruby
LocaleDetector.fallback_locale = 'pl'
```



Copyright © 2011 Exvo.com Development BV, released under the MIT license
1 change: 1 addition & 0 deletions lib/locale_detector.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "locale_detector/fallback_locale"
require "locale_detector/filter"
require "locale_detector/version"

Expand Down
5 changes: 5 additions & 0 deletions lib/locale_detector/fallback_locale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module LocaleDetector
@@fallback_locale = 'en'

mattr_accessor :fallback_locale
end

0 comments on commit ba28e4c

Please sign in to comment.