route_translator 3.2.3 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef0e4ac719821950ba3fea3f94d84bec1e09fb5d
4
- data.tar.gz: afca96b6d293ba9d1a7380f9b325241606b4c6ac
3
+ metadata.gz: 5d1c42a43f7afa3aa88301f402d64e0fbe60ebdf
4
+ data.tar.gz: c873187b33ca3327f482276c780b30e6999e246b
5
5
  SHA512:
6
- metadata.gz: 2a8dc0d13b2ab963e09537c38df4d29f8e13ff50ea6bf16f0d910500a3fa6a954e39946cb738b3d001ef4f6b3837658d2cc621a530fc03d26d810ac390348760
7
- data.tar.gz: b2375cb371910ed1563e334b02a67586aaa9b2ce4867478a171ec4f97fc389d4c36449a7eccde3e736021ccce6e1fdd8c3154f55b8e403a8c6725d3414a2323b
6
+ metadata.gz: 93d3bb5f6ff06529a3d986a90574925d353e4882c472ca3254c405cd4c3736ac9737ae7fb933066b1e7cecd720d6eca211908d311ee2d6e471b774a39a2296e5
7
+ data.tar.gz: aa225c315b5a2afe93ec29e3a80253d840a5191f9031575933ca67231985522b162d0709601a76c68c31959c7e411ea53571bae65b44acbe53f6eb6dc760cb2f
@@ -5,26 +5,38 @@ require 'action_dispatch'
5
5
 
6
6
  require File.expand_path('../route_translator/extensions', __FILE__)
7
7
  require File.expand_path('../route_translator/translator', __FILE__)
8
+ require File.expand_path('../route_translator/host', __FILE__)
8
9
 
9
10
  module RouteTranslator
11
+ extend RouteTranslator::Host
10
12
 
11
13
  TRANSLATABLE_SEGMENT = /^([-_a-zA-Z0-9]+)(\()?/.freeze
12
14
 
13
- Configuration = Struct.new(:force_locale, :hide_locale, :generate_unlocalized_routes, :locale_param_key, :generate_unnamed_unlocalized_routes)
15
+ Configuration = Struct.new(:force_locale, :hide_locale,
16
+ :generate_unlocalized_routes, :locale_param_key,
17
+ :generate_unnamed_unlocalized_routes,
18
+ :host_locales)
14
19
 
15
20
  def self.config(&block)
16
- @config ||= Configuration.new
17
- @config.force_locale ||= false
18
- @config.hide_locale ||= false
19
- @config.generate_unlocalized_routes ||= false
20
- @config.locale_param_key ||= :locale
21
+ @config ||= Configuration.new
22
+ @config.force_locale ||= false
23
+ @config.hide_locale ||= false
24
+ @config.generate_unlocalized_routes ||= false
25
+ @config.locale_param_key ||= :locale
21
26
  @config.generate_unnamed_unlocalized_routes ||= false
27
+ @config.host_locales ||= {}.with_indifferent_access
22
28
  yield @config if block
29
+ resolve_config_conflicts
23
30
  @config
24
31
  end
25
32
 
26
- def self.locale_param_key
27
- self.config.locale_param_key
33
+ def self.resolve_config_conflicts
34
+ if @config.host_locales.present?
35
+ @config.generate_unlocalized_routes = false
36
+ @config.generate_unnamed_unlocalized_routes = false
37
+ @config.force_locale = false
38
+ @config.hide_locale = false
39
+ @config.host_locales = @config.host_locales.with_indifferent_access
40
+ end
28
41
  end
29
-
30
42
  end
@@ -5,7 +5,29 @@ module ActionController
5
5
  around_filter :set_locale_from_url
6
6
 
7
7
  def set_locale_from_url(&block)
8
- I18n.with_locale params[RouteTranslator.locale_param_key], &block
8
+ with_host_locale { I18n.with_locale(params[RouteTranslator.locale_param_key], &block) }
9
9
  end
10
+
11
+ private
12
+
13
+ def with_host_locale(&block)
14
+ host_locale = RouteTranslator::Host.locale_from_host(request.host)
15
+ begin
16
+ if host_locale
17
+ original_default = I18n.default_locale
18
+ original_locale = I18n.locale
19
+
20
+ I18n.default_locale = host_locale
21
+ I18n.locale = host_locale
22
+ end
23
+
24
+ yield
25
+
26
+ ensure
27
+ I18n.default_locale = original_default if host_locale
28
+ I18n.locale = original_locale if host_locale
29
+ end
30
+ end
31
+
10
32
  end
11
33
  end
@@ -0,0 +1,29 @@
1
+ module RouteTranslator
2
+ module Host
3
+ def self.locale_from_host(host)
4
+ matches = RouteTranslator.config.host_locales.detect {|key, locale| host =~ regex_for(key) }
5
+ matched_locale = if matches && host_match = matches.first
6
+ locale = RouteTranslator.config.host_locales[host_match].to_sym
7
+ locale if I18n.available_locales.include?(locale)
8
+ end
9
+ matched_locale || I18n.default_locale
10
+ end
11
+
12
+ def self.regex_for(host_string)
13
+ escaped = Regexp.escape(host_string).gsub('\*', '.*?').gsub('\.', '\.?')
14
+ Regexp.new("^#{escaped}$", Regexp::IGNORECASE)
15
+ end
16
+
17
+ def native_locale?(locale)
18
+ !!locale.to_s.match(/native_/)
19
+ end
20
+
21
+ def native_locales
22
+ config.host_locales.values.map {|locale| :"native_#{locale}" }
23
+ end
24
+
25
+ def locale_param_key
26
+ self.config.locale_param_key
27
+ end
28
+ end
29
+ end
@@ -12,32 +12,35 @@ module RouteTranslator
12
12
  helper_list.push(new_helper_name.to_sym) unless helper_list.include?(new_helper_name.to_sym)
13
13
 
14
14
  helper_container.__send__(:define_method, new_helper_name) do |*args|
15
- locale_suffix = I18n.locale.to_s.underscore
16
- if respond_to?("#{old_name}_#{locale_suffix}_#{suffix}")
15
+ locale_suffix = I18n.locale.to_s.underscore
16
+ default_locale_suffix = I18n.default_locale.to_s.underscore
17
+ args_hash = args.select {|arg| arg.is_a?(Hash) }.first
18
+ args_locale_suffix = args_hash[:locale].to_s.underscore if args_hash.present?
19
+ if RouteTranslator.config.host_locales.present?
20
+ if args.blank? || args_locale_suffix == default_locale_suffix
21
+ __send__("#{old_name}_native_#{default_locale_suffix}_#{suffix}", *args)
22
+ elsif args_locale_suffix
23
+ __send__("#{old_name}_#{args_locale_suffix}_#{suffix}", *args)
24
+ end
25
+ elsif respond_to?("#{old_name}_#{locale_suffix}_#{suffix}")
17
26
  __send__("#{old_name}_#{locale_suffix}_#{suffix}", *args)
18
27
  else
19
28
  __send__("#{old_name}_#{I18n.default_locale.to_s.underscore}_#{suffix}", *args)
20
29
  end
21
30
  end
22
-
23
31
  end
24
32
  end
25
33
 
26
34
  def self.translations_for(app, conditions, requirements, defaults, route_name, anchor, route_set, &block)
27
35
  add_untranslated_helpers_to_controllers_and_views(route_name, route_set.named_routes.module, route_set.named_routes.helpers)
28
- # Make sure the default locale is translated in last place to avoid
29
- # problems with wildcards when default locale is omitted in paths. The
30
- # default routes will catch all paths like wildcard if it is translated first
31
- available_locales = I18n.available_locales.dup
32
- available_locales.delete I18n.default_locale
33
- available_locales.push I18n.default_locale
36
+
34
37
  available_locales.each do |locale|
35
38
  new_conditions = conditions.dup
36
39
  new_conditions[:path_info] = translate_path(conditions[:path_info], locale)
37
40
  if new_conditions[:required_defaults] && !new_conditions[:required_defaults].include?(RouteTranslator.locale_param_key)
38
41
  new_conditions[:required_defaults] << RouteTranslator.locale_param_key if new_conditions[:required_defaults]
39
42
  end
40
- new_defaults = defaults.merge(RouteTranslator.locale_param_key => locale.to_s)
43
+ new_defaults = defaults.merge(RouteTranslator.locale_param_key => locale.to_s.gsub('native_', ''))
41
44
  new_requirements = requirements.merge(RouteTranslator.locale_param_key => locale.to_s)
42
45
  new_route_name = translate_name(route_name, locale)
43
46
  new_route_name = nil if new_route_name && route_set.named_routes.routes[new_route_name.to_sym] #TODO: Investigate this :(
@@ -50,20 +53,24 @@ module RouteTranslator
50
53
  end
51
54
  end
52
55
 
56
+ private
57
+ def self.available_locales
58
+ available_locales = I18n.available_locales.dup
59
+ available_locales.push *RouteTranslator.native_locales if RouteTranslator.native_locales.present?
60
+ # Make sure the default locale is translated in last place to avoid
61
+ # problems with wildcards when default locale is omitted in paths. The
62
+ # default routes will catch all paths like wildcard if it is translated first.
63
+ available_locales.push(available_locales.delete(I18n.default_locale))
64
+ end
65
+
53
66
  # Translates a path and adds the locale prefix.
54
67
  def self.translate_path(path, locale)
55
68
  new_path = path.dup
56
69
  final_optional_segments = new_path.slice!(/(\([^\/]+\))$/)
57
70
  translated_segments = new_path.split(/\/|\./).map{ |seg| translate_path_segment(seg, locale) }.select{ |seg| !seg.blank? }
58
71
 
59
- # if not hiding locale then
60
- # add locale prefix if it's not the default locale,
61
- # or forcing locale to all routes,
62
- # or already generating actual unlocalized routes
63
- if !RouteTranslator.config.hide_locale && (!default_locale?(locale) || RouteTranslator.config.force_locale || RouteTranslator.config.generate_unlocalized_routes || RouteTranslator.config.generate_unnamed_unlocalized_routes)
64
- if !locale_param_present?(new_path)
65
- translated_segments.unshift locale.to_s.downcase
66
- end
72
+ if display_locale?(locale) && !locale_param_present?(new_path)
73
+ translated_segments.unshift(locale.to_s.downcase)
67
74
  end
68
75
 
69
76
  joined_segments = translated_segments.inject do |memo, segment|
@@ -74,6 +81,14 @@ module RouteTranslator
74
81
  "/#{joined_segments}#{final_optional_segments}".gsub(/\/\(\//, '(/')
75
82
  end
76
83
 
84
+ def self.display_locale?(locale)
85
+ !RouteTranslator.config.hide_locale && !RouteTranslator.native_locale?(locale) &&
86
+ (!default_locale?(locale) ||
87
+ RouteTranslator.config.force_locale ||
88
+ RouteTranslator.config.generate_unlocalized_routes ||
89
+ RouteTranslator.config.generate_unnamed_unlocalized_routes)
90
+ end
91
+
77
92
  def self.translate_name(n, locale)
78
93
  "#{n}_#{locale.to_s.underscore}" if n.present?
79
94
  end
@@ -87,7 +102,7 @@ module RouteTranslator
87
102
  # "people" will be translated, if there is no translation, the path
88
103
  # segment is blank, begins with a ":" (param key) or "*" (wildcard),
89
104
  # the segment is returned untouched
90
- def self.translate_path_segment segment, locale
105
+ def self.translate_path_segment(segment, locale)
91
106
  return segment if segment.blank? or segment.starts_with?(":") or segment.starts_with?("(") or segment.starts_with?("*")
92
107
 
93
108
  appended_part = segment.slice!(/(\()$/)
@@ -97,7 +112,8 @@ module RouteTranslator
97
112
  end
98
113
 
99
114
  def self.translate_string(str, locale)
100
- res = I18n.translate(str, :scope => :routes, :locale => locale, :default => str)
115
+ locale = "#{locale}".gsub('native_', '')
116
+ res = I18n.translate(str, :scope => :routes, :locale => locale, :default => str)
101
117
  URI.escape(res)
102
118
  end
103
119
 
@@ -1,3 +1,3 @@
1
1
  module RouteTranslator
2
- VERSION = '3.2.3'
2
+ VERSION = '3.2.4'
3
3
  end
@@ -0,0 +1,4 @@
1
+ RouteTranslator.config do |config|
2
+ config.host_locales['*.es'] = 'es'
3
+ config.host_locales['ru.*.com'] = 'ru'
4
+ end
@@ -3,7 +3,10 @@
3
3
 
4
4
  en:
5
5
  routes:
6
- dummy: 'dummy'
6
+ dummy: dummy
7
7
  es:
8
8
  routes:
9
- dummy: 'dummy'
9
+ dummy: dummy
10
+ ru:
11
+ routes:
12
+ dummy: манекен
@@ -2,5 +2,8 @@ Dummy::Application.routes.draw do
2
2
  localized do
3
3
  get 'dummy', :to => 'dummy#dummy'
4
4
  end
5
+
6
+ root :to => 'dummy#dummy'
7
+
5
8
  mount DummyMountedApp.new => '/dummy_mounted_app'
6
9
  end
data/test/host_test.rb ADDED
@@ -0,0 +1,99 @@
1
+ #encoding: utf-8
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
3
+
4
+ class TestHostsFromLocale < MiniTest::Unit::TestCase
5
+ include RouteTranslator::TestHelper
6
+ def setup
7
+ I18n.backend = I18n::Backend::Simple.new
8
+ I18n.load_path = [ File.expand_path('../locales/routes.yml', __FILE__) ]
9
+ I18n.reload!
10
+
11
+ config_host_locales({
12
+ '*.something.es' => :es,
13
+ '*.ru.subdomain.domain.*' => :ru,
14
+ 'russia.something.net' => :ru,
15
+ '*.com' => :en
16
+ })
17
+ end
18
+
19
+ def teardown
20
+ config_host_locales({})
21
+ I18n.default_locale = :en
22
+ end
23
+
24
+ def test_wildcard_at_beginning_matches
25
+ assert_equal :en, RouteTranslator::Host.locale_from_host('something.com')
26
+ end
27
+
28
+ def test_wildcard_at_beginning_with_subdomain_matches
29
+ assert_equal :en, RouteTranslator::Host.locale_from_host('www.domain.com')
30
+ end
31
+
32
+ def test_wildcard_at_beginning_without_subdomain_matches
33
+ assert_equal :en, RouteTranslator::Host.locale_from_host('domain.com')
34
+ end
35
+
36
+ def test_wildcard_at_end_with_subdomain_matches
37
+ assert_equal :es, RouteTranslator::Host.locale_from_host('www.something.es')
38
+ end
39
+
40
+ def test_wildcard_at_end_without_subdomain_matches
41
+ assert_equal :es, RouteTranslator::Host.locale_from_host('something.es')
42
+ end
43
+
44
+ def test_no_wildcard_matches
45
+ assert_equal :ru, RouteTranslator::Host.locale_from_host('russia.something.net')
46
+ end
47
+
48
+ def test_multiple_wildcard_matches
49
+ assert_equal :ru, RouteTranslator::Host.locale_from_host('www.ru.subdomain.domain.biz')
50
+ end
51
+
52
+ def test_case_is_ignored
53
+ assert_equal :es, RouteTranslator::Host.locale_from_host('www.SoMeThInG.ES')
54
+ end
55
+
56
+ def test_precedence_if_more_than_one_match
57
+ config_host_locales({ 'russia.*' => :ru, '*.com' => :en })
58
+ assert_equal :ru, RouteTranslator::Host.locale_from_host('russia.com')
59
+
60
+ config_host_locales({ '*.com' => :en, 'russia.*' => :ru })
61
+ assert_equal :en, RouteTranslator::Host.locale_from_host('russia.com')
62
+ end
63
+
64
+ def test_default_locale_if_no_matches
65
+ assert_equal I18n.default_locale, RouteTranslator::Host.locale_from_host('nomatches.co.uk')
66
+ end
67
+
68
+ def test_readme_examples_work
69
+ config_host_locales(
70
+ {
71
+ '*.es' => :es, # matches ['domain.es', 'subdomain.domain.es', 'www.long.string.of.subdomains.es'] etc.
72
+ 'ru.wikipedia.*' => :ru, # matches ['ru.wikipedia.org', 'ru.wikipedia.net', 'ru.wikipedia.com'] etc.
73
+ '*.subdomain.domain.*' => :ru, # matches ['subdomain.domain.org', 'www.subdomain.domain.net'] etc.
74
+ 'news.bbc.co.uk' => :en, # matches ['news.bbc.co.uk'] only
75
+ }
76
+ )
77
+
78
+ examples_1 = ['domain.es', 'subdomain.domain.es', 'www.long.string.of.subdomains.es']
79
+ examples_2 = ['ru.wikipedia.org', 'ru.wikipedia.net', 'ru.wikipedia.com']
80
+ examples_3 = ['subdomain.domain.org', 'www.subdomain.domain.net']
81
+ examples_4 = ['news.bbc.co.uk']
82
+
83
+ examples_1.each do |domain|
84
+ assert_equal :es, RouteTranslator::Host.locale_from_host(domain)
85
+ end
86
+
87
+ examples_2.each do |domain|
88
+ assert_equal :ru, RouteTranslator::Host.locale_from_host(domain)
89
+ end
90
+
91
+ examples_3.each do |domain|
92
+ assert_equal :ru, RouteTranslator::Host.locale_from_host(domain)
93
+ end
94
+
95
+ examples_4.each do |domain|
96
+ assert_equal :en, RouteTranslator::Host.locale_from_host(domain)
97
+ end
98
+ end
99
+ end
@@ -1,5 +1,6 @@
1
+ #encoding: utf-8
1
2
  require File.expand_path('../test_helper', __FILE__)
2
- require 'route_translator'
3
+
3
4
  require File.expand_path('../dummy/dummy_mounted_app', __FILE__)
4
5
  require File.expand_path('../dummy/config/environment', __FILE__)
5
6
 
@@ -20,13 +21,50 @@ class IntegrationTest < class_to_inherit
20
21
  assert_equal "Good", @response.body
21
22
  assert_response :success
22
23
  end
23
-
24
+
24
25
  def test_i18n_locale_thread_safe
25
26
  config_default_locale_settings 'en'
26
-
27
27
  get '/es/dummy'
28
28
  assert_equal 'es', @response.body
29
-
29
+
30
30
  assert_equal :en, I18n.locale
31
31
  end
32
+
33
+ def test_host_locales
34
+ ## root of es com
35
+ host! 'www.testapp.es'
36
+ get '/'
37
+ assert_equal 'es', @response.body
38
+ assert_response :success
39
+
40
+ ## native es route on es com
41
+ host! 'www.testapp.es'
42
+ get '/dummy'
43
+ assert_equal 'es', @response.body
44
+ assert_response :success
45
+
46
+ ## ru route on es com
47
+ host! 'www.testapp.es'
48
+ get URI.escape('/ru/манекен')
49
+ assert_equal 'ru', @response.body
50
+ assert_response :success
51
+
52
+ ## root of ru com
53
+ host! 'ru.testapp.com'
54
+ get '/'
55
+ assert_equal 'ru', @response.body
56
+ assert_response :success
57
+
58
+ ## native ru route on ru com
59
+ host! 'ru.testapp.com'
60
+ get URI.escape('/манекен')
61
+ assert_equal 'ru', @response.body
62
+ assert_response :success
63
+
64
+ ## es route on ru com
65
+ host! 'ru.testapp.com'
66
+ get '/es/dummy'
67
+ assert_equal 'es', @response.body
68
+ assert_response :success
69
+ end
32
70
  end
data/test/routing_test.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  #encoding: utf-8
2
2
  require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
3
- require 'route_translator'
4
3
 
5
4
  class PeopleController < ActionController::Base; end
6
5
  class ProductsController < ActionController::Base; end
@@ -22,6 +21,7 @@ class TranslateRoutesTest < ActionController::TestCase
22
21
  config_generate_unlocalized_routes false
23
22
  config_default_locale_settings("en")
24
23
  config_generate_unnamed_unlocalized_routes false
24
+ config_host_locales({})
25
25
  end
26
26
 
27
27
  def test_unnamed_root_route
@@ -95,7 +95,6 @@ class TranslateRoutesTest < ActionController::TestCase
95
95
  end
96
96
  end
97
97
 
98
-
99
98
  assert_routing '/en/products', :controller => 'products', :action => 'index', :locale => 'en'
100
99
  assert_routing '/productos', :controller => 'products', :action => 'index', :locale => 'es'
101
100
  assert_routing({:path => '/productos/1', :method => "GET"}, {:controller => 'products', :action => 'show', :id => '1', :locale => 'es'})
@@ -431,7 +430,7 @@ class TranslateRoutesTest < ActionController::TestCase
431
430
  # The dynamic route maps to the current locale
432
431
  assert_equal '/es/gente', @routes.url_helpers.people_path
433
432
  end
434
-
433
+
435
434
  def test_blank_localized_routes
436
435
  I18n.locale = 'en'
437
436
  config_default_locale_settings 'en'
@@ -441,11 +440,11 @@ class TranslateRoutesTest < ActionController::TestCase
441
440
  get 'people/blank', :to => 'people#index', :as => 'people'
442
441
  end
443
442
  end
444
-
443
+
445
444
  I18n.locale = 'en'
446
445
  assert_routing '/people/blank', :controller => 'people', :action => 'index', :locale => 'en'
447
446
  assert_equal '/people/blank', @routes.url_helpers.people_en_path
448
-
447
+
449
448
  I18n.locale = 'es'
450
449
  assert_routing '/es/gente', :controller => 'people', :action => 'index', :locale => 'es'
451
450
  assert_equal '/es/gente', @routes.url_helpers.people_es_path
@@ -481,6 +480,25 @@ class TranslateRoutesTest < ActionController::TestCase
481
480
  assert_routing '/people', :controller => 'people', :action => 'index', :locale => 'en'
482
481
  end
483
482
 
483
+ def test_host_locales
484
+ config_host_locales({ '*.es' => 'es', '*.com' => 'en' })
485
+
486
+ draw_routes do
487
+ localized do
488
+ resources :people
489
+ end
490
+ root :to => 'people#index'
491
+ end
492
+
493
+ assert_recognizes({:controller => 'people', :action => 'index', :locale => 'es'}, { :path => 'http://testapp.es/gente', :method => :get })
494
+ assert_recognizes({:controller => 'people', :action => 'index', :locale => 'es'}, { :path => 'http://testapp.es/es/gente', :method => :get })
495
+ assert_recognizes({:controller => 'people', :action => 'index'}, { :path => 'http://testapp.es/', :method => :get })
496
+
497
+ assert_recognizes({:controller => 'people', :action => 'index', :locale => 'en'}, { :path => 'http://testapp.com/people', :method => :get })
498
+ assert_recognizes({:controller => 'people', :action => 'index'}, { :path => 'http://testapp.com/', :method => :get })
499
+ end
500
+
501
+
484
502
  def test_action_controller_gets_locale_setter
485
503
  ActionController::Base.instance_methods.include?('set_locale_from_url')
486
504
  end
@@ -504,7 +522,8 @@ class ProductsControllerTest < ActionController::TestCase
504
522
  I18n.load_path = [ File.expand_path('../locales/routes.yml', __FILE__) ]
505
523
  I18n.reload!
506
524
 
507
- config_default_locale_settings 'en'
525
+ config_default_locale_settings 'es'
526
+ config_host_locales({:es => 'es'})
508
527
 
509
528
  draw_routes do
510
529
  localized do
@@ -519,12 +538,12 @@ class ProductsControllerTest < ActionController::TestCase
519
538
  config_generate_unlocalized_routes false
520
539
  config_default_locale_settings("en")
521
540
  config_generate_unnamed_unlocalized_routes false
541
+ config_host_locales({})
522
542
  end
523
543
 
524
544
  def test_url_helpers_are_included
525
-
526
545
  #doing it this way because assert_nothing_raised doesn't work on all rails versions
527
- %w(product_path product_url product_es_path product_es_url).each do |method|
546
+ %w(product_path product_url product_es_path product_es_url product_native_es_path product_native_es_url).each do |method|
528
547
  begin
529
548
  send(method)
530
549
  rescue Exception => e
@@ -533,4 +552,3 @@ class ProductsControllerTest < ActionController::TestCase
533
552
  end
534
553
  end
535
554
  end
536
-
data/test/test_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ #encoding: utf-8
2
+
1
3
  require 'test/unit'
2
4
  require 'minitest/mock'
3
5
  require 'minitest/unit'
@@ -57,6 +59,10 @@ module RouteTranslator
57
59
  RouteTranslator.config.generate_unnamed_unlocalized_routes = boolean
58
60
  end
59
61
 
62
+ def config_host_locales(hash)
63
+ RouteTranslator.config.host_locales = hash.with_indifferent_access
64
+ end
65
+
60
66
  def path_string(route)
61
67
  path = route.respond_to?(:path) ? route.path : route.to_s.split(' ')[1]
62
68
  path.respond_to?(:spec) ? path.spec.to_s : path.to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.3
4
+ version: 3.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raul Murciano
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-25 00:00:00.000000000 Z
12
+ date: 2014-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -65,6 +65,7 @@ files:
65
65
  - lib/route_translator/extensions/action_controller.rb
66
66
  - lib/route_translator/extensions/mapper.rb
67
67
  - lib/route_translator/extensions/route_set.rb
68
+ - lib/route_translator/host.rb
68
69
  - lib/route_translator/translator.rb
69
70
  - lib/route_translator/version.rb
70
71
  - test/dummy/app/controllers/dummy_controller.rb
@@ -72,12 +73,14 @@ files:
72
73
  - test/dummy/config/application.rb
73
74
  - test/dummy/config/boot.rb
74
75
  - test/dummy/config/environment.rb
76
+ - test/dummy/config/initializers/route_translator.rb
75
77
  - test/dummy/config/initializers/secret_token.rb
76
78
  - test/dummy/config/initializers/session_store.rb
77
79
  - test/dummy/config/locales/all.yml
78
80
  - test/dummy/config/routes.rb
79
81
  - test/dummy/dummy_mounted_app.rb
80
82
  - test/dummy/script/rails
83
+ - test/host_test.rb
81
84
  - test/integration_test.rb
82
85
  - test/locales/routes.yml
83
86
  - test/routing_test.rb
@@ -111,12 +114,14 @@ test_files:
111
114
  - test/dummy/config/application.rb
112
115
  - test/dummy/config/boot.rb
113
116
  - test/dummy/config/environment.rb
117
+ - test/dummy/config/initializers/route_translator.rb
114
118
  - test/dummy/config/initializers/secret_token.rb
115
119
  - test/dummy/config/initializers/session_store.rb
116
120
  - test/dummy/config/locales/all.yml
117
121
  - test/dummy/config/routes.rb
118
122
  - test/dummy/dummy_mounted_app.rb
119
123
  - test/dummy/script/rails
124
+ - test/host_test.rb
120
125
  - test/integration_test.rb
121
126
  - test/locales/routes.yml
122
127
  - test/routing_test.rb