world-flags 0.3.2 → 0.3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -0
- data/VERSION +1 -1
- data/lib/world_flags/helper/locale.rb +12 -1
- data/world-flags.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -249,6 +249,17 @@ before_filter :set_locale
|
|
249
249
|
|
250
250
|
And it should set the I18n.locale appropriately, trying `params[locale], browser, ip address` in succession, defaulting to `I18n.default_locale`.
|
251
251
|
|
252
|
+
|
253
|
+
Under the covers, the `set_locale` filter uses the following method to get the locale:
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
def locales
|
257
|
+
[params[:locale], extract_locale_from_tld, browser_locale, ip_country_code, I18n.default_locale].downcase
|
258
|
+
end
|
259
|
+
```
|
260
|
+
|
261
|
+
Note: You can override this method to set which the priority order for getting the user locale.
|
262
|
+
|
252
263
|
For each locale it will check if it is a valid locale. By default it will call `valid_locales` in the controller, which will first try `I18n.available_locales` and then fall-back to `WorldFlags#valid_locales`.
|
253
264
|
You can override this behavior by defining you custom `valid_locales` method in the controller.
|
254
265
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.2
|
1
|
+
0.3.2.1
|
@@ -14,8 +14,19 @@ module WorldFlags
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def locales
|
17
|
-
[params[:locale], browser_locale, ip_country_code, I18n.default_locale].downcase
|
17
|
+
[params[:locale], extract_locale_from_tld, browser_locale, ip_country_code, I18n.default_locale].downcase
|
18
18
|
end
|
19
|
+
|
20
|
+
# Get locale from top-level domain or return nil if such locale is not available
|
21
|
+
# You have to put something like:
|
22
|
+
# 127.0.0.1 application.com
|
23
|
+
# 127.0.0.1 application.it
|
24
|
+
# 127.0.0.1 application.pl
|
25
|
+
# in your /etc/hosts file to try this out locally
|
26
|
+
def extract_locale_from_tld
|
27
|
+
parsed_locale = request.host.split('.').last
|
28
|
+
I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil
|
29
|
+
end
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
data/world-flags.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: world-flags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.2
|
4
|
+
version: 0.3.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -165,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
segments:
|
167
167
|
- 0
|
168
|
-
hash: -
|
168
|
+
hash: -2190799221489192684
|
169
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
170
|
none: false
|
171
171
|
requirements:
|