gettext-setup 0.28 → 0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26b13ff0d0fa9a44b156dbc8d9196fa7f0ec2974
4
- data.tar.gz: df14184c767513cf61870658ef8968c5e8d76fbc
3
+ metadata.gz: f8da8fd9251397ed014f16b48dea5b14640d800c
4
+ data.tar.gz: d627fbab3ccae583c2762a035138446afb01648e
5
5
  SHA512:
6
- metadata.gz: 74b6d2e5689e91e796a0c8c75e767c1fbffc955b752d4dd340abdfa5a25391ca1d29649efd6cea16fbb5d58a23e85da9f04ff0dc955719419eb93614aff79856
7
- data.tar.gz: 35d1f5cf80a0674c907add49aff503c5965cf9c6c3939be9ff8956548bdb7aeb8ae391b43732c8125527191cb0df4a3cd6d080e3500358daaff9f9f0889ce06c
6
+ metadata.gz: 1e628881df88dfc63c0626b1aa807175c8a3d9cb12a42da9e10fef82beb7fd8fb7b7e3f7c4c032eeea1cf58397eccdb9bf8da94f34174a4d810d07c6ab839b56
7
+ data.tar.gz: 22de28a46e580a41f0e8322b0ebf88349f8de4ac46124537b579d8406ce837a0ebd52cb8021765e59a1879fb9981f6fc4e54dbddde3396b4477300ae3b74dbcf
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require 'fast_gettext'
4
2
  require 'yaml'
5
3
  require 'locale'
@@ -23,11 +21,7 @@ module GettextSetup
23
21
  # valid `options` fields:
24
22
  # :file_format - one of the supported backends for fast_gettext (e.g. :po, :mo, :yaml, etc.)
25
23
  def self.initialize(locales_path = 'locales', options = {})
26
- config_path = File.absolute_path('config.yaml', locales_path)
27
- File.exist?(config_path) || raise(NoConfigFoundError, config_path)
28
-
29
- @config = YAML.load_file(config_path)['gettext']
30
- @locales_path = locales_path
24
+ GettextSetup.initialize_config(locales_path)
31
25
 
32
26
  # Make the translation methods available everywhere
33
27
  Object.send(:include, FastGettext::Translation)
@@ -49,6 +43,18 @@ module GettextSetup
49
43
  Locale.set_default(default_locale)
50
44
  end
51
45
 
46
+ # Sets up the config class variables.
47
+ #
48
+ # Call this without calling initialize when you only need to deal with the
49
+ # translation files and you don't need runtime translation.
50
+ def self.initialize_config(locales_path = 'locales')
51
+ config_path = File.absolute_path('config.yaml', locales_path)
52
+ File.exist?(config_path) || raise(NoConfigFoundError, config_path)
53
+
54
+ @config = YAML.load_file(config_path)['gettext']
55
+ @locales_path = locales_path
56
+ end
57
+
52
58
  def self.config?
53
59
  raise NoConfigFoundError, File.join(locales_path, 'config.yaml') unless @config
54
60
  @config
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require 'erb'
4
2
  require 'json'
5
3
 
@@ -1,7 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require 'open3'
4
2
  require 'English'
3
+ require 'tempfile'
5
4
 
6
5
  module GettextSetup
7
6
  module Pot
@@ -54,10 +53,18 @@ module GettextSetup
54
53
  # The directory for the locales.
55
54
  # @param [:target_path] opts
56
55
  # The output path for the new POT file.
56
+ # @param [:header_only] opts
57
+ # Set to true to create a .pot file with only a header
57
58
  def self.generate_new_pot(opts = {})
58
59
  locales_path = opts[:locales_path] || GettextSetup.locales_path
59
- GettextSetup.initialize(locales_path)
60
+ GettextSetup.initialize_config(locales_path)
60
61
  target_path = opts[:target_path] || pot_file_path
62
+ input_files = if opts[:header_only]
63
+ tmpfile = Tempfile.new('gettext-setup.tmp')
64
+ tmpfile.path
65
+ else
66
+ files_to_translate.join(' ')
67
+ end
61
68
  config = GettextSetup.config
62
69
  package_name = config['package_name']
63
70
  bugs_address = config['bugs_address']
@@ -69,14 +76,15 @@ module GettextSetup
69
76
  "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
70
77
  "--package-name '#{package_name}' " \
71
78
  "--package-version '#{version}' " \
72
- "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
73
- files_to_translate.join(' '))
79
+ "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " \
80
+ "#{input_files}")
81
+ tmpfile.unlink if tmpfile
74
82
  $CHILD_STATUS.success?
75
83
  end
76
84
 
77
85
  def self.generate_new_po(language, locales_path = GettextSetup.locales_path,
78
86
  pot_file = nil, po_file = nil)
79
- GettextSetup.initialize(locales_path)
87
+ GettextSetup.initialize_config(locales_path)
80
88
  language ||= ENV['LANGUAGE']
81
89
  pot_file ||= GettextSetup::Pot.pot_file_path
82
90
  po_file ||= GettextSetup::Pot.po_file_path(language)
@@ -116,7 +124,7 @@ module GettextSetup
116
124
  end
117
125
 
118
126
  def self.update_pot(locales_path = GettextSetup.locales_path, path = nil)
119
- GettextSetup.initialize(locales_path)
127
+ GettextSetup.initialize_config(locales_path)
120
128
  path ||= pot_file_path
121
129
 
122
130
  if !File.exist? path
@@ -147,7 +155,7 @@ module GettextSetup
147
155
  # The directory for the locales.
148
156
  def self.merge(opts = {})
149
157
  locales_path = opts[:locales_path] || GettextSetup.locales_path
150
- GettextSetup.initialize(locales_path)
158
+ GettextSetup.initialize_config(locales_path)
151
159
  target_filename = GettextSetup.config['project_name'] + '.pot'
152
160
  target_path = File.expand_path(target_filename, locales_path)
153
161
  oldpot_dir = File.expand_path('oldpot', locales_path)
@@ -156,9 +164,9 @@ module GettextSetup
156
164
  if File.exist? target_path
157
165
  FileUtils.mkdir_p(oldpot_dir)
158
166
  begin
159
- FileUtils.mv(target_path, oldpot_path)
160
- rescue
161
- raise "There was a problem creating .pot backup #{oldpot_path}, merge failed."
167
+ FileUtils.cp(target_path, oldpot_path)
168
+ rescue Errno::ENOENT => e
169
+ raise "There was a problem creating .pot backup #{oldpot_path}, merge failed: #{e.message}"
162
170
  end
163
171
  puts "Warning - #{target_filename} already exists and will be relocated to oldpot/old_#{target_filename}."
164
172
  end
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require_relative '../gettext-setup/gettext_setup'
4
2
  require_relative '../gettext-setup/pot'
5
3
  require_relative '../gettext-setup/metadata_pot'
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'rspec/expectations'
3
2
  require_relative '../../spec_helper'
4
3
 
@@ -62,6 +62,17 @@ describe GettextSetup::Pot do
62
62
  expect(contents).to match(/Puppet, LLC/)
63
63
  expect(contents).to match(/test_strings.rb:1/)
64
64
  end
65
+ it 'builds a POT file with :header_only' do
66
+ path = File.join(Dir.mktmpdir, 'new.pot')
67
+ expect do
68
+ GettextSetup::Pot.generate_new_pot(locales_path: fixture_locales_path, target_path: path, header_only: true)
69
+ end.to output('').to_stdout # STDOUT is determined in `update_pot`
70
+ contents = File.read(path)
71
+ expect(contents).to_not match(/Hello, world/)
72
+ expect(contents).to match(/Fixture locales/)
73
+ expect(contents).to match(/docs@puppetlabs.com/)
74
+ expect(contents).to match(/Puppet, LLC/)
75
+ end
65
76
  end
66
77
 
67
78
  context 'generate_new_po' do
@@ -153,7 +164,7 @@ describe GettextSetup::Pot do
153
164
  before :all do
154
165
  { 'ruby' => 'ruby.pot', 'puppet' => 'puppet.pot', 'metadata' => 'metadata.pot' }.each do |pot_type, pot_name|
155
166
  File.open(File.join(merge_locales_path, pot_name), 'w') do |file|
156
- file.write <<-EOF
167
+ file.write <<-POT
157
168
  # Copyright (C) 2017 Puppet, Inc.
158
169
  # This file is distributed under the same license as the puppetlabs-mysql package.
159
170
  # FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
@@ -175,7 +186,7 @@ describe GettextSetup::Pot do
175
186
  #: ../lib/puppet/parser/functions/mysql_strip_hash.rb:11
176
187
  msgid "this is a #{pot_type} string"
177
188
  msgstr ""
178
- EOF
189
+ POT
179
190
  end
180
191
  end
181
192
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gettext-setup
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.28'
4
+ version: '0.29'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-01 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_gettext
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.1'
139
139
  - !ruby/object:Gem::Dependency
140
- name: simplecov
140
+ name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: rubocop
154
+ name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  version: '0'
225
225
  requirements: []
226
226
  rubyforge_project:
227
- rubygems_version: 2.5.2
227
+ rubygems_version: 2.5.1
228
228
  signing_key:
229
229
  specification_version: 4
230
230
  summary: A gem to ease internationalization with fast_gettext