i18n_strategy 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -7
- data/lib/i18n_strategy/initializer.rb +1 -1
- data/lib/i18n_strategy/strategy.rb +1 -1
- data/lib/i18n_strategy/version.rb +1 -1
- data/spec/controllers/locale_spec.rb +1 -1
- metadata +30 -17
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -3,30 +3,46 @@
|
|
3
3
|
i18n_strategy provides a very much simple way to detect and set locale
|
4
4
|
in your Rails application.
|
5
5
|
|
6
|
+
In
|
7
|
+
[i18n section of Rails Guide](http://edgeguides.rubyonrails.org/i18n.html),
|
8
|
+
there's a description on Rails i18n API. It's comprehensive and has
|
9
|
+
enough information to implement our own locale detection
|
10
|
+
strategy. However, it doesn't provide us some automatic way to handle
|
11
|
+
users' locale.
|
12
|
+
|
13
|
+
I've wanted some easier way to handle it. So I hacked up this library
|
14
|
+
which provides a thin wrapper over Rails i18n API and allows you to
|
15
|
+
detect and set request users' locale easily.
|
16
|
+
|
6
17
|
## Usage
|
7
18
|
|
8
19
|
Add a line below into your `Gemfile`:
|
9
20
|
|
10
|
-
```
|
21
|
+
```ruby
|
11
22
|
gem 'i18n_strategy'
|
12
23
|
```
|
13
24
|
|
14
25
|
Then, set your custom strategy into `I18nStrategy.strategy`, which is
|
15
26
|
to detect a locale for a user visiting your application, and also set
|
16
27
|
available languages in your application via
|
17
|
-
`I18nStrategy.
|
28
|
+
`I18nStrategy.available_locales`.
|
18
29
|
|
19
30
|
`initializers/i18n_strategy`:
|
20
31
|
|
21
|
-
```
|
32
|
+
```ruby
|
33
|
+
# Just for example
|
22
34
|
module MyStrategy
|
23
35
|
def detect_locale
|
24
|
-
params[:
|
36
|
+
if params[:local] && I18nStrategy.available_locales.include?(params[:locale])
|
37
|
+
params[:locale]
|
38
|
+
else
|
39
|
+
I18n.default_locale
|
40
|
+
end
|
25
41
|
end
|
26
42
|
end
|
27
43
|
|
28
44
|
I18nStrategy.strategy = MyStrategy
|
29
|
-
I18nStrategy.
|
45
|
+
I18nStrategy.available_locales = %w[ja en]
|
30
46
|
```
|
31
47
|
|
32
48
|
Users' locale detected by the strategy is automatically set to
|
@@ -55,9 +71,9 @@ to say, it can duplicate your existing method.
|
|
55
71
|
In case above, you can set another method name to be called via this
|
56
72
|
method.
|
57
73
|
|
58
|
-
### I18nStrategy.
|
74
|
+
### I18nStrategy.available_locales
|
59
75
|
|
60
|
-
Set available
|
76
|
+
Set available locales in your application.
|
61
77
|
|
62
78
|
The default strategy utilizes this method to detect whether the
|
63
79
|
language from users can be available in your application or not.
|
metadata
CHANGED
@@ -1,83 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_strategy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Kentaro Kuribayashi
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - '>='
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 3.0.0
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- - '>='
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 3.0.0
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: http_accept_language
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: 2.0.0pre
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: 2.0.0pre
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rake
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: rspec
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- - '>='
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '0'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- - '>='
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '0'
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: rspec-rails
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
|
-
- - '>='
|
83
|
+
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
75
85
|
version: '0'
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
|
-
- - '>='
|
91
|
+
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
82
93
|
version: '0'
|
83
94
|
description: Provides a very much simple way to detect and set locale in your Rails
|
@@ -106,28 +117,30 @@ files:
|
|
106
117
|
- spec/spec_helper.rb
|
107
118
|
homepage: https://github.com/kentaro/i18n_strategy
|
108
119
|
licenses: []
|
109
|
-
metadata: {}
|
110
120
|
post_install_message:
|
111
121
|
rdoc_options: []
|
112
122
|
require_paths:
|
113
123
|
- lib
|
114
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
115
126
|
requirements:
|
116
|
-
- - '>='
|
127
|
+
- - ! '>='
|
117
128
|
- !ruby/object:Gem::Version
|
118
129
|
version: '0'
|
119
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
120
132
|
requirements:
|
121
|
-
- - '>='
|
133
|
+
- - ! '>='
|
122
134
|
- !ruby/object:Gem::Version
|
123
135
|
version: '0'
|
124
136
|
requirements: []
|
125
137
|
rubyforge_project:
|
126
|
-
rubygems_version:
|
138
|
+
rubygems_version: 1.8.23
|
127
139
|
signing_key:
|
128
|
-
specification_version:
|
140
|
+
specification_version: 3
|
129
141
|
summary: Provides a very much simple way to detect and set locale in your Rails application
|
130
142
|
test_files:
|
131
143
|
- spec/app/test_app.rb
|
132
144
|
- spec/controllers/locale_spec.rb
|
133
145
|
- spec/spec_helper.rb
|
146
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: b9fc1d2a94f64ccd3870735db85194c5f9e5a8a3
|
4
|
-
data.tar.gz: 7df0d69f52325135fb136c69293c932a249032b6
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: cebe8451beb95867607626687ff5c5c97c1cc6b6985d3e6b3ae0fac6af432c473670fe92bef5ab0147eb60cd0bb5d2a80c833afbf889f6f05e80c31d1a5151e4
|
7
|
-
data.tar.gz: ceda354a65cec73626d7f62cf85e50949bc750c11b0e5b07df8744b142a8147dcf7bffeafb422f9b62769ac4cf1b742ac00945d5cfabfa72765fc3d7ee0cd1da
|