padrino-localization 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +127 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/lib/padrino-localization.rb +61 -0
- data/lib/padrino-localization/middleware.rb +88 -0
- data/padrino-localization.gemspec +91 -0
- data/test/middleware_test.rb +35 -0
- data/test/padrino-localization_test.rb +57 -0
- data/test/test_app/.components +7 -0
- data/test/test_app/app/app.rb +8 -0
- data/test/test_app/app/controllers/main.rb +9 -0
- data/test/test_app/app/helpers/application_helper.rb +2 -0
- data/test/test_app/config.ru +2 -0
- data/test/test_app/config/apps.rb +27 -0
- data/test/test_app/config/boot.rb +24 -0
- data/test/test_app/public/favicon.ico +0 -0
- data/test/test_helper.rb +21 -0
- metadata +193 -0
data/.document
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.2@padrino-localization
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "padrino"
|
4
|
+
|
5
|
+
group :development, :test do
|
6
|
+
gem "test-spec"
|
7
|
+
gem "yard", "~> 0.6.0"
|
8
|
+
gem "bundler", "~> 1.0.0"
|
9
|
+
gem "jeweler", "~> 1.6.4"
|
10
|
+
|
11
|
+
gem "debugger", "~> 1.1.3", :platform => :ruby_19
|
12
|
+
gem "simplecov", "~> 0.6.4", :platform => :ruby_19
|
13
|
+
|
14
|
+
gem 'ruby-debug', :platform => :ruby_18
|
15
|
+
gem "rcov", "~> 1.0.0", :platform => :ruby_18
|
16
|
+
|
17
|
+
gem "i18n"
|
18
|
+
gem "capybara"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.7)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
addressable (2.3.2)
|
8
|
+
capybara (1.1.2)
|
9
|
+
mime-types (>= 1.16)
|
10
|
+
nokogiri (>= 1.3.3)
|
11
|
+
rack (>= 1.0.0)
|
12
|
+
rack-test (>= 0.5.4)
|
13
|
+
selenium-webdriver (~> 2.0)
|
14
|
+
xpath (~> 0.1.4)
|
15
|
+
childprocess (0.3.4)
|
16
|
+
ffi (~> 1.0, >= 1.0.6)
|
17
|
+
columnize (0.3.6)
|
18
|
+
debugger (1.1.4)
|
19
|
+
columnize (>= 0.3.1)
|
20
|
+
debugger-linecache (~> 1.1.1)
|
21
|
+
debugger-ruby_core_source (~> 1.1.3)
|
22
|
+
debugger-linecache (1.1.2)
|
23
|
+
debugger-ruby_core_source (>= 1.1.1)
|
24
|
+
debugger-ruby_core_source (1.1.3)
|
25
|
+
ffi (1.1.4)
|
26
|
+
git (1.2.5)
|
27
|
+
http_router (0.10.2)
|
28
|
+
rack (>= 1.0.0)
|
29
|
+
url_mount (~> 0.2.1)
|
30
|
+
i18n (0.6.0)
|
31
|
+
jeweler (1.6.4)
|
32
|
+
bundler (~> 1.0)
|
33
|
+
git (>= 1.2.5)
|
34
|
+
rake
|
35
|
+
libwebsocket (0.1.5)
|
36
|
+
addressable
|
37
|
+
linecache (0.46)
|
38
|
+
rbx-require-relative (> 0.0.4)
|
39
|
+
mail (2.3.3)
|
40
|
+
i18n (>= 0.4.0)
|
41
|
+
mime-types (~> 1.16)
|
42
|
+
treetop (~> 1.4.8)
|
43
|
+
mime-types (1.19)
|
44
|
+
multi_json (1.3.6)
|
45
|
+
nokogiri (1.5.5)
|
46
|
+
padrino (0.10.7)
|
47
|
+
padrino-admin (= 0.10.7)
|
48
|
+
padrino-cache (= 0.10.7)
|
49
|
+
padrino-core (= 0.10.7)
|
50
|
+
padrino-gen (= 0.10.7)
|
51
|
+
padrino-helpers (= 0.10.7)
|
52
|
+
padrino-mailer (= 0.10.7)
|
53
|
+
padrino-admin (0.10.7)
|
54
|
+
padrino-core (= 0.10.7)
|
55
|
+
padrino-helpers (= 0.10.7)
|
56
|
+
padrino-cache (0.10.7)
|
57
|
+
padrino-core (= 0.10.7)
|
58
|
+
padrino-core (0.10.7)
|
59
|
+
activesupport (~> 3.2.0)
|
60
|
+
http_router (~> 0.10.2)
|
61
|
+
sinatra (~> 1.3.1)
|
62
|
+
thor (~> 0.15.2)
|
63
|
+
tilt (~> 1.3.0)
|
64
|
+
padrino-gen (0.10.7)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
padrino-core (= 0.10.7)
|
67
|
+
padrino-helpers (0.10.7)
|
68
|
+
i18n (~> 0.6)
|
69
|
+
padrino-core (= 0.10.7)
|
70
|
+
padrino-mailer (0.10.7)
|
71
|
+
mail (~> 2.3.0)
|
72
|
+
padrino-core (= 0.10.7)
|
73
|
+
polyglot (0.3.3)
|
74
|
+
rack (1.4.1)
|
75
|
+
rack-protection (1.2.0)
|
76
|
+
rack
|
77
|
+
rack-test (0.6.1)
|
78
|
+
rack (>= 1.0)
|
79
|
+
rake (0.9.2.2)
|
80
|
+
rbx-require-relative (0.0.9)
|
81
|
+
rcov (1.0.0)
|
82
|
+
ruby-debug (0.10.4)
|
83
|
+
columnize (>= 0.1)
|
84
|
+
ruby-debug-base (~> 0.10.4.0)
|
85
|
+
ruby-debug-base (0.10.4)
|
86
|
+
linecache (>= 0.3)
|
87
|
+
rubyzip (0.9.9)
|
88
|
+
selenium-webdriver (2.25.0)
|
89
|
+
childprocess (>= 0.2.5)
|
90
|
+
libwebsocket (~> 0.1.3)
|
91
|
+
multi_json (~> 1.0)
|
92
|
+
rubyzip
|
93
|
+
simplecov (0.6.4)
|
94
|
+
multi_json (~> 1.0)
|
95
|
+
simplecov-html (~> 0.5.3)
|
96
|
+
simplecov-html (0.5.3)
|
97
|
+
sinatra (1.3.2)
|
98
|
+
rack (~> 1.3, >= 1.3.6)
|
99
|
+
rack-protection (~> 1.2)
|
100
|
+
tilt (~> 1.3, >= 1.3.3)
|
101
|
+
test-spec (0.10.0)
|
102
|
+
thor (0.15.4)
|
103
|
+
tilt (1.3.3)
|
104
|
+
treetop (1.4.10)
|
105
|
+
polyglot
|
106
|
+
polyglot (>= 0.3.1)
|
107
|
+
url_mount (0.2.1)
|
108
|
+
rack
|
109
|
+
xpath (0.1.4)
|
110
|
+
nokogiri (~> 1.3)
|
111
|
+
yard (0.6.8)
|
112
|
+
|
113
|
+
PLATFORMS
|
114
|
+
ruby
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
bundler (~> 1.0.0)
|
118
|
+
capybara
|
119
|
+
debugger (~> 1.1.3)
|
120
|
+
i18n
|
121
|
+
jeweler (~> 1.6.4)
|
122
|
+
padrino
|
123
|
+
rcov (~> 1.0.0)
|
124
|
+
ruby-debug
|
125
|
+
simplecov (~> 0.6.4)
|
126
|
+
test-spec
|
127
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 kot-begemot
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= padrino-localization
|
2
|
+
|
3
|
+
The gem that allows to localize your application.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
* First install the gem
|
8
|
+
|
9
|
+
With Bundle
|
10
|
+
|
11
|
+
#Gemfile
|
12
|
+
gem "padrino-localization"
|
13
|
+
|
14
|
+
#irb
|
15
|
+
bundle install
|
16
|
+
|
17
|
+
or with gem
|
18
|
+
|
19
|
+
gem install padrino-localization
|
20
|
+
|
21
|
+
* Now it should be added to middleware
|
22
|
+
|
23
|
+
Padrino.use(Padrino::Localization::Middleware, __DEFINE_HERE_LOCALES__)
|
24
|
+
|
25
|
+
# config/apps.rb
|
26
|
+
Padrino.use(Padrino::Localization::Middleware, %w(en ru))
|
27
|
+
|
28
|
+
* Next, register urls helpers in your application
|
29
|
+
|
30
|
+
class UfoSeti < Padrino::Application
|
31
|
+
...
|
32
|
+
register Padrion::Localization::Urls
|
33
|
+
...
|
34
|
+
end
|
35
|
+
|
36
|
+
* And that's it. All existing urls now will be automatically localized, so there is no need to change anything,
|
37
|
+
it just requires the translation for your I18n. If you also define a locale for specific url, it should contain :locale => 'de'.
|
38
|
+
You can also predefine the default locale like that: I18n.default_locale = "de"
|
39
|
+
|
40
|
+
== Contributing to padrino-localization
|
41
|
+
|
42
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
43
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
44
|
+
* Fork the project
|
45
|
+
* Start a feature/bugfix branch
|
46
|
+
* Commit and push until you are happy with your contribution
|
47
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
48
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
49
|
+
|
50
|
+
== Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2012 kot-begemot. See LICENSE.txt for further details.
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "padrino-localization"
|
18
|
+
gem.homepage = "http://github.com/kot-begemot/padrino-localization"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Padrino localization Gem}
|
21
|
+
gem.description = %Q{This gem allows you to localalize your padrino application with ease}
|
22
|
+
gem.email = "max@studentify.nl"
|
23
|
+
gem.authors = ["kot-begemot"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
require 'yard'
|
38
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'padrino-localization/middleware'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
module Localization
|
5
|
+
MAPPING = '/(:locale)/'.freeze
|
6
|
+
|
7
|
+
module Urls
|
8
|
+
def self.registered(app)
|
9
|
+
app.helpers self
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.instance_eval do
|
14
|
+
alias_method_chain :url, :locale
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
###
|
19
|
+
# Generates an URL with a current locale, for a resource, inside of application.
|
20
|
+
#
|
21
|
+
# Example:
|
22
|
+
#
|
23
|
+
# url_for_with_locale(:users) # /ru/users
|
24
|
+
#
|
25
|
+
# url_for_with_locale('/') # /ru/
|
26
|
+
#
|
27
|
+
# url_for_with_locale(:posts, :new, :locale => 'se') # /se/posts/new
|
28
|
+
#
|
29
|
+
def url_with_locale *args
|
30
|
+
locale_scope = (::I18n.locale == ::I18n.default_locale) ? {} : {locale: ::I18n.locale}
|
31
|
+
if args.last.kind_of? Hash
|
32
|
+
# should not overwrite provided locale
|
33
|
+
args.last.merge!(locale_scope)
|
34
|
+
url_without_locale *args
|
35
|
+
else
|
36
|
+
url_without_locale *args, locale_scope
|
37
|
+
end.gsub('//','/')
|
38
|
+
end
|
39
|
+
|
40
|
+
###
|
41
|
+
# Returns a link, unless application locale is equivalent to those from URL.
|
42
|
+
#
|
43
|
+
# Examples:
|
44
|
+
#
|
45
|
+
# link_to_unless_current_locale :ru, "Main page", url(:main, :index, :locale => :ru)
|
46
|
+
# # => "Main page"
|
47
|
+
#
|
48
|
+
# link_to_unless_current_locale :ru, "Main page", url(:main, :index, :locale => :ru)
|
49
|
+
# # => "Main page"
|
50
|
+
#
|
51
|
+
def link_to_unless_current_locale *opts, &block
|
52
|
+
locale = opts.shift.to_s
|
53
|
+
if locale == ::I18n.locale.to_s
|
54
|
+
opts.first
|
55
|
+
else
|
56
|
+
link_to *opts, &block
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Localization
|
3
|
+
class Middleware
|
4
|
+
attr_reader :languages
|
5
|
+
alias_method :langs, :languages
|
6
|
+
|
7
|
+
def initialize(app, langs)
|
8
|
+
@app = app
|
9
|
+
self.languages = langs
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
@env = env
|
14
|
+
set_locale
|
15
|
+
response_array = @app.call(@env)
|
16
|
+
unset_locale
|
17
|
+
response_array
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def languages= langs
|
23
|
+
@languages = langs.collect do |l|
|
24
|
+
raise ArgumentError.new("An arguments should be 2 latters long") unless l.to_s =~ /\A[a-z]{2}\Z/i
|
25
|
+
l.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias_method :langs=, :languages=
|
29
|
+
|
30
|
+
def locale_pattern
|
31
|
+
@locale_pattern ||= /\A\/(#{langs.join('|')})?(\/?.*|)/i
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_locale
|
35
|
+
::I18n.locale = locale_from_url.to_sym if locale_defined_in_url?
|
36
|
+
end
|
37
|
+
|
38
|
+
def unset_locale
|
39
|
+
::I18n.locale = ::I18n.default_locale if locale_defined_in_url?
|
40
|
+
@locale_set = @locale = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
###
|
44
|
+
# Determine locale from the request URL and return it as a string, it it
|
45
|
+
# is matching any of provided locales
|
46
|
+
# If locale matching failed an empty String will be returned.
|
47
|
+
#
|
48
|
+
# Examples:
|
49
|
+
#
|
50
|
+
# #http://www.example.com/se
|
51
|
+
# locale_from_url # => 'se'
|
52
|
+
#
|
53
|
+
# #http://www.example.com/de/posts
|
54
|
+
# locale_from_url # => 'se'
|
55
|
+
#
|
56
|
+
# #http://www.example.com/ursers
|
57
|
+
# locale_from_url # => ''
|
58
|
+
#
|
59
|
+
def locale_from_url path_info = nil
|
60
|
+
@locale_set ||= begin
|
61
|
+
@locale ||= (match = (path_info || @env['PATH_INFO']).match(locale_pattern)) ? match[1] : nil
|
62
|
+
@env['PATH_INFO'] = match[2] if match && @env.try(:fetch, 'PATH_INFO')
|
63
|
+
true
|
64
|
+
end
|
65
|
+
@locale
|
66
|
+
end
|
67
|
+
|
68
|
+
###
|
69
|
+
# Try to determine, weather the locale is defined, from request URL, if it is matching any of
|
70
|
+
# provided locales, and returns boolean as a result.
|
71
|
+
#
|
72
|
+
# Examples:
|
73
|
+
#
|
74
|
+
# #http://www.example.com/se
|
75
|
+
# locale_from_url # => true
|
76
|
+
#
|
77
|
+
# #http://www.example.com/de/posts
|
78
|
+
# locale_from_url # => true
|
79
|
+
#
|
80
|
+
# #http://www.example.com/ursers
|
81
|
+
# locale_from_url # => false
|
82
|
+
#
|
83
|
+
def locale_defined_in_url?
|
84
|
+
!locale_from_url.blank?
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "padrino-localization"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["kot-begemot"]
|
12
|
+
s.date = "2012-08-05"
|
13
|
+
s.description = "This gem allows you to localalize your padrino application with ease"
|
14
|
+
s.email = "max@studentify.nl"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rvmrc",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/padrino-localization.rb",
|
29
|
+
"lib/padrino-localization/middleware.rb",
|
30
|
+
"padrino-localization.gemspec",
|
31
|
+
"test/middleware_test.rb",
|
32
|
+
"test/padrino-localization_test.rb",
|
33
|
+
"test/test_app/.components",
|
34
|
+
"test/test_app/app/app.rb",
|
35
|
+
"test/test_app/app/controllers/main.rb",
|
36
|
+
"test/test_app/app/helpers/application_helper.rb",
|
37
|
+
"test/test_app/config.ru",
|
38
|
+
"test/test_app/config/apps.rb",
|
39
|
+
"test/test_app/config/boot.rb",
|
40
|
+
"test/test_app/public/favicon.ico",
|
41
|
+
"test/test_helper.rb"
|
42
|
+
]
|
43
|
+
s.homepage = "http://github.com/kot-begemot/padrino-localization"
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = "1.8.10"
|
47
|
+
s.summary = "Padrino localization Gem"
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_runtime_dependency(%q<padrino>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<test-spec>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
58
|
+
s.add_development_dependency(%q<debugger>, ["~> 1.1.3"])
|
59
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0.6.4"])
|
60
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rcov>, ["~> 1.0.0"])
|
62
|
+
s.add_development_dependency(%q<i18n>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<capybara>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<padrino>, [">= 0"])
|
66
|
+
s.add_dependency(%q<test-spec>, [">= 0"])
|
67
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
70
|
+
s.add_dependency(%q<debugger>, ["~> 1.1.3"])
|
71
|
+
s.add_dependency(%q<simplecov>, ["~> 0.6.4"])
|
72
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rcov>, ["~> 1.0.0"])
|
74
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
75
|
+
s.add_dependency(%q<capybara>, [">= 0"])
|
76
|
+
end
|
77
|
+
else
|
78
|
+
s.add_dependency(%q<padrino>, [">= 0"])
|
79
|
+
s.add_dependency(%q<test-spec>, [">= 0"])
|
80
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
81
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
82
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
83
|
+
s.add_dependency(%q<debugger>, ["~> 1.1.3"])
|
84
|
+
s.add_dependency(%q<simplecov>, ["~> 0.6.4"])
|
85
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
86
|
+
s.add_dependency(%q<rcov>, ["~> 1.0.0"])
|
87
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
88
|
+
s.add_dependency(%q<capybara>, [">= 0"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class MiddlewareTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@middleware = Padrino::Localization::Middleware.new nil, [:en,:ru]
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_root_matching_without_locale
|
10
|
+
assert_nil @middleware.send :locale_from_url, '/'
|
11
|
+
assert_equal ::I18n.default_locale, ::I18n.locale
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_set_correct_locale
|
15
|
+
assert_equal 'en', @middleware.send(:locale_from_url, '/en')
|
16
|
+
assert_equal :en, @middleware.send(:set_locale)
|
17
|
+
assert_equal :en, ::I18n.locale
|
18
|
+
|
19
|
+
@middleware.send(:unset_locale)
|
20
|
+
assert_equal ::I18n.default_locale, ::I18n.locale
|
21
|
+
|
22
|
+
assert_equal 'ru', @middleware.send(:locale_from_url, '/ru')
|
23
|
+
assert_equal :ru, @middleware.send(:set_locale)
|
24
|
+
assert_equal :ru, ::I18n.locale
|
25
|
+
|
26
|
+
@middleware.send(:unset_locale)
|
27
|
+
assert_equal ::I18n.default_locale, ::I18n.locale
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_set_incorrect_locale
|
31
|
+
assert_equal nil, @middleware.send(:locale_from_url, '/test')
|
32
|
+
assert_equal nil, @middleware.send(:set_locale)
|
33
|
+
assert_equal ::I18n.default_locale, ::I18n.locale
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class MainControllerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Capybara.app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_root_without_locale
|
10
|
+
visit "/"
|
11
|
+
|
12
|
+
assert_equal 200, page.status_code
|
13
|
+
assert page.has_content? "translation missing: en.main.index"
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_root_with_locale_1
|
17
|
+
visit "/en"
|
18
|
+
assert_equal 200, page.status_code
|
19
|
+
assert page.has_content? "translation missing: en.main.index"
|
20
|
+
|
21
|
+
visit "/en/"
|
22
|
+
assert_equal 200, page.status_code
|
23
|
+
assert page.has_content? "translation missing: en.main.index"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_root_with_locale_2
|
27
|
+
visit "/ru"
|
28
|
+
assert_equal 200, page.status_code
|
29
|
+
assert page.has_content? "translation missing: ru.main.index"
|
30
|
+
|
31
|
+
visit "/ru/"
|
32
|
+
assert_equal 200, page.status_code
|
33
|
+
assert page.has_content? "translation missing: ru.main.index"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_welcome_with_locale_1
|
37
|
+
visit "/en/welcome"
|
38
|
+
assert_equal 200, page.status_code
|
39
|
+
assert page.has_content? "translation missing: en.main.welcome"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_welcome_with_locale_2
|
43
|
+
visit "/ru/welcome"
|
44
|
+
assert_equal 200, page.status_code
|
45
|
+
assert page.has_content? "translation missing: ru.main.welcome"
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_wrong_page_without_locale
|
49
|
+
visit "/test"
|
50
|
+
assert_equal 404, page.status_code
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_wrong_page_with_locale
|
54
|
+
visit "/en/test"
|
55
|
+
assert_equal 404, page.status_code
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
##
|
2
|
+
# This file mounts each app in the Padrino project to a specified sub-uri.
|
3
|
+
# You can mount additional applications using any of these commands below:
|
4
|
+
#
|
5
|
+
# Padrino.mount("blog").to('/blog')
|
6
|
+
# Padrino.mount("blog", :app_class => "BlogApp").to('/blog')
|
7
|
+
# Padrino.mount("blog", :app_file => "path/to/blog/app.rb").to('/blog')
|
8
|
+
#
|
9
|
+
# You can also map apps to a specified host:
|
10
|
+
#
|
11
|
+
# Padrino.mount("Admin").host("admin.example.org")
|
12
|
+
# Padrino.mount("WebSite").host(/.*\.?example.org/)
|
13
|
+
# Padrino.mount("Foo").to("/foo").host("bar.example.org")
|
14
|
+
#
|
15
|
+
# Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'.
|
16
|
+
# Note 2: If you use the host matching remember to respect the order of the rules.
|
17
|
+
#
|
18
|
+
# By default, this file mounts the parimary app which was generated with this project.
|
19
|
+
# However, the mounted app can be modified as needed:
|
20
|
+
#
|
21
|
+
# Padrino.mount(:app_file => "path/to/file", :app_class => "Blog").to('/')
|
22
|
+
#
|
23
|
+
|
24
|
+
Padrino.use(Padrino::Localization::Middleware, ['en' , 'ru'])
|
25
|
+
|
26
|
+
# Mounts the core application for this project
|
27
|
+
Padrino.mount("TestApp").to('/')
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
# Defines our constants
|
3
|
+
PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
|
4
|
+
PADRINO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
5
|
+
|
6
|
+
# Only have default and environemtn gems
|
7
|
+
Bundler.setup(:default, :test)
|
8
|
+
# Only require default and environment gems
|
9
|
+
Bundler.require(:default, :test)
|
10
|
+
|
11
|
+
##
|
12
|
+
# Add here your before load hooks
|
13
|
+
#
|
14
|
+
Padrino.before_load do
|
15
|
+
::I18n.default_locale = :en
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Add here your after load hooks
|
20
|
+
#
|
21
|
+
Padrino.after_load do
|
22
|
+
end
|
23
|
+
|
24
|
+
Padrino.load!
|
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'capybara'
|
3
|
+
require 'capybara/dsl'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'debugger'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
require 'padrino-localization'
|
10
|
+
|
11
|
+
require File.join(File.dirname(__FILE__), 'test_app', 'config', 'boot')
|
12
|
+
|
13
|
+
I18n.locale = :en
|
14
|
+
|
15
|
+
class Test::Unit::TestCase
|
16
|
+
include Capybara::DSL
|
17
|
+
|
18
|
+
def app
|
19
|
+
@app || Padrino.application
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padrino-localization
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kot-begemot
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: padrino
|
16
|
+
requirement: &87211030 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *87211030
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: test-spec
|
27
|
+
requirement: &87210680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *87210680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
requirement: &87210340 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.6.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *87210340
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &87157680 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *87157680
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &87157280 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.6.4
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *87157280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: debugger
|
71
|
+
requirement: &87156640 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.1.3
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *87156640
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: simplecov
|
82
|
+
requirement: &87156130 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.6.4
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *87156130
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: ruby-debug
|
93
|
+
requirement: &87155750 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *87155750
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: rcov
|
104
|
+
requirement: &87155330 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.0.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *87155330
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: i18n
|
115
|
+
requirement: &87154890 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *87154890
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: capybara
|
126
|
+
requirement: &87154520 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *87154520
|
135
|
+
description: This gem allows you to localalize your padrino application with ease
|
136
|
+
email: max@studentify.nl
|
137
|
+
executables: []
|
138
|
+
extensions: []
|
139
|
+
extra_rdoc_files:
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.rdoc
|
142
|
+
files:
|
143
|
+
- .document
|
144
|
+
- .rvmrc
|
145
|
+
- Gemfile
|
146
|
+
- Gemfile.lock
|
147
|
+
- LICENSE.txt
|
148
|
+
- README.rdoc
|
149
|
+
- Rakefile
|
150
|
+
- VERSION
|
151
|
+
- lib/padrino-localization.rb
|
152
|
+
- lib/padrino-localization/middleware.rb
|
153
|
+
- padrino-localization.gemspec
|
154
|
+
- test/middleware_test.rb
|
155
|
+
- test/padrino-localization_test.rb
|
156
|
+
- test/test_app/.components
|
157
|
+
- test/test_app/app/app.rb
|
158
|
+
- test/test_app/app/controllers/main.rb
|
159
|
+
- test/test_app/app/helpers/application_helper.rb
|
160
|
+
- test/test_app/config.ru
|
161
|
+
- test/test_app/config/apps.rb
|
162
|
+
- test/test_app/config/boot.rb
|
163
|
+
- test/test_app/public/favicon.ico
|
164
|
+
- test/test_helper.rb
|
165
|
+
homepage: http://github.com/kot-begemot/padrino-localization
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - ! '>='
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
segments:
|
179
|
+
- 0
|
180
|
+
hash: -640946865
|
181
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
|
+
none: false
|
183
|
+
requirements:
|
184
|
+
- - ! '>='
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 1.8.10
|
190
|
+
signing_key:
|
191
|
+
specification_version: 3
|
192
|
+
summary: Padrino localization Gem
|
193
|
+
test_files: []
|