localizer_rails 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +72 -62
- data/lib/localizer_rails/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3644371397c6f5017271befc6444cfc36d0dc8a
|
|
4
|
+
data.tar.gz: ac255a81643018c3f717358f684a8b7d60edd426
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3e2fc1803eda158cd2fcc0fe81bce79fc490dfc0acc88e93a4221d9d9fed0eb5406632386e8dd32d81313b1daec3ea6faa92691863d2335deb1f16ddee67b37
|
|
7
|
+
data.tar.gz: 3663a468b152fcc22304d04676a13e0e25402c38542d4345f703b7a67bf13b4a88f37a772180650699bcc16e8c8f0969a5981c0c071b3334936ccee099eb45c2
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Just some handy utilities to manage site localization, generator provided
|
|
|
4
4
|
|
|
5
5
|
1. set/retrieve language if none selected
|
|
6
6
|
2. build language menu (bootstrap 3+ compatible)
|
|
7
|
-
3.
|
|
7
|
+
3. _[optional]_ convenience partials and Kaminari pluralization patch (up to v0.16.3)
|
|
8
8
|
|
|
9
9
|
Requirements
|
|
10
10
|
------------
|
|
@@ -12,16 +12,18 @@ Rails version: 4+
|
|
|
12
12
|
|
|
13
13
|
**Gemfile**:
|
|
14
14
|
|
|
15
|
-
gem 'localizer_rails', '0.1.
|
|
15
|
+
gem 'localizer_rails', '0.1.1'
|
|
16
16
|
**Style**:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
|
|
18
|
+
@import 'localizer_rails/localizer_rails';
|
|
19
|
+
OR
|
|
20
|
+
|
|
21
|
+
require localizer_rails
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
Description
|
|
23
25
|
-----------
|
|
24
|
-
###
|
|
26
|
+
### **_set_loc_** method
|
|
25
27
|
|
|
26
28
|
finds the best-match for `I18n.locale` through a cascading search:
|
|
27
29
|
|
|
@@ -34,12 +36,15 @@ finds the best-match for `I18n.locale` through a cascading search:
|
|
|
34
36
|
|
|
35
37
|
and sets values accordingly (cookies, link_to, ...)
|
|
36
38
|
|
|
37
|
-
1. use in
|
|
38
|
-
|
|
39
|
+
1. use in **_before_action_**:
|
|
40
|
+
|
|
41
|
+
<pre>before_action LocalizerRails::SetLoc</pre>
|
|
39
42
|
|
|
40
|
-
2. use in
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
2. use in **_routes_**, too:
|
|
44
|
+
|
|
45
|
+
<pre>
|
|
46
|
+
scope ":locale", locale: /#{LocalizerRails.active_locales.join("|")}/ do ...
|
|
47
|
+
...
|
|
43
48
|
match '*path', to: redirect { |p, req|
|
|
44
49
|
Localizer.set_locale(req)
|
|
45
50
|
if( ! (Localizer.active_locales.any? { |word| req.path.starts_with? ("/#{word}/") }) )
|
|
@@ -56,30 +61,30 @@ and sets values accordingly (cookies, link_to, ...)
|
|
|
56
61
|
},
|
|
57
62
|
via: [ :get, :post, :patch, :delete ],
|
|
58
63
|
status: '301'
|
|
64
|
+
</pre>
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
### **<i>active_locales_map</i>** method
|
|
66
|
+
### **_active_locales_map_** method
|
|
62
67
|
|
|
63
68
|
builds an hash of locale key/value pairs useful to build a `locale_menu`
|
|
64
69
|
|
|
65
|
-
|
|
70
|
+
_[optional]_ override and edit `config/LocalizerRails/lang_countries.yml`
|
|
66
71
|
|
|
67
72
|
<pre>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
:da:
|
|
74
|
+
:lang_default: 'Danish'
|
|
75
|
+
:lang_local: 'Dansk'
|
|
76
|
+
:country_default: 'Denmark'
|
|
77
|
+
:country_local: 'Danmark'
|
|
78
|
+
:country_code: 'DK'
|
|
79
|
+
:fo-FO:
|
|
80
|
+
:lang_default: 'Faroese'
|
|
81
|
+
:lang_local: 'Føroyskt'
|
|
82
|
+
:country_default: 'Faroe Islands'
|
|
83
|
+
:country_local: 'Føroyar'
|
|
84
|
+
:country_code: 'FO'
|
|
80
85
|
</pre>
|
|
81
86
|
|
|
82
|
-
|
|
87
|
+
_where_
|
|
83
88
|
|
|
84
89
|
* __:lang_default__: language name in default language (ex.: english)
|
|
85
90
|
* __:lang_local__: language name in local language/alphabet
|
|
@@ -90,69 +95,70 @@ xtra country specs, use if `locale_menu` lists countries instead of languages:
|
|
|
90
95
|
* __:country_local__: country name in local language/alphabet
|
|
91
96
|
* __:country_code__: country ISO code
|
|
92
97
|
|
|
93
|
-
|
|
98
|
+
**_NOTE_**: languages will be listed ONLY if included in `i18n.available_locales`
|
|
94
99
|
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
_[optional]_ edit **_LI structure_** and attributes in
|
|
101
|
+
<pre>app/views/LocalizerRails/_item[.bootstrap].html.erb</pre>
|
|
97
102
|
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
_[optional]_ edit **_LI elements_** and their display order in
|
|
104
|
+
<pre>app/views/LocalizerRails/_elements.html.erb</pre>
|
|
100
105
|
|
|
101
106
|
__CONFIGURATION__
|
|
102
107
|
|
|
103
|
-
|
|
108
|
+
_[optional]_ override and edit `config/initializers/LocalizerRails/LocalizerRails_prefs.rb`
|
|
104
109
|
|
|
105
110
|
<pre>
|
|
106
111
|
LocalizerRails::Conf.configure do |conf|
|
|
107
112
|
conf.variable_name = value
|
|
108
|
-
|
|
113
|
+
...
|
|
114
|
+
</pre>
|
|
109
115
|
|
|
110
116
|
__OPTIONS:__
|
|
111
117
|
|
|
112
|
-
* __conf.merge_lang_countries_tables__
|
|
118
|
+
* __conf.merge_lang_countries_tables__ (boolean)<br/>
|
|
113
119
|
if a copy of the `lang_countries.yml` file is found in your application you can force the engine to use ONLY your file or the MERGED hash
|
|
114
120
|
- the engine's file will be used if no override `lang_countries` file is found in your application
|
|
115
|
-
- defaults to
|
|
121
|
+
- defaults to **_true_** (= merge files if override file is found)
|
|
116
122
|
|
|
117
123
|
* __conf.all_available_locales__ (boolean)<br/>
|
|
118
|
-
- set to
|
|
124
|
+
- set to `true` if
|
|
119
125
|
- you want to load all locales in `I18n.available_locales`
|
|
120
126
|
- you have already selected a limited bunch of locale files to be loaded in `your config.i18n.available_locales = [:en,'es-CO', :de]`
|
|
121
|
-
- set to
|
|
122
|
-
- defaults to
|
|
127
|
+
- set to `false` if you want to specify the locale files in the custom list below (`conf.active_locales`)
|
|
128
|
+
- defaults to **_true_**
|
|
123
129
|
|
|
124
|
-
|
|
130
|
+
**_Hint:_** install [rails-i18n] (https://github.com/svenfuchs/rails-i18n) to add pluralization rules and a bunch of translated language files.
|
|
125
131
|
|
|
126
132
|
|
|
127
133
|
* __conf.active_locales__ (:sym)<br/>
|
|
128
134
|
define which locales your application will use
|
|
129
135
|
- locales not included in `I18n.available_locales` will be ignored
|
|
130
|
-
- defaults to
|
|
136
|
+
- defaults to **_[I18n.default_locale]_**
|
|
131
137
|
|
|
132
|
-
* __conf.country_downcase__
|
|
138
|
+
* __conf.country_downcase__ (boolean)<br/>
|
|
133
139
|
load locale files depending on your setup:
|
|
134
|
-
- true = use browser's HTTP_ACCEPT_LANGUAGE format (en-us)
|
|
135
|
-
- false = use ISO rules in your `[localefile].yml` (en-US) as in `rails-i18n` locale files
|
|
136
|
-
- defaults to
|
|
140
|
+
- `true` = use browser's HTTP_ACCEPT_LANGUAGE format (en-us)
|
|
141
|
+
- `false` = use ISO rules in your `[localefile].yml` (en-US) as in `rails-i18n` locale files
|
|
142
|
+
- defaults to **_false_**
|
|
137
143
|
|
|
138
|
-
* __conf.display_local_language__
|
|
144
|
+
* __conf.display_local_language__ (boolean)<br/>
|
|
139
145
|
display menu language names in their own idiom and alphabet or always in the default site language:
|
|
140
|
-
- true = 'Italiano', 'Español', 'Deutsch', ...
|
|
141
|
-
- false = 'Italian', 'Spanish', 'German', ... (or whatever language your `config.i18n.default_locale` defaults to)
|
|
142
|
-
- defaults to
|
|
146
|
+
- `true` = 'Italiano', 'Español', 'Deutsch', ...
|
|
147
|
+
- `false` = 'Italian', 'Spanish', 'German', ... (or whatever language your `config.i18n.default_locale` defaults to)
|
|
148
|
+
- defaults to **_false_**
|
|
143
149
|
|
|
144
|
-
* __conf.use_bootstrap__
|
|
150
|
+
* __conf.use_bootstrap__ (boolean)<br/>
|
|
145
151
|
use bootstrap-style in `locale_menu` (you need to include bootstrap-sass (or similar) in your gemfile and import it in your stylesheet), as opposed to this engine's provided style
|
|
146
|
-
- defaults to
|
|
152
|
+
- defaults to **_false_** (= use engine's style)
|
|
147
153
|
|
|
148
|
-
* __conf.cookie_expires__
|
|
154
|
+
* __conf.cookie_expires__ (Date | nil)<br/>
|
|
149
155
|
set a custom expiration date for the `:cookies[:locale]`
|
|
150
156
|
- Date can be in the format 20.year.from_now.utc (same as cookies.permanent)
|
|
151
|
-
- defaults to
|
|
157
|
+
- defaults to **_nil_** (session length)
|
|
152
158
|
|
|
153
|
-
* __conf.store_in_session__
|
|
159
|
+
* __conf.store_in_session__ (boolean)<br/>
|
|
154
160
|
store `I18n.locale` also in session?
|
|
155
|
-
- defaults to
|
|
161
|
+
- defaults to **_false_**
|
|
156
162
|
|
|
157
163
|
## Extras (optional)
|
|
158
164
|
|
|
@@ -161,12 +167,14 @@ store `I18n.locale` also in session?
|
|
|
161
167
|
[Kaminari] (https://github.com/amatsuda/kaminari) (up to current v0.16.3) handles pluralization through <i>pluralize</i>.<br/>
|
|
162
168
|
In case of localization with foreign languages (eventually with multiple plural forms, such as cyrillic) this method often outputs incorrect results.<br/>
|
|
163
169
|
The generator installs an override for Kaminari's `ActionViewExtension#page_entries_info`, following a bright hint by <a href="https://github.com/Linuus" target="_blank">Linuus</a> found on <a href="https://github.com/amatsuda/kaminari/pull/309" target="_blank">GitHub</a> (see 'Credits' below).<br/>
|
|
164
|
-
The patch uses model_name and AR's count
|
|
165
|
-
|
|
170
|
+
The patch uses model_name and AR's count.
|
|
171
|
+
|
|
172
|
+
**_Note:_** You need to install the [kaminari ~> 0.16] (https://github.com/amatsuda/kaminari) and [kaminari-i18n] (https://github.com/tigrish/kaminari-i18n) gems.
|
|
166
173
|
|
|
167
174
|
### **Bootstrap 3+ NAVBAR raw partial**
|
|
168
|
-
The generator installs a raw partial with the code for a Bootstrap 3+ NAVBAR featuring the language menu, modify it to suit your needs
|
|
169
|
-
|
|
175
|
+
The generator installs a raw partial with the code for a Bootstrap 3+ NAVBAR featuring the language menu, modify it to suit your needs.
|
|
176
|
+
|
|
177
|
+
**_Note:_** You need to install [bootstrap-sass] (https://github.com/twbs/bootstrap-sass) or a similar gem.
|
|
170
178
|
|
|
171
179
|
### **dummy app**
|
|
172
180
|
Type the following lines in your Terminal application to see a working example:
|
|
@@ -176,8 +184,9 @@ Type the following lines in your Terminal application to see a working example:
|
|
|
176
184
|
$ cd path-to-your-dir/localizer_rails
|
|
177
185
|
$ bundle install
|
|
178
186
|
$ rails s
|
|
179
|
-
Check out comments included in the code
|
|
180
|
-
|
|
187
|
+
Check out comments included in the code.
|
|
188
|
+
|
|
189
|
+
**_Note:_** to simulate the 'production' error handling remember to set `config.consider_all_requests_local` in `config/environments/development.rb` to `false`.
|
|
181
190
|
|
|
182
191
|
|
|
183
192
|
## Credits
|
|
@@ -186,6 +195,7 @@ Thanks to [Linuus](https://github.com/Linuus) for suggesting a viable way to pat
|
|
|
186
195
|
|
|
187
196
|
## Copyright
|
|
188
197
|
|
|
189
|
-
Copyright (c) 2015 by [Giovanni Bellono](mailto://giovanni.bellono@gmail.com)
|
|
198
|
+
Copyright (c) 2015 by [Giovanni Bellono](mailto://giovanni.bellono@gmail.com)
|
|
199
|
+
|
|
190
200
|
See [LICENSE](https://github.com/gbellono/localizer_rails/blob/master/MIT-LICENSE) for details.
|
|
191
201
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: localizer_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- giovanni bellono
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-08-
|
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -38,8 +38,8 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '1.7'
|
|
41
|
-
description:
|
|
42
|
-
|
|
41
|
+
description: Rails engine - sets I18n.locale through a best-match cascading search
|
|
42
|
+
and builds locale_menu (Bootstrap 3+ supported).
|
|
43
43
|
email:
|
|
44
44
|
- giovanni.bellono@gmail.com
|
|
45
45
|
executables: []
|
|
@@ -327,5 +327,6 @@ rubyforge_project:
|
|
|
327
327
|
rubygems_version: 2.4.5
|
|
328
328
|
signing_key:
|
|
329
329
|
specification_version: 4
|
|
330
|
-
summary: Rails engine -
|
|
330
|
+
summary: Rails engine - sets best-match I18n.locale and builds locale_menu (Bootstrap
|
|
331
|
+
3+ supported).
|
|
331
332
|
test_files: []
|