tolk 1.3.9 → 1.3.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,23 +5,18 @@ $(function () {
5
5
  e.preventDefault();
6
6
 
7
7
  var row = $(this).parents("tr")
8
- , original = row.find(".phrase .original").text();
8
+ , original_text = row.find(".original textarea").val();
9
9
 
10
- row.find(".translation textarea").addClass("dirty").val(original.trim());
11
-
12
- // Bind the dirty callback after copy
13
- window.onbeforeunload = confirm;
10
+ row.find(".translation textarea").val(original_text.trim()).trigger("change");
14
11
  });
15
12
 
16
13
  // avoid lose data
17
- $(".translations textarea").bind("blur", function () {
18
- if ($(this).is(".dirty")) {
19
- window.onbeforeunload = confirm;
20
- }
14
+ $(".translations textarea").bind("keydown", function () {
15
+ window.onbeforeunload = confirm;
21
16
  });
22
17
 
23
- $(".translations textarea").bind("keydown", function () {
24
- $(this).addClass("dirty");
18
+ $(".translations textarea").bind("change", function () {
19
+ window.onbeforeunload = confirm;
25
20
  });
26
21
 
27
22
  $("input.save, input.apply").click(function () {
@@ -1,37 +1,21 @@
1
1
  $(function () {
2
- var interpolation = new RegExp("%{\\w+}", "g");
3
-
4
- $(".phrase .value").each(function () {
5
- var text = $('<div/>').text($(this).text()).html()
6
- , token_text;
7
-
8
- token_text = text.replace(interpolation, function (match) {
9
- return '<span class="interpolation" title="Don\'t translate this word">' + match + '</span>';
10
- });
11
-
12
- $(this).html(token_text);
13
- });
14
2
 
15
- $(".translations textarea").bind("focus", function () {
16
- $(this).parents("tr").toggleClass('active');
17
- });
18
-
19
- $(".translations textarea").bind("blur", function () {
20
- $(this).parents("tr").toggleClass('active');
21
-
22
- var row = $(this).parents("tr")
23
- , original_text = row.find(".phrase .original").text()
24
- , translated_text = $(this).val()
25
- , original_interpolations = original_text.match(interpolation) || []
26
- , translated_interpolations = translated_text.match(interpolation) || []
27
- , not_match;
3
+ var interpolation = new RegExp("%{\\w+}", "g");
4
+
5
+ $(".translations textarea").bind("change", function () {
6
+ var row = $(this).parents("tr")
7
+ , original_text = row.find(".original textarea").val()
8
+ , translated_text = $(this).val()
9
+ , original_interpolations = original_text.match(interpolation) || []
10
+ , translated_interpolations = translated_text.match(interpolation) || []
11
+ , not_match;
28
12
 
29
- not_match = translated_text.length > 0 &&
30
- ($(original_interpolations).not(translated_interpolations).length !== 0 ||
31
- $(translated_interpolations).not(original_interpolations).length !== 0);
13
+ not_match = translated_text.length > 0 &&
14
+ ($(original_interpolations).not(translated_interpolations).length !== 0 ||
15
+ $(translated_interpolations).not(original_interpolations).length !== 0);
32
16
 
33
- row.find(".actions .warning").toggle(not_match);
17
+ row.find(".actions .warning").toggle(not_match);
34
18
 
35
- });
19
+ });
36
20
 
37
21
  });
@@ -1,9 +1,17 @@
1
-
2
1
  $(function () {
3
2
 
4
3
  // Fit text area height
5
- $('td textarea').each(function () {
4
+ $('.translations textarea').each(function () {
6
5
  $(this).css({ height: $(this).parent('td').css('height')});
7
6
  });
8
7
 
8
+ // Mark active textarea
9
+ $(".translations textarea").bind("focus", function () {
10
+ $(this).parents("tr").toggleClass('active');
11
+ });
12
+
13
+ $(".translations textarea").bind("blur", function () {
14
+ $(this).parents("tr").toggleClass('active');
15
+ });
16
+
9
17
  });
@@ -241,7 +241,7 @@ span.notice {
241
241
  display: inline-block;
242
242
  }
243
243
 
244
- div.original {
244
+ div.previous {
245
245
  color: #999;
246
246
  margin: 5px 0;
247
247
  padding: 1px 8px 4px;
@@ -252,7 +252,7 @@ div.updated {
252
252
  padding: 1px 8px 4px;
253
253
  }
254
254
 
255
- table.translations div.original span.key {
255
+ table.translations div.previous span.key {
256
256
  margin: 0 0 -2px;
257
257
  padding: 0;
258
258
  }
@@ -332,7 +332,7 @@ table.translations td.actions .warning {
332
332
  color: orange;
333
333
  padding: 2px 4px;
334
334
  display: none;
335
- cursor: default;
335
+ cursor: help;
336
336
  }
337
337
 
338
338
  table.translations tr.active td {
@@ -343,20 +343,21 @@ table.translations .highlight {
343
343
  background-color: yellow;
344
344
  }
345
345
 
346
- table.translations .original {
346
+ table.translations .original textarea {
347
347
  display: none;
348
348
  }
349
349
 
350
- table.translations .interpolation {
350
+ table.translations .original .interpolation,
351
+ table.translations .original .carriage_return,
352
+ table.translations .original .boolean {
351
353
  color: #2fadcf;
352
- font-family: Courier;
354
+ font-family: Courier, monospace;
353
355
  font-weight: bold;
354
- cursor: pointer;
356
+ cursor: help;
355
357
  }
356
358
 
357
- table.translations .phrase .carriage_return, table.translations .phrase .boolean {
358
- color: #2fadcf;
359
- font-weight: bold;
359
+ table.translations .original .carriage_return:before {
360
+ content: "¶";
360
361
  }
361
362
 
362
363
  /*-------------------------------------------------
@@ -1,7 +1,17 @@
1
1
  module Tolk
2
2
  module ApplicationHelper
3
3
  def format_i18n_value(value)
4
- h(yaml_value(value)).gsub(/\n/, '<span class="carriage_return">&crarr;</span><br />').html_safe
4
+ value = h(yaml_value(value))
5
+ value = highlight_linebreaks(value)
6
+ value = highligh_interpolations(value)
7
+ end
8
+
9
+ def highlight_linebreaks(value)
10
+ value.gsub(/\n/, '<span class="carriage_return" title="Line break"><br /></span>').html_safe
11
+ end
12
+
13
+ def highligh_interpolations(value)
14
+ value.gsub(/%{\w+}/, '<span class="interpolation" title="Leave this word untranslated">\0</span>').html_safe
5
15
  end
6
16
 
7
17
  def format_i18n_text_area_value(value)
@@ -51,12 +51,9 @@ module Tolk
51
51
  all - [primary_locale]
52
52
  end
53
53
 
54
- def dump_all(to = self.locales_config_path)
54
+ def dump_all(to = nil, exporter = Tolk::Export)
55
55
  secondary_locales.each do |locale|
56
- File.open("#{to}/#{locale.name}.yml", "w+") do |file|
57
- data = locale.to_hash
58
- data.respond_to?(:ya2yaml) ? file.write(data.ya2yaml(:syck_compatible => true)) : file.write(YAML.dump(data).force_encoding file.external_encoding.name)
59
- end
56
+ exporter.dump(name: locale.name, data: locale.to_hash, destination: to)
60
57
  end
61
58
  end
62
59
 
@@ -61,6 +61,7 @@ module Tolk
61
61
  end
62
62
  super unless value == text
63
63
  else
64
+ value = value.strip if value.is_a?(String)
64
65
  super unless value.to_s == text
65
66
  end
66
67
  end
@@ -30,25 +30,21 @@
30
30
  <a class="copy" href="#" tabindex="-1" title="Copy original translation">&larr;</a><br>
31
31
  <span class="warning" title="Interpolation keys don't match">⚠</span>
32
32
  </td>
33
- <td class="phrase">
34
-
33
+ <td class="original">
34
+ <%= text_area_tag :"translations[][original_text]", format_i18n_text_area_value(phrase.translations.primary.text), :disabled => true %>
35
+
35
36
  <% if action_name == 'updated' %>
36
37
  <div class="updated">
37
38
  <span class="key">Updated</span>
38
39
  <%= format_i18n_value(phrase.translations.primary.text) -%>
39
40
  <%= boolean_warning if phrase.translations.primary.boolean? -%>
40
41
  </div>
41
- <div class="original">
42
- <span class="key">Original</span>
42
+ <div class="previous">
43
+ <span class="key">Previous</span>
43
44
  <%= format_i18n_value(phrase.translations.primary.previous_text) -%>
44
45
  </div>
45
46
  <% else %>
46
- <div class="original">
47
- <%= format_i18n_value(phrase.translations.primary.text) -%>
48
- </div>
49
- <div class="value">
50
- <%= format_i18n_value(phrase.translations.primary.text) -%>
51
- </div>
47
+ <%= format_i18n_value(phrase.translations.primary.text) -%>
52
48
  <%= boolean_warning if phrase.translations.primary.boolean? -%>
53
49
  <% end %>
54
50
 
@@ -34,18 +34,16 @@
34
34
  <a class="copy" href="#" tabindex="-1" title="Copy original translation">&larr;</a><br>
35
35
  <span class="warning" title="Interpolation keys don't match">⚠</span>
36
36
  </td>
37
- <td class="phrase">
38
- <div class="original">
37
+ <td class="original">
38
+ <%= text_area_tag :"translations[][original_text]", format_i18n_text_area_value(phrase.translations.primary.text), :disabled => true %>
39
+
40
+ <% if params[:q].present? -%>
41
+ <%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
42
+ <% else -%>
39
43
  <%= format_i18n_value(phrase.translations.primary.text) -%>
40
- </div>
41
- <div class="value">
42
- <% if params[:q].present? -%>
43
- <%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
44
- <% else -%>
45
- <%= format_i18n_value(phrase.translations.primary.text) -%>
46
- <% end -%>
47
- <%= boolean_warning if phrase.translations.primary.boolean? -%>
48
- </div>
44
+ <% end -%>
45
+ <%= boolean_warning if phrase.translations.primary.boolean? -%>
46
+
49
47
  <span class="key" title="<%= phrase.key %>"><%= truncate(phrase.key, :length => 100) %></span>
50
48
  </td>
51
49
  </tr>
@@ -31,21 +31,19 @@
31
31
  <a class="copy" href="#" tabindex="-1" title="Copy original translation">&larr;</a><br>
32
32
  <span class="warning" title="Interpolation keys don't match">⚠</span>
33
33
  </td>
34
- <td class="phrase">
35
- <div class="original">
34
+ <td class="original">
35
+ <%= text_area_tag :"translations[][original_text]", format_i18n_text_area_value(phrase.translations.primary.text), :disabled => true %>
36
+
37
+ <% if params[:q].present? -%>
38
+ <%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
39
+ <% else -%>
36
40
  <%= format_i18n_value(phrase.translations.primary.text) -%>
37
- </div>
38
- <div class="value">
39
- <% if params[:q].present? -%>
40
- <%= highlight(format_i18n_value(phrase.translations.primary.text), params[:q]) -%>
41
- <% else -%>
42
- <%= format_i18n_value(phrase.translations.primary.text) -%>
43
- <% end -%>
44
- <%= boolean_warning if phrase.translations.primary.boolean? -%>
45
- </div>
41
+ <% end -%>
42
+ <%= boolean_warning if phrase.translations.primary.boolean? -%>
43
+
46
44
  <span class="key" title="<%= phrase.key %>"><%= params[:k].present? ?
47
- highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
48
- h(truncate(phrase.key, :length => 100)) %></span>
45
+ highlight(h(truncate(phrase.key, :length => 100)), params[:k]) :
46
+ h(truncate(phrase.key, :length => 100)) %></span>
49
47
  </td>
50
48
  </tr>
51
49
  <% end %>
data/lib/tolk.rb CHANGED
@@ -4,6 +4,7 @@ require 'tolk/config'
4
4
  require 'tolk/engine'
5
5
  require 'tolk/sync'
6
6
  require 'tolk/import'
7
+ require 'tolk/export'
7
8
 
8
9
  module Tolk
9
10
  # Setup Tolk
@@ -0,0 +1,28 @@
1
+ module Tolk
2
+ class Export
3
+ attr_reader :name, :data, :destination
4
+
5
+ def initialize(args)
6
+ @name = args.fetch(:name, '')
7
+ @data = args.fetch(:data, {})
8
+ @destination = args.fetch(:destination, self.class.dump_path)
9
+ end
10
+
11
+ def dump
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)
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def dump(args)
19
+ new(args).dump
20
+ end
21
+
22
+ def dump_path
23
+ Tolk::Locale._dump_path
24
+ end
25
+ end
26
+
27
+ end
28
+ end
data/lib/tolk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tolk
2
- VERSION = "1.3.9"
2
+ VERSION = "1.3.10"
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.9
4
+ version: 1.3.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-03-22 00:00:00.000000000 Z
16
+ date: 2013-07-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: will_paginate
@@ -64,6 +64,7 @@ files:
64
64
  - lib/tasks/tolk_tasks.rake
65
65
  - lib/tolk/config.rb
66
66
  - lib/tolk/engine.rb
67
+ - lib/tolk/export.rb
67
68
  - lib/tolk/import.rb
68
69
  - lib/tolk/sync.rb
69
70
  - lib/tolk/version.rb