i18nline 0.0.8.alpha → 0.0.10.alpha

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: 190237220ad03c94845f1bc328fe174afb79b991
4
- data.tar.gz: 5fc07ed257c12b829ec203ca7822cb98b95330d8
3
+ metadata.gz: 84be485a4a066f3df39cb5e042119dd5fc148fd8
4
+ data.tar.gz: 3795a0deaff69a57779f1eb6d4456ec9d629fd23
5
5
  SHA512:
6
- metadata.gz: 3e354c5232f27c88d5d9ad21622a47b9d47443e3639618745219e9b17bc0e561d772e52bc118a29fb37a51a8a56dbc006fa568d25fae67781221efb8135e9a72
7
- data.tar.gz: 1c68a02650571a608efac21ae567a6abbfbf2669dcf3a38a0a07605f73d13fb80f965dd993e6d186dbbbce01600eaee12365c56595f77a6adbb3881ad4142e55
6
+ metadata.gz: a2e0c707fe888eed80b4b9d181ea0029bd296748589f05a151f0af94fd8dd67e5a7b3e05e5f0f7358c90c72a8a2bccfc8610d2614a5109b954f484e6705ae1f9
7
+ data.tar.gz: ba3161979348cbf5708444b5bd7b27593d61d95326be4a0df7d09db84cb2d4d7466cb23e0240184bc5dea2e845b6e57a983a8d5a39b01cdaf5807fcc9b9694a7
@@ -2,6 +2,10 @@
2
2
  background-color: #EED3D7;
3
3
  }
4
4
 
5
+ #edit_key_set .panel-warning{
6
+ background-color: #FBEED5;
7
+ }
8
+
5
9
  body {
6
10
  font-size: 14px !important;
7
11
  }
@@ -31,6 +31,8 @@ module I18nline
31
31
  is_proc: translations.first.is_proc
32
32
  )
33
33
 
34
+ @should_show_yaml_warning = check_yaml_warning(translations)
35
+
34
36
  render "edit_key" and return
35
37
  end
36
38
 
@@ -52,12 +54,12 @@ module I18nline
52
54
  params[:tr_set][:translation].each do |translation|
53
55
  db_translation = Translation.find(translation.first)
54
56
  if db_translation
55
- db_translation.value = translation.last[:value]
57
+ db_translation.value = convert_to_object(translation.last[:value])
56
58
  db_translation.is_proc = is_proc
57
59
  if translation.last[:make_nil].presence == "1"
58
60
  # it is likely that if value was nil and now is not, 'make_nil' has been left marked
59
61
  # as a mistake, so in that case we ignore it and apply the new value:
60
- unless db_translation.value_changed? and db_translation.value_was.nil?
62
+ unless db_translation.value_changed? && db_translation.value_was.nil? && db_translation.value.present?
61
63
  db_translation.value = nil
62
64
  end
63
65
  end
@@ -69,18 +71,6 @@ module I18nline
69
71
  redirect_to :translations, notice: "Update successful."
70
72
  end
71
73
 
72
- # PATCH/PUT /translations/1
73
- def update
74
- if translation_params[:make_nil].presence == "1"
75
- params[:translation][:value] = nil
76
- end
77
- if @translation.update(translation_params)
78
- redirect_to @translation, notice: 'Translation was successfully updated.'
79
- else
80
- render action: 'edit'
81
- end
82
- end
83
-
84
74
  private
85
75
  # Use callbacks to share common setup or constraints between actions.
86
76
  def set_translation
@@ -91,5 +81,29 @@ module I18nline
91
81
  def translation_params
92
82
  params.require(:translation).permit(:value, :is_proc, :make_nil)
93
83
  end
84
+
85
+ def convert_to_object(value)
86
+ # gsub part is keeping integrity of serialized objects, such as arrays:
87
+ result = value.gsub("\r\n", "\n")
88
+ if value.start_with?("---")
89
+ begin
90
+ result = YAML::load(value)
91
+ rescue Exception => exception
92
+ logger.debug "I18nline: Exception found trying to parse yaml to convert translation value to object:"
93
+ logger.debug exception
94
+ end
95
+ end
96
+ result
97
+ end
98
+
99
+ def check_yaml_warning(translations)
100
+ should_show = false
101
+ if I18nline.show_yaml_warning
102
+ if translations.select{|tt| tt.value and tt.value.class != String}.any?
103
+ should_show = true
104
+ end
105
+ end
106
+ should_show
107
+ end
94
108
  end
95
109
  end
@@ -22,6 +22,14 @@
22
22
  </div>
23
23
  </div>
24
24
  </div>
25
+ <% if @should_show_yaml_warning %>
26
+ <div class="panel panel-default panel-warning">
27
+ <div class="panel-body">
28
+ Please, <b>note:</b> <br>
29
+ At least one translation below is using <a href="http://en.wikipedia.org/wiki/Yaml">Yaml</a>. If you are not familiar with Yaml and serialization, please don't touch the dashes at the beginning of some lines.
30
+ </div>
31
+ </div>
32
+ <% end %>
25
33
  <% @tr_set.translations.each do |translation| %>
26
34
  <% panel_color = translation.value.nil? ? "panel-danger" : "panel-info" %>
27
35
  <div class="panel panel-default <%= panel_color %>">
@@ -29,8 +37,10 @@
29
37
  <%= f.fields_for "translation[]", translation do |tl_form| %>
30
38
  <div class="input-group col-sm-offset-2">
31
39
  <span class="input-group-addon"><%= translation.locale %></span>
32
- <% rows = (translation.value.to_s.length / 100) + 1 %>
33
- <%= tl_form.text_area :value, class: "form-control", rows: "#{rows}" %>
40
+ <% translation.value = translation.value.to_yaml if translation.value && translation.value.class != String %>
41
+ <% rows = (translation.value.to_s.length / 120) + 1 %>
42
+ <% height = rows * 36 %>
43
+ <%= tl_form.text_area :value, class: "form-control", style: "height:#{height}px !important;" %>
34
44
  </div>
35
45
  <div class="form-group">
36
46
  <div class="col-sm-offset-2 col-sm-10">
@@ -18,4 +18,10 @@ I18nline.setup do |config|
18
18
 
19
19
  # Missing translations will be generated for this locales.
20
20
  #config.enabled_locales = %w(en es it)
21
+
22
+ # Complex translations use serialized yaml objects. If the translator changes
23
+ # the serialization markers, the translation can be made unusable.
24
+ # If 'show_yaml_warning' is set to true, a warning message will appear
25
+ # when accessing a translation set presenting serialized data.
26
+ #config.show_yaml_warning = true
21
27
  end
@@ -1,3 +1,3 @@
1
1
  module I18nline
2
- VERSION = "0.0.8.alpha"
2
+ VERSION = "0.0.10.alpha"
3
3
  end
data/lib/i18nline.rb CHANGED
@@ -18,6 +18,9 @@ module I18nline
18
18
  mattr_accessor :enabled_locales
19
19
  @@enabled_locales = %w(en es it)
20
20
 
21
+ mattr_accessor :show_yaml_warning
22
+ @@show_yaml_warning = true
23
+
21
24
  def self.setup
22
25
  yield self
23
26
  end
@@ -18,4 +18,10 @@ I18nline.setup do |config|
18
18
 
19
19
  # Missing translations will be generated for this locales.
20
20
  config.enabled_locales = %w(en es it pt)
21
+
22
+ # Complex translations use serialized yaml objects. If the translator changes
23
+ # the serialization markers, the translation can be made unusable.
24
+ # If 'show_yaml_warning' is set to true, a warning message will appear
25
+ # when accessing a translation set presenting serialized data.
26
+ config.show_yaml_warning = true
21
27
  end
Binary file