lolita-translation 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,150 +31,3 @@ This is a fork of http://github.com/dmitry/has_translations with small changes.
31
31
  Blog::Article.sync_translation_table!
32
32
 
33
33
  And run `rake db:seed` and it will do it for you. It also updates the table if you add news columns in the `translations :name, :title .....` method.
34
-
35
- HasTranslations v0.3.1
36
- ======================
37
-
38
- This simple plugin creates translations for your model.
39
- Uses delegation pattern: http://en.wikipedia.org/wiki/Delegation_pattern
40
-
41
- Tested with ActiveRecord versions: 2.3.5, 2.3.9, 3.0.0 (to test with Rails 3 run `rake RAILS_VERSION=3.0`)
42
-
43
- Installation
44
- ============
45
-
46
- gem install has_translations
47
-
48
- or as a plugin
49
-
50
- script/plugin install git://github.com/dmitry/has_translations.git
51
-
52
- Example
53
- =======
54
-
55
- For example you have Article model and you want to have title and text to be translated.
56
-
57
- Create model named ArticleTranslation (Rule: [CamelCaseModelName]Translation)
58
-
59
- Migration should have `locale` as a string with two letters and `belongs_to associative id`, like:
60
-
61
- class CreateArticleTranslations < ActiveRecord::Migration
62
- def self.up
63
- create_table :article_translations do |t|
64
- t.integer :article_id, :null => false
65
- t.string :locale, :null => false, :limit => 2
66
- t.string :title, :null => false
67
- t.text :text, :null => false
68
- end
69
-
70
- add_index :article_translations, [:article_id, :locale], :unique => true
71
- end
72
-
73
- def self.down
74
- drop_table :article_translations
75
- end
76
- end
77
-
78
- Add to article model `translations :value1, :value2`:
79
-
80
- class Article < ActiveRecord::Base
81
- translations :title, :text
82
- end
83
-
84
- And that's it. Now you can add your translations using:
85
-
86
- article = Article.create
87
-
88
- article.translations.create(:locale => 'en', :title => 'title', :text => 'text') # or ArticleTranslation.create(:article => article, :locale => 'en', :title => 'title', :text => 'text')
89
- article.translations.create(:locale => 'ru', :title => 'заголовок', :text => 'текст')
90
- article.reload # reload cached translations association array
91
- I18n.locale = :en
92
- article.text # text
93
- I18n.locale = :ru
94
- article.title # заголовок
95
-
96
- You can use text filtering plugins, like acts_as_sanitiled and validations, and anything else that is available to the ActiveRecord:
97
-
98
- class ArticleTranslation < ActiveRecord::Base
99
- acts_as_sanitiled :title, :text
100
-
101
- validates_presence_of :title, :text
102
- validates_length_of :title, :maximum => 100
103
- end
104
-
105
- Options:
106
-
107
- * :fallback => true [default: false] - fallback 1) default locale; 2) first from translations;
108
- * :reader => false [default: true] - add reader to the model object
109
- * :writer => true [default: false] - add writer to the model object
110
- * :nil => nil [default: ''] - if no model found by default returns empty string, you can set it for example to `nil` (no `lambda` supported)
111
-
112
- It's better to use translations with `accepts_nested_attributes_for`:
113
-
114
- accepts_nested_attributes_for :translations
115
-
116
- To create a form for this you can use `all_translations` method. It's have all
117
- the locales that you have added using the `I18n.available_locales=` method.
118
- If translation for one of the locale isn't exists, it will build it with :locale.
119
- So an example which I used in the production (using `formtastic` gem):
120
-
121
- <% semantic_form_for [:admin, @article] do |f| %>
122
- <%= f.error_messages %>
123
-
124
- <% f.inputs :name => "Basic" do %>
125
- <% object.all_translations.values.each do |translation| %>
126
- <% f.semantic_fields_for :translations, translation do |ft| %>
127
- <%= ft.input :title, :label => "Title #{ft.object.locale.to_s.upcase}" %>
128
- <%= ft.input :text, :label => "Text #{ft.object.locale.to_s.upcase}" %>
129
- <%= ft.input :locale, :as => :hidden %>
130
- <% end %>
131
- <% end %>
132
- <% end %>
133
- <% end %>
134
-
135
- Sometimes you have validations in the translation model, and if you want to skip
136
- the translations that you don't want to add to the database, you can use
137
- `:reject_if` option, which is available for the `accepts_nested_attributes_for`:
138
-
139
- accepts_nested_attributes_for :translations, :reject_if => lambda { |attrs| attrs['title'].blank? && attrs['text'].blank? }
140
-
141
- named_scope `translated(locale)` - with that named_scope you can find only
142
- those models that is translated only to specific locale. For example if you will
143
- have 2 models, one is translated to english and the second one isn't, then it
144
- `Article.translated(:en)` will find only first one.
145
-
146
- PS
147
- ==
148
-
149
- I suggest you to use latest i18n gem, include it in your rails 2 environment:
150
-
151
- config.gem 'i18n', :version => '0.4.1' # change version to the latest
152
-
153
- TODO
154
- ====
155
-
156
- * add installation description to readme
157
- * model and migration generators
158
- * caching
159
- * write more examples: fallback feature
160
- * write blog post about comparison and benefits of this plugin between another translation model plugins
161
-
162
-
163
- Alternatives
164
- ============
165
-
166
- I know three of them:
167
-
168
- * [puret](http://github.com/jo/puret) - special for Rails 3 and almost the same as this project.
169
- * [globalite2](http://github.com/joshmh/globalize2) - a lot of magic.
170
- * [model_translations](http://github.com/janne/model_translations) - almost the same as this project, but more with more code in lib.
171
- * [translatable_columns](http://github.com/iain/translatable_columns) - different approach: every column have own postfix "_#{locale}" in the same table (sometimes it could be fine).
172
-
173
-
174
- Used in
175
- =======
176
-
177
- [noch.es](http://noch.es/), [eten.es](http://www.eten.es), [sem.ee](http://sem.ee/)
178
-
179
-
180
- Copyright (c) 2009-2010 [Dmitry Polushkin], released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -69,7 +69,8 @@
69
69
  }
70
70
  $.each(columns,function(i,column){
71
71
  $('#has_translations_'+column).blur(function(){
72
- $('#object_translation_fields_'+$("#has_translations_locale").val()+' .'+$(this).attr("name").split("_")[2]).val($(this).val())
72
+ alert('#object_translation_fields_'+$("#has_translations_locale").val()+' .'+column)
73
+ $('#object_translation_fields_'+$("#has_translations_locale").val()+' .'+column).val($(this).val())
73
74
  })
74
75
  })
75
76
  </script>
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lolita-translation}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ITHouse", "Gatis Tomsons", "Arturs Meisters"]
12
- s.date = %q{2011-08-01}
12
+ s.date = %q{2011-08-02}
13
13
  s.description = %q{Translates models in Lolita}
14
14
  s.email = %q{support@ithouse.lv}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolita-translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,12 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-01 00:00:00.000000000 +03:00
14
+ date: 2011-08-02 00:00:00.000000000 +03:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
19
- requirement: &74136740 !ruby/object:Gem::Requirement
19
+ requirement: &80022330 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 3.0.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *74136740
27
+ version_requirements: *80022330
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: shoulda
30
- requirement: &74136150 !ruby/object:Gem::Requirement
30
+ requirement: &80001760 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
- version_requirements: *74136150
38
+ version_requirements: *80001760
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: bundler
41
- requirement: &74135560 !ruby/object:Gem::Requirement
41
+ requirement: &80000980 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: 1.0.0
47
47
  type: :development
48
48
  prerelease: false
49
- version_requirements: *74135560
49
+ version_requirements: *80000980
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: jeweler
52
- requirement: &74118460 !ruby/object:Gem::Requirement
52
+ requirement: &79999400 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: 1.5.2
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *74118460
60
+ version_requirements: *79999400
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rcov
63
- requirement: &74117810 !ruby/object:Gem::Requirement
63
+ requirement: &79998150 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ! '>='
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '0'
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *74117810
71
+ version_requirements: *79998150
72
72
  description: Translates models in Lolita
73
73
  email: support@ithouse.lv
74
74
  executables: []
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: 283995089
118
+ hash: -1027194769
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements: