subdomain_locale 1.0.beta6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +63 -24
- data/subdomain_locale.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da9fa1546e807d5b21bf511496257ef32741596
|
4
|
+
data.tar.gz: e15c64020a71c4dee2f4a001a1c90b5f25735f51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22ae781fa5583463102c0b25f942a65f9c5ebcae46409e8ed281efef0640394ca972bb8eadb76926df0f29e08825f3c380233d575e17c6122f46516cdea13528
|
7
|
+
data.tar.gz: 42a64ecad75d68ba195b611c82e74493f1b96e9622dcb40e9ccf270a26a3be23bd3a42f35af769ec589c36b271bcb4cc1f21b3bc27df39f96adbc01cc6d024d6
|
data/Readme.md
CHANGED
@@ -1,57 +1,96 @@
|
|
1
1
|
# Subdomain Locale (for Rails)
|
2
2
|
|
3
|
-
|
3
|
+
A multi-language website requires some way to detect a user's locale.
|
4
|
+
Subdomain is one option.
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
gem
|
6
|
+
## Setup
|
7
|
+
|
8
|
+
Add the gem to your Gemfile. Set a default subdomain.
|
8
9
|
|
10
|
+
```ruby
|
9
11
|
# config/application.rb
|
10
|
-
|
11
|
-
|
12
|
+
|
13
|
+
# I18n library now recommends you to enforce available locales.
|
14
|
+
config.i18n.enforce_available_locales = true
|
15
|
+
config.i18n.available_locales = :en, :ru
|
16
|
+
|
17
|
+
# See "Configuration" for difference between these:
|
18
|
+
config.default_locale = :ru
|
19
|
+
config.i18n.default_locale = :en
|
12
20
|
```
|
13
21
|
|
14
|
-
|
22
|
+
Subdomains will now determine the current locale:
|
15
23
|
|
16
|
-
|
17
|
-
|
18
|
-
http://en-us.lvh.me:3000/ - I18n.locale is set to :en-US
|
19
|
-
http://www.lvh.me:3000/ - again, default
|
24
|
+
* Selected locale (:en) http://en.example.com/
|
25
|
+
* Default locale (:ru) http://example.com/
|
20
26
|
|
21
|
-
|
27
|
+
Add links to the new subdomains using :locale URL parameter:
|
22
28
|
|
23
29
|
```erb
|
24
|
-
<%
|
30
|
+
<% [:ru, :en].each do |locale| %>
|
25
31
|
<%= link_to locale, params.merge(locale: locale) %>
|
26
32
|
<% end %>
|
27
33
|
```
|
28
34
|
|
29
|
-
##
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
You can hook a special subdomain name with a locale:
|
30
38
|
|
31
39
|
```ruby
|
32
|
-
#
|
40
|
+
config.subdomain_locale["us"] = :"en-US" # us.lvh.me
|
41
|
+
config.subdomain_locale["ca"] = :"en-CA" # ca.lvh.me
|
42
|
+
config.subdomain_locale["ua"] = :uk # ua.lvh.me
|
43
|
+
```
|
44
|
+
|
45
|
+
Default locale will link to the default subdomain (main domain by default: lvh.me).
|
46
|
+
If you prefer "www" use this config option:
|
33
47
|
|
34
|
-
|
35
|
-
|
36
|
-
# config.subdomain_locales = {"us" => "en-US", "ca" => "en-CA"}
|
48
|
+
```ruby
|
49
|
+
config.default_subdomain = "www"
|
37
50
|
```
|
38
51
|
|
39
|
-
|
52
|
+
English developers prefer to see English in console and other places.
|
53
|
+
This is why we have a separate default locale for the website:
|
40
54
|
|
41
|
-
|
55
|
+
```ruby
|
56
|
+
config.default_locale = :ru
|
57
|
+
config.i18n.default_locale = :en
|
58
|
+
```
|
59
|
+
|
60
|
+
For example, with this config example.com will be in Russian,
|
61
|
+
while validation errors in console are still in English.
|
62
|
+
|
63
|
+
|
64
|
+
You can also override our controller method to completely ignore subdomain locale.
|
65
|
+
For example, if you want admin panel to always be in English:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class AdminController
|
69
|
+
# This is alrady an around_filter
|
70
|
+
def set_locale(&block)
|
71
|
+
I18n.with_locale(:en, &block)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Testing
|
77
|
+
|
78
|
+
This gem is tested against Rails 3.2 and 4.0.
|
42
79
|
|
43
80
|
```
|
44
81
|
gem install isolate
|
45
82
|
rake test:all
|
46
83
|
```
|
47
84
|
|
48
|
-
|
49
85
|
## Changelog
|
50
86
|
|
51
|
-
|
87
|
+
1.0.0
|
52
88
|
|
53
|
-
*
|
54
|
-
*
|
89
|
+
* Now compatible with the new I18n.enforce\_available\_locales.
|
90
|
+
* No subdomain is now deafult instead of "www". Can be reverted by setting config.default\_domain.
|
91
|
+
* Separate website's default locale (config.default\_locale) from the global default locale (config.i18n.default\_locale).
|
92
|
+
* Test gem in the whole Rails stack (3.2, 4.0).
|
93
|
+
* Add config.subdomain_locale for indirect mapping ("us" => :"en-US").
|
55
94
|
|
56
95
|
0.1.1
|
57
96
|
|
data/subdomain_locale.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "subdomain_locale"
|
5
|
-
spec.version = "1.0.
|
5
|
+
spec.version = "1.0.0"
|
6
6
|
spec.authors = ["Semyon Perepelitsa"]
|
7
7
|
spec.email = ["sema@sema.in"]
|
8
|
-
spec.summary = "Set I18n locale based on subdomain"
|
8
|
+
spec.summary = "Set I18n locale based on subdomain (Rails plugin)."
|
9
9
|
spec.homepage = "https://github.com/semaperepelitsa/subdomain_locale"
|
10
10
|
spec.license = "MIT"
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subdomain_locale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Semyon Perepelitsa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -73,15 +73,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- - "
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.2.
|
81
|
+
rubygems_version: 2.2.2
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
|
-
summary: Set I18n locale based on subdomain
|
84
|
+
summary: Set I18n locale based on subdomain (Rails plugin).
|
85
85
|
test_files:
|
86
86
|
- test/dummy/app/controllers/application_controller.rb
|
87
87
|
- test/dummy/app/controllers/hello_controller.rb
|