rails-i18nterface 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d59eaee1ac2132b444d68917c3b806ceb8c67b0
4
- data.tar.gz: 78c730d3102298405f2a7f950922c847e8a620a3
3
+ metadata.gz: 5b88e2c4e5270456757b8c9a9b998f5ddb7def00
4
+ data.tar.gz: 64757f096941c68ed2ffa7862379a76a9f9c04e7
5
5
  SHA512:
6
- metadata.gz: a9d4dd157eeecf8bcde799f4d4fc1e4c17ef3af10b1041e7e0742404729d8e8ee26edd5924e455f264d62e7ae2f93be81e16879f828951cbbeb1167d5955a18f
7
- data.tar.gz: 36c97ab831b493816f5b24c6b6d85bea7e546e2774f47dfc53472536800b19f84a2787b664be87ecfae43ebb2b4b50599b77688fe5c2db954538c12a89e5e859
6
+ metadata.gz: 70d0037c6d3ffc3386801e895de0843a8560cb39b2d861abfd6de87e8553233940da641f9e4c89b7116bc5675292aab1a625a381ece2dbe725773e12eba4d2ed
7
+ data.tar.gz: cc9315ef2a375204dba6cb998125f12b42cb1d94bc71fd3353f3fab79264854b7c45a971cf5c3ae1aafbfd7382a2b1734c5e069d63d7fe86b6cf9f3983f53c43
data/README.md CHANGED
@@ -45,10 +45,12 @@ rake db:migrate
45
45
  ### Protect access
46
46
 
47
47
  You may want to protect the translation engine to admin and create a constraint
48
- in your routes:
48
+ in your routes (note that you don't want to mount it when you launch tests):
49
49
  ```ruby
50
50
  constraints AdminConstraint.new do
51
- mount RailsI18nterface::Engine => "/translate", :as => "translate_engine"
51
+ unless Rails.env.test?
52
+ mount RailsI18nterface::Engine => "/translate", :as => "translate_engine"
53
+ end
52
54
  end
53
55
  ```
54
56
 
@@ -58,5 +58,21 @@ $.domReady(function() {
58
58
  filter = $(this).data("id");
59
59
  filterThat(filter,false);
60
60
  });
61
-
61
+ $(".delete").on("click", function(e) {
62
+ e.preventDefault();
63
+ e.stopPropagation();
64
+ key = $(this).previous().text();
65
+ if (confirm("Are you sure you want to delete the key "+key+" from database ?")) {
66
+ $.ajax({
67
+ url: 'delete/'+key,
68
+ method: 'delete',
69
+ success: function(resp) {
70
+ alert(resp);
71
+ },
72
+ error: function(resp,msg) {
73
+ alert("Error: "+resp.statusText);
74
+ }
75
+ })
76
+ }
77
+ });
62
78
  });
@@ -390,16 +390,53 @@ div.translation em strong {
390
390
  .translation .right {
391
391
  float: right;
392
392
  }
393
- .translation .right .file {
394
- padding: 0 5px;
393
+ .translation .files {
394
+ padding: 1px 5px;
395
395
  background-color: #369;
396
396
  color: #fff;
397
- border-radius: 3px;
397
+ border-radius: 3px 3px 0 0;
398
+ float: right;
399
+ display: inline;
400
+ margin-left: 10px;
401
+ position: relative;
402
+ cursor: pointer;
403
+ }
404
+
405
+ .translation .files .count {
406
+ display: inline-block;
407
+
408
+ }
409
+ .translation .files .filelist {
410
+ display: none;
411
+ position: absolute;
412
+ top: 15px;
413
+ right: 0;
414
+ left: auto;
415
+ width: 300px;
416
+ background-color: #fff;
417
+ padding: 5px 10px;
418
+ border: 1px solid #369;
419
+ z-index: 1;
420
+ color: #000;
421
+ }
422
+ .translation .files:hover .filelist {
398
423
  display: block;
399
424
  }
400
425
  .translation .key {
401
426
  color: #666;
402
427
  }
428
+ .translation .delete {
429
+ padding: 0 5px;
430
+ text-decoration: none;
431
+ background-color: #999;
432
+ color: #fff;
433
+ border-radius: 10px;
434
+ font-size: 10px;
435
+ font-weight: bold;
436
+ }
437
+ .translation .delete:hover {
438
+ background-color: #900;
439
+ }
403
440
  .translation .keytext {
404
441
  padding: 5px;
405
442
  color: #678;
@@ -17,11 +17,25 @@ module RailsI18nterface
17
17
  @total_entries = @keys.size
18
18
  end
19
19
 
20
+ def destroy
21
+ term = Translation.find_by_key(params[:key])
22
+ if term.destroy!
23
+ render json: 'ok'
24
+ else
25
+ render json: 'error'
26
+ end
27
+ end
28
+
20
29
  def load_db_translations
21
30
  @versions = {}
22
31
  @dbvalues = {@to_locale => {}}
23
32
  (Translation.where(:locale => @to_locale) || []).each { |translation|
24
33
  @versions[translation.key] = translation.updated_at.to_i
34
+ yaml_value = I18n.backend.send(:lookup, @to_locale, translation.key)
35
+ if (yaml_value and translation.value != yaml_value)
36
+ translation.value = yaml_value
37
+ Translation.where(key: translation.key).first.update_attribute(:value, yaml_value)
38
+ end
25
39
  @dbvalues[@to_locale][translation.key] = translation.value
26
40
  @keys << translation.key
27
41
  }
@@ -79,14 +79,19 @@
79
79
  <div class="translation">
80
80
  <p class="edit-form">
81
81
  <%= hidden_field_tag("version[#{key}]", @versions[key] || '0') %>
82
- <% if n_lines > 1 %>
83
- <span class="right">
82
+ <% if n_lines > 1 %>
83
+ <div class="right">
84
+ <% if @files[key] %>
85
+ <div class="files">
86
+ <div class="count">found in <%= @files[key].count %> files</div>
87
+ <div class="filelist">
88
+ <div><%= @files[key].join("</div><div>").html_safe %></div>
89
+ </div>
90
+ </div>
91
+ <% end %>
84
92
  <span class="key"><%=h key %></span>
85
- <% if @files[key] %>
86
- <span class="file"><%= @files[key].join("</span><span class=\"file\">").html_safe %></span>
87
- <% end %>
88
- </span>
89
- </span>
93
+ <a href="#" class="delete" title="Delete this key from database">X</a>
94
+ </div>
90
95
  <div class="long-translation">
91
96
  <div class="translation-text">
92
97
  <pre id="<%= tid %>_original"><%= from_text %></pre>
@@ -98,21 +103,26 @@
98
103
  </div>
99
104
  <div class="clear"></div>
100
105
  </div>
101
- <% else %>
102
- <span class="translation-text">
103
- <code class="keytext" id="<%= tid %>_original"><%= from_text %></code>
104
- </span>
105
- <span class="right">
106
- <span class="key" ><%=h key %></span>
107
- <% if @files[key] %>
108
- <span class="file"><%= @files[key].join("</span><span class=\"file\">").html_safe %></span>
109
- <% end %>
110
- </span>
111
- </span>
106
+ <% else %>
107
+ <div class="right">
108
+ <% if @files[key] %>
109
+ <div class="files">
110
+ <div class="count">found in <%= @files[key].count %> files</div>
111
+ <div class="filelist">
112
+ <div><%= @files[key].join("</div><div>").html_safe %></div>
113
+ </div>
114
+ </div>
115
+ <% end %>
116
+ <span class="key" ><%=h key %></span>
117
+ <a href="#" class="delete" title="Delete this key from database">X</a>
118
+ </div>
119
+ <div class="translation-text">
120
+ <code class="keytext" id="<%= tid %>_original"><%= from_text %></code>
121
+ </div>
112
122
 
113
- <%= text_field_tag(field_name, to_text, :size => line_size, :id => tid) %>
114
- <% end %>
115
- </p>
123
+ <%= text_field_tag(field_name, to_text, :size => line_size, :id => tid) %>
124
+ <% end %>
125
+ </p>
116
126
  <p>
117
127
  </p>
118
128
  </div>
data/config/routes.rb CHANGED
@@ -4,4 +4,5 @@ RailsI18nterface::Engine.routes.draw do
4
4
  put '/translate' => 'translate#update'
5
5
  get '/reload' => 'translate#reload', :as => 'translate_reload'
6
6
  get '/export' => 'translate#export', :as => 'translate_export'
7
+ delete '/delete/*key' => 'translate#destroy', format: false
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module RailsI18nterface
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -519,3 +519,13 @@ Migrating to CreateTranslations (20110921112044)
519
519
   (0.4ms) CREATE TABLE "translations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "locale" varchar(255), "key" varchar(255), "value" text, "interpolations" text, "is_proc" boolean DEFAULT 'f', "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
520
520
   (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110921112044')
521
521
   (151.3ms) commit transaction
522
+ Connecting to database specified by database.yml
523
+  (0.1ms) select sqlite_version(*)
524
+  (214.8ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
525
+  (158.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
526
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
527
+ Migrating to CreateTranslations (20110921112044)
528
+  (0.0ms) begin transaction
529
+  (0.3ms) CREATE TABLE "translations" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "locale" varchar(255), "key" varchar(255), "value" text, "interpolations" text, "is_proc" boolean DEFAULT 'f', "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
530
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20110921112044')
531
+  (129.3ms) commit transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-i18nterface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mose