lolita-translation 0.0.4 → 0.1.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/.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
@@ -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,44 +1,43 @@
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.
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 `Article.sync_translation_table!` to your `db/seeds.rb` and run it.
13
+
14
+ ### Examples
15
+
16
+ Translations table holds only translations, but not the original data from default_locale, so:
17
+
18
+ I18n.default_locale = :en
19
+ I18n.locale = :lv
20
+
21
+ a = Article.create :title => "Title in EN"
22
+ a.title # returns blank, because current locale is LV and there is no translation in it
23
+ #=> ""
24
+ I18n.locale = :en
25
+ a.title
26
+ #=> "Title in EN"
27
+ a.translations.create :title => "Title in LV", :locale => 'lv'
28
+ I18n.locale = :lv
29
+ a.title
30
+ #=> "Title in LV"
31
+
32
+ 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.
33
+
34
+ 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.
35
+
36
+
37
+ ### Credits
38
+
39
+ Inspired by http://github.com/dmitry/has_translations
40
+
41
+ ### License
42
+
43
+ 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,5 @@
1
- 0.0.4
1
+ <<<<<<< HEAD
2
+ 0.1.0
3
+ =======
4
+ 0.0.4
5
+ >>>>>>> 38796e7ad979f60efef15f97f75b327353a5833b
@@ -0,0 +1,7 @@
1
+ <% content_for :script do %>
2
+ <%=javascript_include_tag "lolita/translation"%>
3
+ <% end %>
4
+
5
+ <% content_for :style do %>
6
+ <%= stylesheet_link_tag 'lolita/translation.css', :media => 'screen, projection' %>
7
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <% locale = tab_form.object.respond_to?(:locale) ? tab_form.object.locale : ::I18n.default_locale %>
2
+ <div class="language-wrap" id="<%=locale%>_attributes_for_<%= tab.name %>" style="display:<%=locale == ::I18n.default_locale ? "block" : "none"%>">
3
+ <%=content %>
4
+ </div>
@@ -0,0 +1,8 @@
1
+ <ul class="tab-language-switch" id="<%=tab.name%>_language_swith">
2
+ <% I18n.available_locales.each do |short_locale| %>
3
+ <% active = I18n.default_locale == short_locale %>
4
+ <li class="<%=active ? "active" : ""%>" data-locale="<%=short_locale%>" data-tab="<%=tab.name%>">
5
+ <%= short_locale.to_s.capitalize %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
@@ -1,9 +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
9
  only-update: "Translation is possible only after save."
@@ -1,8 +1,8 @@
1
- Description:
2
- Explain the generator
3
-
4
- Example:
5
- ./script/generate has_translations Thing
6
-
7
- This will create:
8
- what/will/it/create
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ ./script/generate has_translations Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,13 @@
1
+ require 'generators/helpers/file_helper'
2
+ module LolitaTranslation
3
+ module Generators
4
+ class AssetsGenerator < Rails::Generators::Base
5
+ include Lolita::Generators::FileHelper
6
+ desc "Copy all from public directory to project public directory."
7
+ def copy_all
8
+ root=File.expand_path("../../../../",__FILE__)
9
+ copy_dir("public",:root=>root)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,8 +1,8 @@
1
- class HasTranslationsGenerator < Rails::Generator::NamedBase
2
- def manifest
3
- record do |m|
4
- # m.directory "lib"
5
- # m.template 'README', "README"
6
- end
7
- end
8
- end
1
+ class HasTranslationsGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # m.directory "lib"
5
+ # m.template 'README', "README"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+ module LolitaMenu
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ desc "Copy assets."
6
+
7
+ def copy_assets
8
+ generate("lolita_menu:assets")
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -1,12 +1,60 @@
1
-
2
- require 'lolita-translation/string.rb'
3
- require 'lolita-translation/has_translations.rb'
4
- require 'lolita-translation/rails'
5
-
6
- module Lolita
7
- module Configuration
8
- module Tab
9
- autoload :Translation, "lolita-translation/configuration/tab/translation"
10
- end
11
- end
1
+
2
+ require 'lolita-translation/string.rb'
3
+ require 'lolita-translation/has_translations.rb'
4
+ require 'lolita-translation/rails'
5
+
6
+ module Lolita
7
+ module Translation
8
+ class << self
9
+ def translatable?(tab)
10
+ tab.dbi.klass.respond_to?(:translations) && (tab.fields.map(&:name) & tab.dbi.klass.translation_attrs).any?
11
+ end
12
+
13
+ def create_translations_nested_form(resource,tab)
14
+ resource.build_nested_translations
15
+ nested_form = Lolita::Configuration::NestedForm.new(tab,:translations)
16
+ nested_form.expandable = false
17
+ nested_form.field_style = :normal
18
+
19
+ fields = tab.fields.reject{|field|
20
+ !resource.class.translation_attrs.include?(field.name.to_sym)
21
+ }
22
+ fields << Lolita::Configuration::Field.add(nested_form.dbi,:locale,:hidden)
23
+ nested_form.fields=fields
24
+ nested_form
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ Lolita::Hooks.component(:"/lolita/configuration/tab/form").before do
31
+ tab = self.component_locals[:tab]
32
+ if Lolita::Translation.translatable?(tab)
33
+ self.send(:render_component,"lolita/translation",:switch, :tab => tab)
34
+ end
35
+ end
36
+
37
+ Lolita::Hooks.component(:"/lolita/configuration/tab/fields").after do
38
+ tab = self.component_locals[:tab]
39
+ if Lolita::Translation.translatable?(tab)
40
+ self.render_component Lolita::Translation.create_translations_nested_form(self.resource,tab)
41
+ end
42
+ end
43
+
44
+ Lolita::Hooks.component(:"/lolita/configuration/tab/fields").around do
45
+ tab = self.component_locals[:tab]
46
+ if Lolita::Translation.translatable?(tab)
47
+ self.send(:render_component,"lolita/translation",:language_wrap,:tab => tab, :content => let_content)
48
+ end
49
+ end
50
+
51
+ Lolita::Hooks.component(:"/lolita/configuration/nested_form/fields").around do
52
+ tab = self.component_locals[:nested_form].parent
53
+ if Lolita::Translation.translatable?(tab)
54
+ self.send(:render_component,"lolita/translation",:language_wrap, :tab => tab, :content => let_content)
55
+ end
56
+ end
57
+
58
+ Lolita::Hooks.component(:"/lolita/configuration/tabs/display").before do
59
+ self.render_component "lolita/translation", :assets
12
60
  end