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
data/.document CHANGED
@@ -1,4 +1,4 @@
1
- lib/**/*.rb
2
- -
3
- features/**/*.feature
4
- LICENSE.txt
1
+ lib/**/*.rb
2
+ -
3
+ features/**/*.feature
4
+ LICENSE.txt
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color
1
+ --color
data/Gemfile CHANGED
@@ -1,24 +1,24 @@
1
- source "http://rubygems.org"
2
-
3
- gem "lolita", '~>3.2.0.rc.3'
4
- gem "hiredis", "~> 0.3.1"
5
- gem "redis", "~> 2.2.2", :require => ["redis/connection/hiredis", "redis"]
6
- gem "yajl-ruby", "~> 1.0.0"
7
- gem "easy_translate", "~> 0.2.1"
8
-
9
- group :development do
10
- gem "shoulda", ">= 0"
11
- gem "bundler", "~> 1.0.0"
12
- gem "jeweler", "~> 1.5.2"
13
- gem "rcov", ">= 0"
14
- end
15
-
16
- group :test do
17
- gem "rspec","~>2.6.0"
18
- gem "rspec-rails", "~>2.6.0"
19
- gem "webmock", "~> 1.7.6"
20
- # gem "mongo", "~> 1.3.0"
21
- # gem "mongoid", "~> 2.0.0"
22
- # gem "bson_ext", "~> 1.4.0"
23
- gem 'ruby-debug19', :require => 'ruby-debug'
24
- end
1
+ source "http://rubygems.org"
2
+
3
+ gem "lolita", '3.1.18'
4
+ gem "hiredis", "~> 0.3.1"
5
+ gem "redis", "~> 2.2.2", :require => ["redis/connection/hiredis", "redis"]
6
+ gem "yajl-ruby", "~> 1.0.0"
7
+ gem "easy_translate", "~> 0.2.1"
8
+
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ end
15
+
16
+ group :test do
17
+ gem "rspec","~>2.6.0"
18
+ gem "rspec-rails", "~>2.6.0"
19
+ gem "webmock", "~> 1.7.6"
20
+ # gem "mongo", "~> 1.3.0"
21
+ # gem "mongoid", "~> 2.0.0"
22
+ # gem "bson_ext", "~> 1.4.0"
23
+ gem 'ruby-debug19', :require => 'ruby-debug'
24
+ end
data/History.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ === Version 0.2.0
2
+ * Enhancements
3
+ * Redis configuration and access to attributes goes through Lolita.i18n
4
+ * Redis initialization process works automaticly
5
+
6
+ * Changes
7
+ * Google translation temporary removed from
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
@@ -1,27 +1,27 @@
1
- # About
2
-
3
- Lolita I18n is Lolita[https://github.com/ithouse/lolita] plugin, that enables .yml file translation from WEB interface.
4
-
5
- ## Usage
6
-
7
- * setup rails 3.1 project with ["Lolita"](https://github.com/ithouse/lolita)
8
- * setup [Redis DB](http://redis.io) on your server
9
- * add `gem 'lolita-i18n'` into Gemfile
10
- * add `I18n.backend = Lolita::I18n.load Redis.new(:db => REDIS_DB)` into your `config/initializers/lolita.rb`
11
- * add `REDIS_DB = 10` in your production/staging environment file.
12
- * open `/lolita/i18n` and start translating
13
-
14
- ## Contributing to lolita-i18n
15
-
16
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
17
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
18
- * Fork the project
19
- * Start a feature/bugfix branch
20
- * Commit and push until you are happy with your contribution
21
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
- * 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.
23
-
24
- == Copyright
25
-
26
- Copyright (c) 2011 ITHouse (Latvia). See LICENSE.txt for
1
+ # About
2
+
3
+ Lolita I18n is Lolita[https://github.com/ithouse/lolita] plugin, that enables .yml file translation from WEB interface.
4
+
5
+ ## Usage
6
+
7
+ * setup rails 3.1 project with ["Lolita"](https://github.com/ithouse/lolita)
8
+ * setup [Redis DB](http://redis.io) on your server
9
+ * add `gem 'lolita-i18n'` into Gemfile
10
+ * in your lolita setup block add `config.i18n.store = {:db => REDIS_DB}` or `config.i18n.store = Redis.new`
11
+ * add `REDIS_DB = your db number` in your environment files.
12
+ * open `/lolita/i18n` and start translating
13
+
14
+ ## Contributing to lolita-i18n
15
+
16
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
17
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
18
+ * Fork the project
19
+ * Start a feature/bugfix branch
20
+ * Commit and push until you are happy with your contribution
21
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
+ * 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.
23
+
24
+ == Copyright
25
+
26
+ Copyright (c) 2011 ITHouse (Latvia). See LICENSE.txt for
27
27
  further details.
data/Rakefile CHANGED
@@ -1,46 +1,46 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "lolita-i18n"
16
- gem.homepage = "http://github.com/ithouse/lolita-i18n"
17
- gem.license = "MIT"
18
- gem.summary = %Q{Lolita plugin, that enables .yml management}
19
- gem.description = %Q{Lolita plugin, that enables .yml files management from administrative interface. Also faster access to translations, that DB store}
20
- gem.email = "support@ithouse.lv"
21
- gem.authors = ["ITHouse (Latvia)","Arturs Meisters", "Gatis Tomsons"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
- require 'rake/testtask'
30
- Rake::TestTask.new(:test) do |test|
31
- test.libs << 'lib' << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
-
36
- task :default => :test
37
-
38
- require 'rdoc/task'
39
- RDoc::Task.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "lolita-i18n #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "lolita-i18n"
16
+ gem.homepage = "http://github.com/ithouse/lolita-i18n"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Lolita plugin, that enables .yml management}
19
+ gem.description = %Q{Lolita plugin, that enables .yml files management from administrative interface. Also faster access to translations, that DB store}
20
+ gem.email = "support@ithouse.lv"
21
+ gem.authors = ["ITHouse (Latvia)","Arturs Meisters", "Gatis Tomsons"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ RDoc::Task.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "lolita-i18n #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.18
@@ -1,39 +1,43 @@
1
- class Lolita::I18nController < ApplicationController
2
- include Lolita::Controllers::UserHelpers
3
- before_filter :authenticate_lolita_user!, :set_current_locale
4
-
5
- layout "lolita/application"
6
-
7
- def index
8
- @translation_keys=Lolita::I18n.flatten_keys
9
- end
10
-
11
- def update
12
- respond_to do |format|
13
- format.json do
14
- render :nothing => true, :json => {error: !Lolita::I18n::Backend.set(params[:id],params[:translation])}
15
- end
16
- end
17
- end
18
-
19
- def translate_untranslated
20
- respond_to do |format|
21
- format.json do
22
- google_translate = Lolita::I18n::GoogleTranslate.new @active_locale
23
- google_translate.run
24
- render :nothing => true, :status => 200, :json => {errors: google_translate.errors, :translated => google_translate.untranslated}
25
- end
26
- end
27
- end
28
-
29
- private
30
-
31
- def next_locale
32
- ::I18n::available_locales.collect{|locale| locale if locale != ::I18n.default_locale}.compact.first
33
- end
34
-
35
- def set_current_locale
36
- @active_locale = (params[:active_locale] || next_locale).to_sym
37
- end
38
-
1
+ class Lolita::I18nController < ApplicationController
2
+ include Lolita::ControllerAdditions
3
+ before_filter :authenticate_lolita_user!, :set_current_locale
4
+
5
+ layout "lolita/application"
6
+
7
+ def index
8
+ @translation_keys=Lolita.i18n.flatten_keys
9
+ end
10
+
11
+ def update
12
+ respond_to do |format|
13
+ format.json do
14
+ render :nothing => true, :json => {error: !Lolita::I18n::Backend.set(params[:id],params[:translation])}
15
+ end
16
+ end
17
+ end
18
+
19
+ def translate_untranslated
20
+ respond_to do |format|
21
+ format.json do
22
+ google_translate = Lolita::I18n::GoogleTranslate.new @active_locale
23
+ google_translate.run
24
+ render :nothing => true, :status => 200, :json => {errors: google_translate.errors, :translated => google_translate.untranslated}
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def is_lolita_resource?
32
+ true
33
+ end
34
+
35
+ def next_locale
36
+ ::I18n::available_locales.collect{|locale| locale if locale != ::I18n.default_locale}.compact.first
37
+ end
38
+
39
+ def set_current_locale
40
+ @active_locale = (params[:active_locale] || next_locale).to_sym
41
+ end
42
+
39
43
  end
@@ -1,25 +1,25 @@
1
- module Lolita
2
- module I18nHelper
3
- def locale_options
4
- ::I18n::available_locales.collect{|locale|
5
- [::I18n.t(locale, :default => locale), locale] unless [::I18n.default_locale,@active_locale].include?(locale)
6
- }.compact.insert(0,[::I18n.t("lolita-i18n.choose-other-language", :default => "Choose other language"),""])
7
- end
8
-
9
- def show_translation key
10
- value = ::I18n.t(key, :locale => @active_locale, :default => '')
11
- unless value.blank?
12
- value
13
- else
14
- value = Lolita::I18n::GoogleTranslate.get_translation(@active_locale,key)
15
- unless value.blank?
16
- content_tag(:span, value, :class => "unapproved")
17
- end
18
- end
19
- end
20
-
21
- def is_untranslated key
22
- Lolita::I18n::GoogleTranslate.get_translation(@active_locale,key)
23
- end
24
- end
1
+ module Lolita
2
+ module I18nHelper
3
+ def locale_options
4
+ (::I18n::available_locales).collect{|locale|
5
+ [::I18n.t(locale, :default => locale), locale] unless [::I18n.default_locale,@active_locale].include?(locale)
6
+ }.compact.insert(0,[::I18n.t("lolita-i18n.choose-other-language", :default => "Choose other language"),""])
7
+ end
8
+
9
+ def show_translation key
10
+ value = ::I18n.t(key, :locale => @active_locale, :default => '')
11
+ unless value.blank?
12
+ value
13
+ else
14
+ value = Lolita::I18n::GoogleTranslate.get_translation(@active_locale,key)
15
+ unless value.blank?
16
+ content_tag(:span, value, :class => "unapproved")
17
+ end
18
+ end
19
+ end
20
+
21
+ def is_untranslated key
22
+ Lolita::I18n::GoogleTranslate.get_translation(@active_locale,key)
23
+ end
24
+ end
25
25
  end
@@ -1,34 +1,36 @@
1
- - content_for :style do
2
- = stylesheet_link_tag "lolita/i18n/application", :media => "screen,projection"
3
- - content_for :script do
4
- = javascript_include_tag "lolita/i18n/application"
5
- .box.i18n-bo
6
- .boxtitle
7
- %h1.black= ::I18n.t('lolita-i18n.title', :default => "Static content translation")
8
- .arrow
9
- .list
10
- %div.actions
11
- .filters
12
- = check_box_tag "show_untranslated", nil, params[:show_untranslated]
13
- = label_tag "show_untranslated", "Show translations that need approval"
14
-
15
- %button.translate{:'data-url' => translate_untranslated_lolita_i18n_index_path, :'data-locale' => @active_locale} Translate empty translations with Google
16
- .clear
17
- %table
18
- %thead
19
- %tr
20
- %th{:style => "width:450px"}
21
- = label_tag :active_locale, I18n.t(@active_locale, :default => @active_locale)
22
- - if locale_options.size > 1
23
- = select_tag :active_locale, options_for_select(locale_options), :id => "active_locale"
24
- %th{:style => "width:90%"}= ::I18n.t(::I18n.default_locale)
25
- %tbody
26
- - @translation_keys.each do |key|
27
- - if !params[:show_untranslated] or is_untranslated(key)
28
- %tr
29
- %td{:style => "width:450px", :'data-key' => key, :'data-locale' => @active_locale}
30
- %p= show_translation key
31
- %td{:style => "width:90%", :'data-key' => key, :'data-locale' => ::I18n.default_locale}
32
- %p= ::I18n.t(key, :locale => ::I18n.default_locale, :default => "")
33
- %span.hint
1
+ - content_for :style do
2
+ = stylesheet_link_tag "lolita/i18n/application", :media => "screen,projection"
3
+ - content_for :script do
4
+ =# javascript_include_tag "lolita/i18n/application"
5
+ = javascript_include_tag "lolita/i18n/i18n.js"
6
+ = javascript_include_tag "lolita/i18n/spin.min.js"
7
+ .box.i18n-bo
8
+ .boxtitle
9
+ %h1.black= ::I18n.t('lolita-i18n.title', :default => "Static content translation")
10
+ .arrow
11
+ .list
12
+ / %div.actions
13
+ / .filters
14
+ / = check_box_tag "show_untranslated", nil, params[:show_untranslated]
15
+ / = label_tag "show_untranslated", "Show translations that need approval"
16
+
17
+ / %button.translate{:'data-url' => translate_untranslated_lolita_i18n_index_path, :'data-locale' => @active_locale} Translate empty translations with Google
18
+ / .clear
19
+ %table
20
+ %thead
21
+ %tr
22
+ %th{:style => "width:450px"}
23
+ = label_tag :active_locale, I18n.t(@active_locale, :default => @active_locale)
24
+ - if locale_options.size > 1
25
+ = select_tag :active_locale, options_for_select(locale_options), :id => "active_locale"
26
+ %th{:style => "width:90%"}= ::I18n.t(::I18n.default_locale)
27
+ %tbody
28
+ - @translation_keys.each do |key|
29
+ - if !params[:show_untranslated] or is_untranslated(key)
30
+ %tr
31
+ %td{:style => "width:450px", :'data-key' => key, :'data-locale' => @active_locale}
32
+ %p= show_translation key
33
+ %td{:style => "width:90%", :'data-key' => key, :'data-locale' => ::I18n.default_locale}
34
+ %p= ::I18n.t(key, :locale => ::I18n.default_locale, :default => "")
35
+ %span.hint
34
36
  = key