localeapp 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # Version 0.4.0
2
+
3
+ * Use Psych to generate the yaml if it's available (This will completely change
4
+ your yaml the first time you do a localeapp pull and Psych is available)
5
+ * Report when the directory to write the yml to doesn't exist (Thanks Robin
6
+ Mehner)
7
+
1
8
  # Version 0.3.2
2
9
 
3
10
  * Use yml rather than json when making api calls to localeapp.com. This avoids
data/README.md CHANGED
@@ -137,6 +137,17 @@ You can also add a new locale to a project via localeapp.com. This will create
137
137
  missing translations for every translation key. You will need to restart any
138
138
  listeners completely to pick up the new locale.
139
139
 
140
+ ## Syck, Psych, and creating YAML
141
+
142
+ Since ruby 1.9.3-p0 Psych has been the default YAML engine in Ruby. Psych is
143
+ based on libyaml and fixes a number of issues with the previous YAML library,
144
+ Syck. localeapp.com uses 1.9.3 and Psych for all its YAML processing. The
145
+ localeapp gem will use Psych if it is available but falls back to the ya2yaml
146
+ library if not. ya2yaml supports UTF-8 (which Syck doesn't handle very well)
147
+ but it does write YAML differently to Psych so you will notice differences
148
+ between exporting directly from localeapp.com and doing localeapp pull on the
149
+ command line unless you're using 1.9.3+ or have installed Psych as a gem.
150
+
140
151
  ### Proxies
141
152
 
142
153
  If you need to go through a proxy server, you can configure it with:
@@ -159,5 +170,5 @@ See [this article on Ruby Inside][1] for some more details.
159
170
 
160
171
  ### Support and feedback
161
172
 
162
- You can contact us via the support link at the bottom of the page, emailing
163
- info@localeapp.com, or on campfire at https://localeapp.campfirenow.com/d77b5
173
+ You can contact us via the support link at the bottom of the page or emailing
174
+ info@localeapp.com
@@ -99,6 +99,16 @@ Feature: localeapp executable
99
99
  And help should not be displayed
100
100
  And a file named "config/locales/en.yml" should exist
101
101
 
102
+ Scenario: Running pull without having a locales dir
103
+ In order to retreive my translations
104
+ Given I have a translations on localeapp.com for the project with api key "MYAPIKEY"
105
+ And an initializer file
106
+ When I run `localeapp pull`
107
+ Then the output should contain:
108
+ """
109
+ Could not write locale file, please make sure that config/locales exists and is writeable
110
+ """
111
+
102
112
  Scenario: Running push on a file
103
113
  In order to send my translations
104
114
  When I have a valid project on localeapp.com with api key "MYAPIKEY"
@@ -8,7 +8,7 @@ module Localeapp
8
8
 
9
9
  def post_translation(locale, key, options, value = nil)
10
10
  options ||= {}
11
- translation = { :key => key, :locale => locale, :substitutions => options.keys, :description => value}
11
+ translation = { :key => key, :locale => locale, :substitutions => options.keys.sort, :description => value}
12
12
  @data = { :translation => translation }
13
13
  api_call :create_translation,
14
14
  :payload => @data.to_json,
@@ -25,13 +25,22 @@ module Localeapp
25
25
 
26
26
  if translations[short_code]
27
27
  atomic_write(filename) do |file|
28
- file.write translations.ya2yaml[5..-1]
28
+ file.write generate_yaml(translations)
29
29
  end
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
34
  private
35
+
36
+ def generate_yaml(translations)
37
+ if defined? Psych
38
+ Psych.dump(translations)[4..-1]
39
+ else
40
+ translations.ya2yaml[5..-1]
41
+ end
42
+ end
43
+
35
44
  def remove_flattened_key!(hash, locale, key)
36
45
  keys = I18n.normalize_keys(locale, key, '').map(&:to_s)
37
46
  current_key = keys.shift
@@ -57,6 +66,11 @@ module Localeapp
57
66
 
58
67
  # originally from ActiveSupport
59
68
  def atomic_write(file_name, temp_dir = Dir.tmpdir)
69
+ target_dir = File.dirname(file_name)
70
+ unless File.directory?(target_dir)
71
+ raise "Could not write locale file, please make sure that #{target_dir} exists and is writeable"
72
+ end
73
+
60
74
  temp_file = Tempfile.new(File.basename(file_name), temp_dir)
61
75
  yield temp_file
62
76
  temp_file.close
@@ -1,3 +1,3 @@
1
1
  module Localeapp
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/localeapp.gemspec CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Christopher Dell", "Chris McGrath"]
10
10
  s.email = ["chris@tigrish.com", "chris@octopod.info"]
11
- s.homepage = "http://rubygems.org/gems/localeapp"
12
- s.summary = %q{Add missing translation keys to localeapp.com}
13
- s.description = %q{Post any unfound translation keys to the Locale SaaS}
11
+ s.homepage = "http://www.localeapp.com"
12
+ s.summary = %q{Easy i18n translation management with localeapp.com}
13
+ s.description = %q{Synchronizes i18n translation keys and content with localeapp.com so you don't have to manage translations by hand.}
14
14
 
15
15
  s.rubyforge_project = "localeapp"
16
16
 
@@ -12,7 +12,7 @@ describe Localeapp::Sender, "#post_translation(locale, key, options, value = nil
12
12
  :translation => {
13
13
  :key => "test.key",
14
14
  :locale => "en",
15
- :substitutions => ['foo', 'bar'],
15
+ :substitutions => ['bar', 'foo'],
16
16
  :description => "test content"
17
17
  }
18
18
  }
@@ -21,7 +21,7 @@ describe Localeapp::Updater, ".update(data)" do
21
21
  do_update({
22
22
  'translations' => {
23
23
  'en' => {
24
- 'foo' => { 'monkey' => 'hello', 'night' => 'night' }
24
+ 'foo' => { 'monkey' => 'hello', 'night' => 'the night' }
25
25
  },
26
26
  'es' => {
27
27
  'foo' => { 'monkey' => 'hola', 'night' => 'noche' }
@@ -34,18 +34,21 @@ describe Localeapp::Updater, ".update(data)" do
34
34
  ],
35
35
  'locales' => %w{en es}
36
36
  })
37
- File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
37
+ if defined? Psych
38
+ File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
39
+ en:
40
+ foo:
41
+ monkey: hello
42
+ night: the night
43
+ EN
44
+ else
45
+ File.read(File.join(@yml_dir, 'en.yml')).should == <<-EN
38
46
  en:
39
47
  foo:
40
48
  monkey: hello
41
- night: night
49
+ night: "the night"
42
50
  EN
43
- File.read(File.join(@yml_dir, 'es.yml')).should == <<-ES
44
- es:
45
- foo:
46
- monkey: hola
47
- night: noche
48
- ES
51
+ end
49
52
  end
50
53
 
51
54
  it "deletes keys in the yml files when updates are empty" do
@@ -58,11 +61,19 @@ ES
58
61
  ],
59
62
  'locales' => %w{es}
60
63
  })
61
- File.read(File.join(@yml_dir, 'es.yml')).should == <<-ES
64
+ if defined? Psych
65
+ File.read(File.join(@yml_dir, 'es.yml')).should == <<-ES
66
+ es:
67
+ foo:
68
+ monkey: Mono
69
+ ES
70
+ else
71
+ File.read(File.join(@yml_dir, 'es.yml')).should == <<-ES
62
72
  es:
63
73
  foo:
64
74
  monkey: Mono
65
75
  ES
76
+ end
66
77
  end
67
78
 
68
79
  it "creates a new yml file if an unknown locale is passed" do
@@ -72,10 +83,17 @@ ES
72
83
  },
73
84
  'locales' => ['ja']
74
85
  })
75
- File.read(File.join(@yml_dir, 'ja.yml')).should == <<-JA
86
+ if defined? Psych
87
+ File.read(File.join(@yml_dir, 'ja.yml')).should == <<-JA
88
+ ja:
89
+ foo: bar
90
+ JA
91
+ else
92
+ File.read(File.join(@yml_dir, 'ja.yml')).should == <<-JA
76
93
  ja:
77
94
  foo: bar
78
95
  JA
96
+ end
79
97
  end
80
98
 
81
99
  it "doesn't create a new yml file if an unknown locale is passed but it has no translations" do
@@ -86,4 +104,4 @@ JA
86
104
  })
87
105
  File.exist?(File.join(@yml_dir, 'ja.yml')).should be_false
88
106
  end
89
- end
107
+ 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: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.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: 2011-12-20 00:00:00 Z
19
+ date: 2012-02-21 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: i18n
@@ -182,7 +182,7 @@ dependencies:
182
182
  version: 1.3.0
183
183
  type: :development
184
184
  version_requirements: *id011
185
- description: Post any unfound translation keys to the Locale SaaS
185
+ description: Synchronizes i18n translation keys and content with localeapp.com so you don't have to manage translations by hand.
186
186
  email:
187
187
  - chris@tigrish.com
188
188
  - chris@octopod.info
@@ -236,7 +236,6 @@ files:
236
236
  - lib/localeapp/updater.rb
237
237
  - lib/localeapp/version.rb
238
238
  - localeapp.gemspec
239
- - run_ci
240
239
  - spec/fixtures/empty_log.yml
241
240
  - spec/fixtures/en.yml
242
241
  - spec/fixtures/es.yml
@@ -260,7 +259,7 @@ files:
260
259
  - spec/support/i18n/missing_translation.rb
261
260
  - spec/support/localeapp_integration_data.rb
262
261
  - spec/support/localeapp_synchronization_data.rb
263
- homepage: http://rubygems.org/gems/localeapp
262
+ homepage: http://www.localeapp.com
264
263
  licenses: []
265
264
 
266
265
  post_install_message:
@@ -289,10 +288,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
288
  requirements: []
290
289
 
291
290
  rubyforge_project: localeapp
292
- rubygems_version: 1.8.10
291
+ rubygems_version: 1.8.15
293
292
  signing_key:
294
293
  specification_version: 3
295
- summary: Add missing translation keys to localeapp.com
294
+ summary: Easy i18n translation management with localeapp.com
296
295
  test_files:
297
296
  - features/localeapp_binary.feature
298
297
  - features/step_definitions/cli_steps.rb
data/run_ci DELETED
@@ -1,5 +0,0 @@
1
- #!/bin/sh
2
- source "$HOME/.rvm/scripts/rvm"
3
- rvm gemset use $BUILD_RUBY_VERSION@localeapp
4
- bundle install
5
- rake