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 +5 -5
- data/Gemfile +9 -9
- data/LICENSE.txt +20 -20
- data/README.md +44 -33
- data/Rakefile +53 -53
- data/VERSION +1 -1
- data/app/views/components/lolita/configuration/tab/translation/_display.html.erb +78 -76
- data/config/locales/en.yml +9 -8
- data/config/locales/lv.yml +9 -0
- data/lib/generators/lolita_translation/USAGE +8 -8
- data/lib/generators/lolita_translation/has_translations_generator.rb +8 -8
- data/lib/lolita-translation.rb +11 -11
- data/lib/lolita-translation/configuration/tab/translation.rb +13 -13
- data/lib/lolita-translation/has_translations.rb +294 -294
- data/lib/lolita-translation/rails.rb +4 -4
- data/lib/lolita-translation/string.rb +18 -18
- data/lib/tasks/has_translations_tasks.rake +4 -4
- data/lolita-translation.gemspec +3 -3
- data/lolita-translations.gemspec +60 -60
- data/spec/has_translations_spec.rb +43 -43
- data/spec/spec.opts +2 -2
- data/spec/spec_helper.rb +98 -98
- metadata +14 -14
- data/app/views/lolita/has_translations/_tab.html.erb +0 -78
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
I18n.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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.
|
1
|
+
0.0.4
|
@@ -1,76 +1,78 @@
|
|
1
|
-
<% if resource.new_record? %>
|
2
|
-
<
|
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
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
textarea.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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 %>
|
data/config/locales/en.yml
CHANGED
@@ -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."
|