lolita-translation 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc20174ac98f712d9ee2a4f45973cc8cca9e0286
4
+ data.tar.gz: cc14813d6a22f407017347e9e4cb467368e859c2
5
+ SHA512:
6
+ metadata.gz: b90088d1f9c8cbc0b7ef7e296da256847a64c39ca0132dcad28e1198fc26cb5ba6282ec22cc9e8757e8b5a89765112261a90e5a77f7cbadbd5956e293170c4e2
7
+ data.tar.gz: b1bcdf5e21767e1fb38c6d476fa9570619be40c5e47bb8829b24061753e5b6793d918bd4b10a503faac03681ef36b6eadf411e7f3931cc0de3413b2d29ee2565
data/Gemfile CHANGED
@@ -1,3 +1,15 @@
1
- source :rubygems
1
+ source "http://rubygems.org"
2
+
2
3
  gemspec
3
4
 
5
+ group :test do
6
+ gem 'rails', '~> 3.2.12'
7
+ gem 'rspec-rails', '~> 2.14'
8
+ gem 'ffaker', '~> 1.16.2'
9
+ gem 'capybara', '~> 2.1'
10
+ gem 'selenium-webdriver', '~> 2.33.0'
11
+ gem 'sqlite3', '~> 1.3.7'
12
+ gem 'byebug'
13
+ gem 'cover_me'
14
+ gem "coffee-rails"
15
+ end
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  gem "lolita-translation"
7
7
 
8
8
  ### Usage
9
-
9
+
10
10
  1. Add `include Lolita::Translation` in your model.
11
11
  2. Call `translate :title, :body` in your model and pass column names to translate.
12
12
  3. Add `Article.sync_translation_table!` to your `db/seeds.rb` and run it.
@@ -20,7 +20,7 @@ Translations table holds only translations, but not the original data from defau
20
20
 
21
21
  I18n.default_locale = :en
22
22
  I18n.locale = :lv
23
-
23
+
24
24
  a = Article.create :title => "Title in EN"
25
25
  a.title # returns blank, because current locale is LV and there is no translation in it
26
26
  #=> ""
@@ -29,7 +29,7 @@ Translations table holds only translations, but not the original data from defau
29
29
  #=> "Title in EN"
30
30
  a.translations.create :title => "Title in LV", :locale => 'lv'
31
31
  I18n.locale = :lv
32
- a.title
32
+ a.title
33
33
  #=> "Title in LV"
34
34
 
35
35
  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.
@@ -41,6 +41,6 @@ The `ModelNameTranslation` class is created for you automaticly with all validat
41
41
 
42
42
  Inspired by http://github.com/dmitry/has_translations
43
43
 
44
- ### License
44
+ ### License
45
45
 
46
46
  Copyright © 2011 ITHouse. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'rspec/core/rake_task'
3
4
 
4
5
  Bundler::GemHelper.install_tasks
5
-
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -1,7 +1,6 @@
1
1
  $(function(){
2
- $(".tab-language-switch li").live("click",function(){
2
+ $(".tab-language-switch li").on("click",function(){
3
3
  $(this).parent().children("li").removeClass("active");
4
- //$(".tab-language-switch li").removeClass("active");
5
4
  $(this).addClass("active");
6
5
  var locale = $(this).data("locale"),
7
6
  tab_name = $(this).data("tab"),
@@ -43,13 +43,13 @@ module Lolita
43
43
  def override_klass_attributes method_names
44
44
  method_names.each do |method_name, attribute|
45
45
  validate_attribute_method_and_attribute(method_name, attribute)
46
- base_klass.instance_eval do
47
- define_method(method_name) do
46
+ base_klass.instance_eval do
47
+ define_method(method_name) do
48
48
  translation_record.attribute(attribute)
49
49
  end
50
50
  end
51
51
  end
52
- end
52
+ end
53
53
 
54
54
  private
55
55
 
@@ -59,7 +59,7 @@ module Lolita
59
59
 
60
60
  def validate_attribute_method_and_attribute(method_name, attribute)
61
61
  raise ArgumentError.new("#{method_name} is not valid attribute reader name") unless method_name
62
- raise ArgumentError.new("#{attribute} is not valid attribute name") unless attribute
62
+ raise ArgumentError.new("#{attribute} is not valid attribute name") unless attribute
63
63
  end
64
64
 
65
65
  def implementation_warn
@@ -100,4 +100,4 @@ module Lolita
100
100
 
101
101
  end
102
102
  end
103
- end
103
+ end
@@ -20,8 +20,8 @@ module Lolita
20
20
 
21
21
  def override_klass_attributes(attributes)
22
22
  add_ar_klass_attr_accessible(attributes + default_attributes)
23
- expanded_attributes = attributes.inject({}){|hsh,attribute|
24
- hsh[attribute] = attribute
23
+ expanded_attributes = attributes.inject({}){|hsh,attribute|
24
+ hsh[attribute] = attribute
25
25
  hsh
26
26
  }
27
27
  super(expanded_attributes)
@@ -34,14 +34,14 @@ module Lolita
34
34
  end
35
35
 
36
36
  def add_ar_klass_attr_accessible attributes
37
- klass.class_eval do
37
+ klass.class_eval do
38
38
  attr_accessible :locale, *attributes
39
39
  end
40
40
  end
41
41
 
42
42
  def add_ar_klass_associations
43
43
  if self.configuration
44
- klass.belongs_to association_name, :inverse_of => translations_association_name
44
+ klass.belongs_to association_name
45
45
  end
46
46
  end
47
47
 
@@ -50,13 +50,13 @@ module Lolita
50
50
  ar_translation_builder = self
51
51
 
52
52
  klass.validates(:locale,{
53
- :presence => true,
53
+ :presence => true,
54
54
  :uniqueness => {:scope => association_key},
55
55
  })
56
56
  klass.validates(association_name, :presence => true, :on => :update)
57
57
  klass.validates_each(:locale) do |record, attr, value|
58
58
  original_record = record.send(ar_translation_builder.association_name)
59
- if original_record && original_record.original_locale.to_s == value.to_s
59
+ if original_record && original_record.original_locale.to_s == value.to_s
60
60
  record.errors.add(attr, 'is used as default locale')
61
61
  end
62
62
  end
@@ -65,8 +65,8 @@ module Lolita
65
65
 
66
66
  def add_ar_klass_class_methods
67
67
  ar_translation_builder = self
68
- klass.singleton_class.instance_eval do
69
- define_method(:table_name) do
68
+ klass.singleton_class.instance_eval do
69
+ define_method(:table_name) do
70
70
  ar_translation_builder.table_name
71
71
  end
72
72
  end
@@ -75,10 +75,9 @@ module Lolita
75
75
  def call_base_klass_class_methods
76
76
  if self.configuration
77
77
  base_klass.has_many(translations_association_name, {
78
- :class_name => class_name,
79
- :foreign_key => association_key,
80
- :dependent => :destroy,
81
- :inverse_of => association_name
78
+ :class_name => class_name,
79
+ :foreign_key => association_key,
80
+ :dependent => :destroy
82
81
  })
83
82
  base_klass.accepts_nested_attributes_for translations_association_name, :allow_destroy => true, :reject_if => nested_attributes_rejection_proc
84
83
  base_klass.attr_accessible :translations_attributes, locale_field_name
@@ -94,11 +93,11 @@ module Lolita
94
93
  def add_validations_to_base_klass
95
94
  if base_klass.column_names.include?(locale_field_name.to_s)
96
95
  base_klass.validates locale_field_name, :presence => true
97
- base_klass.before_validation do
96
+ base_klass.before_validation do
98
97
  def_locale = self.send(self.translations_configuration.locale_field_name)
99
98
  unless def_locale
100
99
  self.send(:"#{self.translations_configuration.locale_field_name}=",self.translation_record.system_current_locale)
101
- end
100
+ end
102
101
  end
103
102
  end
104
103
  end
@@ -4,7 +4,7 @@ module Lolita
4
4
 
5
5
  def self.included(base)
6
6
  base.extend(Lolita::Translation::ORM::ClassMethods)
7
- base.class_eval do
7
+ base.class_eval do
8
8
  include Lolita::Translation::ORM::InstanceMethods
9
9
  end
10
10
  end
@@ -30,7 +30,7 @@ module Lolita
30
30
  end
31
31
 
32
32
  def locales
33
- if options[:locales]
33
+ if options[:locales]
34
34
  Lolita::Translation::Locales.new(options[:locales])
35
35
  else
36
36
  Lolita::Translation.locales
@@ -54,7 +54,7 @@ module Lolita
54
54
  end
55
55
 
56
56
  private
57
-
57
+
58
58
  def build_translation_class
59
59
  @builder = Lolita::Translation::TranslationClassBuilder.new(self.klass, self)
60
60
  @translation_class = @builder.build_class
@@ -64,4 +64,4 @@ module Lolita
64
64
  end
65
65
 
66
66
  end
67
- end
67
+ end
@@ -25,7 +25,7 @@ module Lolita
25
25
  else
26
26
  result.push(locale)
27
27
  end
28
- result
28
+ result
29
29
  end
30
30
  end
31
31
 
@@ -50,7 +50,7 @@ module Lolita
50
50
  end
51
51
 
52
52
  def populate_locales!
53
- unless @locales
53
+ unless @locales
54
54
  @locales = locale_names.map do |locale_name|
55
55
  Lolita::Translation::Locale.new(locale_name)
56
56
  end
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  Lolita::Hooks.component(:"/lolita/configuration/tab/fields").after do
9
9
  tab = self.component_locals[:tab]
10
- if tab.translatable?
10
+ if tab.translatable?
11
11
  self.render_component tab.build_translations_nested_form(self.resource)
12
12
  end
13
13
  end
@@ -16,12 +16,12 @@ Lolita::Hooks.component(:"/lolita/configuration/tab/fields").around do
16
16
  tab = self.component_locals[:tab]
17
17
  if tab.translatable?
18
18
  content = nil
19
- resource.in(resource.original_locale) do
19
+ resource.in(resource.original_locale) do
20
20
  content = let_content
21
21
  end
22
22
  self.send(:render_component,"lolita/translation",:language_wrap, {
23
- :tab => tab,
24
- :content => content,
23
+ :tab => tab,
24
+ :content => content,
25
25
  :active => true,
26
26
  :translation_locale => resource.original_locale
27
27
  })
@@ -34,8 +34,8 @@ Lolita::Hooks.component(:"/lolita/configuration/nested_form/fields").around do
34
34
  tab = self.component_locals[:nested_form].parent
35
35
  if tab.translatable? && current_form.object.respond_to?(:locale)
36
36
  self.send(:render_component,"lolita/translation",:language_wrap, {
37
- :tab => tab,
38
- :content => let_content,
37
+ :tab => tab,
38
+ :content => let_content,
39
39
  :active => false,
40
40
  :translation_locale => current_form.object.locale
41
41
  })
@@ -41,7 +41,7 @@ module Lolita
41
41
  def has_translation_for?(locale)
42
42
  nil
43
43
  end
44
-
44
+
45
45
  private
46
46
 
47
47
  def adapter
@@ -80,7 +80,7 @@ module Lolita
80
80
  end
81
81
 
82
82
  def locale
83
- if has_locale_column?
83
+ if has_locale_column?
84
84
  if value = orm_record.attributes[locale_field] and value.to_s.size > 0
85
85
  value
86
86
  else
@@ -88,7 +88,7 @@ module Lolita
88
88
  end
89
89
  else
90
90
  system_default_locale
91
- end
91
+ end
92
92
  end
93
93
 
94
94
  def attribute(name)
@@ -128,14 +128,14 @@ module Lolita
128
128
  end
129
129
 
130
130
  def find_translation_by_locale given_locale
131
- translations.detect{|translation|
131
+ translations.detect{|translation|
132
132
  translation.locale.to_s == given_locale.to_s
133
133
  }
134
134
  end
135
135
  end
136
136
 
137
137
  class MongoidRecord < AbstractRecord
138
-
138
+
139
139
  end
140
140
 
141
141
  attr_reader :original_record, :default_locale, :orm_wrapper
@@ -158,7 +158,7 @@ module Lolita
158
158
 
159
159
  def build_nested_translations
160
160
  available_locales.each do |locale|
161
- unless self.default_locale.to_s == locale.to_s
161
+ unless self.default_locale.to_s == locale.to_s
162
162
  attributes = { :locale => locale.to_s }
163
163
  original_record.translations.build(attributes) unless orm_wrapper.has_translation_for?(locale)
164
164
  end
@@ -167,7 +167,7 @@ module Lolita
167
167
 
168
168
  def default_locale=(value)
169
169
  @orm_wrapper.default_locale = value
170
- end
170
+ end
171
171
 
172
172
  def in(locale)
173
173
  old_locale = @record_current_locale
@@ -181,7 +181,7 @@ module Lolita
181
181
  def system_current_locale
182
182
  ::I18n.locale
183
183
  end
184
-
184
+
185
185
  private
186
186
 
187
187
  def available_locales
@@ -199,7 +199,7 @@ module Lolita
199
199
  MongoidRecord.new(original_record,@configuration)
200
200
  else
201
201
  AbstractRecord.new(original_record,@configuration)
202
- end
202
+ end
203
203
  end
204
204
 
205
205
  def is_mongoid_record?
@@ -2,8 +2,8 @@ module Lolita
2
2
  module Translation
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 6
6
- PATCH = 3
5
+ MINOR = 7
6
+ PATCH = 0
7
7
  BUILD = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -18,19 +18,8 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.licenses = ["MIT"]
20
20
 
21
- s.add_runtime_dependency(%q<lolita>, ["~> 3.2.0.rc.14"])
22
-
23
- s.add_development_dependency(%q<rails>, ["~> 3.2.3"])
24
- s.add_development_dependency(%q<rspec>, ["~> 2.9.0"])
25
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.9.0"])
26
- s.add_development_dependency(%q<ffaker>, ["~> 1"])
27
- s.add_development_dependency(%q<capybara>, ["~> 1.1.2"])
28
- s.add_development_dependency(%q<capybara-webkit>, ["~> 0.11.0"])
29
- s.add_development_dependency(%q<cover_me>, ["~> 1.2.0"])
30
- s.add_development_dependency(%q<sqlite3>, ["~> 1.3.6"])
31
- s.add_development_dependency(%q<debugger>,[">0"])
32
-
21
+ s.add_runtime_dependency(%q<lolita>, ["~> 3.2"])
33
22
  s.files = `git ls-files`.split("\n")
34
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
35
24
  s.require_paths = ["lib"]
36
25
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ feature "In order to translate resource As system user I want to switch from original resource to translations" do
4
+
5
+ scenario "As user in resource create form I see language switch and current language is active and I can switch to other languages" do
6
+ visit "/lolita/posts/new"
7
+ language_selector_text = page.find(".tab-language-switch").text
8
+ ::I18n.available_locales.each do |locale|
9
+ language_selector_text.should match(/#{locale.to_s.capitalize}/)
10
+ end
11
+ end
12
+
13
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "In order to internationalize all content I can enter information in any language and translate to any other language" do
4
-
3
+ feature "In order to internationalize all content I can enter information in any language and translate to any other language", js: true do
4
+
5
5
  def click_save_btn
6
6
  save_btn = page.find("button[data-type='save&close']")
7
7
  save_btn.click
@@ -12,7 +12,7 @@ describe "In order to internationalize all content I can enter information in an
12
12
  Category.create!(default_options.merge(options))
13
13
  end
14
14
 
15
- it "As user I can enter information in same language as system uses and resource will be stored in that language" do
15
+ scenario "As user I can enter information in same language as system uses and resource will be stored in that language" do
16
16
  visit "/lolita/posts/new"
17
17
  fill_in "post_title", :with => "lv-title"
18
18
  fill_in "post_body", :with => "lv-body"
@@ -21,7 +21,7 @@ describe "In order to internationalize all content I can enter information in an
21
21
  page.should have_content("lv-body")
22
22
  end
23
23
 
24
- it "As user I can enter information in language that I am using currently and original resource will be save in that language" do
24
+ scenario "As user I can enter information in language that I am using currently and original resource will be save in that language" do
25
25
  visit "/lolita/posts/new?locale=ru"
26
26
  fill_in "post_title", :with => "ru-title"
27
27
  fill_in "post_body", :with => "ru-body"
@@ -31,8 +31,8 @@ describe "In order to internationalize all content I can enter information in an
31
31
  page.should have_content("ru-body")
32
32
  end
33
33
 
34
- it "As user I can open previously saved resource, in different language than mine, and resource will be shown in resource original language and I will see that" do
35
- I18n.locale = :ru
34
+ scenario "As user I can open previously saved resource, in different language than mine, and resource will be shown in resource original language and I will see that" do
35
+ I18n.locale = :ru
36
36
  category = create_category(:name => "ru-name")
37
37
  visit("/lolita/categories/#{category.id}/edit?locale=lv")
38
38
  page.should have_selector(".tab-language-switch li.active", :text => "Ru")
@@ -40,8 +40,8 @@ describe "In order to internationalize all content I can enter information in an
40
40
  ru_content.should be_visible
41
41
  end
42
42
 
43
- it "As user I can open previously saved resource, in different language than mine, and change original information and that information will be save in original resource" do
44
- I18n.locale = :ru
43
+ scenario "As user I can open previously saved resource, in different language than mine, and change original information and that information will be save in original resource" do
44
+ I18n.locale = :ru
45
45
  category = create_category(:name => "ru-name")
46
46
  visit("/lolita/categories/#{category.id}/edit?locale=lv")
47
47
  page.fill_in "category_name", :with => "changed-ru-name"
@@ -51,9 +51,9 @@ describe "In order to internationalize all content I can enter information in an
51
51
  name_inp.value.should eq("changed-ru-name")
52
52
  end
53
53
 
54
- it "As user I can open previously saved resource, in different language than mine, and change information for my language, and it will be saved as translation", :js => true do
54
+ scenario "As user I can open previously saved resource, in different language than mine, and change information for my language, and it will be saved as translation", :js => true do
55
55
  pending "test gives time, should check why not error but timeout"
56
- # I18n.locale = :ru
56
+ # I18n.locale = :ru
57
57
  # category = create_category(:name => "ru-name")
58
58
  # visit("/lolita/categories/#{category.id}/edit?locale=lv")
59
59
  # page.execute_script(%Q{$(".tab-language-switch li[data-locale='lv']").click()})