lolita-translation 0.0.3 → 0.0.4

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/.document CHANGED
@@ -1,5 +1,5 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rails", ">=3.0.0"
4
- group :development do
5
- gem "shoulda", ">= 0"
6
- gem "bundler", "~> 1.0.0"
7
- gem "jeweler", "~> 1.5.2"
8
- gem "rcov", ">= 0"
9
- end
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", ">=3.0.0"
4
+ group :development do
5
+ gem "shoulda", ">= 0"
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.5.2"
8
+ gem "rcov", ">= 0"
9
+ end
data/LICENSE.txt CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2011 ITHouse
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.
1
+ Copyright (c) 2011 ITHouse
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.md CHANGED
@@ -1,33 +1,44 @@
1
- LolitaHasTranslations
2
- ======================
3
-
4
- This is a fork of http://github.com/dmitry/has_translations with small changes.
5
-
6
- 1. The main difference is that the translations table holds only translations, but not the original data from default_locale, so:
7
-
8
- I18n.default_locale = :en
9
- I18n.locale = :lv
10
-
11
- a = Article.create :title => "Title in EN"
12
- a.title
13
- # returns blank, because current locale is LV and there is no translation in it
14
- => ""
15
- I18n.locale = :en
16
- a.title
17
- => "Title in EN"
18
- a.translations.create :title => "Title in LV", :locale => 'lv'
19
- I18n.locale = :lv
20
- a.title
21
- => "Title in LV"
22
-
23
- 2. When a "find" is executed and current language is not the same as default language then :translations are added to :includes
24
- to pre fetch all translations.
25
-
26
- 3. The "ModelNameTranslation" class is created for you automaticly with all validations for ranslated fields. Of course you can create it manualy for custom vlidations and other.
27
-
28
- 4. You dont have to create migration for the translation table, just add a line for every translated model in `db/seed.rb`
29
-
30
- TextPage.sync_translation_table!
31
- Blog::Article.sync_translation_table!
32
-
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.
1
+ # LolitaTranslations
2
+
3
+
4
+ ### Install
5
+
6
+ gem "lolita"
7
+ gem "lolita-translation"
8
+
9
+ ### Usage
10
+
11
+ 1. Call `translations :title, :body` in your model and pass column names to translate.
12
+ 2. Add `tab :translation` into `lolita do ....` block to see the translation tab.
13
+ 3. Add `Article.sync_translation_table!` to your `db/seeds.rb` and run it.
14
+
15
+ ### Examples
16
+
17
+ Translations table holds only translations, but not the original data from default_locale, so:
18
+
19
+ I18n.default_locale = :en
20
+ I18n.locale = :lv
21
+
22
+ a = Article.create :title => "Title in EN"
23
+ a.title # returns blank, because current locale is LV and there is no translation in it
24
+ #=> ""
25
+ I18n.locale = :en
26
+ a.title
27
+ #=> "Title in EN"
28
+ a.translations.create :title => "Title in LV", :locale => 'lv'
29
+ I18n.locale = :lv
30
+ a.title
31
+ #=> "Title in LV"
32
+
33
+ When a "find" is executed and current language is not the same as default language then `:translations` are added to `:includes` to pre fetch all translations.
34
+
35
+ The `ModelNameTranslation` class is created for you automaticly with all validations for ranslated fields. Of course you can create it manualy for custom vlidations and other.
36
+
37
+
38
+ ### Credits
39
+
40
+ Inspired by http://github.com/dmitry/has_translations
41
+
42
+ ### License
43
+
44
+ Copyright © 2011 ITHouse. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,53 +1,53 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "lolita-translation"
16
- gem.homepage = "http://github.com/ithouse/lolita-translations"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Lolita models translation plugin}
19
- gem.description = %Q{Translates models in Lolita}
20
- gem.email = "support@ithouse.lv"
21
- gem.authors = ["ITHouse", "Gatis Tomsons", "Arturs Meisters"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'spec'
32
- test.pattern = 'spec/**/*_spec.rb'
33
- test.verbose = true
34
- end
35
-
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'spec'
39
- test.pattern = 'spec/**/*_spec.rb'
40
- test.verbose = true
41
- end
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "lolita-translation #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "lolita-translation"
16
+ gem.homepage = "http://github.com/ithouse/lolita-translations"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Lolita models translation plugin}
19
+ gem.description = %Q{Translates models in Lolita}
20
+ gem.email = "support@ithouse.lv"
21
+ gem.authors = ["ITHouse", "Gatis Tomsons", "Arturs Meisters"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'spec'
32
+ test.pattern = 'spec/**/*_spec.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'spec'
39
+ test.pattern = 'spec/**/*_spec.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "lolita-translation #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,76 +1,78 @@
1
- <% if resource.new_record? %>
2
- <p>-</p>
3
- <% else %>
4
- <form "#">
5
- <div class="tab-content">
6
- <div class="field" id="field_translation_language">
7
- <label for="translation_language"><%=I18n.t("lolita.tabs.translation.fields.language")%>
8
- <div class="field-value" id="field_translation_language_value">
9
- <%= select_tag :has_translations_locale, options_for_select([""] + I18n.available_locales.clone.delete_if{|l| l == I18n.default_locale}), :onchange => "switch_has_translations_language($(this))" %>
10
- </div>
11
- </div>
12
-
13
- <div id="has_translations_fields" class="field" style="display: none">
14
- <% resource.class.columns_has_translations.each do |column| %>
15
- <label for="<%=column.name%>_field"><%=resource.class.human_attribute_name(column.name)%></label>
16
- <div class="fl field-value" id="<%=column.name%>_field">
17
- <% if column.type == :string %>
18
- <%= text_field_tag 'has_translations_' + column.name, nil, :class => 'txt' %>
19
- <% elsif column.type == :text %>
20
- <%= text_area_tag 'has_translations_' + column.name, nil, :class => "textarea",:rows=>20, :cols=>40 %>
21
- <% end %>
22
- </div>
23
- <% end %>
24
- </div>
25
- </div>
26
- </form>
27
- <% resource.build_nested_translations %>
28
- <%= form_for resource, :url => "/" do |form| %>
29
- <%= form.fields_for :translations do |tf| %>
30
- <div id="object_translation_fields_<%= tf.object.locale %>">
31
- <% resource.class.columns_has_translations.each do |column| %>
32
- <%= tf.hidden_field column.name, :class => column.name %>
33
- <% end %>
34
- <%= tf.hidden_field :id, :class => "id" %>
35
- <%= tf.hidden_field tf.object.class.master_id, :value => resource.id %>
36
- <%= tf.hidden_field :locale, :class => "locale" %>
37
- </div>
38
- <% end %>
39
- <% end %>
40
- <script type="text/javascript">
41
- var columns = [<%= resource.class.columns_has_translations.map{|r| "'#{r.name}'"}.join(",") %>];
42
- var blur = false;
43
- function switch_has_translations_language(select){
44
- var locale = select.val();
45
- if(locale == ""){
46
- $('#has_translations_fields').hide()
47
- }else{
48
- $.each(columns,function(i,column){
49
- var content = $('#object_translation_fields_'+locale+' .'+column).val();
50
- $('#has_translations_'+column).val(content);
51
- if($('#has_translations_'+column).get(0).tagName == 'TEXTAREA'){
52
- tinymce.EditorManager.getInstanceById('has_translations_'+column).setContent(content);
53
- }
54
- });
55
- $('#has_translations_fields').show()
56
- }
57
- if(!blur){
58
- $.each($('#has_translations_fields textarea'), function(i,area){
59
- var item = $(area);
60
- var tiny_editor = tinymce.EditorManager.getInstanceById(item.attr("id"));
61
- tinymce.dom.Event.add(tiny_editor.getWin(), "blur", function(){
62
- var textarea = $(tinymce.EditorManager.getInstanceById(item.attr("id")).getElement());
63
- tiny_editor.save();
64
- textarea.blur();
65
- });
66
- });
67
- blur = true;
68
- }
69
- }
70
- $.each(columns,function(i,column){
71
- $('#has_translations_'+column).blur(function(){
72
- $('#object_translation_fields_'+$("#has_translations_locale").val()+' .'+column).val($(this).val())
73
- })
74
- })
75
- </script>
76
- <% end %>
1
+ <% if resource.new_record? %>
2
+ <form "#"><%= t('lolita.tabs.translation.only-update') %></form>
3
+ <% else %>
4
+ <form "#">
5
+ <div class="tab-content">
6
+ <div class="field" id="field_translation_language">
7
+ <label for="translation_language"><%=I18n.t("lolita.tabs.translation.fields.language")%>
8
+ <div class="field-value" id="field_translation_language_value">
9
+ <%= select_tag :has_translations_locale, options_for_select([""] + I18n.available_locales.clone.delete_if{|l| l == I18n.default_locale}), :onchange => "switch_has_translations_language($(this))" %>
10
+ </div>
11
+ </div>
12
+
13
+ <div id="has_translations_fields" class="field" style="display: none">
14
+ <% resource.class.columns_has_translations.each do |column| %>
15
+ <label for="<%=column.name%>_field"><%=resource.class.human_attribute_name(column.name)%></label>
16
+ <div class="fl field-value" id="<%=column.name%>_field">
17
+ <% if column.type == :string %>
18
+ <%= text_field_tag 'has_translations_' + column.name, nil, :class => 'txt' %>
19
+ <% elsif column.type == :text %>
20
+ <%= text_area_tag 'has_translations_' + column.name, nil,:rows=>20, :cols=>40 %>
21
+ <% end %>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+ </div>
26
+ </form>
27
+ <% resource.build_nested_translations %>
28
+ <%= form_for resource, :url => "/" do |form| %>
29
+ <%= form.fields_for :translations do |tf| %>
30
+ <div id="object_translation_fields_<%= tf.object.locale %>">
31
+ <% resource.class.columns_has_translations.each do |column| %>
32
+ <%= tf.hidden_field column.name, :class => column.name %>
33
+ <% end %>
34
+ <%= tf.hidden_field :id, :class => "id" %>
35
+ <%= tf.hidden_field tf.object.class.master_id, :value => resource.id %>
36
+ <%= tf.hidden_field :locale, :class => "locale" %>
37
+ </div>
38
+ <% end %>
39
+ <% end %>
40
+ <script type="text/javascript">
41
+ var columns = [<%= resource.class.columns_has_translations.map{|r| "'#{r.name}'"}.join(",") %>];
42
+ var blur = false;
43
+ function switch_has_translations_language(select){
44
+ var locale = select.val();
45
+ if(locale == ""){
46
+ $('#has_translations_fields').hide()
47
+ }else{
48
+ $.each(columns,function(i,column){
49
+ var content = $('#object_translation_fields_'+locale+' .'+column).val();
50
+ $('#has_translations_'+column).val(content);
51
+ if($('#has_translations_'+column).get(0).tagName == 'TEXTAREA'){
52
+ tinymce.EditorManager.getInstanceById('has_translations_'+column).setContent(content);
53
+ $('#has_translations_'+column+'_tbl').css('width','100%').css('height','250px');
54
+ $('#has_translations_'+column+'_ifr').css('width','100%').css('height','250px');
55
+ }
56
+ });
57
+ $('#has_translations_fields').show()
58
+ }
59
+ if(!blur){
60
+ $.each($('#has_translations_fields textarea'), function(i,area){
61
+ var item = $(area);
62
+ var tiny_editor = tinymce.EditorManager.getInstanceById(item.attr("id"));
63
+ tinymce.dom.Event.add(tiny_editor.getWin(), "blur", function(){
64
+ var textarea = $(tinymce.EditorManager.getInstanceById(item.attr("id")).getElement());
65
+ tiny_editor.save();
66
+ textarea.blur();
67
+ });
68
+ });
69
+ blur = true;
70
+ }
71
+ }
72
+ $.each(columns,function(i,column){
73
+ $('#has_translations_'+column).blur(function(){
74
+ $('#object_translation_fields_'+$("#has_translations_locale").val()+' .'+column).val($(this).val())
75
+ })
76
+ })
77
+ </script>
78
+ <% end %>
@@ -1,8 +1,9 @@
1
- en:
2
- lolita:
3
- tabs:
4
- titles:
5
- translation: Translation
6
- translation:
7
- fields:
8
- language: Language
1
+ en:
2
+ lolita:
3
+ tabs:
4
+ titles:
5
+ translation: Translation
6
+ translation:
7
+ fields:
8
+ language: Language
9
+ only-update: "Translation is possible only after save."
@@ -0,0 +1,9 @@
1
+ lv:
2
+ lolita:
3
+ tabs:
4
+ titles:
5
+ translation: Tulkojums
6
+ translation:
7
+ fields:
8
+ language: Valoda
9
+ only-update: "Tulkot iespējams tikai pēc saglabāšanas."