rails-translate-routes 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -32
- data/README.rdoc +24 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/controller_test_helper.rb +2 -2
- data/lib/rails-translate-routes.rb +40 -2
- data/rails-translate-routes.gemspec +5 -5
- data/test/helper.rb +0 -1
- metadata +15 -15
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
actionmailer (3.1.3)
|
5
|
-
actionpack (= 3.1.3)
|
6
|
-
mail (~> 2.3.0)
|
7
4
|
actionpack (3.1.3)
|
8
5
|
activemodel (= 3.1.3)
|
9
6
|
activesupport (= 3.1.3)
|
@@ -19,17 +16,8 @@ GEM
|
|
19
16
|
activesupport (= 3.1.3)
|
20
17
|
builder (~> 3.0.0)
|
21
18
|
i18n (~> 0.6)
|
22
|
-
activerecord (3.1.3)
|
23
|
-
activemodel (= 3.1.3)
|
24
|
-
activesupport (= 3.1.3)
|
25
|
-
arel (~> 2.2.1)
|
26
|
-
tzinfo (~> 0.3.29)
|
27
|
-
activeresource (3.1.3)
|
28
|
-
activemodel (= 3.1.3)
|
29
|
-
activesupport (= 3.1.3)
|
30
19
|
activesupport (3.1.3)
|
31
20
|
multi_json (~> 1.0)
|
32
|
-
arel (2.2.1)
|
33
21
|
builder (3.0.0)
|
34
22
|
erubis (2.7.0)
|
35
23
|
git (1.2.5)
|
@@ -40,14 +28,8 @@ GEM
|
|
40
28
|
git (>= 1.2.5)
|
41
29
|
rake
|
42
30
|
json (1.6.5)
|
43
|
-
mail (2.3.0)
|
44
|
-
i18n (>= 0.4.0)
|
45
|
-
mime-types (~> 1.16)
|
46
|
-
treetop (~> 1.4.8)
|
47
|
-
mime-types (1.17.2)
|
48
31
|
minitest (2.10.1)
|
49
32
|
multi_json (1.0.4)
|
50
|
-
polyglot (0.3.3)
|
51
33
|
rack (1.3.6)
|
52
34
|
rack-cache (1.1)
|
53
35
|
rack (>= 0.4)
|
@@ -57,14 +39,6 @@ GEM
|
|
57
39
|
rack
|
58
40
|
rack-test (0.6.1)
|
59
41
|
rack (>= 1.0)
|
60
|
-
rails (3.1.3)
|
61
|
-
actionmailer (= 3.1.3)
|
62
|
-
actionpack (= 3.1.3)
|
63
|
-
activerecord (= 3.1.3)
|
64
|
-
activeresource (= 3.1.3)
|
65
|
-
activesupport (= 3.1.3)
|
66
|
-
bundler (~> 1.0)
|
67
|
-
railties (= 3.1.3)
|
68
42
|
railties (3.1.3)
|
69
43
|
actionpack (= 3.1.3)
|
70
44
|
activesupport (= 3.1.3)
|
@@ -79,13 +53,9 @@ GEM
|
|
79
53
|
hike (~> 1.2)
|
80
54
|
rack (~> 1.0)
|
81
55
|
tilt (~> 1.1, != 1.3.0)
|
82
|
-
sqlite3 (1.3.
|
56
|
+
sqlite3 (1.3.6)
|
83
57
|
thor (0.14.6)
|
84
58
|
tilt (1.3.3)
|
85
|
-
treetop (1.4.10)
|
86
|
-
polyglot
|
87
|
-
polyglot (>= 0.3.1)
|
88
|
-
tzinfo (0.3.31)
|
89
59
|
|
90
60
|
PLATFORMS
|
91
61
|
ruby
|
@@ -94,5 +64,5 @@ DEPENDENCIES
|
|
94
64
|
bundler (~> 1.0.0)
|
95
65
|
jeweler (~> 1.6.4)
|
96
66
|
minitest
|
97
|
-
|
67
|
+
railties (>= 3.1)
|
98
68
|
sqlite3
|
data/README.rdoc
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
= rails-translate-routes
|
2
2
|
|
3
|
+
Important change from version 0.0.5 (Feb 2012) to 0.1.0 (June 2012): if you're updating from an earlier version take into account that now translations defined in routes.yml are namespaced to avoid conflicts with other translations from app (thanks to cawel for the patch). To upgrade you just have to add the namespace 'routes' to your routes.yml (see example in the below docs).
|
4
|
+
|
3
5
|
Rails >=3.1 routes translations based on Raul's translate_routes (https://github.com/raul/translate_routes).
|
4
6
|
|
5
7
|
It's currently a stripped down version of the forked gem, adding some bugfixes for rails 3.1 and features I needed for my project. See doc below to see what it can do.
|
@@ -41,11 +43,13 @@ We want to have them in two languages english and spanish, to accomplish this wi
|
|
41
43
|
2) Now we can write translations on a standard YAML file (e.g: in config/locales/routes.yml), including all the locales and their translations:
|
42
44
|
|
43
45
|
en:
|
44
|
-
|
46
|
+
routes:
|
47
|
+
# you can leave empty locales, for example the default one
|
45
48
|
es:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
routes:
|
50
|
+
products: productos
|
51
|
+
contact: contacto
|
52
|
+
new: crear
|
49
53
|
|
50
54
|
3) Include this filter in your ApplicationController:
|
51
55
|
|
@@ -151,6 +155,20 @@ You can specify the following option:
|
|
151
155
|
|
152
156
|
Note that the 'no_prefixes' option will override the 'prefix_on_default_locale' option.
|
153
157
|
|
158
|
+
<b>Keep untranslated routes</b>
|
159
|
+
|
160
|
+
In case you want to keep access to untranslated routes, for easier api or ajax integration for example. Resulting in this structure:
|
161
|
+
|
162
|
+
/en/available-products
|
163
|
+
/fr/produits-disponibles/
|
164
|
+
/products/
|
165
|
+
|
166
|
+
You can specify the following option:
|
167
|
+
|
168
|
+
ActionDispatch::Routing::Translator.translate_from_file('config/locales/routes.yml', { :keep_untranslated_routes => true })
|
169
|
+
|
170
|
+
This option is not meant to be used with :no_prefixes.
|
171
|
+
|
154
172
|
<b>Namespaced backends</b>
|
155
173
|
|
156
174
|
I usually build app backend in namespaced controllers, routes, ... using translated routes will result in duplicated routes or prefixed ones. In most cases you won't want to have the backend in several languages, you can set 'routes.rb' this way:
|
@@ -194,6 +212,8 @@ Thanks to:
|
|
194
212
|
* Johan Gyllenspetz (https://github.com/gyllen)
|
195
213
|
* Nico Ritsche (https://github.com/ncri)
|
196
214
|
* Jean-Loup Fenaux (https://github.com/jlfenaux)
|
215
|
+
* Cyril Mouge (https://github.com/shingara)
|
216
|
+
* Nicolas Arbogast (https://github.com/NicoArbogast)
|
197
217
|
|
198
218
|
* Main development of forked gem:
|
199
219
|
* Raul Murciano (http://github.com/raul)
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# This monkey patch injects the locale in the controller's params
|
1
|
+
# This monkey patch injects the locale in the controller's params
|
2
2
|
# Reason: ActionController::TestCase doesn't support "default_url_options"
|
3
3
|
#
|
4
4
|
# Example: when the request you are testing needs the locale, e.g.
|
@@ -11,7 +11,7 @@ class ActionController::TestCase
|
|
11
11
|
|
12
12
|
module Behavior
|
13
13
|
def process_with_default_locale(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
|
14
|
-
parameters = { :locale => I18n.default_locale }.merge(parameters || {} )
|
14
|
+
parameters = { :locale => I18n.default_locale.to_s }.merge(parameters || {} )
|
15
15
|
process_without_default_locale(action, parameters, session, flash, http_method)
|
16
16
|
end
|
17
17
|
alias_method_chain :process, :default_locale
|
@@ -52,6 +52,21 @@ class RailsTranslateRoutes
|
|
52
52
|
@no_prefixes = no_prefixes
|
53
53
|
end
|
54
54
|
|
55
|
+
# option allowing to keep untranslated routes
|
56
|
+
# *Ex:
|
57
|
+
# *resources :users
|
58
|
+
# *translated routes
|
59
|
+
# en/members
|
60
|
+
# fr/membres
|
61
|
+
# /users
|
62
|
+
def keep_untranslated_routes
|
63
|
+
@keep_untranslated_routes ||= false
|
64
|
+
end
|
65
|
+
|
66
|
+
def keep_untranslated_routes= keep_untranslated_routes
|
67
|
+
@keep_untranslated_routes = keep_untranslated_routes
|
68
|
+
end
|
69
|
+
|
55
70
|
class << self
|
56
71
|
# Default locale suffix generator
|
57
72
|
def locale_suffix locale
|
@@ -117,7 +132,7 @@ class RailsTranslateRoutes
|
|
117
132
|
def add_dictionary_from_file file_path
|
118
133
|
yaml = YAML.load_file(file_path)
|
119
134
|
yaml.each_pair do |locale, translations|
|
120
|
-
merge_translations locale, translations
|
135
|
+
merge_translations locale, translations['routes']
|
121
136
|
end
|
122
137
|
set_available_locales_from_dictionary
|
123
138
|
end
|
@@ -244,9 +259,14 @@ class RailsTranslateRoutes
|
|
244
259
|
|
245
260
|
# Generate translations for a single route for all available locales
|
246
261
|
def translations_for route
|
262
|
+
translated_routes = []
|
247
263
|
available_locales.map do |locale|
|
248
|
-
translate_route
|
264
|
+
translated_routes << translate_route(route, locale)
|
249
265
|
end
|
266
|
+
|
267
|
+
# add untranslated_route without url helper if we want to keep untranslated routes
|
268
|
+
translated_routes << untranslated_route(route) if @keep_untranslated_routes
|
269
|
+
translated_routes
|
250
270
|
end
|
251
271
|
|
252
272
|
# Generate translation for a single route for one locale
|
@@ -268,6 +288,23 @@ class RailsTranslateRoutes
|
|
268
288
|
[route.app, conditions, requirements, defaults, new_name]
|
269
289
|
end
|
270
290
|
|
291
|
+
# Re-generate untranslated routes (original routes) with name set to nil (which prevents conflict with default untranslated_urls)
|
292
|
+
def untranslated_route route
|
293
|
+
conditions = {}
|
294
|
+
if Rails.version >= '3.2'
|
295
|
+
conditions[:path_info] = route.path.spec.to_s
|
296
|
+
conditions[:request_method] = parse_request_methods route.verb if route.verb != //
|
297
|
+
conditions[:subdomain] = route.constraints[:subdomain] if route.constraints
|
298
|
+
else
|
299
|
+
conditions[:path_info] = route.path
|
300
|
+
conditions[:request_method] = parse_request_methods route.conditions[:request_method] if route.conditions.has_key? :request_method
|
301
|
+
end
|
302
|
+
requirements = route.requirements
|
303
|
+
defaults = route.defaults
|
304
|
+
|
305
|
+
[route.app, conditions, requirements, defaults]
|
306
|
+
end
|
307
|
+
|
271
308
|
# Add prefix for all non-default locales
|
272
309
|
def add_prefix? locale
|
273
310
|
if @no_prefixes
|
@@ -345,6 +382,7 @@ module ActionDispatch
|
|
345
382
|
r = RailsTranslateRoutes.init_from_file(File.join(Rails.root, file_path))
|
346
383
|
r.prefix_on_default_locale = true if options && options[:prefix_on_default_locale] == true
|
347
384
|
r.no_prefixes = true if options && options[:no_prefixes] == true
|
385
|
+
r.keep_untranslated_routes = true if options && options[:keep_untranslated_routes] == true
|
348
386
|
r.translate Rails.application.routes
|
349
387
|
end
|
350
388
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rails-translate-routes"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Francesc Pla"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-06-20"
|
13
13
|
s.description = "Simple gem to translate routes in Rails 3.x based on translate_routes"
|
14
14
|
s.email = "francesc@francesc.net"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,20 +40,20 @@ Gem::Specification.new do |s|
|
|
40
40
|
s.specification_version = 3
|
41
41
|
|
42
42
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
-
s.add_runtime_dependency(%q<
|
43
|
+
s.add_runtime_dependency(%q<railties>, [">= 3.1"])
|
44
44
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
45
45
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
46
46
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
47
47
|
s.add_development_dependency(%q<minitest>, [">= 0"])
|
48
48
|
else
|
49
|
-
s.add_dependency(%q<
|
49
|
+
s.add_dependency(%q<railties>, [">= 3.1"])
|
50
50
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
51
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
52
52
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
53
53
|
s.add_dependency(%q<minitest>, [">= 0"])
|
54
54
|
end
|
55
55
|
else
|
56
|
-
s.add_dependency(%q<
|
56
|
+
s.add_dependency(%q<railties>, [">= 3.1"])
|
57
57
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
58
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
59
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-translate-routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: railties
|
16
|
+
requirement: &70352912284960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
21
|
+
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70352912284960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70352912284200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70352912284200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70352912283440 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70352912283440
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &70352912282700 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70352912282700
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: minitest
|
60
|
-
requirement: &
|
60
|
+
requirement: &70352912281900 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70352912281900
|
69
69
|
description: Simple gem to translate routes in Rails 3.x based on translate_routes
|
70
70
|
email: francesc@francesc.net
|
71
71
|
executables: []
|
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash:
|
104
|
+
hash: 2092619227610633287
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|