sinatra-r18n 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/lib/sinatra/r18n.rb +6 -2
- data/spec/app/app.rb +4 -0
- data/spec/sinatra-r18n_spec.rb +15 -0
- metadata +11 -13
data/README.rdoc
CHANGED
@@ -38,6 +38,12 @@ information.
|
|
38
38
|
|
39
39
|
require 'sinatra/r18n'
|
40
40
|
|
41
|
+
If your application inherits from <tt>Sinatra::Base</tt> also add:
|
42
|
+
|
43
|
+
class YourApp < Sinatra::Base
|
44
|
+
register Sinatra::R18n
|
45
|
+
set :root, File.dirname(__FILE__)
|
46
|
+
|
41
47
|
4. Add locale to your URLs. For example:
|
42
48
|
|
43
49
|
get '/:locale/posts/:id' do
|
data/lib/sinatra/r18n.rb
CHANGED
@@ -54,9 +54,13 @@ module Sinatra #::nodoc::
|
|
54
54
|
app.set :default_locale, 'en'
|
55
55
|
app.set :translations, Proc.new { File.join(app.root, 'i18n/') }
|
56
56
|
|
57
|
-
::R18n.untranslated
|
57
|
+
::R18n::Filters.off(:untranslated)
|
58
|
+
::R18n::Filters.add(::R18n::Untranslated, :untranslated_html) do
|
59
|
+
|content, config, translated_path, untranslated_path, path|
|
60
|
+
"#{translated_path}<span style='color: red'>#{untranslated_path}</span>"
|
61
|
+
end
|
58
62
|
app.configure :production do
|
59
|
-
::R18n.
|
63
|
+
::R18n::Filters.add(::R18n::Untranslated, :hide_untranslated) { '' }
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
data/spec/app/app.rb
CHANGED
data/spec/sinatra-r18n_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
|
|
4
4
|
describe Sinatra::R18n do
|
5
5
|
after do
|
6
6
|
set :default_locale, 'en'
|
7
|
+
set :environment, :test
|
7
8
|
end
|
8
9
|
|
9
10
|
it "should translate messages" do
|
@@ -43,4 +44,18 @@ describe Sinatra::R18n do
|
|
43
44
|
last_response.body.should == 'en: English; ru: Русский'
|
44
45
|
end
|
45
46
|
|
47
|
+
it "should format untranslated string" do
|
48
|
+
get '/untranslated'
|
49
|
+
last_response.should be_ok
|
50
|
+
last_response.body.should == "post.<span style='color: red'>no</span>"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should hide untranslated string in production" do
|
54
|
+
set :environment, :production
|
55
|
+
|
56
|
+
get '/untranslated'
|
57
|
+
last_response.should be_ok
|
58
|
+
last_response.body.should == "post.<span style='color: red'>no</span>"
|
59
|
+
end
|
60
|
+
|
46
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-r18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey "A.I." Sitnik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-29 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,9 +20,9 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.3.
|
23
|
+
version: 0.3.2
|
24
24
|
version:
|
25
|
-
description: A Sinatra extension that provides i18n support to translate your web
|
25
|
+
description: " A Sinatra extension that provides i18n support to translate your web\n application. It is just a wrap for R18n core library.\n It can format numbers and time to the rules of the user locale,\n has translation for common words, storage translation in YAML format with\n pluralization, procedures and user filters and has special support for\n countries with two official languages.\n"
|
26
26
|
email: andrey@sitnik.ru
|
27
27
|
executables: []
|
28
28
|
|
@@ -32,12 +32,13 @@ extra_rdoc_files:
|
|
32
32
|
- README.rdoc
|
33
33
|
- LICENSE
|
34
34
|
files:
|
35
|
-
- lib/sinatra
|
36
35
|
- lib/sinatra/r18n.rb
|
37
36
|
- LICENSE
|
38
37
|
- README.rdoc
|
39
38
|
has_rdoc: true
|
40
39
|
homepage: http://r18n.rubyforge.org/
|
40
|
+
licenses: []
|
41
|
+
|
41
42
|
post_install_message:
|
42
43
|
rdoc_options: []
|
43
44
|
|
@@ -58,17 +59,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
59
|
requirements: []
|
59
60
|
|
60
61
|
rubyforge_project: sinatra-r18n
|
61
|
-
rubygems_version: 1.3.
|
62
|
+
rubygems_version: 1.3.5
|
62
63
|
signing_key:
|
63
|
-
specification_version:
|
64
|
+
specification_version: 3
|
64
65
|
summary: A Sinatra extension that provides i18n support to translate your web application.
|
65
66
|
test_files:
|
66
|
-
- spec/spec_helper.rb
|
67
67
|
- spec/sinatra-r18n_spec.rb
|
68
|
-
- spec/
|
69
|
-
- spec/app/
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/app/views/post.erb
|
70
|
+
- spec/app/app.rb
|
70
71
|
- spec/app/i18n/ru.yml
|
71
72
|
- spec/app/i18n/en.yml
|
72
|
-
- spec/app/app.rb
|
73
|
-
- spec/app/views
|
74
|
-
- spec/app/views/post.erb
|