rails-localization 0.2.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -3
- data/Gemfile +20 -13
- data/Gemfile.lock +113 -122
- data/README.rdoc +62 -7
- data/VERSION +1 -1
- data/lib/rails-localization.rb +26 -2
- data/lib/rails-localization/controller.rb +22 -0
- data/lib/rails-localization/engine.rb +6 -0
- data/lib/rails-localization/i18n.rb +9 -0
- data/lib/rails-localization/route_set.rb +12 -0
- data/lib/rails-localization/router.rb +15 -0
- data/lib/rails-localization/url_options.rb +34 -0
- data/rails-localization.gemspec +25 -44
- data/test/i18n_integration_test.rb +28 -0
- data/test/mapper_integration_test.rb +45 -0
- data/test/rails-localization_test.rb +47 -47
- data/test/support/capybara_helper.rb +9 -5
- data/test/test_app/Gemfile +4 -0
- data/test/test_app/Gemfile.lock +93 -0
- data/test/test_app/Rakefile +7 -0
- data/test/test_app/app/controllers/users_controller.rb +1 -1
- data/test/test_app/config/application.rb +1 -4
- data/test/test_app/config/environments/development.rb +3 -3
- data/test/test_app/config/environments/production.rb +2 -0
- data/test/test_app/config/environments/test.rb +2 -3
- data/test/test_app/config/routes.rb +10 -7
- data/test/test_helper.rb +3 -8
- data/test/urls_overwriting_test.rb +9 -17
- metadata +34 -130
- data/.rvmrc +0 -1
- data/lib/rails-localization/middleware.rb +0 -8
- data/lib/rails-localization/routes_set_ext.rb +0 -61
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use --create 1.9.2@rails-localization
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Localization
|
5
|
-
module RoutesSetExt
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
def url_for_with_locale(options = {})
|
10
|
-
finalize!
|
11
|
-
options = (options || {}).reverse_merge!(default_url_options)
|
12
|
-
|
13
|
-
handle_positional_args(options)
|
14
|
-
|
15
|
-
user, password = extract_authentication(options)
|
16
|
-
path_segments = options.delete(:_path_segments)
|
17
|
-
script_name = options.delete(:script_name)
|
18
|
-
|
19
|
-
path = options[:host].blank? ? '' : get_locale_segment(options).to_s
|
20
|
-
path << (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s
|
21
|
-
|
22
|
-
path_options = options.except(*self.class::RESERVED_OPTIONS)
|
23
|
-
path_options = yield(path_options) if block_given?
|
24
|
-
|
25
|
-
path_addition, params = generate(path_options, path_segments || {})
|
26
|
-
path << path_addition
|
27
|
-
params.merge!(options[:params] || {})
|
28
|
-
|
29
|
-
ActionDispatch::Http::URL.url_for(options.merge!({
|
30
|
-
:path => path,
|
31
|
-
:params => params,
|
32
|
-
:user => user,
|
33
|
-
:password => password
|
34
|
-
}))
|
35
|
-
end
|
36
|
-
alias_method :url_for, :url_for_with_locale
|
37
|
-
|
38
|
-
protected
|
39
|
-
|
40
|
-
def get_locale_segment parameters
|
41
|
-
parameters ||= {}
|
42
|
-
locale = parameters.delete(:locale)
|
43
|
-
return if locale == false
|
44
|
-
locale ||= ::I18n.locale
|
45
|
-
|
46
|
-
if locale.to_sym != ::I18n.default_locale
|
47
|
-
raise Rails::Localization::UnknownLocaleError.new("Not supported locale: #{locale}. If this locale should be \
|
48
|
-
supported, add it to Middelware (#{Rails.root.join('config','application.rb')})") unless Rails::Localization::Middleware.languages.include?(locale.to_s)
|
49
|
-
|
50
|
-
"/#{locale}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
ActiveSupport.on_load(:before_initialize) do
|
60
|
-
ActionDispatch::Routing::RouteSet.send :include, Rails::Localization::RoutesSetExt
|
61
|
-
end
|