tolk 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,20 +3,20 @@ Defaults
3
3
  -------------------------------------------------*/
4
4
 
5
5
  acronym, abbr {
6
- font-variant: small-caps;
7
- text-transform: lowercase;
6
+ font-variant: small-caps;
7
+ text-transform: lowercase;
8
8
  font-weight: bold;
9
9
  }
10
10
 
11
- .center {text-align: center;}
12
- .large {font-size: larger;}
11
+ .center {text-align: center;}
12
+ .large {font-size: larger;}
13
13
  .small {font-size: smaller;}
14
14
  strong {font-weight: bold;}
15
15
  em {font-style: italic;}
16
16
 
17
- .clear {clear: both;}
18
- .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
19
- .clearfix { display: inline-block; }
17
+ .clear {clear: both;}
18
+ .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
19
+ .clearfix { display: inline-block; }
20
20
  .clearfix{ display: block; }
21
21
 
22
22
  a {color: #888;}
@@ -28,8 +28,8 @@ Layout
28
28
 
29
29
  body {
30
30
  font-family: "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
31
- background: #e5e5e5;
32
- color: #333;
31
+ background: #e5e5e5;
32
+ color: #333;
33
33
  margin: 0;
34
34
  padding: 0;
35
35
  font-size: 14px;
@@ -288,7 +288,7 @@ table.translations .highlight {
288
288
  background-color: yellow;
289
289
  }
290
290
 
291
- table.translations .phrase .carriage_return {
291
+ table.translations .phrase .carriage_return, table.translations .phrase .boolean {
292
292
  color: #2fadcf;
293
293
  font-weight: bold;
294
294
  }
@@ -10,14 +10,18 @@ module Tolk
10
10
 
11
11
  def yaml_value(value)
12
12
  if value.present?
13
- unless value.is_a?(String)
13
+ unless value.is_a?(String) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
14
14
  value = value.respond_to?(:ya2yaml) ? value.ya2yaml(:syck_compatible => true) : value.to_yaml
15
15
  end
16
16
  end
17
-
17
+
18
18
  value
19
19
  end
20
20
 
21
+ def boolean_warning
22
+ '<span class="boolean">(Do not translate -- Enter true or false)</span>'.html_safe
23
+ end
24
+
21
25
  def tolk_locale_selection
22
26
  existing_locale_names = Tolk::Locale.all.map(&:name)
23
27
 
@@ -64,7 +64,8 @@ module Tolk
64
64
  self.special_prefixes.include?(prefix) || self.special_keys.include?(key)
65
65
  end
66
66
 
67
- PLURALIZATION_KEYS = ['none', 'one', 'two', 'few', 'many', 'other']
67
+ # http://cldr.unicode.org/index/cldr-spec/plural-rules - TODO: usage of 'none' isn't standard-conform
68
+ PLURALIZATION_KEYS = ['none', 'zero', 'one', 'two', 'few', 'many', 'other']
68
69
  def pluralization_data?(data)
69
70
  keys = data.keys.map(&:to_s)
70
71
  keys.all? {|k| PLURALIZATION_KEYS.include?(k) }
@@ -5,7 +5,8 @@ module Tolk
5
5
  scope :containing_text, lambda {|query| where("tolk_translations.text LIKE ?", "%#{query}%") }
6
6
 
7
7
  serialize :text
8
- validates_presence_of :text, :if => proc {|r| r.primary.blank? && !r.explicit_nil }
8
+ serialize :previous_text
9
+ validates_presence_of :text, :if => proc {|r| r.primary.blank? && !r.explicit_nil && !r.boolean?}
9
10
  validate :check_matching_variables, :if => proc { |tr| tr.primary_translation.present? }
10
11
 
11
12
  validates_uniqueness_of :phrase_id, :scope => :locale_id
@@ -27,6 +28,10 @@ module Tolk
27
28
  attr_accessor :explicit_nil
28
29
  before_validation :set_explicit_nil
29
30
 
31
+ def boolean?
32
+ text.is_a?(TrueClass) || text.is_a?(FalseClass) || text == 't' || text == 'f'
33
+ end
34
+
30
35
  def up_to_date?
31
36
  not out_of_date?
32
37
  end
@@ -45,24 +50,47 @@ module Tolk
45
50
 
46
51
  def text=(value)
47
52
  value = value.to_s if value.kind_of?(Fixnum)
48
- super unless value.to_s == text
53
+ if primary_translation && primary_translation.boolean?
54
+ value = case value.to_s.downcase.strip
55
+ when 'true', 't'
56
+ true
57
+ when 'false', 'f'
58
+ false
59
+ else
60
+ self.explicit_nil = true
61
+ nil
62
+ end
63
+ super unless value == text
64
+ else
65
+ super unless value.to_s == text
66
+ end
49
67
  end
50
68
 
51
69
  def value
52
70
  if text.is_a?(String) && /^\d+$/.match(text)
53
71
  text.to_i
72
+ elsif (primary_translation || self).boolean?
73
+ %w[true t].member?(text.to_s.downcase.strip)
54
74
  else
55
75
  text
56
76
  end
57
77
  end
58
78
 
59
79
  def self.detect_variables(search_in)
60
- case search_in
80
+ variables = case search_in
61
81
  when String then Set.new(search_in.scan(/\{\{(\w+)\}\}/).flatten + search_in.scan(/\%\{(\w+)\}/).flatten)
62
82
  when Array then search_in.inject(Set[]) { |carry, item| carry + detect_variables(item) }
63
83
  when Hash then search_in.values.inject(Set[]) { |carry, item| carry + detect_variables(item) }
64
84
  else Set[]
65
85
  end
86
+
87
+ # delete special i18n variable used for pluralization itself (might not be used in all values of
88
+ # the pluralization keys, but is essential to use pluralization at all)
89
+ if search_in.is_a?(Hash) && Tolk::Locale.pluralization_data?(search_in)
90
+ variables.delete_if {|v| v == 'count' }
91
+ else
92
+ variables
93
+ end
66
94
  end
67
95
 
68
96
  def variables
@@ -92,7 +120,18 @@ module Tolk
92
120
  end
93
121
  end
94
122
 
95
- self.text = nil if primary_translation.text.class != self.text.class
123
+ if primary_translation.boolean?
124
+ self.text = case self.text.to_s.strip
125
+ when 'true'
126
+ true
127
+ when 'false'
128
+ false
129
+ else
130
+ nil
131
+ end
132
+ elsif primary_translation.text.class != self.text.class
133
+ self.text = nil
134
+ end
96
135
  end
97
136
 
98
137
  true
@@ -110,10 +149,10 @@ module Tolk
110
149
 
111
150
  def check_matching_variables
112
151
  unless variables_match?
113
- if primary_translation.variables.empty? || primary_translation.variables.class == Set
114
- self.errors.add(:text, "The original does not contain variables, so they should not be included.")
152
+ if primary_translation.variables.empty?
153
+ self.errors.add(:variables, "The primary translation does not contain substitutions, so this should neither.")
115
154
  else
116
- self.errors.add(:text, "The translation should contain the variables #{primary_translation.to_a.to_sentence}.")
155
+ self.errors.add(:variables, "The translation should contain the substitutions of the primary translation: (#{primary_translation.variables.to_a.join(', ')}), found (#{self.variables.to_a.join(', ')}).")
117
156
  end
118
157
  end
119
158
  end
@@ -31,6 +31,7 @@
31
31
  <div class="updated">
32
32
  <span class="key">Updated</span>
33
33
  <%= format_i18n_value(phrase.translations.primary.text) -%>
34
+ <%= boolean_warning if phrase.translations.primary.boolean? -%>
34
35
  </div>
35
36
  <div class="original">
36
37
  <span class="key">Original</span>
@@ -38,6 +39,7 @@
38
39
  </div>
39
40
  <% else %>
40
41
  <%= format_i18n_value(phrase.translations.primary.text) -%>
42
+ <%= boolean_warning if phrase.translations.primary.boolean? -%>
41
43
  <% end %>
42
44
 
43
45
  <span class="key"><%= phrase.key %></span>
@@ -35,6 +35,7 @@
35
35
  <% else -%>
36
36
  <%= format_i18n_value(phrase.translations.primary.text) -%>
37
37
  <% end -%>
38
+ <%= boolean_warning if phrase.translations.primary.boolean? -%>
38
39
  <span class="key" title="<%= phrase.key %>"><%= truncate(phrase.key, :length => 100) %></span>
39
40
  </td>
40
41
  </tr>
@@ -32,6 +32,7 @@
32
32
  <% else -%>
33
33
  <%= format_i18n_value(phrase.translations.primary.text) -%>
34
34
  <% end -%>
35
+ <%= boolean_warning if phrase.translations.primary.boolean? -%>
35
36
  <span class="key" title="<%= phrase.key %>"><%= params[:k].present? ?
36
37
  highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
37
38
  h(truncate(phrase.key, :length => 100)) %></span>
data/lib/tolk/import.rb CHANGED
@@ -8,13 +8,13 @@ module Tolk
8
8
 
9
9
  def import_secondary_locales
10
10
  locales = Dir.entries(self.locales_config_path)
11
-
12
- locale_block_filter = Proc.new {
11
+
12
+ locale_block_filter = Proc.new {
13
13
  |l| ['.', '..'].include?(l) ||
14
14
  !l.ends_with?('.yml') ||
15
15
  l.match(/(.*\.){2,}/) # reject files of type xxx.en.yml
16
16
  }
17
- locales = locales.reject(&locale_block_filter).map {|x| x.split('.').first }
17
+ locales = locales.reject(&locale_block_filter).map {|x| x.split('.').first }
18
18
  locales = locales - [Tolk::Locale.primary_locale.name]
19
19
  locales.each {|l| import_locale(l) }
20
20
  end
@@ -32,9 +32,13 @@ module Tolk
32
32
 
33
33
  if phrase
34
34
  translation = locale.translations.new(:text => value, :phrase => phrase)
35
- count = count + 1 if translation.save
35
+ if translation.save
36
+ count = count + 1
37
+ elsif translation.errors[:variables].present?
38
+ puts "[WARN] Key '#{key}' from '#{locale_name}.yml' could not be saved: #{translation.errors[:variables].first}"
39
+ end
36
40
  else
37
- puts "[ERROR] Key '#{key}' was found in #{locale_name}.yml but #{Tolk::Locale.primary_language_name} translation is missing"
41
+ puts "[ERROR] Key '#{key}' was found in '#{locale_name}.yml' but #{Tolk::Locale.primary_language_name} translation is missing"
38
42
  end
39
43
  end
40
44
 
data/lib/tolk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tolk
2
- VERSION = "1.3.3"
2
+ VERSION = "1.3.4"
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.3.3
4
+ version: 1.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-09-05 00:00:00.000000000 Z
15
+ date: 2012-10-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: will_paginate