subdomain_locale 1.0.beta5 → 1.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subdomain_locale/mapping.rb +2 -2
- data/lib/subdomain_locale/railtie.rb +5 -2
- data/subdomain_locale.gemspec +1 -1
- data/test/dummy/config/application.rb +2 -1
- data/test/rails_test.rb +8 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 451e8afface6f75567cd9c4057f06dece6963bb5
|
4
|
+
data.tar.gz: a3f9bb42af3d2e191da53ab0b0c938d6361135ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e51dfa3412c056bb4f037440758b8be1cfaa45ebccd02cbd178ce770b76ebccee944569e0b54bab7a8adf12e2ad541d6ad60327c6be5ede32dd5cbf47938b3e8
|
7
|
+
data.tar.gz: 1d36125d9dc0a122e0dbb90efa24ef61f7395f569464b770f291d84f4ada319b7ab4f63a709ccfc4a5b54aa01700eb56df755d93d7830870b9eeafdfdbc431ea
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SubdomainLocale
|
2
2
|
class << self
|
3
|
-
attr_accessor :mapping
|
3
|
+
attr_accessor :mapping, :default_locale
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.default_fallback(locale)
|
7
7
|
if I18n.locale_available?(locale)
|
8
8
|
locale
|
9
9
|
else
|
10
|
-
|
10
|
+
default_locale
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -3,12 +3,15 @@ require "rails/railtie"
|
|
3
3
|
module SubdomainLocale
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
config.subdomain_locale = {}
|
6
|
-
config.
|
6
|
+
config.default_subdomain = "" # or "www"
|
7
|
+
config.default_locale = nil
|
7
8
|
|
8
9
|
# Execute after all application initializers, I18n is often configured there.
|
9
10
|
config.after_initialize do |app|
|
10
11
|
require "subdomain_locale/mapping"
|
11
|
-
|
12
|
+
SubdomainLocale.default_locale = app.config.default_locale || I18n.default_locale
|
13
|
+
|
14
|
+
default = { app.config.default_subdomain => SubdomainLocale.default_locale }
|
12
15
|
mapping = default.merge(app.config.subdomain_locale)
|
13
16
|
SubdomainLocale.mapping = Mapping.new(mapping)
|
14
17
|
end
|
data/subdomain_locale.gemspec
CHANGED
@@ -5,8 +5,9 @@ require "subdomain_locale/railtie"
|
|
5
5
|
module Dummy
|
6
6
|
class Application < Rails::Application
|
7
7
|
config.i18n.enforce_available_locales = true
|
8
|
-
config.i18n.default_locale = :en
|
9
8
|
config.i18n.available_locales = :en, :ru, :uk
|
9
|
+
|
10
|
+
config.default_locale = :ru
|
10
11
|
config.subdomain_locale["ua"] = :uk
|
11
12
|
|
12
13
|
config.secret_key_base = '-'
|
data/test/rails_test.rb
CHANGED
@@ -7,8 +7,8 @@ class HelloControllerTest < ActionController::TestCase
|
|
7
7
|
get :world
|
8
8
|
menu = css_select("menu a")
|
9
9
|
assert_equal "/", menu[0]["href"]
|
10
|
-
assert_equal "http://example.com/", menu[1]["href"]
|
11
|
-
assert_equal "http://
|
10
|
+
assert_equal "http://en.example.com/", menu[1]["href"]
|
11
|
+
assert_equal "http://example.com/", menu[2]["href"]
|
12
12
|
assert_equal "http://ua.example.com/", menu[3]["href"]
|
13
13
|
assert_equal "http://beta.example.com/", menu[4]["href"]
|
14
14
|
end
|
@@ -17,14 +17,14 @@ class HelloControllerTest < ActionController::TestCase
|
|
17
17
|
@request.host = "example.com"
|
18
18
|
get :world
|
19
19
|
assert_response :ok
|
20
|
-
assert_select "p", "
|
20
|
+
assert_select "p", "Привет"
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_direct
|
24
|
-
@request.host = "
|
24
|
+
@request.host = "en.example.com"
|
25
25
|
get :world
|
26
26
|
assert_response :ok
|
27
|
-
assert_select "p", "
|
27
|
+
assert_select "p", "Hello"
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_custom
|
@@ -43,13 +43,13 @@ class HelloControllerTest < ActionController::TestCase
|
|
43
43
|
def test_other
|
44
44
|
@request.host = "wtf.example.com"
|
45
45
|
get :world
|
46
|
-
assert_select "p", "
|
46
|
+
assert_select "p", "Привет"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
class HelloMailerTest < ActionController::TestCase
|
51
51
|
def test
|
52
|
-
mail = I18n.with_locale(:
|
53
|
-
assert_equal "http://
|
52
|
+
mail = I18n.with_locale(:uk) { HelloMailer.world }
|
53
|
+
assert_equal "http://ua.example.com/", mail.body.to_s.lines[3].chomp
|
54
54
|
end
|
55
55
|
end
|
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.beta6
|
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-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: 1.3.1
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.2.
|
81
|
+
rubygems_version: 2.2.0
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Set I18n locale based on subdomain
|