r18n-rails 0.4.14 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.yardopts CHANGED
@@ -1,3 +1,3 @@
1
1
  --charset utf-8
2
2
  -
3
- README.rdoc
3
+ README.md
data/LICENSE CHANGED
@@ -10,7 +10,7 @@
10
10
  the terms and conditions of version 3 of the GNU General Public
11
11
  License, supplemented by the additional permissions listed below.
12
12
 
13
- 0. Additional Definitions.
13
+ 0. Additional Definitions.
14
14
 
15
15
  As used herein, "this License" refers to version 3 of the GNU Lesser
16
16
  General Public License, and the "GNU GPL" refers to version 3 of the GNU
@@ -111,7 +111,7 @@ the following:
111
111
  a copy of the Library already present on the user's computer
112
112
  system, and (b) will operate properly with a modified version
113
113
  of the Library that is interface-compatible with the Linked
114
- Version.
114
+ Version.
115
115
 
116
116
  e) Provide Installation Information, but only if you would otherwise
117
117
  be required to provide such information under section 6 of the
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # R18n for Rails
2
+
3
+ R18n-rails is a gem to add out-of-box R18n support to Rails I18n.
4
+
5
+ It is a wrapper for R18n Rails API and R18n core libraries. See R18n core
6
+ documentation for more information.
7
+
8
+ ## Features
9
+
10
+ R18n for Rails is fully compatibile with Rails I18n, and add extra features:
11
+
12
+ * Nice Ruby-style syntax.
13
+ * Filters.
14
+ * Model Translation (or any Ruby object).
15
+ * Autodetect user locales.
16
+ * Flexible locales.
17
+ * Total flexibility.
18
+
19
+ See full features in [main README](https://github.com/ai/r18n/blob/master/README.md).
20
+
21
+ ## How To
22
+
23
+ 1. Add `r18n-rails` gem to your `Gemfile`:
24
+
25
+ ```
26
+ gem 'r18n-rails'
27
+ ```
28
+ Now R18n will autodetect user locales.
29
+ 2. Define your way to set locale manually. R18n will find it in
30
+ `params[:locale]` or `session[:locale]`. Best way is a put optional
31
+ locale prefix to URLs:
32
+
33
+ ```ruby
34
+ match ':controller/:action'
35
+ match ':locale/:controller/:action'
36
+ ```
37
+
38
+ 3. Print available translations, to choose from them manually (and to help
39
+ search engines):
40
+
41
+ ```haml
42
+ %ul
43
+ - r18n.available_locales.each do |locale|
44
+ %li
45
+ %a( href="/#{locale.code}/" )= locale.title
46
+ ```
47
+
48
+ 4. Translations in I18n format are stored in
49
+ <tt>config/locales/<i>locale</i>.yml</tt>:
50
+
51
+ ```yaml
52
+ en:
53
+ user:
54
+ name: "User name is %{name}"
55
+ count:
56
+ zero: "No users"
57
+ one: "One user"
58
+ many: "%{count} users"
59
+ ```
60
+ Translations in R18n format go to <tt>app/i18n/<i>locale</i>.yml</tt>:
61
+
62
+ ```yaml
63
+ user:
64
+ name: User name is %1
65
+ count: !!pl
66
+ 0: No users
67
+ 1: 1 user
68
+ n: %1 users
69
+ ```
70
+
71
+ 5. Use translated messages in views. You can use Rails I18n syntax:
72
+
73
+ ```ruby
74
+ t 'user.name', :name => 'John'
75
+ t 'user.count', :count => 5
76
+ ```
77
+ or R18n syntax:
78
+
79
+ ```ruby
80
+ t.user.name(:name => 'John') # for Rails I18n named variables
81
+ t.user.name('John') # for R18n variables
82
+ t.user.count(5)
83
+ ```
84
+
85
+ 6. Print dates and numbers in user’s tradition:
86
+
87
+ ```ruby
88
+ l Date.today, :standard #=> "20/12/2009"
89
+ l Time.now, :full #=> "20th of December, 2009 12:00"
90
+ l 1234.5 #=> "1,234.5"
91
+ ```
92
+
93
+ 7. Translate models. You can use `R18n::Translated` mixin for any Ruby class,
94
+ not only for ActiveRecord models
95
+
96
+ 1. Add to migration columns for each of the supported locales, named as
97
+ <tt><i>name</i>_<i>locale</i></tt>:
98
+
99
+ ```ruby
100
+ t.string :title_en
101
+ t.string :title_ru
102
+
103
+ t.string :text_en
104
+ t.string :text_ru
105
+ ```
106
+
107
+ 2. Add `R18n::Translated` mixin to model:
108
+
109
+ ```ruby
110
+ class Post < ActiveRecord::Base
111
+ include R18n::Translated
112
+ ```
113
+
114
+ 3. Call `translations` method in model with all columns to be translated:
115
+
116
+ ```ruby
117
+ translations :title, :text
118
+ ```
119
+ Now model will have virtual methods `title`, `text`, `title=`
120
+ and `text=`, which will call `title_ru` or `title_en` and etc based
121
+ on current user locales.
122
+
123
+ 8. Download translations for Rails system messages (validation, etc) from
124
+ https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale and
125
+ put them to `config/locales/` (because them use Rails I18n format).
126
+ 9. Add your own translations filters to `app/i18n/filters.rb`:
127
+
128
+ ```ruby
129
+ R18n::Filters.add('gender') do |translation, config, user|
130
+ translation[user.gender]
131
+ end
132
+ ```
133
+ And use in translations:
134
+
135
+ ```yaml
136
+ log:
137
+ signup: !!gender
138
+ male: Он зарегистрировался
139
+ female: Она зарегистрировалась
140
+ ```
141
+ and application:
142
+
143
+ ```ruby
144
+ t.log.signup(user)
145
+ ```
146
+
147
+ ## License
148
+
149
+ R18n is licensed under the GNU Lesser General Public License version 3.
150
+ You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
151
+
152
+ ## Author
153
+
154
+ Andrey “A.I.” Sitnik <andrey@sitnik.ru>
data/Rakefile CHANGED
@@ -21,7 +21,8 @@ YARD::Rake::YardocTask.new do |yard|
21
21
  end
22
22
 
23
23
  task :clobber_doc do
24
- rm_r 'doc' rescue nil
24
+ rm_r 'doc' rescue nil
25
+ rm_r '.yardoc' rescue nil
25
26
  end
26
27
  task :clobber_package do
27
28
  rm_r 'pkg' rescue nil
data/lib/r18n-rails.rb CHANGED
@@ -19,19 +19,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  require 'pathname'
21
21
  require 'r18n-core'
22
- require 'r18n-core/translated'
23
22
  require 'r18n-rails-api'
24
23
 
25
24
  dir = Pathname(__FILE__).dirname.expand_path + 'r18n-rails'
26
25
  require dir + 'helpers'
27
26
  require dir + 'controller'
28
27
  require dir + 'translated'
28
+ require dir + 'filters'
29
29
 
30
- R18n::Filters.off(:untranslated)
31
- R18n::Filters.on(:untranslated_html)
30
+ R18n.default_places { [Rails.root.join('app/i18n'), R18n::Loader::Rails.new] }
32
31
 
33
32
  ActionController::Base.helper(R18n::Rails::Helpers)
34
33
  ActionController::Base.send(:include, R18n::Rails::Controller)
35
34
  ActionController::Base.send(:before_filter, :set_r18n)
36
-
37
- ActionMailer::Base.helper(R18n::Rails::Helpers)
35
+ unless Rails.env.production?
36
+ ActionController::Base.send(:before_filter, :reload_r18n_filters)
37
+ end
38
+
39
+ ActionMailer::Base.helper(R18n::Rails::Helpers) if defined? ActionMailer
40
+
41
+ ActiveSupport.on_load(:after_initialize) do
42
+ env = ENV['LANG']
43
+ env = env.split('.').first if env
44
+ locale = env || I18n.default_locale.to_s
45
+ if defined? Rails::Console and not defined? Wirble
46
+ i18n = R18n::I18n.new(locale, R18n.default_places,
47
+ :off_filters => :untranslated,
48
+ :on_filters => :untranslated_bash)
49
+ R18n.set(i18n)
50
+ else
51
+ R18n.set(locale)
52
+ end
53
+ end
@@ -38,13 +38,17 @@ module R18n
38
38
  locales.insert(0, session[:locale])
39
39
  end
40
40
 
41
- places = [::Rails.root.join('app/i18n'), R18n::Loader::Rails.new]
42
-
43
- R18n::I18n.new(locales, places)
41
+ R18n::I18n.new(locales, R18n.default_places,
42
+ :off_filters => :untranslated, :on_filters => :untranslated_html)
44
43
  end
45
44
 
46
45
  ::I18n.backend = R18n::Backend.new
47
46
  end
47
+
48
+ # Reload filters from ruby files in `app/i18n`.
49
+ def reload_r18n_filters
50
+ R18n::Rails::Filters.reload!
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -0,0 +1,57 @@
1
+ =begin
2
+ Load R18n filters from Rails app directory.
3
+
4
+ Copyright (C) 2012 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
5
+
6
+ This program is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ =end
19
+
20
+ module R18n
21
+ module Rails
22
+ # Load and remove filters from ruby files in `app/i18n`.
23
+ class Filters
24
+ class << self
25
+ # Path list of filters, which are loaded from app dir.
26
+ attr_accessor :loaded
27
+
28
+ # Path to filters. Should be set to `app/i18n`.
29
+ attr_writer :path
30
+ def path
31
+ @path || ::Rails.root.join('app/i18n')
32
+ end
33
+
34
+ # Load all ruby files from `app/i18n` and remember loaded filters.
35
+ def load!
36
+ @loaded = R18n::Filters.listen {
37
+ Pathname.glob(path.join('**/*.rb').to_s) { |i| load i.to_s; }
38
+ }.map { |i| i.name }
39
+ end
40
+
41
+ # Shortcut to call `remove!` and `load!`.
42
+ def reload!
43
+ remove!
44
+ load!
45
+ end
46
+
47
+ # Remove filters, loaded by `load!`.
48
+ def remove!
49
+ @loaded.each { |i| R18n::Filters.delete(i) }
50
+ @loaded = []
51
+ end
52
+ end
53
+ end
54
+
55
+ Filters.loaded = []
56
+ end
57
+ end
@@ -24,7 +24,7 @@ module R18n
24
24
  # * <tt>r18n.available_locales</tt> – available application translations.
25
25
  # * <tt>r18n.locales</tt> – List of user locales
26
26
  # * <tt>r18n.reload!</tt> – Reload R18n translations
27
- #
27
+ #
28
28
  # You can get translations by <tt>r18n.user.name</tt>, but +t+ helper is
29
29
  # more beautiful, short and also support R18n syntax.
30
30
  def r18n
@@ -32,7 +32,7 @@ module R18n
32
32
  end
33
33
 
34
34
  # Extend +t+ helper to use also R18n syntax.
35
- #
35
+ #
36
36
  # t 'user.name' # Rails I18n style
37
37
  # t.user.name # R18n style
38
38
  def t(*params)
@@ -45,7 +45,7 @@ module R18n
45
45
  alias :translate :t
46
46
 
47
47
  # Extend +l+ helper to use also R18n syntax.
48
- #
48
+ #
49
49
  # l Time.now # Rails I18n default format
50
50
  # l Time.now, :format => :short # Rails I18n style
51
51
  # l Time.now, :human # R18n style
data/r18n-rails.gemspec CHANGED
@@ -12,18 +12,17 @@ Gem::Specification.new do |s|
12
12
  R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,
13
13
  translation support for any classes, time and number localization, several
14
14
  user language support, agnostic core package with out-of-box support for
15
- Rails, Sinatra, Merb and desktop applications.
15
+ Rails, Sinatra and desktop applications.
16
16
  EOF
17
17
 
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.extra_rdoc_files = ['README.rdoc', 'LICENSE']
21
- s.require_path = 'lib'
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
21
+ s.require_path = 'lib'
22
22
 
23
- s.author = 'Andrey "A.I." Sitnik'
24
- s.email = 'andrey@sitnik.ru'
25
- s.homepage = 'http://r18n.rubyforge.org/'
26
- s.rubyforge_project = 'r18n-rails'
23
+ s.author = 'Andrey "A.I." Sitnik'
24
+ s.email = 'andrey@sitnik.ru'
25
+ s.homepage = 'https://github.com/ai/r18n/tree/master/r18n-rails'
27
26
 
28
27
  s.add_dependency 'r18n-rails-api', ["= #{R18n::VERSION}"]
29
28
 
@@ -33,5 +32,6 @@ Gem::Specification.new do |s|
33
32
  s.add_development_dependency "rails", [">= 3"]
34
33
  s.add_development_dependency "rspec", [">= 2"]
35
34
  s.add_development_dependency "rspec-rails", [">= 2"]
35
+ s.add_development_dependency "redcarpet", [">= 0"]
36
36
  end
37
37
 
@@ -36,4 +36,8 @@ class TestController < ApplicationController
36
36
  def human_time
37
37
  render :text => l(Time.now, :human)
38
38
  end
39
+
40
+ def filter
41
+ render :text => t.ruby
42
+ end
39
43
  end
@@ -1,2 +1,6 @@
1
1
  r18n:
2
2
  translations: supported
3
+ ruby: !!rails
4
+ Ruby
5
+ html:
6
+ <b>
@@ -0,0 +1,3 @@
1
+ R18n::Filters.add('rails', :rails_custom_filter) do |content, config, *params|
2
+ content.gsub('Ruby', 'Rails')
3
+ end
@@ -0,0 +1,7 @@
1
+ class TestMailer < ActionMailer::Base
2
+ default :from => 'from@example.com'
3
+
4
+ def test
5
+ mail(:to => 'to@example.com')
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ <%= t.html %> <%= t.user.no_tr %>
@@ -0,0 +1,3 @@
1
+ <%= r18n.user.name %>
2
+ <%= t 'user.name' %>
3
+ <%= t.user.name %>
@@ -15,5 +15,11 @@ module App
15
15
  config.action_view.javascript_expansions[:defaults] = []
16
16
  config.encoding = "utf-8"
17
17
  config.filter_parameters += [:password]
18
+
19
+ def config.database_configuration
20
+ sqlite = { 'adapter' => 'sqlite3', 'database' => ':memory:' }
21
+ sqlite['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
22
+ { 'development' => sqlite, 'test' => sqlite, 'production' => sqlite }
23
+ end
18
24
  end
19
25
  end
@@ -1,10 +1,10 @@
1
1
  App::Application.configure do
2
- config.cache_classes = true
3
- config.whiny_nils = true
4
- config.consider_all_requests_local = true
5
- config.action_controller.perform_caching = false
6
- config.action_dispatch.show_exceptions = false
7
- config.action_controller.allow_forgery_protection = false
8
- config.action_mailer.delivery_method = :test
9
- config.active_support.deprecation = :stderr
2
+ config.cache_classes = true
3
+ config.whiny_nils = true
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.action_dispatch.show_exceptions = false
7
+ config.action_controller.allow_forgery_protection = false
8
+ config.action_mailer.delivery_method = :test
9
+ config.active_support.deprecation = :stderr
10
10
  end
data/spec/rails_spec.rb CHANGED
@@ -50,7 +50,7 @@ describe TestController, :type => :controller do
50
50
  it 'should format untranslated' do
51
51
  get :untranslated
52
52
  response.should be_success
53
- response.body.should == 'user.<span style="color: red">not.exists</span>'
53
+ response.body.should == 'user.<span style="color: red">[not.exists]</span>'
54
54
  end
55
55
 
56
56
  it "should add methods to controller" do
@@ -94,7 +94,39 @@ describe TestController, :type => :controller do
94
94
  @post.title = 'Запись'
95
95
  @post.title_ru.should == 'Запись'
96
96
  @post.title_en.should == 'Record'
97
- @post.title.should == 'Запись'
97
+ @post.title.should == 'Запись'
98
+ end
99
+
100
+ it "should set default places" do
101
+ R18n.default_places.should == [Rails.root.join('app/i18n'),
102
+ R18n::Loader::Rails.new]
103
+ R18n.set('en')
104
+ R18n.get.user.name.should == 'Name'
105
+ end
106
+
107
+ it "should translate mails" do
108
+ email = TestMailer.test.deliver
109
+ email.encoded.should =~ /Name\r\nName\r\nName\r\n$/
110
+ end
111
+
112
+ it "should reload filters from app directory" do
113
+ get :filter, :locale => 'en'
114
+ response.should be_success
115
+ response.body.should == 'Rails'
116
+ R18n::Rails::Filters.loaded.should == [:rails_custom_filter]
117
+
118
+ R18n::Filters.defined[:rails_custom_filter].block = proc { 'No' }
119
+ get :filter, :locale => 'en'
120
+
121
+ response.should be_success
122
+ response.body.should == 'Rails'
123
+ end
124
+
125
+ it "should escape html inside R18n" do
126
+ get :safe, :locale => 'en'
127
+ response.should be_success
128
+ response.body.should ==
129
+ "<b> user.<span style=\"color: red\">[no_tr]</span>\n"
98
130
  end
99
131
 
100
132
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,8 @@
1
- require 'rubygems'
1
+ require 'pp'
2
2
 
3
3
  ENV['RAILS_ENV'] ||= 'test'
4
- require 'pp'
5
- require File.expand_path(File.join(File.dirname(__FILE__), 'app/config/environment'))
4
+ dir = File.dirname(__FILE__)
5
+ require File.expand_path(File.join(dir, 'app/config/environment'))
6
+ require File.expand_path(File.join(dir, '../lib/r18n-rails'))
6
7
 
7
- require 'rspec'
8
8
  require 'rspec/rails'
9
-
metadata CHANGED
@@ -1,151 +1,170 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: r18n-rails
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 14
10
- version: 0.4.14
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrey "A.I." Sitnik
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-25 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- type: :runtime
12
+ date: 2012-06-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: r18n-rails-api
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - "="
27
- - !ruby/object:Gem::Version
28
- hash: 19
29
- segments:
30
- - 0
31
- - 4
32
- - 14
33
- version: 0.4.14
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
34
23
  prerelease: false
35
- requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
- type: :development
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
38
31
  name: bundler
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 1
47
- - 0
48
- - 10
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
49
37
  version: 1.0.10
50
- prerelease: false
51
- requirement: *id002
52
- - !ruby/object:Gem::Dependency
53
38
  type: :development
54
- name: yard
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
64
39
  prerelease: false
65
- requirement: *id003
66
- - !ruby/object:Gem::Dependency
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.10
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
67
54
  type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
68
63
  name: rake
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
78
- - - "!="
79
- - !ruby/object:Gem::Version
80
- hash: 59
81
- segments:
82
- - 0
83
- - 9
84
- - 0
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - - ! '!='
71
+ - !ruby/object:Gem::Version
85
72
  version: 0.9.0
86
- prerelease: false
87
- requirement: *id004
88
- - !ruby/object:Gem::Dependency
89
73
  type: :development
90
- name: rails
91
- version_requirements: &id005 !ruby/object:Gem::Requirement
92
- none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- hash: 5
97
- segments:
98
- - 3
99
- version: "3"
100
74
  prerelease: false
101
- requirement: *id005
102
- - !ruby/object:Gem::Dependency
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - - ! '!='
82
+ - !ruby/object:Gem::Version
83
+ version: 0.9.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: rails
86
+ requirement: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '3'
103
92
  type: :development
104
- name: rspec
105
- version_requirements: &id006 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 7
111
- segments:
112
- - 2
113
- version: "2"
114
93
  prerelease: false
115
- requirement: *id006
116
- - !ruby/object:Gem::Dependency
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '3'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rspec
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '2'
117
108
  type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '2'
116
+ - !ruby/object:Gem::Dependency
118
117
  name: rspec-rails
119
- version_requirements: &id007 !ruby/object:Gem::Requirement
120
- none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 7
125
- segments:
126
- - 2
127
- version: "2"
118
+ requirement: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '2'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '2'
132
+ - !ruby/object:Gem::Dependency
133
+ name: redcarpet
134
+ requirement: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
128
141
  prerelease: false
129
- requirement: *id007
130
- description: " Out-of-box R18n support for Ruby on Rails.\n It is just a wrapper for R18n Rails API and R18n core libraries.\n R18n has nice Ruby-style syntax, filters, flexible locales, custom loaders,\n translation support for any classes, time and number localization, several\n user language support, agnostic core package with out-of-box support for\n Rails, Sinatra, Merb and desktop applications.\n"
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ description: ! " Out-of-box R18n support for Ruby on Rails.\n It is just a wrapper
149
+ for R18n Rails API and R18n core libraries.\n R18n has nice Ruby-style syntax,
150
+ filters, flexible locales, custom loaders,\n translation support for any classes,
151
+ time and number localization, several\n user language support, agnostic core
152
+ package with out-of-box support for\n Rails, Sinatra and desktop applications.\n"
131
153
  email: andrey@sitnik.ru
132
154
  executables: []
133
-
134
155
  extensions: []
135
-
136
- extra_rdoc_files:
137
- - README.rdoc
156
+ extra_rdoc_files:
157
+ - README.md
138
158
  - LICENSE
139
- files:
159
+ files:
140
160
  - .rspec
141
161
  - .yardopts
142
- - Gemfile
143
- - Gemfile.lock
144
162
  - LICENSE
145
- - README.rdoc
163
+ - README.md
146
164
  - Rakefile
147
165
  - lib/r18n-rails.rb
148
166
  - lib/r18n-rails/controller.rb
167
+ - lib/r18n-rails/filters.rb
149
168
  - lib/r18n-rails/helpers.rb
150
169
  - lib/r18n-rails/translated.rb
151
170
  - r18n-rails.gemspec
@@ -153,16 +172,17 @@ files:
153
172
  - spec/app/app/controllers/test_controller.rb
154
173
  - spec/app/app/helpers/application_helper.rb
155
174
  - spec/app/app/i18n/en.yml
175
+ - spec/app/app/i18n/filters.rb
156
176
  - spec/app/app/i18n/ru.yml
177
+ - spec/app/app/mailers/test_mailer.rb
157
178
  - spec/app/app/models/post.rb
158
179
  - spec/app/app/views/test/helpers.html.erb
180
+ - spec/app/app/views/test/safe.html.erb
181
+ - spec/app/app/views/test_mailer/test.text.erb
159
182
  - spec/app/config.ru
160
183
  - spec/app/config/application.rb
161
184
  - spec/app/config/boot.rb
162
- - spec/app/config/database.yml
163
185
  - spec/app/config/environment.rb
164
- - spec/app/config/environments/development.rb
165
- - spec/app/config/environments/production.rb
166
186
  - spec/app/config/environments/test.rb
167
187
  - spec/app/config/initializers/secret_token.rb
168
188
  - spec/app/config/initializers/session_store.rb
@@ -173,39 +193,35 @@ files:
173
193
  - spec/app/script/rails
174
194
  - spec/rails_spec.rb
175
195
  - spec/spec_helper.rb
176
- homepage: http://r18n.rubyforge.org/
196
+ homepage: https://github.com/ai/r18n/tree/master/r18n-rails
177
197
  licenses: []
178
-
179
198
  post_install_message:
180
199
  rdoc_options: []
181
-
182
- require_paths:
200
+ require_paths:
183
201
  - lib
184
- required_ruby_version: !ruby/object:Gem::Requirement
202
+ required_ruby_version: !ruby/object:Gem::Requirement
185
203
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
204
+ requirements:
205
+ - - ! '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ segments:
191
209
  - 0
192
- version: "0"
193
- required_rubygems_version: !ruby/object:Gem::Requirement
210
+ hash: -282881312323170006
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
212
  none: false
195
- requirements:
196
- - - ">="
197
- - !ruby/object:Gem::Version
198
- hash: 3
199
- segments:
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ segments:
200
218
  - 0
201
- version: "0"
219
+ hash: -282881312323170006
202
220
  requirements: []
203
-
204
- rubyforge_project: r18n-rails
205
- rubygems_version: 1.7.2
221
+ rubyforge_project:
222
+ rubygems_version: 1.8.23
206
223
  signing_key:
207
224
  specification_version: 3
208
225
  summary: R18n for Rails
209
226
  test_files: []
210
-
211
227
  has_rdoc:
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source :rubygems
2
-
3
- group :test do
4
- gem 'sqlite3'
5
- end
6
-
7
- gem 'psych', :platforms => :mri_19, :group => [ :test, :development ]
8
-
9
- gem 'r18n-core', :path => '../r18n-core/'
10
- gem 'r18n-rails-api', :path => '../r18n-rails-api/'
11
-
12
- gemspec
data/Gemfile.lock DELETED
@@ -1,130 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- r18n-rails (0.4.14)
5
- r18n-rails-api (= 0.4.14)
6
-
7
- PATH
8
- remote: ../r18n-core/
9
- specs:
10
- r18n-core (0.4.14)
11
-
12
- PATH
13
- remote: ../r18n-rails-api/
14
- specs:
15
- r18n-rails-api (0.4.14)
16
- i18n
17
- r18n-core (= 0.4.14)
18
-
19
- GEM
20
- remote: http://rubygems.org/
21
- specs:
22
- actionmailer (3.2.0)
23
- actionpack (= 3.2.0)
24
- mail (~> 2.4.0)
25
- actionpack (3.2.0)
26
- activemodel (= 3.2.0)
27
- activesupport (= 3.2.0)
28
- builder (~> 3.0.0)
29
- erubis (~> 2.7.0)
30
- journey (~> 1.0.0)
31
- rack (~> 1.4.0)
32
- rack-cache (~> 1.1)
33
- rack-test (~> 0.6.1)
34
- sprockets (~> 2.1.2)
35
- activemodel (3.2.0)
36
- activesupport (= 3.2.0)
37
- builder (~> 3.0.0)
38
- activerecord (3.2.0)
39
- activemodel (= 3.2.0)
40
- activesupport (= 3.2.0)
41
- arel (~> 3.0.0)
42
- tzinfo (~> 0.3.29)
43
- activeresource (3.2.0)
44
- activemodel (= 3.2.0)
45
- activesupport (= 3.2.0)
46
- activesupport (3.2.0)
47
- i18n (~> 0.6)
48
- multi_json (~> 1.0)
49
- arel (3.0.0)
50
- builder (3.0.0)
51
- diff-lcs (1.1.3)
52
- erubis (2.7.0)
53
- hike (1.2.1)
54
- i18n (0.6.0)
55
- journey (1.0.0)
56
- json (1.6.5)
57
- mail (2.4.1)
58
- i18n (>= 0.4.0)
59
- mime-types (~> 1.16)
60
- treetop (~> 1.4.8)
61
- mime-types (1.17.2)
62
- multi_json (1.0.4)
63
- polyglot (0.3.3)
64
- psych (1.2.2)
65
- rack (1.4.1)
66
- rack-cache (1.1)
67
- rack (>= 0.4)
68
- rack-ssl (1.3.2)
69
- rack
70
- rack-test (0.6.1)
71
- rack (>= 1.0)
72
- rails (3.2.0)
73
- actionmailer (= 3.2.0)
74
- actionpack (= 3.2.0)
75
- activerecord (= 3.2.0)
76
- activeresource (= 3.2.0)
77
- activesupport (= 3.2.0)
78
- bundler (~> 1.0)
79
- railties (= 3.2.0)
80
- railties (3.2.0)
81
- actionpack (= 3.2.0)
82
- activesupport (= 3.2.0)
83
- rack-ssl (~> 1.3.2)
84
- rake (>= 0.8.7)
85
- rdoc (~> 3.4)
86
- thor (~> 0.14.6)
87
- rake (0.9.2.2)
88
- rdoc (3.12)
89
- json (~> 1.4)
90
- rspec (2.8.0)
91
- rspec-core (~> 2.8.0)
92
- rspec-expectations (~> 2.8.0)
93
- rspec-mocks (~> 2.8.0)
94
- rspec-core (2.8.0)
95
- rspec-expectations (2.8.0)
96
- diff-lcs (~> 1.1.2)
97
- rspec-mocks (2.8.0)
98
- rspec-rails (2.8.1)
99
- actionpack (>= 3.0)
100
- activesupport (>= 3.0)
101
- railties (>= 3.0)
102
- rspec (~> 2.8.0)
103
- sprockets (2.1.2)
104
- hike (~> 1.2)
105
- rack (~> 1.0)
106
- tilt (~> 1.1, != 1.3.0)
107
- sqlite3 (1.3.5)
108
- thor (0.14.6)
109
- tilt (1.3.3)
110
- treetop (1.4.10)
111
- polyglot
112
- polyglot (>= 0.3.1)
113
- tzinfo (0.3.31)
114
- yard (0.7.4)
115
-
116
- PLATFORMS
117
- ruby
118
-
119
- DEPENDENCIES
120
- bundler (>= 1.0.10)
121
- psych
122
- r18n-core!
123
- r18n-rails!
124
- r18n-rails-api!
125
- rails (>= 3)
126
- rake (>= 0, != 0.9.0)
127
- rspec (>= 2)
128
- rspec-rails (>= 2)
129
- sqlite3
130
- yard
data/README.rdoc DELETED
@@ -1,230 +0,0 @@
1
- = R18n for Rails
2
-
3
- R18n-rails is a gem to add out-of-box R18n support to Rails I18n.
4
-
5
- It is a wrapper for R18n Rails API and R18n core libraries. See R18n core
6
- documentation for more information.
7
-
8
- == Features
9
-
10
- R18n for Rails is fully compatibile with Rails I18n, and add extra features:
11
-
12
- === R18n Syntax
13
-
14
- You can use more compact, explicit and ruby-style syntax.
15
-
16
- Translations in R18n format will be loaded from <tt>app/i18n/_locale_.yml</tt>:
17
-
18
- user:
19
- name: User name is %1
20
- count: !!pl
21
- 0: No users
22
- 1: 1 user
23
- n: %1 users
24
-
25
- R18n extends +t+ helper to add optional R18n syntax:
26
-
27
- t.user.name('John') #=> "User name is John"
28
- t.user.count(5) #=> "5 users"
29
- t.not.exists | 'default' #=> "default"
30
-
31
- === Filters
32
-
33
- R18n has flexible architecture based on filters. Variables, pluralization,
34
- untranslated are common filters, and you can change them all. For example,
35
- write untranslated keys to file:
36
-
37
- R18n::Filters.add(::R18n::Untranslated, :write_untranslated) do
38
- |v, c, translated, untranslated, path|
39
- File.open('untranslated.list', 'w') do |io|
40
- io.puts(path)
41
- end
42
- end
43
-
44
- R18n already has filters for HTML escaping, lambdas, Textile and Markdown:
45
-
46
- hi: !!markdown
47
- **Hi**, people!
48
- greater: !!escape
49
- 1 < 2 is true
50
-
51
- i18n.hi #=> "<p><strong>Hi</strong>, people!</p>"
52
- i18n.greater #=> "1 &lt; 2 is true"
53
-
54
- === Model Translation
55
-
56
- R18n can add i18n support for your ActiveRecord model and any other class
57
- (include DataMapper, MongoMapper, Mongoid):
58
-
59
- 1. Add separate columns for all supported translations:
60
-
61
- def self.up
62
- create_table :posts do |t|
63
- t.string :title_en
64
- t.string :title_ru
65
- end
66
- end
67
-
68
- 2. Add virtual method +title+, which will use <tt>title_<i>locale</i></tt>
69
- methods to find actual translation:
70
-
71
- class Post < ActiveRecord::Base
72
- include R18n::Translated
73
- translations :title
74
- end
75
-
76
- # For Russian user
77
- post = Post.new
78
- post.title_en = 'Post'
79
- post.title_ru = 'Запись'
80
- post.title = 'Запись'
81
-
82
- post.title = 'Другая' # will use title_ru, by first user's locale
83
-
84
- === Time Fomatters
85
-
86
- R18n add +full+ time formatter based on locale info:
87
-
88
- # English
89
- l Time.now, :full #=> "1st of December, 2009 12:00"
90
-
91
- # French
92
- l Time.now, :full #=> "1er décembre 2009 12:00"
93
-
94
- === Locales
95
-
96
- R18n contains locales info, so it supports locale pluralization and fallback
97
- rules for non-English locales out-of-box:
98
-
99
- # Russian have different plural rules:
100
- user:
101
- count: !!pl
102
- 0: Нет пользователей
103
- 1: %1 пользователь
104
- 2: %1 пользователя
105
- n: %1 пользователей
106
-
107
- t.user.count(2) #=> "2 пользователя"
108
- t.user.count(21) #=> "21 пользователь"
109
-
110
- === Autodetect User Locales
111
-
112
- R18n automatically generate fallbacks for current user, based on
113
- user locales list from HTTP_ACCEPT_LANGUAGE, locale info (in some countries
114
- people know several languages), and default locale.
115
-
116
- For example, if user know Kazakh and German, R18n will try find translations in:
117
- Kazakh → German → Russian (second language in Kazakhstan) → English (default
118
- locale).
119
-
120
- === Separated I18n
121
-
122
- You can create another R18n I18n instance with another languages. For example,
123
- to send e-mail for English admin on error with French user:
124
-
125
- puts I18n.t :error # Show error in French
126
-
127
- admin_i18n = R18n::I18n.new(@admin_locales, Rails.root + 'app/i18n')
128
- send_email(admin_i18n.error_messages)
129
-
130
- == How To
131
-
132
- 1. Add <tt>r18n-rails</tt> gem to your <tt>config/environment.rb</tt>:
133
-
134
- config.gem 'r18n-rails'
135
-
136
- Now R18n will autodetect user locales.
137
- 2. Define your way to set locale manually. R18n will find it in
138
- <tt>params[:locale]</tt> or <tt>session[:locale]</tt>. Best way is a put
139
- optional locale prefix to URLs:
140
-
141
- map.connect ':controller/:action'
142
- map.connect ':locale/:controller/:action'
143
-
144
- 3. Print available translations, to choose from them manually (and to helpsearch
145
- engines):
146
-
147
- <ul>
148
- <% r18n.available_locales.each do |locale| %>
149
- <li>
150
- <a href="/<%= locale.code %>/"><%= locale.title %></a>
151
- </li>
152
- <% end %>
153
- </ul>
154
-
155
- 4. Translations in I18n format are stored in
156
- <tt>config/locales/_locale_.yml</tt>:
157
-
158
- en:
159
- user:
160
- name: "User name is %{name}"
161
- count:
162
- zero: "No users"
163
- one: "One user"
164
- many: "%{count} users"
165
-
166
- Translations in R18n format go to <tt>app/i18n/_locale_.yml</tt>:
167
-
168
- user:
169
- name: User name is %1
170
- count: !!pl
171
- 0: No users
172
- 1: 1 user
173
- n: %1 users
174
-
175
- 5. Use translated messages in views. You can use Rails I18n syntax:
176
-
177
- t 'user.name', :name => 'John'
178
- t 'user.count', :count => 5
179
-
180
- or R18n syntax:
181
-
182
- t.user.name(:name => 'John') # for Rails I18n named variables
183
- t.user.name('John') # for R18n variables
184
- t.user.count(5)
185
-
186
- 6. Print dates and numbers in user’s tradition:
187
-
188
- l Date.today, :standard #=> "20/12/2009"
189
- l Time.now, :full #=> "20th of December, 2009 12:00"
190
- l 1234.5 #=> "1,234.5"
191
-
192
- 7. Translate models:
193
-
194
- 1. Add to migration columns for each of the supported locales, named as
195
- <tt><i>name</i>_<i>locale</i></tt>:
196
-
197
- t.string :title_en
198
- t.string :title_ru
199
-
200
- t.string :text_en
201
- t.string :text_ru
202
-
203
- 2. Add <tt>R18n::Translated</tt> mixin to model:
204
-
205
- class Post < ActiveRecord::Base
206
- include R18n::Translated
207
-
208
- 3. Call +translations+ method in model with all columns to be translated:
209
-
210
- translations :title, :text
211
-
212
- Now model will have virtual methods +title+, +text+, <tt>title=</tt>
213
- and <tt>text=</tt>, which will call +title_ru+ or +title_en+ and etc based
214
- on current user locales.
215
-
216
- You can use <tt>R18n::Translated</tt> mixin for any Ruby class, not only for
217
- ActiveRecord models.
218
-
219
- 8. Download translations for Rails system messages (validation, etc) from
220
- https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale and
221
- put them to <tt>config/locales/</tt> (because them use Rails I18n format).
222
-
223
- == License
224
-
225
- R18n is licensed under the GNU Lesser General Public License version 3.
226
- You can read it in LICENSE file or in http://www.gnu.org/licenses/lgpl.html.
227
-
228
- == Author
229
-
230
- Andrey “A.I.” Sitnik <andrey@sitnik.ru>
@@ -1,17 +0,0 @@
1
- development:
2
- adapter: sqlite3
3
- database: db/development.sqlite3
4
- pool: 5
5
- timeout: 5000
6
-
7
- test:
8
- adapter: sqlite3
9
- database: db/test.sqlite3
10
- pool: 5
11
- timeout: 5000
12
-
13
- production:
14
- adapter: sqlite3
15
- database: db/production.sqlite3
16
- pool: 5
17
- timeout: 5000
@@ -1,11 +0,0 @@
1
- App::Application.configure do
2
- config.cache_classes = false
3
- config.whiny_nils = true
4
- config.consider_all_requests_local = true
5
- config.action_view.debug_rjs = true
6
- config.action_controller.perform_caching = false
7
- config.action_mailer.raise_delivery_errors = false
8
- config.active_support.deprecation = :log
9
- config.action_dispatch.best_standards_support = :builtin
10
- end
11
-
@@ -1,9 +0,0 @@
1
- App::Application.configure do
2
- config.cache_classes = true
3
- config.consider_all_requests_local = false
4
- config.action_controller.perform_caching = true
5
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
6
- config.serve_static_assets = false
7
- config.i18n.fallbacks = true
8
- config.active_support.deprecation = :notify
9
- end