tolk 1.4.00 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDI5NjM5ZWYxNzY0YmJkNmI3ZDM3ZmY2MzdjZmM2MmM5YmMxODRkOA==
5
- data.tar.gz: !binary |-
6
- MzY0ZmU1ZGU4ZGRmYmZmMDQ0NDU5MzQ0MjMzMDI4YjE3NGM4OTE4OA==
2
+ SHA1:
3
+ metadata.gz: 3c7fdf39ee1f10310cb7c34dfcabdc8e8018468e
4
+ data.tar.gz: 54d0cd52a00f4cb2af889e73a112c119dc2f57ad
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDA4YzMwOWU0ZjdhZDA0Y2QyNmNiYmMzOGI1ZjcyYTY4NmE2MzkwY2ZkNmRl
10
- NWViYjMwYmY5MGFlYzk2ODlhYzkzYmU3OWRlOTkwM2EyOTNmMGFkM2QyYTg5
11
- YTYzOTM1ZTE4ZWRkYjhkY2M4ZDlkMTUxNjgyNmY1OTkwZTBhNGI=
12
- data.tar.gz: !binary |-
13
- NTIzZjY4MGQyOGIyY2Y0ODgwM2VmNTZkZmM5NjhjYWQ0YjIzZjdjNDg1ZTZm
14
- NGVjYTA3Zjg5M2UwOTJmNGQ0ZTNkZTViNTQxZTVhMjI5MTZlODNkMDU5YjU1
15
- MWRjZTg5NGM3ZTU3OGViMDQzMzE1YjBkNmY3MGUxYzU5YjQ0ZDM=
6
+ metadata.gz: 5a0e9a6cb1d4aad16bbf424fe82e89caece0909d6a4e5a7b69ae034c221483e859d1f006604d0653ac869f1e8f33c0c9b25eaedf507abbdd919b36d25afdc9d8
7
+ data.tar.gz: 33462659545170ca060c92484a0760abfade2578eaaead46cec9b205ba8bbb7c16f459f594fa9a9569120f94d0f0e26ed4d27ca3d3d86b3bac1d96dea5bc8d1d
@@ -24,7 +24,7 @@ module Tolk
24
24
  end
25
25
 
26
26
  def update
27
- @locale.translations_attributes = params[:translations]
27
+ @locale.translations_attributes = translation_params
28
28
  @locale.save
29
29
  redirect_to request.referrer
30
30
  end
@@ -39,7 +39,7 @@ module Tolk
39
39
  end
40
40
 
41
41
  def create
42
- Tolk::Locale.create!(params[:tolk_locale])
42
+ Tolk::Locale.create!(locale_params)
43
43
  redirect_to :action => :index
44
44
  end
45
45
 
@@ -71,5 +71,18 @@ module Tolk
71
71
  def find_locale
72
72
  @locale = Tolk::Locale.where('UPPER(name) = UPPER(?)', params[:id]).first!
73
73
  end
74
+
75
+ def locale_params
76
+ params.require(:tolk_locale).permit(:name)
77
+ end
78
+
79
+ # TODO: whitelist incoming translation params
80
+ # translation permitted params: :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
81
+ # test params: "translations"=>[{"id"=>"", "phrase_id"=>"8", "locale_id"=>"5", "text"=>"Dead men don't bite"}, {"id"=>"", "phrase_id"=>"7", "locale_id"=>"5", "text"=>""}]
82
+ def translation_params
83
+ params.require(:translations)
84
+ end
85
+
86
+
74
87
  end
75
88
  end
@@ -15,7 +15,6 @@ module Tolk
15
15
  accepts_nested_attributes_for :translations, :reject_if => proc { |attributes| attributes['text'].blank? }
16
16
  before_validation :remove_invalid_translations_from_target, :on => :update
17
17
 
18
- attr_accessible :name
19
18
  cattr_accessor :locales_config_path
20
19
  self.locales_config_path = self._dump_path
21
20
 
@@ -51,10 +50,12 @@ module Tolk
51
50
  all - [primary_locale]
52
51
  end
53
52
 
54
- def dump_all(to = self.locales_config_path, exporter = Tolk::Export)
55
- secondary_locales.each do |locale|
56
- exporter.dump(name: locale.name, data: locale.to_hash, destination: to)
57
- end
53
+ def dump_all(*args)
54
+ secondary_locales.each { |locale| locale.dump(*args) }
55
+ end
56
+
57
+ def dump_yaml(name, *args)
58
+ find_by_name(name).dump(*args)
58
59
  end
59
60
 
60
61
  def special_key_or_prefix?(prefix, key)
@@ -69,6 +70,10 @@ module Tolk
69
70
  end
70
71
  end
71
72
 
73
+ def dump(to = self.locales_config_path, exporter = Tolk::Export)
74
+ exporter.dump(name: name, data: to_hash, destination: to)
75
+ end
76
+
72
77
  def has_updated_translations?
73
78
  translations.count(:conditions => {:'tolk_translations.primary_updated' => true}) > 0
74
79
  end
@@ -123,8 +128,8 @@ module Tolk
123
128
 
124
129
  phrases = Tolk::Phrase.all.order('tolk_phrases.key ASC')
125
130
 
126
- found_translations_ids = Tolk::Locale.primary_locale.translations.all(:conditions => ["tolk_translations.text LIKE ?", "%#{query}%"], :select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
127
- existing_ids = self.translations.all(:select => 'tolk_translations.phrase_id').map(&:phrase_id).uniq
131
+ found_translations_ids = Tolk::Locale.primary_locale.translations.where(["tolk_translations.text LIKE ?", "%#{query}%"]).to_a.map(&:phrase_id).uniq
132
+ existing_ids = self.translations.select('tolk_translations.phrase_id').to_a.map(&:phrase_id).uniq
128
133
  # phrases = phrases.scoped(:conditions => ['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
129
134
  phrases = phrases.where(['tolk_phrases.id NOT IN (?) AND tolk_phrases.id IN(?)', existing_ids, found_translations_ids]) if existing_ids.present?
130
135
  result = phrases.paginate({:page => page}.merge(options))
@@ -133,13 +138,15 @@ module Tolk
133
138
  end
134
139
 
135
140
  def to_hash
136
- { name => translations.each_with_object({}) do |translation, locale|
137
- if translation.phrase.key.include?(".")
138
- locale.deep_merge!(unsquish(translation.phrase.key, translation.value))
139
- else
140
- locale[translation.phrase.key] = translation.value
141
+ data = translations.includes(:phrase).references(:phrases).order(phrases.arel_table[:key]).
142
+ each_with_object({}) do |translation, locale|
143
+ if translation.phrase.key.include?(".")
144
+ locale.deep_merge!(unsquish(translation.phrase.key, translation.value))
145
+ else
146
+ locale[translation.phrase.key] = translation.value
147
+ end
141
148
  end
142
- end }
149
+ { name => data }
143
150
  end
144
151
 
145
152
  def to_param
@@ -198,9 +205,7 @@ module Tolk
198
205
  end
199
206
 
200
207
  def find_phrases_with_translations(page, conditions = {})
201
- result = Tolk::Phrase.paginate(:page => page,
202
- :conditions => { :'tolk_translations.locale_id' => self.id }.merge(conditions),
203
- :joins => :translations, :order => 'tolk_phrases.key ASC')
208
+ result = Tolk::Phrase.where({ :'tolk_translations.locale_id' => self.id }.merge(conditions)).joins(:translations).order('tolk_phrases.key ASC').paginate(:page => page)
204
209
 
205
210
  result.each do |phrase|
206
211
  phrase.translation = phrase.translations.for(self)
@@ -2,8 +2,6 @@ module Tolk
2
2
  class Phrase < ActiveRecord::Base
3
3
  self.table_name = "tolk_phrases"
4
4
 
5
- attr_accessible :key
6
-
7
5
  validates_uniqueness_of :key
8
6
 
9
7
  cattr_accessor :per_page
@@ -15,8 +15,6 @@ module Tolk
15
15
  belongs_to :locale, :class_name => 'Tolk::Locale'
16
16
  validates_presence_of :locale_id
17
17
 
18
- attr_accessible :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
19
-
20
18
  before_save :set_primary_updated
21
19
 
22
20
  before_save :set_previous_text
@@ -156,7 +154,7 @@ module Tolk
156
154
  end
157
155
  end
158
156
  end
159
-
157
+
160
158
  def validate_text_not_nil
161
159
  return unless text.nil?
162
160
  errors.add :text, :blank
@@ -24,6 +24,11 @@ namespace :tolk do
24
24
  Tolk::Locale.dump_all
25
25
  end
26
26
 
27
+ desc "Generate a single yml file for a specific locale"
28
+ task :dump_yaml, [:locale] => :environment do
29
+ Tolk::Locale.dump_yaml(locale)
30
+ end
31
+
27
32
  desc "Imports data all non default locale yml files to Tolk"
28
33
  task :import => :environment do
29
34
  Rake::Task['tolk:sync'].invoke
@@ -10,7 +10,12 @@ module Tolk
10
10
 
11
11
  def dump
12
12
  File.open("#{destination}/#{name}.yml", "w+") do |file|
13
- data.respond_to?(:ya2yaml) ? file.write(data.ya2yaml(:syck_compatible => true)) : file.write(YAML.dump(data).force_encoding file.external_encoding.name)
13
+ yml = if data.respond_to?(:ya2yaml)
14
+ data.ya2yaml(:syck_compatible => true)
15
+ else
16
+ YAML.dump(data).force_encoding(file.external_encoding.name)
17
+ end
18
+ file.write(yml)
14
19
  end
15
20
  end
16
21
 
@@ -23,6 +28,5 @@ module Tolk
23
28
  Tolk::Locale._dump_path
24
29
  end
25
30
  end
26
-
27
31
  end
28
- end
32
+ end
@@ -53,7 +53,7 @@ module Tolk
53
53
 
54
54
  if translation.changed? && !translation.new_record?
55
55
  # Set the primary updated flag if the primary translation has changed and it is not a new record.
56
- existing_phrase.translations.update_all({ :primary_updated => true }, Tolk::Translation.arel_table[:locale_id].not_eq(primary_locale.id))
56
+ existing_phrase.translations.where(Tolk::Translation.arel_table[:locale_id].not_eq(primary_locale.id)).update_all({ :primary_updated => true })
57
57
  end
58
58
 
59
59
  translation.primary = true
@@ -1,3 +1,3 @@
1
1
  module Tolk
2
- VERSION = "1.4.00"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.00
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -12,48 +12,34 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-12-26 00:00:00.000000000 Z
15
+ date: 2014-04-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: will_paginate
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ! '>='
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
31
- - !ruby/object:Gem::Dependency
32
- name: protected_attributes
33
- requirement: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - ! '>='
28
+ - - ">="
43
29
  - !ruby/object:Gem::Version
44
30
  version: '0'
45
31
  - !ruby/object:Gem::Dependency
46
32
  name: safe_yaml
47
33
  requirement: !ruby/object:Gem::Requirement
48
34
  requirements:
49
- - - ~>
35
+ - - "~>"
50
36
  - !ruby/object:Gem::Version
51
37
  version: '0.8'
52
38
  type: :runtime
53
39
  prerelease: false
54
40
  version_requirements: !ruby/object:Gem::Requirement
55
41
  requirements:
56
- - - ~>
42
+ - - "~>"
57
43
  - !ruby/object:Gem::Version
58
44
  version: '0.8'
59
45
  description: Tolk is a web interface for doing i18n translations packaged as an engine
@@ -64,20 +50,6 @@ extensions: []
64
50
  extra_rdoc_files: []
65
51
  files:
66
52
  - MIT-LICENSE
67
- - config/routes.rb
68
- - init.rb
69
- - lib/generators/tolk/install_generator.rb
70
- - lib/generators/tolk/templates/initializer.erb
71
- - lib/generators/tolk/templates/migration.rb
72
- - lib/generators/tolk/utils.rb
73
- - lib/tasks/tolk_tasks.rake
74
- - lib/tolk/config.rb
75
- - lib/tolk/engine.rb
76
- - lib/tolk/export.rb
77
- - lib/tolk/import.rb
78
- - lib/tolk/sync.rb
79
- - lib/tolk/version.rb
80
- - lib/tolk.rb
81
53
  - app/assets/javascripts/tolk/actions.js
82
54
  - app/assets/javascripts/tolk/application.js
83
55
  - app/assets/javascripts/tolk/interpolations.js
@@ -101,6 +73,20 @@ files:
101
73
  - app/views/tolk/locales/show.html.erb
102
74
  - app/views/tolk/searches/_form.html.erb
103
75
  - app/views/tolk/searches/show.html.erb
76
+ - config/routes.rb
77
+ - init.rb
78
+ - lib/generators/tolk/install_generator.rb
79
+ - lib/generators/tolk/templates/initializer.erb
80
+ - lib/generators/tolk/templates/migration.rb
81
+ - lib/generators/tolk/utils.rb
82
+ - lib/tasks/tolk_tasks.rake
83
+ - lib/tolk.rb
84
+ - lib/tolk/config.rb
85
+ - lib/tolk/engine.rb
86
+ - lib/tolk/export.rb
87
+ - lib/tolk/import.rb
88
+ - lib/tolk/sync.rb
89
+ - lib/tolk/version.rb
104
90
  homepage: http://github.com/tolk/tolk
105
91
  licenses:
106
92
  - MIT
@@ -111,18 +97,19 @@ require_paths:
111
97
  - lib
112
98
  required_ruby_version: !ruby/object:Gem::Requirement
113
99
  requirements:
114
- - - ! '>='
100
+ - - ">="
115
101
  - !ruby/object:Gem::Version
116
102
  version: '0'
117
103
  required_rubygems_version: !ruby/object:Gem::Requirement
118
104
  requirements:
119
- - - ! '>='
105
+ - - ">="
120
106
  - !ruby/object:Gem::Version
121
107
  version: '0'
122
108
  requirements: []
123
109
  rubyforge_project:
124
- rubygems_version: 2.1.11
110
+ rubygems_version: 2.2.2
125
111
  signing_key:
126
112
  specification_version: 4
127
113
  summary: Rails engine providing web interface for managing i18n yaml files
128
114
  test_files: []
115
+ has_rdoc: