localeapp 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -6,6 +6,3 @@ gemfile:
6
6
  - Gemfile.i18n_037
7
7
  - Gemfile.i18n_050
8
8
  - Gemfile.i18n_060
9
- branches:
10
- only:
11
- - master
data/CHANGELOG.md CHANGED
@@ -1,12 +1,19 @@
1
- # HEAD
1
+ # Version 0.5.0
2
2
 
3
- # Version 0.4.2
3
+ * Post translations with default values
4
+ * Change how Psych outputs yaml (for Psych versions >= 1.1.0)
5
+ * Add a --github option when installing to help setup public projects
6
+
7
+ # Version 0.4.3
4
8
 
5
9
  * Make sure Psych is fully loaded before using it (Thanks @tenderlove)
6
10
 
7
- # Version 0.4.1
11
+ # Version 0.4.2
8
12
 
9
13
  * Improve compatibility of Psych with ruby 1.9.2 (Thanks @ardpac)
14
+
15
+ # Version 0.4.1
16
+
10
17
  * Ignore HUP when backgrounded. (Thanks @xijo)
11
18
  * Add --standalone option to install to generate a .localeapp/ config
12
19
  directory. This enables usage outside of rails.
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", ">= 2.4.0"
5
+ gem "bundler", "~> 1.1.2"
6
+ gem "jeweler", "> 1.6.4"
7
+ gem 'i18n-spec'
8
+ gem 'localeapp'
9
+ end
data/README.md CHANGED
@@ -48,6 +48,18 @@ Install the gem and run:
48
48
 
49
49
  This will create a `.localeapp` directory for your configuration files.
50
50
 
51
+ ### Public projects
52
+
53
+ Install the gem and run:
54
+
55
+ localeapp install --github <YOUR_API_KEY>
56
+
57
+ This will create a skeleton project you can push to `<your_gem>-i18n` on
58
+ github. You get a `.localeapp` directory for your configuration files, a
59
+ `locales` directory for the yaml, a `.gitignore` file that ignores `.localeapp`
60
+ and a `README.md` explaining to translators how to find the project on
61
+ localeapp.com.
62
+
51
63
  ## Importing existing content
52
64
 
53
65
  You can import via localeapp.com or with the command line tool. To import
data/bin/localeapp CHANGED
@@ -31,11 +31,16 @@ arg_name "<api_key>"
31
31
  command :install do |c|
32
32
  c.desc "install configuration files in .localeapp/"
33
33
  c.switch [:s, 'standalone']
34
+
35
+ c.desc "install a skeleton project suitable for Github"
36
+ c.switch [:g, 'github']
34
37
 
35
38
  c.action do |global_options, options, args|
36
39
  key = args.first
37
40
  installer = Localeapp::CLI::Install.new
38
- installer.config_type = options[:standalone] ? :standalone : :rails
41
+ installer.config_type = :standalone if options[:standalone]
42
+ installer.config_type = :github if options[:github]
43
+ installer.config_type ||= :rails
39
44
  unless installer.execute(key)
40
45
  exit_now! "", 1
41
46
  end
@@ -50,6 +50,25 @@ Feature: localeapp executable
50
50
  And a file named ".localeapp/config.rb" should exist
51
51
  And the exit status should be 0
52
52
 
53
+ Scenario: Running github install
54
+ In order to configure my public github project and check my api key is correct
55
+ When I have a valid project on localeapp.com with api key "MYAPIKEY"
56
+ And I run `localeapp install --github MYAPIKEY`
57
+ Then the output should contain:
58
+ """
59
+ Localeapp Install
60
+
61
+ Checking API key: MYAPIKEY
62
+ Success!
63
+ Project: Test Project
64
+ Default Locale: en (English)
65
+ """
66
+ And help should not be displayed
67
+ And a file named ".localeapp/config.rb" should exist
68
+ And a file named ".gitignore" should exist
69
+ And a file named "README.md" should exist
70
+ And the exit status should be 0
71
+
53
72
 
54
73
  Scenario: Running install with bad api key
55
74
  In order to configure my project and check my api key is correct
@@ -29,12 +29,19 @@ module Localeapp
29
29
  config_file_path = "config/initializers/localeapp.rb"
30
30
  data_directory = "config/locales"
31
31
  else
32
- output.puts "NOTICE: you probably want to add .localeapp to your .gitignore file"
32
+ if config_type == :standalone
33
+ output.puts "NOTICE: you probably want to add .localeapp to your .gitignore file"
34
+ end
33
35
  config_file_path = ".localeapp/config.rb"
34
36
  data_directory = "locales"
35
37
  end
38
+
36
39
  output.puts "Writing configuration file to #{config_file_path}"
37
- write_configuration_file config_file_path
40
+ if config_type == :github
41
+ write_github_configuration_file config_file_path, project_data
42
+ else
43
+ write_configuration_file config_file_path
44
+ end
38
45
 
39
46
  unless File.directory?(data_directory)
40
47
  output.puts "WARNING: please create the #{data_directory} directory. Your translation data will be stored there."
@@ -58,6 +65,10 @@ module Localeapp
58
65
  Localeapp.configuration.write_standalone_configuration(path)
59
66
  end
60
67
  end
68
+
69
+ def write_github_configuration_file(path, project_data)
70
+ Localeapp.configuration.write_github_configuration(path, project_data)
71
+ end
61
72
  end
62
73
  end
63
74
  end
@@ -171,6 +171,29 @@ Localeapp.configure do |config|
171
171
  config.synchronization_data_file = '.localeapp/log.yml'
172
172
  config.daemon_pid_file = '.localeapp/localeapp.pid'
173
173
  end
174
+ CONTENT
175
+ end
176
+ end
177
+
178
+ def write_github_configuration(path, project_data)
179
+ write_standalone_configuration(path)
180
+ FileUtils.mkdir_p('locales')
181
+ File.open('.gitignore', 'a+') do |file|
182
+ file.write ".localeapp"
183
+ end
184
+ File.open('README.md', 'w+') do |file|
185
+ file.write <<-CONTENT
186
+ # #{project_data['name']}
187
+
188
+ A ruby translation project managed on [Locale](http://www.localeapp.com/) that's open to all!
189
+
190
+ ## Contributing to #{project_data['name']}
191
+
192
+ - Edit the translations directly on the [#{project_data['name']}](http://www.localeapp.com/projects/public?search=#{project_data['name']}) project on Locale.
193
+ - **That's it!**
194
+ - The maintainer will then pull translations from the Locale project and push to Github.
195
+
196
+ Happy translating!
174
197
  CONTENT
175
198
  end
176
199
  end
@@ -0,0 +1,17 @@
1
+ module I18n::Backend::Base
2
+ alias_method :default_without_handler, :default
3
+
4
+ def default(locale, object, subject, options = {})
5
+ result = default_without_handler(locale, object, subject, options)
6
+ return result if ::Localeapp.configuration.sending_disabled?
7
+
8
+ if result
9
+ sender = Localeapp::Sender.new
10
+
11
+ # Make the default value a complete translation
12
+ sender.post_translation(locale, object, options, result)
13
+ end
14
+
15
+ return result
16
+ end
17
+ end
@@ -8,6 +8,8 @@ module Localeapp
8
8
 
9
9
  def post_translation(locale, key, options, value = nil)
10
10
  options ||= {}
11
+ options.delete(:default)
12
+ options.delete(:scope)
11
13
  translation = { :key => key, :locale => locale, :substitutions => options.keys.sort, :description => value}
12
14
  @data = { :translation => translation }
13
15
  api_call :create_translation,
@@ -35,7 +35,7 @@ module Localeapp
35
35
 
36
36
  def generate_yaml(translations)
37
37
  if defined? Psych
38
- Psych.dump(translations)[4..-1]
38
+ Psych.dump(translations, :line_width => -1)[4..-1]
39
39
  else
40
40
  translations.ya2yaml[5..-1]
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/localeapp.rb CHANGED
@@ -33,6 +33,7 @@ require 'localeapp/poller'
33
33
  require 'localeapp/updater'
34
34
  require 'localeapp/key_checker'
35
35
  require 'localeapp/missing_translations'
36
+ require 'localeapp/default_value_handler'
36
37
 
37
38
  require 'localeapp/cli/install'
38
39
  require 'localeapp/cli/pull'
@@ -61,4 +61,11 @@ describe Localeapp::CLI::Install, '.execute(key, output = $stdout)' do
61
61
  @command.execute('API_KEY', @output)
62
62
  @output.string.should_not match(/Your translation data will be stored there./)
63
63
  end
64
+
65
+ it "asks the github configuration to write itself" do
66
+ @command.stub!(:check_key).and_return([true, valid_project_data])
67
+ @command.config_type = :github
68
+ @command.should_receive(:write_github_configuration_file).with('.localeapp/config.rb', valid_project_data)
69
+ @command.execute('API_KEY', @output)
70
+ end
64
71
  end
@@ -340,3 +340,20 @@ CONTENT
340
340
  configuration.write_standalone_configuration(path)
341
341
  end
342
342
  end
343
+
344
+
345
+ describe Localeapp::Configuration, "#write_github_configuration(path, project_data)" do
346
+ let(:configuration) { Localeapp::Configuration.new }
347
+ let(:project_data) { {"name"=>"Test Project", "default_locale"=>{"name"=>"English", "code"=>"en"}} }
348
+ let(:path) { '.localeapp/config.rb' }
349
+
350
+ it "writes github configuration files" do
351
+ configuration.should_receive(:write_standalone_configuration).with(path)
352
+ file = stub('file')
353
+ file.should_receive(:write).exactly(2).times.and_return('content')
354
+ FileUtils.should_receive(:mkdir_p).with('locales')
355
+ File.should_receive(:open).with('.gitignore', 'a+').and_yield(file)
356
+ File.should_receive(:open).with('README.md', 'w+').and_yield(file)
357
+ configuration.write_github_configuration(path, project_data)
358
+ end
359
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ class Klass
4
+ include I18n::Backend::Base
5
+ end
6
+
7
+ describe I18n::Backend::Base, '#default' do
8
+ let(:klass) { Klass.new }
9
+
10
+ it "posts translations to Locale" do
11
+ with_configuration(:sending_environments => ['my_env'], :environment_name => 'my_env' ) do
12
+ sender = Localeapp::Sender.new
13
+ Localeapp::Sender.should_receive(:new).and_return(sender)
14
+ sender.should_receive(:post_translation)
15
+ klass.default('locale', 'object', 'subject')
16
+ end
17
+ end
18
+
19
+ it "doesn't post when sending is disabled" do
20
+ with_configuration(:sending_environments => []) do
21
+ Localeapp::Sender.should_not_receive(:new)
22
+ klass.default('locale', 'object', 'subject')
23
+ end
24
+ end
25
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Localeapp::Sender, "#post_translation(locale, key, options, value = nil)" do
4
4
  before(:each) do
5
- with_configuration(:api_key => "TEST_KEY") do
5
+ with_configuration(:api_key => "TEST_KEY", :sending_environments => ['my_env'], :environment_name => 'my_env') do
6
6
  @sender = Localeapp::Sender.new
7
7
  end
8
8
  end
@@ -24,7 +24,28 @@ describe Localeapp::Sender, "#post_translation(locale, key, options, value = nil
24
24
  :x_localeapp_gem_version => Localeapp::VERSION,
25
25
  :content_type => :json },
26
26
  :method => :post)).and_return(double('response', :code => 200))
27
- @sender.post_translation('en', 'test.key', { 'foo' => 'foo', 'bar' => 'bar' }, 'test content')
27
+ @sender.post_translation('en', 'test.key', { 'foo' => 'foo', 'bar' => 'bar', :default => 'default', :scope => 'scope' }, 'test content')
28
+ end
29
+
30
+ it "posts default translation data to the backend" do
31
+ data = {
32
+ :translation => {
33
+ :key => 'absolutely.missing',
34
+ :locale => 'en',
35
+ :substitutions => ['bar', 'foo'],
36
+ :description => 'a sensible default'
37
+ }
38
+ }
39
+
40
+ RestClient::Request.should_receive(:execute).with(hash_including(
41
+ :url => @sender.translations_url,
42
+ :payload => data.to_json,
43
+ :headers => {
44
+ :x_localeapp_gem_version => Localeapp::VERSION,
45
+ :content_type => :json },
46
+ :method => :post)).and_return(double('response', :code => 200))
47
+
48
+ I18n.t('absolutely.missing', { 'foo' => 'foo', 'bar' => 'bar', :default => 'a sensible default' })
28
49
  end
29
50
  end
30
51
 
@@ -129,4 +129,17 @@ JA
129
129
  })
130
130
  File.exist?(File.join(@yml_dir, 'ja.yml')).should be_false
131
131
  end
132
+
133
+ if defined?(Psych) && Psych::VERSION >= "1.1.0"
134
+ it "doesn't try to wrap long lines in the output" do
135
+ do_update({
136
+ 'translations' => {
137
+ 'en' => { 'foo' => ('bar ' * 30) }
138
+ },
139
+ 'locales' => ['en'],
140
+ 'deleted' => []
141
+ })
142
+ File.read(File.join(@yml_dir, 'en.yml')).should match(/foo: ! 'bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar '/m)
143
+ end
144
+ end
132
145
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localeapp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Dell
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-04-01 00:00:00 Z
19
+ date: 2012-07-04 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n
@@ -200,6 +200,7 @@ files:
200
200
  - .travis.yml
201
201
  - CHANGELOG.md
202
202
  - Gemfile
203
+ - Gemfile.github_project.rb
203
204
  - Gemfile.i18n_037
204
205
  - Gemfile.i18n_050
205
206
  - Gemfile.i18n_060
@@ -221,6 +222,7 @@ files:
221
222
  - lib/localeapp/cli/push.rb
222
223
  - lib/localeapp/cli/update.rb
223
224
  - lib/localeapp/configuration.rb
225
+ - lib/localeapp/default_value_handler.rb
224
226
  - lib/localeapp/exception_handler.rb
225
227
  - lib/localeapp/i18n_shim.rb
226
228
  - lib/localeapp/key_checker.rb
@@ -247,6 +249,7 @@ files:
247
249
  - spec/localeapp/cli/push_spec.rb
248
250
  - spec/localeapp/cli/update_spec.rb
249
251
  - spec/localeapp/configuration_spec.rb
252
+ - spec/localeapp/default_value_handler_spec.rb
250
253
  - spec/localeapp/exception_handler_spec.rb
251
254
  - spec/localeapp/key_checker_spec.rb
252
255
  - spec/localeapp/missing_translations_spec.rb
@@ -308,6 +311,7 @@ test_files:
308
311
  - spec/localeapp/cli/push_spec.rb
309
312
  - spec/localeapp/cli/update_spec.rb
310
313
  - spec/localeapp/configuration_spec.rb
314
+ - spec/localeapp/default_value_handler_spec.rb
311
315
  - spec/localeapp/exception_handler_spec.rb
312
316
  - spec/localeapp/key_checker_spec.rb
313
317
  - spec/localeapp/missing_translations_spec.rb