expat 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 436114e3e51cbd41fa83aad8b22772f4c44b127d
4
- data.tar.gz: b0f16ab44d8d6fb85ab73bb103b5afe91e80caac
3
+ metadata.gz: c9205ebd1f04d3cc1ea7d0635dc4a00e8d3e6b31
4
+ data.tar.gz: ada39731405acbc07114da232971fc4ffec36e2a
5
5
  SHA512:
6
- metadata.gz: 5785307062fd5f47e4766077c5a8f6b7cbaf757d3377f4d0d1a6a74881035b05551895fdf25178f9704816e176ff128aca384cf6f4c5d3997763898e24526d33
7
- data.tar.gz: f82276bb48c22769e20b8117428b368ced69e1b82db58ed6b31fa46bc0f9ab000991a4667352587e7c8ee8bba5fb50a86ba41a0dd320a9dc6ad3ea48c05afbfb
6
+ metadata.gz: e4d9138016aa8389c8854e0e5b71ba75570915df550ee4c296f84389021f774f4e6c98de5a272884c8a73bab9c85ae3a7fe348c422700b9f8d1097e48f00854c
7
+ data.tar.gz: a23282e10acb1ddabf580920bf4afda8940acc84d52d3bc3a284de5b217baa7b4b78e48c7e26bb32579958b69f70f15cd62da09fe623c680f8038e390f48d454
@@ -21,3 +21,8 @@ table {
21
21
  td {
22
22
  border: 1px solid #ccc;
23
23
  }
24
+
25
+ .translation_missing {
26
+ background: #f00;
27
+ color: #fff;
28
+ }
@@ -1,5 +1,19 @@
1
1
  module Expat
2
2
  class ApplicationController < ActionController::Base
3
3
  protect_from_forgery with: :exception
4
+
5
+ protected
6
+
7
+ def list_locales
8
+ locales = []
9
+
10
+ Dir.open("#{Rails.root}/config/locales").each do |file|
11
+ unless ['.', '..'].include?(file) || file[0] == '.'
12
+ locales << file[0...-4] # strip of .yml
13
+ end
14
+ end
15
+
16
+ locales
17
+ end
4
18
  end
5
19
  end
@@ -3,13 +3,7 @@ require_dependency 'expat/application_controller'
3
3
  module Expat
4
4
  class LocalesController < ApplicationController
5
5
  def index
6
- @locales = []
7
-
8
- Dir.open("#{Rails.root}/config/locales").each do |file|
9
- unless ['.', '..'].include?(file) || file[0] == '.'
10
- @locales << file[0...-4] # strip of .yml
11
- end
12
- end
6
+ @locales = list_locales
13
7
  end
14
8
  end
15
9
  end
@@ -5,6 +5,7 @@ module Expat
5
5
  before_action :load_translations
6
6
 
7
7
  def index
8
+ @translations = append_missing_translations @locale, @translations
8
9
  end
9
10
 
10
11
  def edit
@@ -36,9 +37,28 @@ module Expat
36
37
 
37
38
  def load_translations
38
39
  @locale = params[:locale_id]
39
- path = "#{Rails.root}/config/locales/#{@locale}.yml"
40
+ @translations = load_translation @locale
41
+ end
42
+
43
+ def load_translation locale
44
+ path = "#{Rails.root}/config/locales/#{locale}.yml"
40
45
  yml = YAML.load_file path
41
- @translations = iterate yml[@locale], ''
46
+ iterate yml[locale], ''
47
+ end
48
+
49
+ def append_missing_translations current, current_translations
50
+ result = {}
51
+
52
+ list_locales.each do |locale|
53
+ next if current == locale
54
+
55
+ translation = load_translation locale
56
+ (current_translations.keys | translation.keys).each do |key|
57
+ result[key] = current_translations[key]
58
+ end
59
+ end
60
+
61
+ result
42
62
  end
43
63
 
44
64
  def save_translations
@@ -1,5 +1,5 @@
1
1
  <%
2
- if @translation.nil?
2
+ unless params[:id].present?
3
3
  url = locale_translations_path
4
4
  method = :post
5
5
  else
@@ -9,7 +9,7 @@
9
9
  %>
10
10
  <%= form_tag url, method: method do |f| %>
11
11
 
12
- <% if @translation.nil? %>
12
+ <% unless params[:id].present? %>
13
13
  <%= label_tag :key %>
14
14
  <%= text_field_tag :key %><br />
15
15
 
@@ -7,8 +7,13 @@
7
7
  <%= key %>
8
8
  </td>
9
9
  <td>
10
- <%= link_to value, edit_locale_translation_path(
11
- locale_id: @locale, id: key) %>
10
+ <%= link_to edit_locale_translation_path(
11
+ locale_id: @locale, id: key) do %>
12
+ <%= value %>
13
+ <% if value.blank? %>
14
+ <span class="translation_missing">missing</span>
15
+ <% end %>
16
+ <% end %>
12
17
  </td>
13
18
  <td>
14
19
  <%= form_tag locale_translation_path(locale_id: @locale, id: key),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expat
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
  - Frank Groeneveld