lolita-i18n 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -20,5 +20,11 @@ group :test do
20
20
  # gem "mongo", "~> 1.3.0"
21
21
  # gem "mongoid", "~> 2.0.0"
22
22
  # gem "bson_ext", "~> 1.4.0"
23
- gem 'ruby-debug19', :require => 'ruby-debug'
23
+
24
+ # For ruby 1.9.3
25
+ # curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
26
+ # gem install linecache19-0.5.13.gem
27
+ # And then ruby-debug-base19x via
28
+ # gem install --pre ruby-debug-base19x
29
+ gem 'ruby-debug-base19x'
24
30
  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/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.2.0
1
+ 0.3.0
@@ -128,7 +128,7 @@ $ ->
128
128
  new LolitaTranslate $(this)
129
129
  $('#show_untranslated').change ->
130
130
  active_locale = if params('active_locale') == "null" then "" else "active_locale=" + params('active_locale')
131
- if $(this).attr('checked')
131
+ if $(this).is(':checked')
132
132
  window.location.href = "?show_untranslated=true&" + active_locale
133
133
  else
134
134
  window.location.href = "?" + active_locale
@@ -48,22 +48,6 @@ div.list div.actions {
48
48
  padding-left: 20px;
49
49
  }
50
50
  }
51
- button.translate {
52
- position: relative;
53
- padding-left: 30px;
54
- height: 34px;
55
- background-image: url(image-path('lolita/i18n/google_translate_icon.png'));
56
- background-position: 5px 5px;
57
- background-repeat: no-repeat;
58
- box-shadow: inset 0 0 1px 1px #eaeaea;
59
- text-shadow: 0 1px 0 white;
60
- border: 1px solid #bbb;
61
- float: right;
62
- }
63
- button.loading {
64
- background-image: none;
65
- color: #999;
66
- }
67
51
  }
68
52
  div.list table {
69
53
  table-layout: fixed;
@@ -16,16 +16,6 @@ class Lolita::I18nController < ApplicationController
16
16
  end
17
17
  end
18
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
19
  private
30
20
 
31
21
  def is_lolita_resource?
@@ -3,23 +3,15 @@ module Lolita
3
3
  def locale_options
4
4
  (::I18n::available_locales).collect{|locale|
5
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"),""])
6
+ }.compact.insert(0,[::I18n.t("lolita-i18n.choose-other-language", :default => ::I18n.t("lolita-i18n.choose-other-language", :locale => "en")),""])
7
7
  end
8
8
 
9
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
10
+ ::I18n.t(key, :locale => @active_locale, :default => '')
19
11
  end
20
12
 
21
13
  def is_untranslated key
22
- Lolita::I18n::GoogleTranslate.get_translation(@active_locale,key)
14
+ ::I18n.t(key, :locale => @active_locale, :default => "").blank?
23
15
  end
24
16
  end
25
17
  end
@@ -4,16 +4,13 @@
4
4
  = javascript_include_tag "lolita/i18n/application"
5
5
  .box.i18n-bo
6
6
  .boxtitle
7
- %h1.black= ::I18n.t('lolita-i18n.title', :default => "Static content translation")
7
+ %h1.black= ::I18n.t('lolita-i18n.title', :default => ::I18n.t('lolita-i18n.title', :locale => 'en'))
8
8
  .arrow
9
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
10
+ %div.actions
11
+ .filters
12
+ = check_box_tag "show_untranslated", nil, params[:show_untranslated]
13
+ = label_tag "show_untranslated", ::I18n.t('lolita-i18n.show-untranslated', :default => ::I18n.t('lolita-i18n.show-untranslated', :locale => 'en'))
17
14
  %table
18
15
  %thead
19
16
  %tr
@@ -7,4 +7,6 @@ en:
7
7
  lolita-i18n:
8
8
  title: "Static content translation"
9
9
  choose-other-language: "Choose other language"
10
+ show-untranslated: "Show only untranslated translations"
11
+ remove-old: "Remove old translations"
10
12
 
@@ -6,4 +6,6 @@ lv:
6
6
  sv: Zviedru
7
7
  lolita-i18n:
8
8
  title: "Statiskā satura tulkošana"
9
- choose-other-language: "Izvēlies citu valodu"
9
+ choose-other-language: "Izvēlies citu valodu"
10
+ show-untranslated: "Rādīt tikai neiztulkotos tulkojumus"
11
+ remove-old: "Noņemt vecos tulkojumus"
data/config/routes.rb CHANGED
@@ -1,11 +1,11 @@
1
- Rails.application.routes.draw do
2
-
3
- namespace "lolita" do
4
- resources :i18n, :only=>[:update],:constraints=>{:id=>/.*/} do
5
- collection do
6
- put 'translate_untranslated'
7
- get 'index'
8
- end
9
- end
10
- end
1
+ Rails.application.routes.draw do
2
+
3
+ namespace "lolita" do
4
+ resources :i18n, :only=>[:update],:constraints=>{:id=>/.*/} do
5
+ collection do
6
+ put 'translate_untranslated'
7
+ get 'index'
8
+ end
9
+ end
10
+ end
11
11
  end
data/lib/lolita-i18n.rb CHANGED
@@ -18,9 +18,7 @@ module Lolita
18
18
  # config.i18n.store = Redis.new()
19
19
  module I18n
20
20
  autoload :Backend, 'lolita-i18n/backend'
21
- autoload :GoogleTranslate, 'lolita-i18n/google_translate'
22
21
 
23
-
24
22
  class Configuration
25
23
 
26
24
  attr_accessor :yaml_backend
@@ -28,19 +26,17 @@ module Lolita
28
26
  def store
29
27
  unless @store
30
28
  warn "Lolita::I18n No store specified. See Lolita::I18n"
31
- # warn "No Lolita::I18n store specfied."
32
29
  @store = Redis.new
33
- # initialize_chain
34
30
  end
35
31
  @store
36
32
  end
37
33
 
38
34
  def store=(possible_store)
39
35
  @store = if possible_store.is_a?(Hash)
40
- Redis.new(possible_store)
41
- else
42
- possible_store
43
- end
36
+ Redis.new(possible_store)
37
+ else
38
+ possible_store
39
+ end
44
40
  @store
45
41
  end
46
42
 
@@ -66,7 +62,9 @@ module Lolita
66
62
 
67
63
  def include_modules
68
64
  ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Flatten)
69
- ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Memoize)
65
+ ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Pluralization)
66
+ ::I18n::Backend::Simple.send(:include, ::I18n::Backend::Metadata)
67
+ ::I18n::Backend::Simple.send(:include, ::I18n::Backend::InterpolationCompiler)
70
68
  end
71
69
 
72
70
  end
@@ -84,7 +82,14 @@ Lolita.scope.extend(LolitaI18nConfiguration)
84
82
  Lolita.after_setup do
85
83
  Lolita.i18n.yaml_backend = ::I18n.backend
86
84
  Lolita.i18n.include_modules
87
- ::I18n.backend = Lolita.i18n.initialize_chain
85
+ begin
86
+ r = Redis.new
87
+ r.ping
88
+ ::I18n.backend = Lolita.i18n.initialize_chain
89
+ rescue Errno::ECONNREFUSED => e
90
+ warn "Warning: Lolita was unable to connect to Redis DB: #{e}"
91
+ end
92
+
88
93
  end
89
94
 
90
95
  require 'lolita-i18n/module'
@@ -95,16 +100,14 @@ end
95
100
 
96
101
  Lolita.after_routes_loaded do
97
102
  if tree=Lolita::Navigation::Tree[:"left_side_navigation"]
98
- unless tree.branches.detect{|b| b.title=="System"}
99
- branch=tree.append(nil,:title=>"System")
100
- #mapping=Lolita::Mapping.new(:i18n_index,:singular=>:i18n,:class_name=>Object,:controller=>"lolita/i18n")
101
- branch.append(Object,:title=>"I18n",:url=>Proc.new{|view,branch|
103
+ unless tree.branches.detect { |b| b.title=="System" }
104
+ branch=tree.append(nil, :title=>"System")
105
+ branch.append(Object, :title=>"I18n", :url=>Proc.new { |view, branch|
102
106
  view.send(:lolita_i18n_index_path)
103
- }, :active=>Proc.new{|view,parent_branch,branch|
107
+ }, :active=>Proc.new { |view, parent_branch, branch|
104
108
  params=view.send(:params)
105
109
  params[:controller].to_s.match(/lolita\/i18n/)
106
110
  })
107
111
  end
108
112
  end
109
113
  end
110
-
@@ -30,8 +30,7 @@ module Lolita
30
30
  if value.blank?
31
31
  del key
32
32
  else
33
- if Lolita::I18n.backend.store_translations(locale,{translation_key=>value},:escape=>false)
34
- Lolita::I18n::GoogleTranslate.del_translation locale, translation_key
33
+ if Lolita.i18n.backend.store_translations(locale,{translation_key=>value},:escape=>false)
35
34
  true
36
35
  else
37
36
  false
@@ -40,7 +39,7 @@ module Lolita
40
39
  end
41
40
 
42
41
  def del key
43
- Lolita::I18n.store.del key
42
+ Lolita.i18n.store.del key
44
43
  end
45
44
 
46
45
  def locale(key)
data/lolita-i18n.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lolita-i18n"
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ITHouse (Latvia)", "Arturs Meisters", "Gatis Tomsons"]
12
- s.date = "2011-11-11"
12
+ s.date = "2012-02-22"
13
13
  s.description = "Lolita plugin, that enables .yml files management from administrative interface. Also faster access to translations, that DB store"
14
14
  s.email = "support@ithouse.lv"
15
15
  s.extra_rdoc_files = [
@@ -38,13 +38,11 @@ Gem::Specification.new do |s|
38
38
  "config/routes.rb",
39
39
  "lib/lolita-i18n.rb",
40
40
  "lib/lolita-i18n/backend.rb",
41
- "lib/lolita-i18n/google_translate.rb",
42
41
  "lib/lolita-i18n/module.rb",
43
42
  "lib/lolita-i18n/rails.rb",
44
43
  "lolita-i18n.gemspec",
45
44
  "spec/controllers/lolita/i18n_controller_spec.rb",
46
45
  "spec/lolita-i18n/backend_spec.rb",
47
- "spec/lolita-i18n/google_translate_spec.rb",
48
46
  "spec/rails_app/app/controllers/application_controller.rb",
49
47
  "spec/rails_app/config/application.rb",
50
48
  "spec/rails_app/config/enviroment.rb",
@@ -57,12 +55,11 @@ Gem::Specification.new do |s|
57
55
  s.homepage = "http://github.com/ithouse/lolita-i18n"
58
56
  s.licenses = ["MIT"]
59
57
  s.require_paths = ["lib"]
60
- s.rubygems_version = "1.8.10"
58
+ s.rubygems_version = "1.8.15"
61
59
  s.summary = "Lolita plugin, that enables .yml management"
62
60
  s.test_files = [
63
61
  "spec/controllers/lolita/i18n_controller_spec.rb",
64
62
  "spec/lolita-i18n/backend_spec.rb",
65
- "spec/lolita-i18n/google_translate_spec.rb",
66
63
  "spec/rails_app/app/controllers/application_controller.rb",
67
64
  "spec/rails_app/config/application.rb",
68
65
  "spec/rails_app/config/enviroment.rb",
@@ -1,39 +1,30 @@
1
- # coding: utf-8
2
-
3
- USE_RAILS=true unless defined?(USE_RAILS)
4
- require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
5
-
6
- include Lolita::Test::Matchers
7
-
8
- describe Lolita::I18nController do
9
- render_views
10
-
11
- it "should have i18n routes" do
12
- {:get=>"/lolita/i18n"}.should be_routable
13
- {:put=>"/lolita/i18n/1"}.should be_routable
14
- {:put=>"/lolita/i18n/translate_untranslated"}.should be_routable
15
- {:get=>"/lolita/i18n"}.should be_routable
16
- end
17
-
18
- it "should show all translations" do
19
- get :index
20
- response.should render_template("index")
21
- response.body.should match(/#{::I18n.t('lolita-i18n.title')}/)
22
- end
23
-
24
- it "should save translation" do
25
- put :update, :id=>"en.Page title",:translation=>"New title", :format => :json
26
- response.body.should == {error: false}.to_json
27
- ::I18n.t("Page title", :locale => :en).should == "New title"
28
- end
29
-
30
- it "should translate to google" do
31
- stub_request(:post, "http://ajax.googleapis.com/ajax/services/language/translate").
32
- with(:body => "v=2.0&format=text&q=true&langpair=%7Clv&q=true&langpair=%7Clv&q=Posts&langpair=%7Clv&q=Posts%20description&langpair=%7Clv&q=Comments&langpair=%7Clv&q=Comment%20description&langpair=%7Clv&q=Footer%20text&langpair=%7Clv",
33
- :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
34
- to_return(:status => 200, :body => '{"responseData": [{"responseData":{"translatedText":"patiess","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"patiess","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Atbildes","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Atbildes apraksts","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Komentāri","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Cik apraksts","detectedSourceLanguage":"fr"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Kājenes tekstu","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200}], "responseDetails": null, "responseStatus": 200}', :headers => {})
35
-
36
- put :translate_untranslated, :active_locale => :lv, :format => :json
37
- response.body.should == {errors: [], translated: 7}.to_json
38
- end
1
+ # coding: utf-8
2
+
3
+ USE_RAILS=true unless defined?(USE_RAILS)
4
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
5
+
6
+ include Lolita::Test::Matchers
7
+
8
+ describe Lolita::I18nController do
9
+ render_views
10
+
11
+ it "should have i18n routes" do
12
+ {:get=>"/lolita/i18n"}.should be_routable
13
+ {:put=>"/lolita/i18n/1"}.should be_routable
14
+ {:put=>"/lolita/i18n/translate_untranslated"}.should be_routable
15
+ {:get=>"/lolita/i18n"}.should be_routable
16
+ end
17
+
18
+ it "should show all translations" do
19
+ get :index
20
+ response.should render_template("index")
21
+ response.body.should match(/#{::I18n.t('lolita-i18n.title')}/)
22
+ end
23
+
24
+ it "should save translation" do
25
+ put :update, :id=>"en.Page title",:translation=>"New title", :format => :json
26
+ response.body.should == {error: false}.to_json
27
+ ::I18n.t("Page title", :locale => :en).should == "New title"
28
+ end
29
+
39
30
  end
@@ -17,7 +17,7 @@ describe Lolita::I18n::Backend do
17
17
  Lolita::I18n::Backend.set("en.test-key","Hello")
18
18
  Lolita::I18n::Backend.get("en.test-key")[:value].should == "Hello"
19
19
  Lolita::I18n::Backend.set("en.test-key","")
20
- Lolita::I18n.store.get("en.test-key").should be_nil
20
+ Lolita.i18n.store.get("en.test-key").should be_nil
21
21
  end
22
22
 
23
23
  it "should get translation into DB" do
@@ -1,3 +1,3 @@
1
- class ApplicationController < ActionController::Base
2
-
1
+ class ApplicationController < ActionController::Base
2
+
3
3
  end
@@ -1,5 +1,5 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
5
  Test::Application.initialize!
@@ -1,9 +1,9 @@
1
- en:
2
- "Page title": "Page title"
3
- posts:
4
- "Title": Posts
5
- "Description": "Posts description"
6
- comments:
7
- "Title": Comments
8
- "Description": "Comment description"
1
+ en:
2
+ "Page title": "Page title"
3
+ posts:
4
+ "Title": Posts
5
+ "Description": "Posts description"
6
+ comments:
7
+ "Title": Comments
8
+ "Description": "Comment description"
9
9
  "Footer": "Footer text"
@@ -1,3 +1,3 @@
1
- Test::Application.routes.draw do
2
-
1
+ Test::Application.routes.draw do
2
+
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,6 @@ require 'rails'
12
12
  require 'lolita'
13
13
  require File.expand_path('lib/lolita-i18n')
14
14
  require 'webmock/rspec'
15
- require 'ruby-debug'
16
15
 
17
16
  if defined?(USE_RAILS)
18
17
  # require 'mongoid'
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.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-11-11 00:00:00.000000000Z
14
+ date: 2012-02-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: lolita
18
- requirement: &82640050 !ruby/object:Gem::Requirement
18
+ requirement: &77328960 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 3.2.0.rc.6
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *82640050
26
+ version_requirements: *77328960
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hiredis
29
- requirement: &82639690 !ruby/object:Gem::Requirement
29
+ requirement: &77338860 !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: *82639690
37
+ version_requirements: *77338860
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: redis
40
- requirement: &82639370 !ruby/object:Gem::Requirement
40
+ requirement: &77338530 !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: *82639370
48
+ version_requirements: *77338530
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: yajl-ruby
51
- requirement: &82639100 !ruby/object:Gem::Requirement
51
+ requirement: &77338040 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 1.0.0
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *82639100
59
+ version_requirements: *77338040
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: easy_translate
62
- requirement: &82638790 !ruby/object:Gem::Requirement
62
+ requirement: &77337330 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 0.2.1
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *82638790
70
+ version_requirements: *77337330
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: shoulda
73
- requirement: &82638490 !ruby/object:Gem::Requirement
73
+ requirement: &77336670 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *82638490
81
+ version_requirements: *77336670
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: bundler
84
- requirement: &82638220 !ruby/object:Gem::Requirement
84
+ requirement: &77335820 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ~>
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: 1.0.0
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *82638220
92
+ version_requirements: *77335820
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: jeweler
95
- requirement: &82637680 !ruby/object:Gem::Requirement
95
+ requirement: &77335230 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ~>
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: 1.5.2
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *82637680
103
+ version_requirements: *77335230
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rcov
106
- requirement: &82637180 !ruby/object:Gem::Requirement
106
+ requirement: &77351840 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ! '>='
@@ -111,7 +111,7 @@ dependencies:
111
111
  version: '0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *82637180
114
+ version_requirements: *77351840
115
115
  description: Lolita plugin, that enables .yml files management from administrative
116
116
  interface. Also faster access to translations, that DB store
117
117
  email: support@ithouse.lv
@@ -142,13 +142,11 @@ files:
142
142
  - config/routes.rb
143
143
  - lib/lolita-i18n.rb
144
144
  - lib/lolita-i18n/backend.rb
145
- - lib/lolita-i18n/google_translate.rb
146
145
  - lib/lolita-i18n/module.rb
147
146
  - lib/lolita-i18n/rails.rb
148
147
  - lolita-i18n.gemspec
149
148
  - spec/controllers/lolita/i18n_controller_spec.rb
150
149
  - spec/lolita-i18n/backend_spec.rb
151
- - spec/lolita-i18n/google_translate_spec.rb
152
150
  - spec/rails_app/app/controllers/application_controller.rb
153
151
  - spec/rails_app/config/application.rb
154
152
  - spec/rails_app/config/enviroment.rb
@@ -172,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
170
  version: '0'
173
171
  segments:
174
172
  - 0
175
- hash: -153498191
173
+ hash: -798289933
176
174
  required_rubygems_version: !ruby/object:Gem::Requirement
177
175
  none: false
178
176
  requirements:
@@ -181,14 +179,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
179
  version: '0'
182
180
  requirements: []
183
181
  rubyforge_project:
184
- rubygems_version: 1.8.10
182
+ rubygems_version: 1.8.15
185
183
  signing_key:
186
184
  specification_version: 3
187
185
  summary: Lolita plugin, that enables .yml management
188
186
  test_files:
189
187
  - spec/controllers/lolita/i18n_controller_spec.rb
190
188
  - spec/lolita-i18n/backend_spec.rb
191
- - spec/lolita-i18n/google_translate_spec.rb
192
189
  - spec/rails_app/app/controllers/application_controller.rb
193
190
  - spec/rails_app/config/application.rb
194
191
  - spec/rails_app/config/enviroment.rb
@@ -1,76 +0,0 @@
1
- require 'easy_translate'
2
-
3
- module Lolita
4
- module I18n
5
- # Translates untranslated strings using google translate API
6
- class GoogleTranslate
7
- attr_reader :untranslated, :errors
8
- def initialize locale
9
- @locale = locale
10
- @untranslated = 0
11
- @errors = []
12
- end
13
-
14
- def run
15
- unless untranslated_translations.empty?
16
- @untranslated = untranslated_translations.count
17
- untranslated_translations.each_slice(10).to_a.each do |batch|
18
- begin
19
- EasyTranslate.translate(batch.map(&:last), :to => @locale).each_with_index do |result,index|
20
- unless result.blank?
21
- key = batch[index].first
22
- add_translation key, result
23
- add_to_unapproved key
24
- end
25
- end
26
- rescue EasyTranslate::EasyTranslateException => e
27
- @errors << e.to_s
28
- rescue Exception => e
29
- puts "#{e.to_s}\n\n#{$@.join("\n")}"
30
- @errors << e.to_s
31
- break
32
- end
33
- end
34
- end
35
- end
36
-
37
- def untranslated_translations
38
- unless @untranslated_translations
39
- @untranslated_translations = []
40
- Lolita.i18n.flatten_keys.each do |key|
41
- unless unapproved_keys.include?(key)
42
- if !::I18n.t(key, :locale => ::I18n.default_locale, :default => '').blank? && ::I18n.t(key, :locale => @locale, :default => '').blank? && Lolita::I18n::GoogleTranslate.get_translation(@locale,key).blank?
43
- value = ::I18n.t(key, :locale => ::I18n.default_locale, :default => '').to_s
44
- @untranslated_translations << [key,value] unless value.blank?
45
- end
46
- end
47
- end
48
- end
49
- @untranslated_translations
50
- end
51
-
52
- def self.get_translation locale, key
53
- Lolita.i18n.store.get :"#{locale}.g.#{key}"
54
- end
55
-
56
- def self.del_translation locale, key
57
- Lolita.i18n.store.del :"#{locale}.g.#{key}"
58
- end
59
-
60
- private
61
-
62
- def unapproved_keys
63
- @@unapproved_keys ||= Lolita.i18n.store.smembers(:"unapproved_keys_#{@locale}").map(&:to_sym)
64
- end
65
-
66
- def add_translation key, value
67
- Lolita.i18n.store.set :"#{@locale}.g.#{key}", value
68
- end
69
-
70
- def add_to_unapproved key
71
- Lolita.i18n.store.sadd(:"unapproved_keys_#{@locale}",key)
72
- end
73
-
74
- end
75
- end
76
- end
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
-
3
- USE_RAILS=true unless defined?(USE_RAILS)
4
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
5
-
6
- describe Lolita::I18n::GoogleTranslate do
7
- let(:google_translate){
8
- stub_request(:post, "http://ajax.googleapis.com/ajax/services/language/translate").
9
- with(:body => "v=2.0&format=text&q=true&langpair=%7Clv&q=true&langpair=%7Clv&q=Posts&langpair=%7Clv&q=Posts%20description&langpair=%7Clv&q=Comments&langpair=%7Clv&q=Comment%20description&langpair=%7Clv&q=Footer%20text&langpair=%7Clv",
10
- :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
11
- to_return(:status => 200, :body => '{"responseData": [{"responseData":{"translatedText":"patiess","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"patiess","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Atbildes","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Atbildes apraksts","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Komentāri","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Cik apraksts","detectedSourceLanguage":"fr"},"responseDetails":null,"responseStatus":200},{"responseData":{"translatedText":"Kājenes tekstu","detectedSourceLanguage":"en"},"responseDetails":null,"responseStatus":200}], "responseDetails": null, "responseStatus": 200}', :headers => {})
12
-
13
- gt = Lolita::I18n::GoogleTranslate.new(:lv)
14
- gt.run
15
- gt
16
- }
17
-
18
- it "should store google translation" do
19
- google_translate.untranslated_translations.size.should == 7
20
- google_translate.untranslated.should == 7
21
- google_translate.errors.should be_empty
22
- Lolita::I18n::GoogleTranslate.get_translation(:lv, :'posts.Description').should == "Atbildes apraksts"
23
- end
24
-
25
- it "should delete google translation" do
26
- google_translate
27
- Lolita::I18n::GoogleTranslate.get_translation(:lv, :'posts.Description').should == "Atbildes apraksts"
28
- Lolita::I18n::GoogleTranslate.del_translation(:lv, :'posts.Description')
29
- Lolita::I18n::GoogleTranslate.get_translation(:lv, :'posts.Description').should be_nil
30
- end
31
- end