lolita-i18n 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +29 -0
  2. data/Gemfile +11 -25
  3. data/History.rdoc +7 -0
  4. data/README.md +1 -1
  5. data/Rakefile +4 -46
  6. data/app/assets/javascripts/lolita/i18n/application.js +1 -1
  7. data/app/assets/javascripts/lolita/i18n/i18n.js +87 -0
  8. data/app/assets/stylesheets/lolita/i18n/application.scss +8 -7
  9. data/app/controllers/lolita/i18n_controller.rb +27 -9
  10. data/app/helpers/lolita/i18n_helper.rb +40 -7
  11. data/app/views/lolita/i18n/index.html.haml +23 -14
  12. data/config/locales/en.yml +7 -2
  13. data/config/locales/lv.yml +7 -2
  14. data/config/routes.rb +2 -10
  15. data/lib/lolita-i18n.rb +11 -77
  16. data/lib/lolita-i18n/configuration.rb +56 -0
  17. data/lib/lolita-i18n/exceptions.rb +6 -0
  18. data/lib/lolita-i18n/rails.rb +0 -1
  19. data/lib/lolita-i18n/request.rb +219 -0
  20. data/lib/lolita-i18n/version.rb +11 -0
  21. data/lolita-i18n.gemspec +18 -96
  22. data/spec/controllers/lolita/i18n_controller_spec.rb +64 -30
  23. data/spec/helpers/lolita/i18n_helper_spec.rb +70 -0
  24. data/spec/lolita-i18n/configuration_spec.rb +63 -0
  25. data/spec/lolita-i18n/exceptions_spec.rb +15 -0
  26. data/spec/lolita-i18n/request_spec.rb +238 -0
  27. data/spec/lolita-i18n/version_spec.rb +8 -0
  28. data/spec/lolita_i18n_spec.rb +38 -0
  29. data/spec/rails_spec_helper.rb +11 -0
  30. data/spec/requests/translating_spec.rb +51 -0
  31. data/spec/requests/translation_list_spec.rb +36 -0
  32. data/spec/routing/routes_spec.rb +11 -0
  33. data/spec/spec_helper.rb +26 -18
  34. data/spec/{rails_app → test_app}/app/controllers/application_controller.rb +2 -2
  35. data/spec/test_app/config/application.rb +19 -0
  36. data/spec/test_app/config/boot.rb +11 -0
  37. data/spec/{rails_app → test_app}/config/enviroment.rb +4 -4
  38. data/spec/test_app/config/enviroments/test.rb +44 -0
  39. data/spec/test_app/config/initializers/lolita_i18n.rb +4 -0
  40. data/spec/test_app/config/initializers/token.rb +7 -0
  41. data/spec/test_app/config/locales/en.yml +10 -0
  42. data/spec/test_app/config/locales/lv.yml +2 -0
  43. data/spec/test_app/config/locales/ru.yml +2 -0
  44. data/spec/test_app/config/mongoid.yml +6 -0
  45. data/spec/{rails_app → test_app}/config/routes.rb +2 -2
  46. data/spec/test_app/log/.gitkeep +0 -0
  47. data/spec/test_app/log/development.log +734 -0
  48. metadata +69 -80
  49. data/VERSION +0 -1
  50. data/app/assets/javascripts/lolita/i18n/i18n.js.coffee +0 -135
  51. data/lib/lolita-i18n/backend.rb +0 -87
  52. data/spec/lolita-i18n/backend_spec.rb +0 -33
  53. data/spec/rails_app/config/application.rb +0 -18
  54. data/spec/rails_app/config/initializers/lolita_i18n.rb +0 -16
  55. data/spec/rails_app/config/locales/en.yml +0 -10
  56. data/spec/rails_app/config/locales/lv.yml +0 -2
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.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,22 +11,22 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-02-27 00:00:00.000000000 Z
14
+ date: 2012-09-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: lolita
18
- requirement: &83808380 !ruby/object:Gem::Requirement
18
+ requirement: &11765480 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 3.2.0.rc.6
23
+ version: 3.2.0.rc.9
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *83808380
26
+ version_requirements: *11765480
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hiredis
29
- requirement: &83807280 !ruby/object:Gem::Requirement
29
+ requirement: &11764960 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 0.3.1
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *83807280
37
+ version_requirements: *11764960
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: redis
40
- requirement: &83806730 !ruby/object:Gem::Requirement
40
+ requirement: &11764340 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 2.2.2
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *83806730
48
+ version_requirements: *11764340
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: yajl-ruby
51
- requirement: &83805310 !ruby/object:Gem::Requirement
51
+ requirement: &11763640 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,62 +56,18 @@ dependencies:
56
56
  version: 1.0.0
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *83805310
59
+ version_requirements: *11763640
60
60
  - !ruby/object:Gem::Dependency
61
- name: easy_translate
62
- requirement: &83820270 !ruby/object:Gem::Requirement
61
+ name: unicode_utils
62
+ requirement: &11762900 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
66
66
  - !ruby/object:Gem::Version
67
- version: 0.2.1
67
+ version: 1.3.0
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *83820270
71
- - !ruby/object:Gem::Dependency
72
- name: shoulda
73
- requirement: &83816870 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
- type: :development
80
- prerelease: false
81
- version_requirements: *83816870
82
- - !ruby/object:Gem::Dependency
83
- name: bundler
84
- requirement: &83828530 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: 1.0.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: *83828530
93
- - !ruby/object:Gem::Dependency
94
- name: jeweler
95
- requirement: &83824730 !ruby/object:Gem::Requirement
96
- none: false
97
- requirements:
98
- - - ~>
99
- - !ruby/object:Gem::Version
100
- version: 1.5.2
101
- type: :development
102
- prerelease: false
103
- version_requirements: *83824730
104
- - !ruby/object:Gem::Dependency
105
- name: rcov
106
- requirement: &83840380 !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ! '>='
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- type: :development
113
- prerelease: false
114
- version_requirements: *83840380
70
+ version_requirements: *11762900
115
71
  description: Lolita plugin, that enables .yml files management from administrative
116
72
  interface. Also faster access to translations, that DB store
117
73
  email: support@ithouse.lv
@@ -122,16 +78,16 @@ extra_rdoc_files:
122
78
  - README.md
123
79
  files:
124
80
  - .document
81
+ - .gitignore
125
82
  - .rspec
126
83
  - Gemfile
127
84
  - History.rdoc
128
85
  - LICENSE.txt
129
86
  - README.md
130
87
  - Rakefile
131
- - VERSION
132
88
  - app/assets/images/lolita/i18n/google_translate_icon.png
133
89
  - app/assets/javascripts/lolita/i18n/application.js
134
- - app/assets/javascripts/lolita/i18n/i18n.js.coffee
90
+ - app/assets/javascripts/lolita/i18n/i18n.js
135
91
  - app/assets/javascripts/lolita/i18n/spin.min.js
136
92
  - app/assets/stylesheets/lolita/i18n/application.scss
137
93
  - app/controllers/lolita/i18n_controller.rb
@@ -141,21 +97,39 @@ files:
141
97
  - config/locales/lv.yml
142
98
  - config/routes.rb
143
99
  - lib/lolita-i18n.rb
144
- - lib/lolita-i18n/backend.rb
100
+ - lib/lolita-i18n/configuration.rb
145
101
  - lib/lolita-i18n/exceptions.rb
146
102
  - lib/lolita-i18n/module.rb
147
103
  - lib/lolita-i18n/rails.rb
104
+ - lib/lolita-i18n/request.rb
105
+ - lib/lolita-i18n/version.rb
148
106
  - lolita-i18n.gemspec
149
107
  - spec/controllers/lolita/i18n_controller_spec.rb
150
- - spec/lolita-i18n/backend_spec.rb
151
- - spec/rails_app/app/controllers/application_controller.rb
152
- - spec/rails_app/config/application.rb
153
- - spec/rails_app/config/enviroment.rb
154
- - spec/rails_app/config/initializers/lolita_i18n.rb
155
- - spec/rails_app/config/locales/en.yml
156
- - spec/rails_app/config/locales/lv.yml
157
- - spec/rails_app/config/routes.rb
108
+ - spec/helpers/lolita/i18n_helper_spec.rb
109
+ - spec/lolita-i18n/configuration_spec.rb
110
+ - spec/lolita-i18n/exceptions_spec.rb
111
+ - spec/lolita-i18n/request_spec.rb
112
+ - spec/lolita-i18n/version_spec.rb
113
+ - spec/lolita_i18n_spec.rb
114
+ - spec/rails_spec_helper.rb
115
+ - spec/requests/translating_spec.rb
116
+ - spec/requests/translation_list_spec.rb
117
+ - spec/routing/routes_spec.rb
158
118
  - spec/spec_helper.rb
119
+ - spec/test_app/app/controllers/application_controller.rb
120
+ - spec/test_app/config/application.rb
121
+ - spec/test_app/config/boot.rb
122
+ - spec/test_app/config/enviroment.rb
123
+ - spec/test_app/config/enviroments/test.rb
124
+ - spec/test_app/config/initializers/lolita_i18n.rb
125
+ - spec/test_app/config/initializers/token.rb
126
+ - spec/test_app/config/locales/en.yml
127
+ - spec/test_app/config/locales/lv.yml
128
+ - spec/test_app/config/locales/ru.yml
129
+ - spec/test_app/config/mongoid.yml
130
+ - spec/test_app/config/routes.rb
131
+ - spec/test_app/log/.gitkeep
132
+ - spec/test_app/log/development.log
159
133
  homepage: http://github.com/ithouse/lolita-i18n
160
134
  licenses:
161
135
  - MIT
@@ -169,9 +143,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
143
  - - ! '>='
170
144
  - !ruby/object:Gem::Version
171
145
  version: '0'
172
- segments:
173
- - 0
174
- hash: 763032781
175
146
  required_rubygems_version: !ruby/object:Gem::Requirement
176
147
  none: false
177
148
  requirements:
@@ -180,16 +151,34 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
151
  version: '0'
181
152
  requirements: []
182
153
  rubyforge_project:
183
- rubygems_version: 1.8.15
154
+ rubygems_version: 1.8.17
184
155
  signing_key:
185
156
  specification_version: 3
186
157
  summary: Lolita plugin, that enables .yml management
187
158
  test_files:
188
159
  - spec/controllers/lolita/i18n_controller_spec.rb
189
- - spec/lolita-i18n/backend_spec.rb
190
- - spec/rails_app/app/controllers/application_controller.rb
191
- - spec/rails_app/config/application.rb
192
- - spec/rails_app/config/enviroment.rb
193
- - spec/rails_app/config/initializers/lolita_i18n.rb
194
- - spec/rails_app/config/routes.rb
160
+ - spec/helpers/lolita/i18n_helper_spec.rb
161
+ - spec/lolita-i18n/configuration_spec.rb
162
+ - spec/lolita-i18n/exceptions_spec.rb
163
+ - spec/lolita-i18n/request_spec.rb
164
+ - spec/lolita-i18n/version_spec.rb
165
+ - spec/lolita_i18n_spec.rb
166
+ - spec/rails_spec_helper.rb
167
+ - spec/requests/translating_spec.rb
168
+ - spec/requests/translation_list_spec.rb
169
+ - spec/routing/routes_spec.rb
195
170
  - spec/spec_helper.rb
171
+ - spec/test_app/app/controllers/application_controller.rb
172
+ - spec/test_app/config/application.rb
173
+ - spec/test_app/config/boot.rb
174
+ - spec/test_app/config/enviroment.rb
175
+ - spec/test_app/config/enviroments/test.rb
176
+ - spec/test_app/config/initializers/lolita_i18n.rb
177
+ - spec/test_app/config/initializers/token.rb
178
+ - spec/test_app/config/locales/en.yml
179
+ - spec/test_app/config/locales/lv.yml
180
+ - spec/test_app/config/locales/ru.yml
181
+ - spec/test_app/config/mongoid.yml
182
+ - spec/test_app/config/routes.rb
183
+ - spec/test_app/log/.gitkeep
184
+ - spec/test_app/log/development.log
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.2
@@ -1,135 +0,0 @@
1
- class LolitaI18nCell
2
-
3
- constructor: (@td) ->
4
- @p = @td.find('p:first')
5
-
6
- edit: ->
7
- if @td.find('input').size() == 0
8
- @key = @td.attr('data-key')
9
- @locale = @td.attr('data-locale')
10
- input = $('<textarea name="'+@key+'" />').html(@fix_quotes(@p.text().trim()))
11
- input.css('width',@p.width()+'px').css('height', @p.height()+'px')
12
- @p.html("")
13
- @p.hide()
14
- @td.append(input)
15
- input.focus()
16
- that = this
17
-
18
- input.blur ->
19
- that.value = input.val().trim()
20
- input.remove()
21
- that.add_spinner()
22
- that.save()
23
-
24
- input.keyup (e) ->
25
- if e.keyCode == 27
26
- input.trigger('blur')
27
-
28
- save: ->
29
- that = this
30
- $.ajax
31
- type: 'PUT'
32
- url: '/lolita/i18n/' + @locale + '.' + that.key
33
- data: {translation: that.value}
34
- dataType: 'json'
35
- success: (data) ->
36
- if data.error
37
- alert "Error saving translation:\n\n" + data.error
38
- that.remove_spinner()
39
-
40
- add_spinner: ->
41
- opts =
42
- lines: 10
43
- length: 3
44
- width: 2
45
- radius: 5,
46
- color: '#000'
47
- speed: 1
48
- trail: 20
49
- shadow: false
50
-
51
- @spinner = Spinner(opts).spin()
52
- @td.prepend(@spinner.el)
53
- $(@spinner.el).css('top',($(@spinner.el).parent().height() / 2)+ 'px').css('left','5px').css('clear','both')
54
-
55
- remove_spinner: ->
56
- @spinner.stop()
57
- @p.text(@value)
58
- @p.show()
59
-
60
- fix_quotes: (value) ->
61
- value.replace(/\'/g, "&#39;").replace(/\"/g, "&#34;")
62
-
63
- class LolitaTranslate
64
-
65
- constructor: (@button)->
66
- @url = @button.attr('data-url')
67
- @locale = @button.attr('data-locale')
68
- @add_spinner()
69
- @translate()
70
-
71
- translate: ->
72
- that = this
73
-
74
- $.ajax
75
- type: 'PUT'
76
- url: @url
77
- data: {active_locale: @locale}
78
- dataType: 'json'
79
- success: (data) ->
80
- if data.errors.length > 0
81
- alert("Errors\n\n" + data.errors.join("\n"))
82
- that.remove_spinner()
83
- if data.translated > 0
84
- window.location.reload()
85
- else
86
- that.remove_spinner()
87
- error: (request,error) ->
88
- alert "Error 500"
89
- that.remove_spinner()
90
-
91
- add_spinner: ->
92
- opts =
93
- lines: 10
94
- length: 3
95
- width: 2
96
- radius: 5
97
- color: '#000'
98
- speed: 1
99
- trail: 5
100
- shadow: false
101
-
102
- @spinner = Spinner(opts).spin()
103
- @button.append(@spinner.el)
104
- @button.addClass('loading')
105
- @button.attr('disabled',true)
106
- $(@spinner.el).css('position', 'absolute').css('top','17px').css('left','16px')
107
-
108
- remove_spinner: ->
109
- @spinner.stop()
110
- @button.removeClass('loading')
111
- @button.attr('disabled',false)
112
-
113
- params = (name) ->
114
- decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[1,null])[1])
115
-
116
- $ ->
117
- $('.list td p').click ->
118
- cell = new LolitaI18nCell $(this).parent()
119
- cell.edit()
120
- $('.list td span.hint').click ->
121
- cell = new LolitaI18nCell $(this).parent()
122
- cell.edit()
123
- $('#active_locale').change ->
124
- show_untranslated = if params('show_untranslated') == "null" then "" else "&show_untranslated=true"
125
- window.location.href = "?active_locale=" + $(this).val() + show_untranslated
126
- $('button.translate:first').click ->
127
- if confirm('Are you shure?')
128
- new LolitaTranslate $(this)
129
- $('#show_untranslated').change ->
130
- active_locale = if params('active_locale') == "null" then "" else "active_locale=" + params('active_locale')
131
- if $(this).is(':checked')
132
- window.location.href = "?show_untranslated=true&" + active_locale
133
- else
134
- window.location.href = "?" + active_locale
135
-
@@ -1,87 +0,0 @@
1
- module Lolita
2
- module I18n
3
- # Allow to operate with I18n keys and values.
4
- class Backend
5
-
6
- class << self
7
- # Get translation and decode it. Set translate from and to translations.
8
- # Return Hash with
9
- # * <tt>:key</tt> - translation key
10
- # * <tt>:value</tt> - translation
11
- # * <tt>:translate_to</tt> - translation locale, like <i>en</i>
12
- # * <tt>:translate_from</tt> - translation key for default language
13
- def get(key)
14
- result={:key=>key}
15
- result[:value]=decoded_value(key)
16
- result[:original_value]=decoded_value(translate_from(key))
17
- result[:translate_to]=translate_to(key)
18
- result[:translate_from]=translate_from(key)
19
- result
20
- end
21
-
22
- # Store translation, decode and store.
23
- # Accept:
24
- # * <tt>key</tt> - translation key
25
- # * <tt>translation</tt> - String with translation
26
- def set(key,translation)
27
- validate_translation(key,translation)
28
- locale=translate_to(key)
29
- translation_key=translation_key(key)
30
- value=Yajl::Parser.parse(translation.to_json)
31
- if value.blank?
32
- del key
33
- else
34
- if Lolita.i18n.backend.store_translations(locale,{translation_key=>value},:escape=>false)
35
- true
36
- else
37
- false
38
- end
39
- end
40
- end
41
-
42
- def del key
43
- Lolita.i18n.store.del key
44
- end
45
-
46
- def locale(key)
47
- translate_to(key) || ::I18n.default_locale
48
- end
49
-
50
- def translation_key(key)
51
- (key.to_s.split('.')[1..-1]).join(".")
52
- end
53
-
54
- private
55
-
56
- def validate_translation key,translation
57
- validate_interpolation_arguments key,translation
58
- end
59
-
60
- def validate_interpolation_arguments key,translation
61
- in_translation = translation.scan(/(%{\w+})/).map{|m| m.first}.sort
62
- in_original = ::I18n.t(translation_key(key), :locale => ::I18n.default_locale).scan(/(%{\w+})/).map{|m| m.first}.sort
63
- raise Exceptions::MissingInterpolationArgument.new(in_original) unless in_translation == in_original
64
- end
65
-
66
- def keys
67
- @keys||=Lolita.i18n.flattened_translations.keys.sort
68
- end
69
-
70
- def decoded_value(key)
71
- value=Lolita.i18n.backend.store[key]
72
- value ? (Yajl::Parser.parse(value) rescue "") : ::I18n.t(key.split('.')[1..-1].join('.'), :default => "", :locale => translate_to(key))
73
- end
74
-
75
- def translate_to(key)
76
- key.to_s.split(".").first
77
- end
78
-
79
- def translate_from(key,locale=nil)
80
- (key.to_s.split('.')[1..-1]).insert(0,locale || ::I18n.default_locale).join(".")
81
- end
82
-
83
- end
84
-
85
- end
86
- end
87
- end