lolita-i18n 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/LICENSE.txt +20 -20
- data/README.md +11 -1
- data/app/assets/javascripts/lolita/i18n/i18n.js +47 -43
- data/app/helpers/lolita/i18n_helper.rb +25 -9
- data/app/views/lolita/i18n/index.html.haml +8 -6
- data/config/locales/en.yml +2 -1
- data/config/locales/lv.yml +1 -0
- data/lib/lolita-i18n/configuration.rb +10 -3
- data/lib/lolita-i18n/key_value_recorder.rb +26 -0
- data/lib/lolita-i18n/middleware/recorder.rb +15 -0
- data/lib/lolita-i18n/request.rb +6 -2
- data/lib/lolita-i18n/version.rb +2 -2
- data/lib/lolita-i18n.rb +2 -0
- data/spec/helpers/lolita/i18n_helper_spec.rb +28 -21
- data/spec/lolita-i18n/request_spec.rb +17 -6
- metadata +22 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 651b4da84cc95ebe17a949648060438bf5424f76
|
4
|
+
data.tar.gz: 9b2b8dcec371955060a0ad8ad2cf9c38c35f63a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61143734cfd5290f2901a53590cde5488d7626e94b0dc8d193f0bb71983dcca2031ae8a5c109e5d43108b4beec4335b12fb345abaffdb605d8711d1bdfecf17c
|
7
|
+
data.tar.gz: ecdf29b85d156e320ad51666567bd309d0eac46922a5d24964d3d01fdf573e646c900ee7e2c1899dfc12ac2a461192980f135157dbd105209e4fc07fc3d05d18
|
data/Gemfile
CHANGED
@@ -6,11 +6,11 @@ group :test do
|
|
6
6
|
gem 'byebug'
|
7
7
|
gem 'rails', '~> 3.2.0'
|
8
8
|
gem 'simplecov', '~> 0.7.1'
|
9
|
-
gem 'bson_ext', '~> 1.
|
9
|
+
gem 'bson_ext', '~> 1.10.1'
|
10
10
|
gem 'mongoid', '~> 2.7.1'
|
11
11
|
gem 'rspec-rails', '~> 2.14'
|
12
12
|
gem 'capybara', '~> 2.1'
|
13
|
-
gem 'selenium-webdriver', '~> 2.
|
13
|
+
gem 'selenium-webdriver', '~> 2.41.0'
|
14
14
|
gem 'sass', '~> 3.2.3'
|
15
15
|
gem 'coffee-script', '~>2.2.0'
|
16
|
-
end
|
16
|
+
end
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2011 ITHouse (Latvia) and Arturs Meisters
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2011 ITHouse (Latvia) and Arturs Meisters
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -38,6 +38,16 @@ Add this to `unicorn.rb`
|
|
38
38
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
39
39
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
40
40
|
|
41
|
+
## Registering URL's to understand from where translation comes
|
42
|
+
|
43
|
+
In your conifg/evironments/xxx.rb add this:
|
44
|
+
|
45
|
+
MyCool::Application.configure do
|
46
|
+
config.middleware.use Lolita::I18n::Recorder
|
47
|
+
end
|
48
|
+
|
49
|
+
After adding go manualy trough the whole site /urls. All translations will be registerd with linked url.
|
50
|
+
|
41
51
|
---
|
42
52
|
|
43
|
-
Copyright (c)
|
53
|
+
Copyright (c) 2014 ITHouse (Latvia). See LICENSE.txt for further details.
|
@@ -1,72 +1,76 @@
|
|
1
1
|
$(function(){
|
2
2
|
|
3
3
|
$('#active_locale').change(function(){
|
4
|
-
params("active_locale",$(this).val())
|
5
|
-
})
|
4
|
+
params("active_locale",$(this).val());
|
5
|
+
});
|
6
6
|
|
7
7
|
$('#show_untranslated').change(function(){
|
8
|
-
params("show_untranslated", $(this).is(':checked') ? "1" : false)
|
9
|
-
})
|
8
|
+
params("show_untranslated", $(this).is(':checked') ? "1" : false);
|
9
|
+
});
|
10
|
+
|
11
|
+
$('#show_with_url').change(function(){
|
12
|
+
params("show_with_url", $(this).is(':checked') ? "1" : false);
|
13
|
+
});
|
10
14
|
|
11
15
|
var resize = function($textarea) {
|
12
16
|
$textarea[0].style.height = 'auto';
|
13
|
-
$textarea[0].style.height = ($textarea[0].scrollHeight + $textarea.data("offset") ) + 'px';
|
14
|
-
}
|
17
|
+
$textarea[0].style.height = ($textarea[0].scrollHeight + $textarea.data("offset") ) + 'px';
|
18
|
+
};
|
15
19
|
|
16
20
|
var reset_size = function($textarea){
|
17
21
|
$textarea[0].style.height = 'auto';
|
18
|
-
$textarea[0].style.height = ($textarea.data("offset") ) + 'px';
|
19
|
-
}
|
22
|
+
$textarea[0].style.height = ($textarea.data("offset") ) + 'px';
|
23
|
+
};
|
20
24
|
|
21
25
|
$("textarea").each(function(){
|
22
|
-
var t = $(this)[0]
|
26
|
+
var t = $(this)[0];
|
23
27
|
var offset= !window.opera ? (t.offsetHeight - t.clientHeight) : (t.offsetHeight + parseInt(window.getComputedStyle(t, null).getPropertyValue('border-top-width'))) ;
|
24
|
-
$(this).data("offset",offset)
|
25
|
-
})
|
28
|
+
$(this).data("offset",offset);
|
29
|
+
});
|
26
30
|
|
27
31
|
$("textarea").keyup(function(){
|
28
|
-
resize($(this))
|
29
|
-
})
|
32
|
+
resize($(this));
|
33
|
+
});
|
30
34
|
|
31
35
|
$("textarea").focus(function(){
|
32
|
-
resize($(this))
|
33
|
-
$(this).data("original-text",$(this).val())
|
34
|
-
})
|
36
|
+
resize($(this));
|
37
|
+
$(this).data("original-text",$(this).val());
|
38
|
+
});
|
35
39
|
|
36
40
|
$("textarea").blur(function(){
|
37
41
|
if($(this).data("original-text")!=$(this).val()){
|
38
|
-
$(this).data("original-text",false)
|
39
|
-
var $td = $(this).parents("td:eq(0)")
|
40
|
-
var key = $td.data("key")
|
41
|
-
var locale = $td.data("locale")
|
42
|
+
$(this).data("original-text",false);
|
43
|
+
var $td = $(this).parents("td:eq(0)");
|
44
|
+
var key = $td.data("key");
|
45
|
+
var locale = $td.data("locale");
|
42
46
|
var $textareas = $("td[data-key='"+key+"'] textarea");
|
43
|
-
var result_str = ""
|
44
|
-
var result_arr = false
|
45
|
-
var result_json = false
|
47
|
+
var result_str = "";
|
48
|
+
var result_arr = false;
|
49
|
+
var result_json = false;
|
46
50
|
|
47
51
|
if($textareas.length > 1){
|
48
52
|
$textareas.each(function(index){
|
49
|
-
var current_key = locale + "." + $(this).attr("name")
|
50
|
-
var m_data = current_key.match(/\[(\d+)\]$/)
|
53
|
+
var current_key = locale + "." + $(this).attr("name");
|
54
|
+
var m_data = current_key.match(/\[(\d+)\]$/);
|
51
55
|
if(m_data){
|
52
|
-
result_arr = result_arr || []
|
53
|
-
result_arr[parseInt(m_data[m_data.length-1])] = $(this).val()
|
56
|
+
result_arr = result_arr || [];
|
57
|
+
result_arr[parseInt(m_data[m_data.length-1])] = $(this).val();
|
54
58
|
}else{
|
55
|
-
result_json = result_json || {}
|
56
|
-
keys = current_key.split(".")
|
57
|
-
json_key = keys[keys.length-1]
|
58
|
-
result_json[json_key] = $(this).val()
|
59
|
+
result_json = result_json || {};
|
60
|
+
keys = current_key.split(".");
|
61
|
+
json_key = keys[keys.length-1];
|
62
|
+
result_json[json_key] = $(this).val();
|
59
63
|
}
|
60
|
-
})
|
64
|
+
});
|
61
65
|
}else{
|
62
|
-
result_str = $textareas.eq(0).val()
|
66
|
+
result_str = $textareas.eq(0).val();
|
63
67
|
}
|
64
|
-
|
65
|
-
new_id = Base64.encode(key)
|
66
|
-
save(result_arr || result_json || result_str, new_id)
|
68
|
+
|
69
|
+
new_id = Base64.encode(key);
|
70
|
+
save(result_arr || result_json || result_str, new_id);
|
67
71
|
}
|
68
|
-
reset_size($(this))
|
69
|
-
})
|
72
|
+
reset_size($(this));
|
73
|
+
});
|
70
74
|
|
71
75
|
var save = function(post_data,id){
|
72
76
|
$.ajax({
|
@@ -76,12 +80,12 @@ $(function(){
|
|
76
80
|
dataType: 'json',
|
77
81
|
success: function(data){
|
78
82
|
if(data.error){
|
79
|
-
show_error_msg( data.error)
|
83
|
+
show_error_msg( data.error);
|
80
84
|
}
|
81
85
|
},
|
82
86
|
error: function(request){
|
83
|
-
show_error_msg("Connection error! Translation is not saved!")
|
87
|
+
show_error_msg("Connection error! Translation is not saved!");
|
84
88
|
}
|
85
|
-
})
|
86
|
-
}
|
87
|
-
})
|
89
|
+
});
|
90
|
+
};
|
91
|
+
});
|
@@ -7,7 +7,7 @@ module Lolita
|
|
7
7
|
}
|
8
8
|
end
|
9
9
|
|
10
|
-
def translation active_locale, key, original_key, translation, original
|
10
|
+
def translation active_locale, key, original_key, translation, original, url = nil
|
11
11
|
%Q{
|
12
12
|
<td style="width:450px", data-key="#{active_locale}.#{original_key}" data-locale="#{active_locale}">
|
13
13
|
<p>
|
@@ -18,22 +18,38 @@ module Lolita
|
|
18
18
|
<p>
|
19
19
|
#{text_area_tag "#{::I18n.default_locale}.#{key}", original}
|
20
20
|
</p>
|
21
|
-
#{!key.blank?
|
21
|
+
#{!key.blank? ? "<span class='hint'>#{key}</span>" : ''}
|
22
|
+
#{url.present? ? "<span class='hint'>#{url}</span>" : ''}
|
22
23
|
</td>
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
|
27
|
+
def is_untranslated? value
|
28
|
+
if value.is_a?(Array) || value.is_a?(Hash)
|
29
|
+
true
|
30
|
+
else
|
31
|
+
value.blank?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def translation_visible? value, url
|
36
|
+
result = true
|
37
|
+
if params[:show_untranslated]
|
38
|
+
result = result && is_untranslated?(value)
|
39
|
+
end
|
40
|
+
if params[:show_with_url]
|
41
|
+
result = result && url.present?
|
42
|
+
end
|
43
|
+
result
|
28
44
|
end
|
29
45
|
|
30
|
-
def any_translation_visible? values
|
46
|
+
def any_translation_visible? values, url
|
31
47
|
if values.is_a?(Array)
|
32
|
-
values.empty? || values.detect{|value| translation_visible?(value)}
|
48
|
+
values.empty? || values.detect{|value| translation_visible?(value, url)}
|
33
49
|
elsif values.is_a?(Hash)
|
34
|
-
values.empty? || values.detect{|key,value| translation_visible?(value)}
|
50
|
+
values.empty? || values.detect{|key,value| translation_visible?(value, url)}
|
35
51
|
else
|
36
|
-
translation_visible?(values)
|
52
|
+
translation_visible?(values, url)
|
37
53
|
end
|
38
54
|
end
|
39
55
|
|
@@ -47,4 +63,4 @@ module Lolita
|
|
47
63
|
link_to(raw("#{::I18n.t(::I18n.default_locale)} #{params[:sort] && "⇑"}"), url_for_sort, :id => "translation_sort_link")
|
48
64
|
end
|
49
65
|
end
|
50
|
-
end
|
66
|
+
end
|
@@ -11,6 +11,8 @@
|
|
11
11
|
.filters
|
12
12
|
= check_box_tag "show_untranslated", nil, params[:show_untranslated]
|
13
13
|
= label_tag "show_untranslated", ::I18n.t('lolita-i18n.show-untranslated', :default => ::I18n.t('lolita-i18n.show-untranslated'))
|
14
|
+
= check_box_tag "show_with_url", nil, params[:show_with_url]
|
15
|
+
= label_tag "show_with_url", ::I18n.t('lolita-i18n.show-with-url', :default => ::I18n.t('lolita-i18n.show-with-url'))
|
14
16
|
%table
|
15
17
|
%thead
|
16
18
|
%tr
|
@@ -21,20 +23,20 @@
|
|
21
23
|
%tbody
|
22
24
|
- active_locale = @active_locale
|
23
25
|
- @translations.each do |key,value|
|
24
|
-
- if @active_locale && any_translation_visible?(value[:translation])
|
26
|
+
- if @active_locale && any_translation_visible?(value[:translation], value[:url])
|
25
27
|
%tr
|
26
28
|
- if value[:original_translation].is_a?(Hash) || value[:original_translation].is_a?(Array)
|
27
29
|
%td.grouped{:colspan => "2"}
|
28
30
|
%table
|
29
31
|
- if value[:original_translation].is_a?(Hash)
|
30
32
|
- value[:original_translation].each do |c_key,c_value|
|
31
|
-
- if translation_visible?(value[:translation][c_key])
|
33
|
+
- if translation_visible?(value[:translation][c_key], value[:url])
|
32
34
|
%tr
|
33
|
-
= raw(translation(@active_locale,"#{key}.#{c_key}",key,value[:translation][c_key],c_value))
|
35
|
+
= raw(translation(@active_locale,"#{key}.#{c_key}",key,value[:translation][c_key],c_value,value[:url]))
|
34
36
|
- else
|
35
37
|
- value[:original_translation].each_with_index do |c_value,index|
|
36
|
-
- if translation_visible?(value[:translation][index])
|
38
|
+
- if translation_visible?(value[:translation][index], value[:url])
|
37
39
|
%tr
|
38
|
-
= raw(translation(@active_locale, "#{key}[#{index}]", key, value[:translation][index], c_value))
|
40
|
+
= raw(translation(@active_locale, "#{key}[#{index}]", key, value[:translation][index], c_value,value[:url]))
|
39
41
|
- else
|
40
|
-
= raw(translation(@active_locale, key, key, value[:translation], value[:original_translation]))
|
42
|
+
= raw(translation(@active_locale, key, key, value[:translation], value[:original_translation],value[:url]))
|
data/config/locales/en.yml
CHANGED
data/config/locales/lv.yml
CHANGED
@@ -2,7 +2,9 @@ module Lolita
|
|
2
2
|
module I18n
|
3
3
|
class Configuration
|
4
4
|
|
5
|
-
attr_accessor :yaml_backend
|
5
|
+
attr_accessor :yaml_backend,
|
6
|
+
:request_path_info
|
7
|
+
attr_reader :recording_request_path_info
|
6
8
|
|
7
9
|
def load_rails!
|
8
10
|
if Lolita.rails3?
|
@@ -30,7 +32,8 @@ module Lolita
|
|
30
32
|
|
31
33
|
# Lazy create new KeyValue backend with current store.
|
32
34
|
def backend
|
33
|
-
@backend ||=
|
35
|
+
@backend ||= KeyValueRecorder.new(self.store)
|
36
|
+
#@backend ||= ::I18n::Backend::KeyValue.new(self.store)
|
34
37
|
end
|
35
38
|
|
36
39
|
# Load translation from yaml.
|
@@ -92,7 +95,11 @@ module Lolita
|
|
92
95
|
::I18n::Backend::Simple.send(:include, ::I18n::Backend::Pluralization)
|
93
96
|
::I18n::Backend::Simple.send(:include, ::I18n::Backend::InterpolationCompiler)
|
94
97
|
end
|
98
|
+
|
99
|
+
def set_recording_request_path_info
|
100
|
+
@recording_request_path_info = true
|
101
|
+
end
|
95
102
|
end
|
96
103
|
|
97
104
|
end
|
98
|
-
end
|
105
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Lolita
|
2
|
+
module I18n
|
3
|
+
class KeyValueRecorder < ::I18n::Backend::KeyValue
|
4
|
+
protected
|
5
|
+
|
6
|
+
def lookup(locale, key, scope = [], options = {})
|
7
|
+
key = normalize_flat_keys(locale, key, scope, options[:separator])
|
8
|
+
if Lolita.i18n.recording_request_path_info
|
9
|
+
store_request_path_info(key)
|
10
|
+
end
|
11
|
+
value = @store["#{locale}.#{key}"]
|
12
|
+
value = ActiveSupport::JSON.decode(value) if value
|
13
|
+
value.is_a?(Hash) ? value.deep_symbolize_keys : value
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def store_request_path_info(key)
|
19
|
+
return if @store["views.#{key}"].present? ||
|
20
|
+
(Lolita.i18n.request_path_info && Lolita.i18n.request_path_info.match(/^\/lolita/))
|
21
|
+
@store["views.#{key}"] = Lolita.i18n.request_path_info
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lolita
|
2
|
+
module I18n
|
3
|
+
class Recorder
|
4
|
+
def initialize(app, options = {})
|
5
|
+
@app, @options = app, options
|
6
|
+
Lolita.i18n.set_recording_request_path_info
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
Lolita.i18n.request_path_info = env['PATH_INFO']
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/lolita-i18n/request.rb
CHANGED
@@ -109,7 +109,11 @@ module Lolita
|
|
109
109
|
unless @normalized
|
110
110
|
@normalized = {}
|
111
111
|
flatten_keys(@translations,locale) do |key,value,original_value|
|
112
|
-
@normalized[key] = {
|
112
|
+
@normalized[key] = {
|
113
|
+
:translation => value,
|
114
|
+
:original_translation => original_value,
|
115
|
+
:url => Lolita.i18n.store["views.#{key}"]
|
116
|
+
}
|
113
117
|
end
|
114
118
|
end
|
115
119
|
@normalized
|
@@ -128,7 +132,7 @@ module Lolita
|
|
128
132
|
|
129
133
|
def final_value?(value)
|
130
134
|
!value.is_a?(Hash) ||
|
131
|
-
(value.is_a?(Hash) && value.keys.map(&:to_sym).include?(:other) && value.keys.size > 1 && !value.values.detect{|
|
135
|
+
(value.is_a?(Hash) && value.keys.map(&:to_sym).include?(:other) && value.keys.size > 1 && !value.values.detect{|val| val.is_a?(Array) || val.is_a?(Hash)})
|
132
136
|
end
|
133
137
|
|
134
138
|
def translation_value key, value, locale
|
data/lib/lolita-i18n/version.rb
CHANGED
data/lib/lolita-i18n.rb
CHANGED
@@ -13,6 +13,8 @@ module Lolita
|
|
13
13
|
# # or
|
14
14
|
# config.i18n.store = Redis.new() # default store
|
15
15
|
module I18n
|
16
|
+
autoload :Recorder, 'lolita-i18n/middleware/recorder'
|
17
|
+
autoload :KeyValueRecorder, 'lolita-i18n/key_value_recorder'
|
16
18
|
autoload :Request, 'lolita-i18n/request'
|
17
19
|
autoload :Exceptions, 'lolita-i18n/exceptions'
|
18
20
|
autoload :Configuration, 'lolita-i18n/configuration'
|
@@ -10,44 +10,51 @@ describe Lolita::I18nHelper, :rails => true do
|
|
10
10
|
helper.locale_options.should eq(good_locale_options)
|
11
11
|
end
|
12
12
|
|
13
|
+
it "#is_untranslated?" do
|
14
|
+
helper.is_untranslated?("").should be_true
|
15
|
+
helper.is_untranslated?("text").should be_false
|
16
|
+
helper.is_untranslated?([]).should be_true
|
17
|
+
helper.is_untranslated?({}).should be_true
|
18
|
+
end
|
19
|
+
|
13
20
|
it "translation is visible when value is not blank and params does not say to show only untranslated values" do
|
14
|
-
helper.translation_visible?("").should be_true
|
15
|
-
helper.translation_visible?("text").should be_true
|
16
|
-
helper.translation_visible?([]).should be_true
|
17
|
-
helper.translation_visible?({}).should be_true
|
21
|
+
helper.translation_visible?("", nil).should be_true
|
22
|
+
helper.translation_visible?("text", nil).should be_true
|
23
|
+
helper.translation_visible?([], nil).should be_true
|
24
|
+
helper.translation_visible?({}, nil).should be_true
|
18
25
|
|
19
26
|
helper.params[:show_untranslated] = true
|
20
|
-
helper.translation_visible?("").should be_true
|
21
|
-
helper.translation_visible?("text").should be_false
|
22
|
-
helper.translation_visible?([]).should be_true
|
23
|
-
helper.translation_visible?({}).should be_true
|
27
|
+
helper.translation_visible?("", nil).should be_true
|
28
|
+
helper.translation_visible?("text", nil).should be_false
|
29
|
+
helper.translation_visible?([], nil).should be_true
|
30
|
+
helper.translation_visible?({}, nil).should be_true
|
24
31
|
end
|
25
32
|
|
26
33
|
describe "#any_translation_visible?" do
|
27
34
|
it "should detect if any translation from array is visible" do
|
28
|
-
helper.any_translation_visible?([2,1]).should be_true
|
29
|
-
helper.any_translation_visible?([]).should be_true
|
35
|
+
helper.any_translation_visible?([2,1], nil).should be_true
|
36
|
+
helper.any_translation_visible?([], nil).should be_true
|
30
37
|
|
31
38
|
helper.params[:show_untranslated] = true
|
32
|
-
helper.any_translation_visible?([]).should be_true
|
33
|
-
helper.any_translation_visible?(["",1]).should be_true
|
34
|
-
helper.any_translation_visible?(["a","b"]).should be_false
|
39
|
+
helper.any_translation_visible?([], nil).should be_true
|
40
|
+
helper.any_translation_visible?(["",1], nil).should be_true
|
41
|
+
helper.any_translation_visible?(["a","b"], nil).should be_false
|
35
42
|
end
|
36
43
|
|
37
44
|
|
38
45
|
it "should detect if any translation from hash is visible" do
|
39
|
-
helper.any_translation_visible?({:a => "1",:b => "2" }).should be_true
|
40
|
-
helper.any_translation_visible?([]).should be_true
|
46
|
+
helper.any_translation_visible?({:a => "1",:b => "2" }, nil).should be_true
|
47
|
+
helper.any_translation_visible?([], nil).should be_true
|
41
48
|
|
42
49
|
helper.params[:show_untranslated] = true
|
43
|
-
helper.any_translation_visible?({}).should be_true
|
44
|
-
helper.any_translation_visible?({:a => "1",:b => "2" }).should be_false
|
45
|
-
helper.any_translation_visible?({:a => "1",:b => "" }).should be_true
|
50
|
+
helper.any_translation_visible?({}, nil).should be_true
|
51
|
+
helper.any_translation_visible?({:a => "1",:b => "2" }, nil).should be_false
|
52
|
+
helper.any_translation_visible?({:a => "1",:b => "" }, nil).should be_true
|
46
53
|
end
|
47
54
|
|
48
55
|
it "should call #translation_visible? for any other value" do
|
49
|
-
helper.should_receive(:translation_visible?).with("text")
|
50
|
-
helper.any_translation_visible?("text")
|
56
|
+
helper.should_receive(:translation_visible?).with("text", '/url')
|
57
|
+
helper.any_translation_visible?("text", '/url')
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
@@ -67,4 +74,4 @@ describe Lolita::I18nHelper, :rails => true do
|
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
70
|
-
end
|
77
|
+
end
|
@@ -167,17 +167,28 @@ describe Lolita::I18n::Request do
|
|
167
167
|
result.should eq(valid_results)
|
168
168
|
end
|
169
169
|
|
170
|
-
it "should normalize for locale" do
|
170
|
+
it "should normalize for locale" do
|
171
171
|
t = klass.new(translations)
|
172
172
|
valid_results = {
|
173
|
-
:arr => {:translation => [], :original_translation => [1,2]},
|
174
|
-
:str => {:translation => "-no-translation-", :original_translation => "string"},
|
175
|
-
:inter => {:translation => {}, :original_translation => {:one => "one", :other => "other"}},
|
176
|
-
:"hsh.key" => {:translation => "-no-translation-", :original_translation => "value"}
|
173
|
+
:arr => {:translation => [], :original_translation => [1,2], :url => nil},
|
174
|
+
:str => {:translation => "-no-translation-", :original_translation => "string", :url => nil},
|
175
|
+
:inter => {:translation => {}, :original_translation => {:one => "one", :other => "other"}, :url => nil},
|
176
|
+
:"hsh.key" => {:translation => "-no-translation-", :original_translation => "value", :url => nil}
|
177
177
|
}
|
178
178
|
t.normalized(:lv).should eq(valid_results)
|
179
179
|
end
|
180
180
|
|
181
|
+
it "should normalize for locale end retur registerd URL" do
|
182
|
+
Redis.any_instance.stub(:[]).and_return '/kekss'
|
183
|
+
t = klass.new(translations)
|
184
|
+
valid_results = {
|
185
|
+
:arr => {:translation => [], :original_translation => [1,2], :url => '/kekss'},
|
186
|
+
:str => {:translation => "-no-translation-", :original_translation => "string", :url => '/kekss'},
|
187
|
+
:inter => {:translation => {}, :original_translation => {:one => "one", :other => "other"}, :url => '/kekss'},
|
188
|
+
:"hsh.key" => {:translation => "-no-translation-", :original_translation => "value", :url => '/kekss'}
|
189
|
+
}
|
190
|
+
t.normalized(:lv).should eq(valid_results)
|
191
|
+
end
|
181
192
|
end
|
182
193
|
|
183
194
|
let(:request_klass){Lolita::I18n::Request}
|
@@ -235,4 +246,4 @@ describe Lolita::I18n::Request do
|
|
235
246
|
end
|
236
247
|
|
237
248
|
|
238
|
-
end
|
249
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolita-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ITHouse (Latvia)
|
@@ -10,90 +10,90 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: lolita
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - ~>
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - ~>
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '3.2'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: i18n
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - ~>
|
33
|
+
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: 0.6.1
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - ~>
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 0.6.1
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: hiredis
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - ~>
|
47
|
+
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 0.4.5
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ~>
|
54
|
+
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 0.4.5
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: redis
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - ~>
|
61
|
+
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 3.0.3
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - ~>
|
68
|
+
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: 3.0.3
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: yajl-ruby
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- - ~>
|
75
|
+
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.1.0
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - ~>
|
82
|
+
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: 1.1.0
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: unicode_utils
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- - ~>
|
89
|
+
- - "~>"
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: 1.4.0
|
92
92
|
type: :runtime
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- - ~>
|
96
|
+
- - "~>"
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: 1.4.0
|
99
99
|
description: Lolita plugin, that enables .yml files management from administrative
|
@@ -105,9 +105,9 @@ extra_rdoc_files:
|
|
105
105
|
- LICENSE.txt
|
106
106
|
- README.md
|
107
107
|
files:
|
108
|
-
- .document
|
109
|
-
- .gitignore
|
110
|
-
- .rspec
|
108
|
+
- ".document"
|
109
|
+
- ".gitignore"
|
110
|
+
- ".rspec"
|
111
111
|
- Gemfile
|
112
112
|
- History.rdoc
|
113
113
|
- LICENSE.txt
|
@@ -127,6 +127,8 @@ files:
|
|
127
127
|
- lib/lolita-i18n.rb
|
128
128
|
- lib/lolita-i18n/configuration.rb
|
129
129
|
- lib/lolita-i18n/exceptions.rb
|
130
|
+
- lib/lolita-i18n/key_value_recorder.rb
|
131
|
+
- lib/lolita-i18n/middleware/recorder.rb
|
130
132
|
- lib/lolita-i18n/module.rb
|
131
133
|
- lib/lolita-i18n/rails.rb
|
132
134
|
- lib/lolita-i18n/request.rb
|
@@ -167,17 +169,17 @@ require_paths:
|
|
167
169
|
- lib
|
168
170
|
required_ruby_version: !ruby/object:Gem::Requirement
|
169
171
|
requirements:
|
170
|
-
- -
|
172
|
+
- - ">="
|
171
173
|
- !ruby/object:Gem::Version
|
172
174
|
version: '0'
|
173
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
176
|
requirements:
|
175
|
-
- -
|
177
|
+
- - ">="
|
176
178
|
- !ruby/object:Gem::Version
|
177
179
|
version: '0'
|
178
180
|
requirements: []
|
179
181
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
182
|
+
rubygems_version: 2.2.1
|
181
183
|
signing_key:
|
182
184
|
specification_version: 4
|
183
185
|
summary: Lolita plugin, that enables .yml management
|