sinatra-r18n 0.2.3 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -15,7 +15,7 @@ information.
15
15
  month and week days name and give other locale information.
16
16
  * It has translation for commons words, like “OK”, “Cancel”, etc.
17
17
  * It storage translation in rich YAML format. You can put procedures and
18
- pluralization (“1 comment”, “5 comments”) in your translation.
18
+ pluralization (“1 comment”, “5 comments”) or create you own filters.
19
19
 
20
20
  == How To
21
21
  1. Create translations dir <tt>./i18n/</tt>.
@@ -30,6 +30,9 @@ information.
30
30
  0: No comments
31
31
  1: One comment
32
32
  n: %1 comments
33
+
34
+ html: !!html
35
+ <b>Don't escape HTML</b>
33
36
 
34
37
  3. Add R18n to your Sinatra application:
35
38
 
@@ -57,7 +60,7 @@ information.
57
60
 
58
61
  6. Print localized time and numbers. For example:
59
62
 
60
- i18n.l @post.created_at, :date
63
+ i18n.l @post.created_at, :human
61
64
 
62
65
  7. Print available translations. For example in HAML:
63
66
 
data/lib/sinatra/r18n.rb CHANGED
@@ -25,8 +25,6 @@ require 'sinatra/base'
25
25
  gem 'r18n-core', '~>0.2.3'
26
26
  require 'r18n-core'
27
27
 
28
- R18n.untranslated = '%2<span style="color: red">%3</span>'
29
-
30
28
  module Sinatra #::nodoc::
31
29
  module R18n #::nodoc::
32
30
  module Helpers
@@ -44,6 +42,7 @@ module Sinatra #::nodoc::
44
42
  end
45
43
 
46
44
  @i18n = ::R18n::I18n.new(locales, options.translations)
45
+ ::R18n.set(@i18n)
47
46
  else
48
47
  @i18n
49
48
  end
@@ -54,6 +53,11 @@ module Sinatra #::nodoc::
54
53
  app.helpers Helpers
55
54
  app.set :default_locale, 'en'
56
55
  app.set :translations, Proc.new { File.join(app.root, 'i18n/') }
56
+
57
+ ::R18n.untranslated = '%2<span style="color: red">%3</span>'
58
+ app.configure :production do
59
+ ::R18n.untranslated = ''
60
+ end
57
61
  end
58
62
  end
59
63
 
data/spec/app/app.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), '../../lib/sinatra/r18n')
2
3
  require 'sinatra'
3
4
 
4
5
  get '/:locale/posts/:name' do
@@ -11,9 +12,17 @@ get '/:locale/posts/:name/comments' do
11
12
  end
12
13
 
13
14
  get '/locale' do
14
- i18n.locale['title']
15
+ i18n.locale.title
15
16
  end
16
17
 
17
18
  get '/locales' do
18
19
  i18n.translations.map { |i| i.join(': ') }.sort.join('; ')
19
20
  end
21
+
22
+ get '/greater' do
23
+ i18n.greater
24
+ end
25
+
26
+ get '/warning' do
27
+ i18n.warning
28
+ end
data/spec/app/i18n/en.yml CHANGED
@@ -1,3 +1,5 @@
1
+ greater: 1 < 2 is true
2
+ warning: !!html <b>Warning</b>
1
3
  post:
2
4
  title: Post %1
3
5
  comments: !!pl
@@ -2,8 +2,8 @@
2
2
  require File.join(File.dirname(__FILE__), 'spec_helper')
3
3
 
4
4
  describe Sinatra::R18n do
5
- before :all do
6
- ::R18n.set(nil)
5
+ after do
6
+ set :default_locale, 'en'
7
7
  end
8
8
 
9
9
  it "should translate messages" do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '../lib/sinatra/r18n')
2
+ require 'pp'
3
+
3
4
  require File.join(File.dirname(__FILE__), 'app/app')
4
5
 
5
6
  require 'spec/interop/test'
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.2.3
4
+ version: "0.3"
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-07-22 00:00:00 +08:00
12
+ date: 2009-09-26 00:00:00 +04: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.2.3
23
+ version: "0.3"
24
24
  version:
25
- description: A Sinatra extension that provides i18n support to translate your web application. It is just a wrap for R18n core library. It can format numbers and time to the rules of the user locale, has translation for common words, storage translation in YAML format with pluralization and procedures and has special support for countries with two official languages.
25
+ description: A Sinatra extension that provides i18n support to translate your web application. It is just a wrap for R18n core library. It can format numbers and time to the rules of the user locale, has translation for common words, storage translation in YAML format with pluralization, procedures and user filters and has special support for countries with two official languages.
26
26
  email: andrey@sitnik.ru
27
27
  executables: []
28
28
 
@@ -63,12 +63,12 @@ signing_key:
63
63
  specification_version: 2
64
64
  summary: A Sinatra extension that provides i18n support to translate your web application.
65
65
  test_files:
66
+ - spec/spec_helper.rb
66
67
  - spec/sinatra-r18n_spec.rb
67
68
  - spec/app
68
- - spec/app/views
69
- - spec/app/views/post.erb
70
- - spec/app/app.rb
71
69
  - spec/app/i18n
72
- - spec/app/i18n/en.yml
73
70
  - spec/app/i18n/ru.yml
74
- - spec/spec_helper.rb
71
+ - spec/app/i18n/en.yml
72
+ - spec/app/app.rb
73
+ - spec/app/views
74
+ - spec/app/views/post.erb