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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Readme.md +63 -24
  3. data/subdomain_locale.gemspec +2 -2
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 451e8afface6f75567cd9c4057f06dece6963bb5
4
- data.tar.gz: a3f9bb42af3d2e191da53ab0b0c938d6361135ca
3
+ metadata.gz: 5da9fa1546e807d5b21bf511496257ef32741596
4
+ data.tar.gz: e15c64020a71c4dee2f4a001a1c90b5f25735f51
5
5
  SHA512:
6
- metadata.gz: e51dfa3412c056bb4f037440758b8be1cfaa45ebccd02cbd178ce770b76ebccee944569e0b54bab7a8adf12e2ad541d6ad60327c6be5ede32dd5cbf47938b3e8
7
- data.tar.gz: 1d36125d9dc0a122e0dbb90efa24ef61f7395f569464b770f291d84f4ada319b7ab4f63a709ccfc4a5b54aa01700eb56df755d93d7830870b9eeafdfdbc431ea
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
- Moves current locale into subdomain. Installation is quick and simple:
3
+ A multi-language website requires some way to detect a user's locale.
4
+ Subdomain is one option.
4
5
 
5
- ```ruby
6
- # Gemfile
7
- gem 'subdomain_locale', '~> 0.1.0'
6
+ ## Setup
7
+
8
+ Add the gem to your Gemfile. Set a default subdomain.
8
9
 
10
+ ```ruby
9
11
  # config/application.rb
10
- config.i18n.available_locales = [:ru, :az, :en, "en-US"] # Put your own available locales
11
- config.i18n.default_locale = :az # and make one default
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
- Now, start your web server at localhost:3000 and navigate:
22
+ Subdomains will now determine the current locale:
15
23
 
16
- http://lvh.me:3000/ - the default locale (:az)
17
- http://ru.lvh.me:3000/ - I18n.locale is set to :ru
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
- You can also put links to all locales in your view:
27
+ Add links to the new subdomains using :locale URL parameter:
22
28
 
23
29
  ```erb
24
- <% I18n.available_locales.each do |locale| %>
30
+ <% [:ru, :en].each do |locale| %>
25
31
  <%= link_to locale, params.merge(locale: locale) %>
26
32
  <% end %>
27
33
  ```
28
34
 
29
- ## Configuring own subdomain-to-locale mapping
35
+ ## Configuration
36
+
37
+ You can hook a special subdomain name with a locale:
30
38
 
31
39
  ```ruby
32
- # config/application.rb
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
- config.subdomain_locales["us"] = "en-US"
35
- # or even
36
- # config.subdomain_locales = {"us" => "en-US", "ca" => "en-CA"}
48
+ ```ruby
49
+ config.default_subdomain = "www"
37
50
  ```
38
51
 
39
- Having that configured `http://us.lvh.me:3000` will be rendered with :en-US locale.
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
- ## Development setup
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
- master
87
+ 1.0.0
52
88
 
53
- * Support IETF language tag subdomains, e.g. pt-br.
54
- * Allow to create custom mappings, e.g. "us" instead of "en-us".
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
 
@@ -2,10 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "subdomain_locale"
5
- spec.version = "1.0.beta6"
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.beta6
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-03-23 00:00:00.000000000 Z
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: 1.3.1
78
+ version: '0'
79
79
  requirements: []
80
80
  rubyforge_project:
81
- rubygems_version: 2.2.0
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