lolita-i18n 0.1.4 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.document +4 -4
  2. data/.rspec +1 -1
  3. data/Gemfile +24 -24
  4. data/History.rdoc +7 -0
  5. data/LICENSE.txt +20 -20
  6. data/README.md +26 -26
  7. data/Rakefile +46 -46
  8. data/VERSION +1 -1
  9. data/app/controllers/lolita/i18n_controller.rb +42 -38
  10. data/app/helpers/lolita/i18n_helper.rb +24 -24
  11. data/app/views/lolita/i18n/index.html.haml +35 -33
  12. data/config/locales/en.yml +5 -0
  13. data/config/locales/lv.yml +5 -0
  14. data/config/routes.rb +10 -10
  15. data/lib/lolita-i18n/backend.rb +76 -76
  16. data/lib/lolita-i18n/google_translate.rb +6 -6
  17. data/lib/lolita-i18n/rails.rb +7 -6
  18. data/lib/lolita-i18n.rb +116 -81
  19. data/lolita-i18n.gemspec +12 -12
  20. data/{app/assets → public}/images/lolita/i18n/google_translate_icon.png +0 -0
  21. data/{app/assets → public}/javascripts/lolita/i18n/application.js +0 -0
  22. data/public/javascripts/lolita/i18n/i18n.js +169 -0
  23. data/{app/assets → public}/javascripts/lolita/i18n/spin.min.js +0 -0
  24. data/{app/assets/stylesheets/lolita/i18n/application.scss → public/stylesheets/lolita/i18n/application.css} +1 -1
  25. data/spec/controllers/lolita/i18n_controller_spec.rb +38 -38
  26. data/spec/lolita-i18n/backend_spec.rb +27 -27
  27. data/spec/rails_app/app/controllers/application_controller.rb +2 -2
  28. data/spec/rails_app/config/application.rb +18 -18
  29. data/spec/rails_app/config/enviroment.rb +4 -4
  30. data/spec/rails_app/config/initializers/lolita_i18n.rb +16 -15
  31. data/spec/rails_app/config/locales/en.yml +8 -8
  32. data/spec/rails_app/config/routes.rb +2 -2
  33. data/spec/spec_helper.rb +34 -32
  34. metadata +29 -32
  35. data/Gemfile.lock +0 -161
  36. data/app/assets/javascripts/lolita/i18n/i18n.js.coffee +0 -135
@@ -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 " + that.key
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).attr('checked')
132
- window.location.href = "?show_untranslated=true&" + active_locale
133
- else
134
- window.location.href = "?" + active_locale
135
-