i18n-one_sky 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,8 +16,16 @@ require 'rspec/core/rake_task'
16
16
  desc 'Default: run specs.'
17
17
  task :default => :spec
18
18
 
19
- desc "Run specs"
20
- RSpec::Core::RakeTask.new do |t|
21
- t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
22
- # Put spec opts in a file named .rspec in root
19
+ desc "Run all specs"
20
+ RSpec::Core::RakeTask.new() do |t|
21
+ end
22
+
23
+ desc "Run offline specs"
24
+ RSpec::Core::RakeTask.new("spec:offline") do |t|
25
+ t.rspec_opts = %w{--tag ~live}
26
+ end
27
+
28
+ desc "Run live specs"
29
+ RSpec::Core::RakeTask.new("spec:live") do |t|
30
+ t.rspec_opts = %w{--tag live}
23
31
  end
@@ -10,6 +10,8 @@ module I18n
10
10
  Translation = I18n::Backend::ActiveRecord::Translation
11
11
 
12
12
  def download
13
+ puts "Downloading translations for I18n Active Record Backend:"
14
+
13
15
  platform_locales.each do |locale|
14
16
  locale_code = locale["locale"]
15
17
  local_name = locale["name"]["local"]
@@ -23,8 +25,7 @@ module I18n
23
25
  else
24
26
  yaml = platform.translation.download_yaml(locale_code)
25
27
  YAML.load(yaml).each do |code, translations|
26
- puts "Inserting translations:"
27
- puts translations.inspect.to_yaml
28
+ puts " locale: #{locale_code}, count: #{translations.length}"
28
29
  translations.each do |key, value|
29
30
  Translation.locale(i18n_locale_code).delete_all(["key=?", key])
30
31
  Translation.create!(:locale => i18n_locale_code, :key => key.to_s, :value => value)
@@ -61,6 +61,8 @@ module I18n
61
61
  # * api_secret
62
62
  # * project
63
63
  def initialize(options = {})
64
+ verify_options!(options)
65
+
64
66
  @client = ::OneSky::Client.new(options[:api_key], options[:api_secret])
65
67
  @project = @client.project(options[:project])
66
68
  @platform = @project.platform(options[:platform_id])
@@ -109,12 +111,37 @@ module I18n
109
111
  def upload_phrases(phrases)
110
112
  skip, upload = phrases.partition{ |string_key, string| skip_key?(string_key) }
111
113
 
112
- puts "Uploading phrases:"
113
- puts upload.to_yaml
114
+ puts "Uploading strings:"
115
+ puts " count: #{upload.length}"
114
116
  platform.translation.input_phrases(upload)
117
+ end
118
+
119
+ REQUIRED_KEYS = [:api_key, :api_secret, :project, :platform_id]
120
+
121
+ REQUIRED_KEYS_MESSAGE = <<-MESSAGE
122
+ One Sky API Version 2 works differently to Version 1.
123
+
124
+ Translations are now attached to a "platform", as well as a project.
125
+ Eg. there may be one for Android, one for IOS, and one for Web.
115
126
 
116
- puts "Skipped phrases:"
117
- puts skip.to_yaml
127
+ In order to authenticate for this gem, you must now specify the following;
128
+
129
+ * ONE_SKY_API_KEY
130
+ * ONE_SKY_API_SECRET
131
+ * ONE_SKY_PROJECT -- the name of the project
132
+ * ONE_SKY_PLATFORM_ID -- the numeric id of the platform
133
+
134
+ Try running
135
+ rails generate one_sky:init
136
+
137
+ again to regenerate your config.
138
+ MESSAGE
139
+
140
+ def verify_options!(options)
141
+ missing_keys = REQUIRED_KEYS - options.keys
142
+ unless missing_keys.empty?
143
+ raise ::ArgumentError, REQUIRED_KEYS_MESSAGE
144
+ end
118
145
  end
119
146
 
120
147
  def verify_platform!
@@ -10,6 +10,8 @@ module I18n
10
10
 
11
11
  # Store all translations from OneSky in YAMl files.
12
12
  def download(yaml_path)
13
+ puts "Downloading translations for I18n Simple Backend:"
14
+
13
15
  platform_locales.each do |locale|
14
16
  locale_code = locale["locale"]
15
17
  local_name = locale["name"]["local"]
@@ -21,15 +23,16 @@ module I18n
21
23
  else
22
24
  yaml = platform.translation.download_yaml(locale_code)
23
25
 
24
- File.open(File.join(yaml_path, "#{locale_code}_one_sky.yml"), "w") do |f|
26
+ yaml_file_name = "#{locale_code}_one_sky.yml"
27
+ puts " locale: #{locale_code}, file: #{yaml_file_name}"
28
+
29
+ File.open(File.join(yaml_path, yaml_file_name), "w") do |f|
25
30
  f.puts "# PLEASE DO NOT EDIT THIS FILE."
26
31
  f.puts "# This was downloaded from OneSky. Log in to your OneSky account to manage translations on their website."
27
32
  f.puts "# Language code: #{locale_code}"
28
33
  f.puts "# Language name: #{local_name}"
29
34
  f.puts "# Language English name: #{english_name}"
30
35
  f.write yaml
31
-
32
- puts "Writing: #{f.path}"
33
36
  end
34
37
  end
35
38
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Onesky
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -0,0 +1,13 @@
1
+ #
2
+ # To load your OneSky details from the environment
3
+ # just add some erb tags like this.
4
+ #
5
+ # api_key: <%= ENV["ONESKY_API_KEY"] %>
6
+ # api_secret: <%= ENV["ONESKY_API_SECRET"] %>
7
+ # project: <%= ENV["ONESKY_PROJECT"] %>
8
+ # platform_id: <%= ENV["ONESKY_PLATFORM_ID"] %>
9
+ #
10
+ ---
11
+ api_key: abc123
12
+ api_secret: def456
13
+ project: some-project
@@ -0,0 +1,14 @@
1
+ #
2
+ # To load your OneSky details from the environment
3
+ # just add some erb tags like this.
4
+ #
5
+ # api_key: <%= ENV["ONESKY_API_KEY"] %>
6
+ # api_secret: <%= ENV["ONESKY_API_SECRET"] %>
7
+ # project: <%= ENV["ONESKY_PROJECT"] %>
8
+ # platform_id: <%= ENV["ONESKY_PLATFORM_ID"] %>
9
+ #
10
+ ---
11
+ api_key: abc123
12
+ api_secret: def456
13
+ project: some-project
14
+ platform_id: 888
@@ -19,7 +19,7 @@ require 'spec_helper'
19
19
  require 'tmpdir'
20
20
  require 'yaml'
21
21
 
22
- describe I18n::OneSky::SimpleClient, "LIVE", :live => true do
22
+ describe I18n::OneSky::SimpleClient do
23
23
 
24
24
  let(:onesky_api_key) { ENV["ONESKY_API_KEY"] }
25
25
  let(:onesky_api_secret) { ENV["ONESKY_API_SECRET"] }
@@ -38,43 +38,60 @@ describe I18n::OneSky::SimpleClient, "LIVE", :live => true do
38
38
  :platform_id => platform_id)
39
39
  end
40
40
 
41
- context "download" do
41
+
42
+ context "initialization" do
43
+ context "from file" do
44
+ it "works" do
45
+ I18n::OneSky::SimpleClient.from_config(fixture_path("config.yml"))
46
+ end
42
47
 
43
- let(:yaml_path) { Dir.tmpdir }
44
-
45
- def yaml_files
46
- Dir.glob(yaml_path+"/*.yml")
48
+ it "raises if a key is missing" do
49
+ expect{
50
+ I18n::OneSky::SimpleClient.from_config(fixture_path("config-incomplete.yml"))
51
+ }.to raise_error(ArgumentError)
52
+ end
47
53
  end
54
+ end
55
+
56
+ context "LIVE", :live => true do
57
+ context "download" do
48
58
 
49
- before(:each) do
50
- # delete any pre-existing yml files.
51
- File.delete(*yaml_files)
52
- end
59
+ let(:yaml_path) { Dir.tmpdir }
60
+
61
+ def yaml_files
62
+ Dir.glob(yaml_path+"/*.yml")
63
+ end
53
64
 
54
- it "creates yaml files" do
55
- yaml_files.should be_empty
65
+ before(:each) do
66
+ # delete any pre-existing yml files.
67
+ File.delete(*yaml_files)
68
+ end
69
+
70
+ it "creates yaml files" do
71
+ yaml_files.should be_empty
56
72
 
57
- client.download(yaml_path)
73
+ client.download(yaml_path)
58
74
 
59
- yaml_files.should_not be_empty
60
- end
75
+ yaml_files.should_not be_empty
76
+ end
61
77
 
62
- it "creates a yaml file for the chinese locale." do
63
- client.download(yaml_path)
78
+ it "creates a yaml file for the chinese locale." do
79
+ client.download(yaml_path)
64
80
 
65
- chinese_file = yaml_files.detect{|f| f.end_with?("#{chinese_locale}_one_sky.yml") }
66
- yaml = YAML.load(File.read(chinese_file))
67
- yaml.keys.should == [chinese_locale]
68
- end
81
+ chinese_file = yaml_files.detect{|f| f.end_with?("#{chinese_locale}_one_sky.yml") }
82
+ yaml = YAML.load(File.read(chinese_file))
83
+ yaml.keys.should == [chinese_locale]
84
+ end
69
85
 
70
- end
86
+ end
71
87
 
72
- context "upload" do
88
+ context "upload" do
73
89
 
74
- let(:yaml_path) { File.expand_path("../fixtures/files", __FILE__) }
90
+ let(:yaml_path) { File.expand_path("../fixtures/files", __FILE__) }
75
91
 
76
- it "uploads any yaml files in the path" do
77
- client.upload(yaml_path)
92
+ it "uploads any yaml files in the path" do
93
+ client.upload(yaml_path)
94
+ end
78
95
  end
79
96
  end
80
97
 
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,10 @@
1
1
  $:.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'i18n-one_sky'
3
+
4
+ def spec_root_path
5
+ File.expand_path(File.dirname(__FILE__))
6
+ end
7
+
8
+ def fixture_path(file_name)
9
+ File.join(spec_root_path, "fixtures", "files", file_name)
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-one_sky
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -15,7 +15,7 @@ date: 2011-12-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: i18n
18
- requirement: &70239195965320 !ruby/object:Gem::Requirement
18
+ requirement: &70126500654480 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 0.5.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70239195965320
26
+ version_requirements: *70126500654480
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: one_sky
29
- requirement: &70239195960480 !ruby/object:Gem::Requirement
29
+ requirement: &70126500489080 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - =
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 2.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70239195960480
37
+ version_requirements: *70126500489080
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: i18n-active_record
40
- requirement: &70239203730000 !ruby/object:Gem::Requirement
40
+ requirement: &70126500556960 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 0.0.2
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70239203730000
48
+ version_requirements: *70126500556960
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: activesupport
51
- requirement: &70239203729540 !ruby/object:Gem::Requirement
51
+ requirement: &70126500919300 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 2.2.2
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *70239203729540
59
+ version_requirements: *70126500919300
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: rspec
62
- requirement: &70239203729080 !ruby/object:Gem::Requirement
62
+ requirement: &70126500878320 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 2.2.0
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70239203729080
70
+ version_requirements: *70126500878320
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: bundler
73
- requirement: &70239203728620 !ruby/object:Gem::Requirement
73
+ requirement: &70126500833440 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: 1.0.0
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70239203728620
81
+ version_requirements: *70126500833440
82
82
  description: A set of I18n extensions that use OneSky. At its most basic, this allows
83
83
  you to easily submit translation requests to the OneSky service and download available
84
84
  translations as Simple backend YAML files.
@@ -113,6 +113,8 @@ files:
113
113
  - lib/i18n/one_sky/simple_client.rb
114
114
  - lib/i18n/one_sky/version.rb
115
115
  - spec/active_record_client_spec.rb
116
+ - spec/fixtures/files/config-incomplete.yml
117
+ - spec/fixtures/files/config.yml
116
118
  - spec/fixtures/files/en.yml
117
119
  - spec/simple_client_spec.rb
118
120
  - spec/spec_helper.rb
@@ -142,6 +144,8 @@ specification_version: 3
142
144
  summary: I18n extensions using OneSky -- the community-powered translation service.
143
145
  test_files:
144
146
  - spec/active_record_client_spec.rb
147
+ - spec/fixtures/files/config-incomplete.yml
148
+ - spec/fixtures/files/config.yml
145
149
  - spec/fixtures/files/en.yml
146
150
  - spec/simple_client_spec.rb
147
151
  - spec/spec_helper.rb