gettext-setup 0.21 → 0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b248dce3a387753f61e2e062421ae04cc466aa5b
4
- data.tar.gz: 68b67f382958948a1185cb81c91336668da56780
3
+ metadata.gz: 301f3ae1df25e57691ff9a3b68fbbaaba018fb75
4
+ data.tar.gz: ff2707b717e503eee61bdb29b4abf8368abe3603
5
5
  SHA512:
6
- metadata.gz: 8a80db6aecd41ccc0c21e5f8b901cc89a292a7389ea63c207440bdd9b52a1f46be57fbcf5de936d42ba3f34e2b940a4b15a9b99689276f0ad5acfd30d13bf187
7
- data.tar.gz: 3132f258171d67558835213f5c23568dcbea6d664a5881c08d59d08d1da09aefc9bc3e89925c719e307e81bd1b38777e2857220dd768f169c391fcfcc45f821d
6
+ metadata.gz: fba28fcc1c48d5d29a1f5944d8533e59122d93203652697e2416cc56fab2259708414156677861dbaaafc642c294ea92b45b4134669ce4e4c0802d80a4cc411c
7
+ data.tar.gz: d5b6badc80b1ab2e76e28094b6e094f76ef6fe131e49afa3c3e54977304dca13fb2f28f954b67669b3ad4ec0c774ad02c850034b59b4df28300f61738f934a1d
data/README.md CHANGED
@@ -36,11 +36,11 @@ your project:
36
36
  `GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))`
37
37
  (Note that the second line may require modification to find the `locales` directory.
38
38
  1. For client-side applications, add this line:
39
- `FastGettext.locale = GettextSetup.negotiate_locale(GettextSetup.candidate_locales)`
39
+ `GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)`
40
40
  1. For server-side applications, add these lines:
41
41
  ```
42
42
  before do
43
- FastGettext.locale = GettextSetup.negotiate_locale(env["HTTP_ACCEPT_LANGUAGE"])
43
+ GettextSetup.negotiate_locale!(env["HTTP_ACCEPT_LANGUAGE"])
44
44
  end
45
45
  ```
46
46
 
@@ -0,0 +1 @@
1
+ require 'metadata_pot/metadata_pot'
data/lib/gettext-setup.rb CHANGED
@@ -1 +1,3 @@
1
1
  require 'gettext-setup/gettext_setup'
2
+ require 'gettext-setup/metadata_pot'
3
+ require 'gettext-setup/pot'
@@ -5,6 +5,12 @@ require 'yaml'
5
5
  require 'locale'
6
6
 
7
7
  module GettextSetup
8
+ class NoConfigFoundError < RuntimeError
9
+ def initialize(path)
10
+ super("No config.yaml found! (searching: #{path})")
11
+ end
12
+ end
13
+
8
14
  @config = nil
9
15
  @translation_repositories = {}
10
16
  FastGettext.default_available_locales = []
@@ -16,8 +22,10 @@ module GettextSetup
16
22
  # - if using .mo files, an LC_MESSAGES dir in each language dir, with the .mo file in it
17
23
  # valid `options` fields:
18
24
  # :file_format - one of the supported backends for fast_gettext (e.g. :po, :mo, :yaml, etc.)
19
- def self.initialize(locales_path, options = {})
25
+ def self.initialize(locales_path = 'locales', options = {})
20
26
  config_path = File.absolute_path('config.yaml', locales_path)
27
+ File.exist?(config_path) || raise(NoConfigFoundError, config_path)
28
+
21
29
  @config = YAML.load_file(config_path)['gettext']
22
30
  @locales_path = locales_path
23
31
 
@@ -41,6 +49,11 @@ module GettextSetup
41
49
  Locale.set_default(default_locale)
42
50
  end
43
51
 
52
+ def self.config?
53
+ raise NoConfigFoundError, File.join(locales_path, 'config.yaml') unless @config
54
+ @config
55
+ end
56
+
44
57
  def self.add_repository_to_chain(project_name, options)
45
58
  repository = FastGettext::TranslationRepository.build(project_name,
46
59
  path: locales_path,
@@ -50,7 +63,7 @@ module GettextSetup
50
63
  end
51
64
 
52
65
  def self.locales_path
53
- @locales_path
66
+ @locales_path ||= File.join(Dir.pwd, 'locales')
54
67
  end
55
68
 
56
69
  def self.config
@@ -113,4 +126,9 @@ module GettextSetup
113
126
  default_locale
114
127
  end
115
128
  end
129
+
130
+ # Negotiates and sets the locale based on an accept language header.
131
+ def self.negotiate_locale!(accept_header)
132
+ FastGettext.locale = negotiate_locale(accept_header)
133
+ end
116
134
  end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'erb'
4
+ require 'json'
5
+
6
+ module GettextSetup
7
+ module MetadataPot
8
+ def self.metadata_path
9
+ File.join(GettextSetup.locales_path, GettextSetup.config['project_name'] + '_metadata.pot')
10
+ end
11
+
12
+ def self.template_path
13
+ File.join(File.dirname(__FILE__), '../templates/metadata.pot.erb')
14
+ end
15
+
16
+ def self.metadata(metadata_file = 'metadata.json')
17
+ if File.exist?(metadata_file)
18
+ file = open(metadata_file)
19
+ json = file.read
20
+ JSON.parse(json)
21
+ else
22
+ {}
23
+ end
24
+ end
25
+
26
+ def self.pot_string(metadata)
27
+ b = binding.freeze
28
+ # Uses `metadata`
29
+ ERB.new(File.read(template_path)).result(b)
30
+ end
31
+
32
+ def self.generate_metadata_pot(pot_metadata = metadata, path = metadata_path)
33
+ open(path, 'w') do |f|
34
+ f << pot_string(pot_metadata)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,138 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'open3'
4
+ require 'English'
5
+
6
+ module GettextSetup
7
+ module Pot
8
+ def self.text_domain
9
+ FastGettext.text_domain
10
+ end
11
+
12
+ def self.files_to_translate
13
+ files = (GettextSetup.config['source_files'] || []).map do |p|
14
+ Dir.glob(p)
15
+ end.flatten
16
+ # check for optional list of files to exclude from string
17
+ # extraction
18
+ exclusions = (GettextSetup.config['exclude_files'] || []).map do |p|
19
+ Dir.glob(p)
20
+ end.flatten
21
+
22
+ # if file is a directory, take it out of the array. directories
23
+ # cause rxgettext to error out.
24
+ (files - exclusions).reject { |file| File.directory?(file) }
25
+ end
26
+
27
+ def self.pot_file_path
28
+ return if GettextSetup.locales_path.nil?
29
+ return if GettextSetup.config['project_name'].nil?
30
+ File.join(GettextSetup.locales_path, GettextSetup.config['project_name'] + '.pot')
31
+ end
32
+
33
+ def self.po_file_path(language)
34
+ return if GettextSetup.locales_path.nil?
35
+ return if GettextSetup.config['project_name'].nil?
36
+ return if language.nil?
37
+ File.join(GettextSetup.locales_path, language, GettextSetup.config['project_name'] + '.po')
38
+ end
39
+
40
+ def self.string_changes?(old_pot, new_pot)
41
+ # Warnings will be in another language if locale is not set to en_US
42
+ _, stderr, status = Open3.capture3("LANG=en_US msgcmp --use-untranslated '#{old_pot}' '#{new_pot}'")
43
+ if status.exitstatus == 1 || /this message is not used/.match(stderr) || /this message is used but not defined/.match(stderr)
44
+ return true
45
+ end
46
+ return false
47
+ rescue IOError
48
+ # probably means msgcmp is not present on the system
49
+ # so return true to be on the safe side
50
+ return true
51
+ end
52
+
53
+ def self.generate_new_pot(locales_path = GettextSetup.locales_path, path = nil)
54
+ GettextSetup.initialize(locales_path)
55
+ path ||= pot_file_path
56
+ config = GettextSetup.config
57
+ package_name = config['package_name']
58
+ bugs_address = config['bugs_address']
59
+ copyright_holder = config['copyright_holder']
60
+ # Done this way to allow the user to enter an empty string in the config.
61
+ comments_tag = config.key?('comments_tag') ? config['comments_tag'] : 'TRANSLATORS'
62
+ version = `git describe`
63
+ system("rxgettext -o #{path} --no-wrap --sort-by-file " \
64
+ "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
65
+ "--package-name '#{package_name}' " \
66
+ "--package-version '#{version}' " \
67
+ "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
68
+ files_to_translate.join(' '))
69
+ $CHILD_STATUS.success?
70
+ end
71
+
72
+ def self.generate_new_po(language, locales_path = GettextSetup.locales_path,
73
+ pot_file = nil, po_file = nil)
74
+ GettextSetup.initialize(locales_path)
75
+ pot_file ||= GettextSetup::Pot.pot_file_path
76
+ po_file ||= GettextSetup::Pot.po_file_path(language)
77
+
78
+ language ||= ENV['LANGUAGE']
79
+
80
+ # Let's do some pre-verification of the environment.
81
+ if language.nil?
82
+ puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'"
83
+ return
84
+ end
85
+
86
+ language_path = File.dirname(po_file)
87
+ FileUtils.mkdir_p(language_path)
88
+
89
+ if File.exist?(po_file)
90
+ cmd = "msgmerge -U #{po_file} #{pot_file}"
91
+ _, _, _, wait = Open3.popen3(cmd)
92
+ exitstatus = wait.value
93
+ if exitstatus.success?
94
+ puts "PO file #{po_file} merged"
95
+ true
96
+ else
97
+ puts 'PO file merge failed'
98
+ false
99
+ end
100
+ else
101
+ cmd = "msginit --no-translator -l #{language} -o #{po_file} -i #{pot_file}"
102
+ _, _, _, wait = Open3.popen3(cmd)
103
+ exitstatus = wait.value
104
+ if exitstatus.success?
105
+ puts "PO file #{po_file} created"
106
+ true
107
+ else
108
+ puts 'PO file creation failed'
109
+ false
110
+ end
111
+ end
112
+ end
113
+
114
+ def self.update_pot(locales_path = GettextSetup.locales_path, path = nil)
115
+ GettextSetup.initialize(locales_path)
116
+ path ||= pot_file_path
117
+
118
+ if !File.exist? path
119
+ puts 'No existing POT file, generating new'
120
+ result = GettextSetup::Pot.generate_new_pot(locales_path, path)
121
+ puts "POT file #{path} has been generated" if result
122
+ else
123
+ old_pot = path + '.old'
124
+ File.rename(path, old_pot)
125
+ result = GettextSetup::Pot.generate_new_pot(locales_path, path)
126
+ if !result
127
+ puts 'POT creation failed'
128
+ elsif GettextSetup::Pot.string_changes?(old_pot, path)
129
+ File.delete(old_pot)
130
+ puts 'String changes detected, replacing with updated POT file'
131
+ else
132
+ puts 'No string changes detected, keeping old POT file'
133
+ File.rename(old_pot, path)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -1,57 +1,50 @@
1
- # require 'bundler'
2
- # puts File.absolute_path('Gemfile', Dir.pwd)
3
- # Bundler.read_file(File.absolute_path('Gemfile', Dir.pwd))
4
- #
1
+ # -*- encoding: utf-8 -*-
2
+
5
3
  require_relative '../gettext-setup/gettext_setup'
6
- require_relative 'task_helper.rb'
7
- #
8
- # GettextSetup.initialize(File.absolute_path('locales', Dir.pwd))
4
+ require_relative '../gettext-setup/pot'
5
+ require_relative '../gettext-setup/metadata_pot'
9
6
 
10
7
  namespace :gettext do
11
8
  desc 'Generate a new POT file and replace old if strings changed'
9
+
12
10
  task :update_pot do
13
- if !File.exist? pot_file_path
14
- puts 'No existing POT file, generating new'
15
- generate_new_pot
16
- else
17
- old_pot = pot_file_path + '.old'
18
- File.rename(pot_file_path, old_pot)
19
- generate_new_pot
20
- if string_changes?(old_pot, pot_file_path)
21
- File.delete(old_pot)
22
- puts 'String changes detected, replacing with updated POT file'
23
- else
24
- puts 'No string changes detected, keeping old POT file'
25
- File.rename(old_pot, pot_file_path)
26
- end
11
+ begin
12
+ GettextSetup::Pot.update_pot
13
+ rescue GettextSetup::NoConfigFoundError => e
14
+ puts e.message
27
15
  end
28
16
  end
29
17
 
30
18
  desc 'Generate POT file'
31
19
  task :pot do
32
- generate_new_pot
33
- puts "POT file #{pot_file_path} has been generated"
20
+ begin
21
+ result = GettextSetup::Pot.generate_new_pot
22
+ if result
23
+ puts "POT file #{GettextSetup::Pot.pot_file_path} has been generated"
24
+ end
25
+ rescue GettextSetup::NoConfigFoundError => e
26
+ puts e.message
27
+ end
34
28
  end
35
29
 
36
- desc 'Update PO file for a specific language'
37
- task :po, [:language] do |_, args|
38
- language = args.language || ENV['LANGUAGE']
39
-
40
- # Let's do some pre-verification of the environment.
41
- if language.nil?
42
- puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'"
43
- next
30
+ desc 'Generate POT file for metadata'
31
+ task :metadata_pot do
32
+ begin
33
+ result = GettextSetup::MetadataPot.generate_metadata_pot
34
+ if result
35
+ puts "POT metadata file #{GettextSetup::MetadataPot.metadata_path} has been generated"
36
+ end
37
+ rescue GettextSetup::NoConfigFoundError => e
38
+ puts e.message
44
39
  end
40
+ end
45
41
 
46
- language_path = File.join(locale_path, language)
47
- mkdir_p(language_path)
48
-
49
- po_file_path = File.join(language_path,
50
- GettextSetup.config['project_name'] + '.po')
51
- if File.exist?(po_file_path)
52
- system("msgmerge -U #{po_file_path} #{pot_file_path}")
53
- else
54
- system("msginit --no-translator -l #{language} -o #{po_file_path} -i #{pot_file_path}")
42
+ desc 'Update PO file for a specific language'
43
+ task :po, [:language] do |_, args|
44
+ begin
45
+ GettextSetup::Pot.generate_new_po(args.language)
46
+ rescue GettextSetup::NoConfigFoundError => e
47
+ puts e.message
55
48
  end
56
49
  end
57
50
  end
@@ -0,0 +1,23 @@
1
+ #
2
+ #, fuzzy
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: PACKAGE VERSION\n"
6
+ "Report-Msgid-Bugs-To:\n"
7
+ "POT-Creation-Date: <%= DateTime.now %>\n"
8
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
9
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
10
+ "Language-Team: LANGUAGE <LL@li.org>\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "X-Generator: Translate Toolkit 2.0.0\n"<% if metadata.key?('summary') %>
15
+ #. metadata.json
16
+ #: .summary
17
+ msgid "<%= metadata['summary']%>"
18
+ msgstr ""<% end %><% if metadata.key?('description')%>
19
+ #. metadata.json
20
+ #: .description
21
+ msgid "<%= metadata['description']%>"
22
+ msgstr ""
23
+ <% end %>
@@ -0,0 +1,21 @@
1
+ ---
2
+ # This is the project-specific configuration file for setting up
3
+ # fast_gettext for your project.
4
+ gettext:
5
+ # This is used for the name of the .pot and .po files; they will be
6
+ # called <project_name>.pot?
7
+ project_name: 'fixture_locales'
8
+ # This is used in comments in the .pot and .po files to indicate what
9
+ # project the files belong to and should bea little more desctiptive than
10
+ # <project_name>
11
+ package_name: Fixture locales
12
+ # The locale that the default messages in the .pot file are in
13
+ default_locale: en
14
+ # The email used for sending bug reports.
15
+ bugs_address: docs@puppetlabs.com
16
+ # The holder of the copyright.
17
+ copyright_holder: Puppet, LLC.
18
+ # Patterns for +Dir.glob+ used to find all files that might contain
19
+ # translatable content, relative to the project root directory
20
+ source_files:
21
+ - 'spec/fixtures/fixture_locales/*.rb'
@@ -0,0 +1,24 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) 2017 Puppet, LLC.
3
+ # This file is distributed under the same license as the Fixture locales package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: Fixture locales 0.21-6-gc301398\n"
10
+ "\n"
11
+ "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
+ "POT-Creation-Date: 2017-04-12 00:27-0500\n"
13
+ "PO-Revision-Date: 2017-04-12 00:27-0500\n"
14
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
+ "Language-Team: LANGUAGE <LL@li.org>\n"
16
+ "Language: \n"
17
+ "MIME-Version: 1.0\n"
18
+ "Content-Type: text/plain; charset=UTF-8\n"
19
+ "Content-Transfer-Encoding: 8bit\n"
20
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
21
+
22
+ #: test_strings.rb:1
23
+ msgid "Hello, world!"
24
+ msgstr ""
@@ -0,0 +1 @@
1
+ _('Hello, world!')
@@ -18,5 +18,5 @@ gettext:
18
18
  # Patterns for +Dir.glob+ used to find all files that might contain
19
19
  # translatable content, relative to the project root directory
20
20
  source_files:
21
- - 'test_translation.rb'
22
- - '../lib/**/*.rb'
21
+ - 'lib/**/*.rb'
22
+ - 'spec/**/*.rb'
@@ -1,16 +1,16 @@
1
1
  # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) 2016 Puppet Labs, LLC.
2
+ # Copyright (C) 2017 Puppet Labs, LLC.
3
3
  # This file is distributed under the same license as the Sinatra i18n demo package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
5
5
  #
6
6
  #, fuzzy
7
7
  msgid ""
8
8
  msgstr ""
9
- "Project-Id-Version: Sinatra i18n demo init-11-ga552a06\n"
9
+ "Project-Id-Version: Sinatra i18n demo 0.21-4-geccdac4\n"
10
10
  "\n"
11
11
  "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
- "POT-Creation-Date: 2016-06-07 17:38-0500\n"
13
- "PO-Revision-Date: 2016-06-07 17:38-0500\n"
12
+ "POT-Creation-Date: 2017-04-11 20:08-0500\n"
13
+ "PO-Revision-Date: 2017-04-11 20:08-0500\n"
14
14
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
15
  "Language-Team: LANGUAGE <LL@li.org>\n"
16
16
  "Language: \n"
@@ -19,7 +19,22 @@ msgstr ""
19
19
  "Content-Transfer-Encoding: 8bit\n"
20
20
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
21
21
 
22
- #. GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures'))
23
- #: ../../lib/gettext_setup_spec.rb:25
22
+ #: ../../lib/gettext_setup_spec.rb:26 ../../lib/gettext_setup_spec.rb:89 ../../lib/gettext_setup_spec.rb:91
24
23
  msgid "Hello, world!"
25
24
  msgstr ""
25
+
26
+ #: ../../lib/pot_spec.rb:52
27
+ msgid "merged-po-file"
28
+ msgstr ""
29
+
30
+ #: ../../lib/pot_spec.rb:74
31
+ msgid "no-pot-file"
32
+ msgstr ""
33
+
34
+ #: ../../lib/pot_spec.rb:85
35
+ msgid "some-spec-only-string"
36
+ msgstr ""
37
+
38
+ #: ../../lib/pot_spec.rb:104
39
+ msgid "unchanged-string"
40
+ msgstr ""
@@ -4,11 +4,11 @@
4
4
  gettext:
5
5
  # This is used for the name of the .pot and .po files; they will be
6
6
  # called <project_name>.pot?
7
- project_name: 'alt_locales'
7
+ project_name: 'sinatra-i18n'
8
8
  # This is used in comments in the .pot and .po files to indicate what
9
9
  # project the files belong to and should bea little more desctiptive than
10
10
  # <project_name>
11
- package_name: alt_locales
11
+ package_name: Sinatra i18n demo
12
12
  # The locale that the default messages in the .pot file are in
13
13
  default_locale: en
14
14
  # The email used for sending bug reports.
@@ -18,5 +18,4 @@ gettext:
18
18
  # Patterns for +Dir.glob+ used to find all files that might contain
19
19
  # translatable content, relative to the project root directory
20
20
  source_files:
21
- - 'test_translation.rb'
22
- - '../lib/**/*.rb'
21
+ - 'spec/**/*.rb'
@@ -0,0 +1,40 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) 2017 Puppet Labs, LLC.
3
+ # This file is distributed under the same license as the Sinatra i18n demo package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: Sinatra i18n demo 0.21-6-gc301398\n"
10
+ "\n"
11
+ "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
+ "POT-Creation-Date: 2017-04-12 00:27-0500\n"
13
+ "PO-Revision-Date: 2017-04-12 00:27-0500\n"
14
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
+ "Language-Team: LANGUAGE <LL@li.org>\n"
16
+ "Language: \n"
17
+ "MIME-Version: 1.0\n"
18
+ "Content-Type: text/plain; charset=UTF-8\n"
19
+ "Content-Transfer-Encoding: 8bit\n"
20
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
21
+
22
+ #: ../../lib/gettext_setup_spec.rb:26 ../../lib/gettext_setup_spec.rb:89 ../../lib/gettext_setup_spec.rb:91 ../fixture_locales/test_strings.rb:1
23
+ msgid "Hello, world!"
24
+ msgstr ""
25
+
26
+ #: ../../lib/pot_spec.rb:91
27
+ msgid "merged-po-file"
28
+ msgstr ""
29
+
30
+ #: ../../lib/pot_spec.rb:117
31
+ msgid "no-pot-file"
32
+ msgstr ""
33
+
34
+ #: ../../lib/pot_spec.rb:127
35
+ msgid "some-spec-only-string"
36
+ msgstr ""
37
+
38
+ #: ../../lib/pot_spec.rb:144
39
+ msgid "unchanged-string"
40
+ msgstr ""
@@ -12,7 +12,6 @@ describe GettextSetup do
12
12
  end
13
13
  context 'initialize' do
14
14
  it 'sets up correctly' do
15
- # GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures'))
16
15
  expect(GettextSetup.locales_path).to match(/\/spec\/fixtures/)
17
16
  expect(config['project_name']).to eq('sinatra-i18n')
18
17
  expect(config['package_name']).to eq('Sinatra i18n demo')
@@ -37,6 +36,16 @@ describe GettextSetup do
37
36
  expect(GettextSetup.negotiate_locale('de;q=1, en;q=1')).to eq('de')
38
37
  end
39
38
  end
39
+ context 'negotiate_locale!' do
40
+ it 'sets the locale' do
41
+ GettextSetup.negotiate_locale!('de')
42
+ expect(FastGettext.locale).to eq('de')
43
+ expect(_('Hello, world!')).to eq('Hallo, Welt!')
44
+ GettextSetup.negotiate_locale!('en')
45
+ expect(FastGettext.locale).to eq('en')
46
+ expect(_('Hello, world!')).to eq('Hello, world!')
47
+ end
48
+ end
40
49
  context 'setting default_locale' do
41
50
  before :each do
42
51
  GettextSetup.default_locale = 'en'
@@ -62,9 +71,9 @@ describe GettextSetup do
62
71
  end
63
72
  end
64
73
  context 'multiple locales' do
65
- # locales/ loads the de locale and alt_locales/ loads the jp locale
74
+ # locales/ loads the de locale and fixture_locales/ loads the jp locale
66
75
  before(:all) do
67
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'alt_locales'))
76
+ GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'fixture_locales'))
68
77
  end
69
78
  it 'can aggregate locales across projects' do
70
79
  expect(FastGettext.default_available_locales).to include('en')
@@ -80,7 +89,7 @@ describe GettextSetup do
80
89
  end
81
90
  context 'translation repository chain' do
82
91
  before(:all) do
83
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'alt_locales'))
92
+ GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'fixture_locales'))
84
93
  end
85
94
  it 'chain is not nil' do
86
95
  expect(GettextSetup.translation_repositories).not_to be_nil
@@ -92,15 +101,15 @@ describe GettextSetup do
92
101
  expect(_('Hello, world!')).to eq('こんにちは世界')
93
102
  end
94
103
  it 'does not allow duplicate repositories' do
95
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'alt_locales'))
104
+ GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'fixture_locales'))
96
105
  repos = GettextSetup.translation_repositories
97
- expect(repos.select { |k, _| k == 'alt_locales' }.size).to eq(1)
106
+ expect(repos.select { |k, _| k == 'fixture_locales' }.size).to eq(1)
98
107
  end
99
108
  it 'does allow multiple unique domains' do
100
109
  GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'locales'))
101
110
  repos = GettextSetup.translation_repositories
102
111
  expect(repos.size == 2)
103
- expect(repos.select { |k, _| k == 'alt_locales' }.size).to eq(1)
112
+ expect(repos.select { |k, _| k == 'fixture_locales' }.size).to eq(1)
104
113
  expect(repos.select { |k, _| k == 'sinatra-i18n' }.size).to eq(1)
105
114
  end
106
115
  end
@@ -0,0 +1,60 @@
1
+ require 'rspec/expectations'
2
+ require_relative '../spec_helper'
3
+
4
+ require_relative '../../lib/gettext-setup'
5
+
6
+ describe GettextSetup::MetadataPot do
7
+ before(:each) do
8
+ GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'locales'))
9
+ end
10
+ context '#metadata_path' do
11
+ it 'finds the right metadata path' do
12
+ expect(GettextSetup::MetadataPot.metadata_path).to match(/sinatra-i18n_metadata\.pot/)
13
+ end
14
+ end
15
+ context '#pot_string' do
16
+ it 'generates a reasonable POT string' do
17
+ expect(GettextSetup::MetadataPot.pot_string({})).to match(/Last-Translator: FULL NAME <EMAIL@ADDRESS>/)
18
+ end
19
+ it 'includes summary when provided' do
20
+ metadata = { 'summary' => 'abc' }
21
+ expect(GettextSetup::MetadataPot.pot_string(metadata)).to match(/msgid "abc"/)
22
+ end
23
+ it 'includes summary when provided' do
24
+ metadata = { 'description' => 'def' }
25
+ expect(GettextSetup::MetadataPot.pot_string(metadata)).to match(/msgid "def"/)
26
+ end
27
+ it 'includes both summary and description when provided' do
28
+ metadata = { 'summary' => 'abc', 'description' => 'def' }
29
+ result = expect(GettextSetup::MetadataPot.pot_string(metadata))
30
+ result.to match(/msgid "def"/)
31
+ result.to match(/msgid "abc"/)
32
+ end
33
+ end
34
+ context '#load_metadata' do
35
+ it 'loads metadata correctly' do
36
+ Dir.mktmpdir do |dir|
37
+ file = File.join(dir, 'metadata.json')
38
+ File.open(file, 'w') { |f| f.write('{"description":"abcdef", "summary":"ghi"}') }
39
+ metadata = GettextSetup::MetadataPot.metadata(File.join(dir, 'metadata.json').to_s)
40
+ expect(metadata).to eq('description' => 'abcdef', 'summary' => 'ghi')
41
+ end
42
+ end
43
+ it 'uses an empty hash if no metadata.json is found' do
44
+ metadata = GettextSetup::MetadataPot.metadata(File.join(Dir.mktmpdir, 'metadata.json').to_s)
45
+ expect(metadata).to eq({})
46
+ end
47
+ end
48
+ context '#generate_metadata_pot' do
49
+ it 'works with everything supplied' do
50
+ dir = Dir.mktmpdir
51
+ file = File.join(dir, 'metadata.pot')
52
+ metadata = { 'description' => 'abc', 'summary' => 'def' }
53
+ GettextSetup::MetadataPot.generate_metadata_pot(metadata,
54
+ file)
55
+ contents = File.read(file)
56
+ expect(contents).to match(/msgid "abc"/)
57
+ expect(contents).to match(/msgid "def"/)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,162 @@
1
+ require 'rspec/expectations'
2
+ require_relative '../spec_helper.rb'
3
+
4
+ require_relative '../../lib/gettext-setup'
5
+ describe GettextSetup::Pot do
6
+ NoConfigFoundError = GettextSetup::NoConfigFoundError
7
+
8
+ def fixture_locales_path
9
+ File.join(File.dirname(__FILE__), '../fixtures/fixture_locales')
10
+ end
11
+
12
+ def spec_locales_path
13
+ File.join(File.dirname(__FILE__), '../fixtures/spec_locales')
14
+ end
15
+
16
+ def locales_path
17
+ File.join(File.dirname(__FILE__), '../fixtures/locales')
18
+ end
19
+
20
+ describe 'string_changes?', if: msgcmp_present? do
21
+ old_pot = File.absolute_path('../fixtures/string_changes/old.pot', File.dirname(__FILE__))
22
+
23
+ it 'should detect string addition' do
24
+ new_pot = File.absolute_path('../fixtures/string_changes/add.pot', File.dirname(__FILE__))
25
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
26
+ end
27
+
28
+ it 'should detect string removal' do
29
+ new_pot = File.absolute_path('../fixtures/string_changes/remove.pot', File.dirname(__FILE__))
30
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
31
+ end
32
+
33
+ it 'should detect string changes' do
34
+ new_pot = File.absolute_path('../fixtures/string_changes/change.pot', File.dirname(__FILE__))
35
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
36
+ end
37
+
38
+ it 'should not detect non-string changes' do
39
+ new_pot = File.absolute_path('../fixtures/string_changes/non_string_changes.pot', File.dirname(__FILE__))
40
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(false)
41
+ end
42
+ end
43
+
44
+ context 'generate_new_pot' do
45
+ it "fails when GettextSetup can't find a config.yaml" do
46
+ path = File.join(Dir.mktmpdir, 'empty.pot')
47
+ with_captured_stdout do
48
+ expect { GettextSetup::Pot.generate_new_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
49
+ end
50
+ end
51
+ it 'builds a POT file' do
52
+ path = File.join(Dir.mktmpdir, 'new.pot')
53
+ out = with_captured_stdout do
54
+ GettextSetup::Pot.generate_new_pot(fixture_locales_path, path)
55
+ end
56
+ expect(out).to eq('') # STDOUT is determined in `update_pot`.
57
+ contents = File.read(path)
58
+ expect(contents).to match(/Fixture locales/)
59
+ expect(contents).to match(/docs@puppetlabs.com/)
60
+ expect(contents).to match(/Puppet, LLC/)
61
+ expect(contents).to match(/test_strings.rb:1/)
62
+ end
63
+ end
64
+
65
+ context 'generate_new_po' do
66
+ it "fails when GettextSetup can't find a config.yaml" do
67
+ path = File.join(Dir.mktmpdir, 'fails.pot')
68
+ po_path = File.join(Dir.mktmpdir, 'fails.po')
69
+ with_captured_stdout do
70
+ expect { GettextSetup::Pot.generate_new_po('ja', Dir.mktmpdir, path, po_path) }.to raise_error(NoConfigFoundError)
71
+ end
72
+ end
73
+ it 'complains when no language is supplied' do
74
+ stdout = with_captured_stdout do
75
+ GettextSetup::Pot.generate_new_po(nil, fixture_locales_path, Dir.mktmpdir, Dir.mktmpdir)
76
+ end
77
+ result = "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'\n"
78
+ expect(stdout).to eq(result)
79
+ end
80
+ it 'generates new PO file', if: msginit_present? do
81
+ po_path = File.join(Dir.mktmpdir, 'aa', 'tmp.po')
82
+ pot_path = File.join(locales_path, 'sinatra-i18n.pot')
83
+
84
+ stdout = with_captured_stdout do
85
+ GettextSetup::Pot.generate_new_po('aa', locales_path, pot_path, po_path)
86
+ end
87
+ expect(stdout).to eq("PO file #{po_path} created\n")
88
+ end
89
+ it 'merges PO files', if: [msginit_present?, msgmerge_present?] do
90
+ _('merged-po-file')
91
+ po_path = File.join(Dir.mktmpdir, 'aa', 'tmp.po')
92
+ pot_path = GettextSetup::Pot.pot_file_path
93
+
94
+ stdout = with_captured_stdout do
95
+ GettextSetup::Pot.generate_new_po('aa', fixture_locales_path, pot_path, po_path)
96
+ end
97
+ expect(stdout).to eq("PO file #{po_path} created\n")
98
+ contents = File.read(po_path)
99
+ expect(contents).to match(/msgid "Hello, world!"/)
100
+
101
+ new_pot_path = File.join(spec_locales_path, 'sinatra-i18n.pot')
102
+ new_stdout = with_captured_stdout do
103
+ GettextSetup::Pot.generate_new_po('aa', spec_locales_path, new_pot_path, po_path)
104
+ end
105
+ expect(new_stdout).to eq("PO file #{po_path} merged\n")
106
+ new_contents = File.read(po_path)
107
+ expect(new_contents).to match(/merged-po-file/)
108
+ end
109
+ end
110
+
111
+ context 'update_pot' do
112
+ it "fails when GettextSetup can't find a config.yaml" do
113
+ path = File.join(Dir.mktmpdir, 'fail-update.pot')
114
+ with_captured_stdout do
115
+ expect { GettextSetup::Pot.update_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
116
+ end
117
+ end
118
+ it 'creates POT when absent' do
119
+ _('no-pot-file')
120
+ path = File.join(Dir.mktmpdir, 'some-pot.pot')
121
+ stdout = with_captured_stdout do
122
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
123
+ end
124
+ expect(stdout).to eq("No existing POT file, generating new\nPOT file #{path} has been generated\n")
125
+ contents = File.read(path)
126
+ expect(contents).to match(/msgid "no-pot-file"/)
127
+ end
128
+ it 'updates POT when something changes', if: [msginit_present?, msgmerge_present?] do
129
+ _('some-spec-only-string')
130
+ path = File.join(Dir.mktmpdir, 'some-pot.pot')
131
+ stdout = with_captured_stdout do
132
+ GettextSetup::Pot.update_pot(fixture_locales_path, path)
133
+ end
134
+ expect(stdout).to eq("No existing POT file, generating new\nPOT file #{path} has been generated\n")
135
+ contents = File.read(path)
136
+ expect(contents).to match(/Language-Team: LANGUAGE <LL@li.org>/)
137
+ expect(contents).not_to match(/some-spec-only-string/)
138
+ output = with_captured_stdout do
139
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
140
+ end
141
+ new_contents = File.read(path)
142
+ expect(new_contents).to match(/some-spec-only-string/)
143
+ expect(output).to eq("String changes detected, replacing with updated POT file\n")
144
+ end
145
+ it "doesn't update the POT when nothing changes", if: [msginit_present?, msgcmp_present?] do
146
+ _('unchanged-string')
147
+ path = File.join(Dir.mktmpdir, 'some-pot.pot')
148
+ stdout = with_captured_stdout do
149
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
150
+ end
151
+ expect(stdout).to eq("No existing POT file, generating new\nPOT file #{path} has been generated\n")
152
+ contents = File.read(path)
153
+ expect(contents).to match(/unchanged-string/)
154
+ new_stdout = with_captured_stdout do
155
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
156
+ end
157
+ new_contents = File.read(path)
158
+ expect(new_contents).to eq(contents)
159
+ expect(new_stdout).to eq("No string changes detected, keeping old POT file\n")
160
+ end
161
+ end
162
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,37 @@
1
1
  require 'simplecov'
2
+ require_relative '../lib/gettext-setup'
3
+
4
+ GettextSetup.initialize(File.join(File.dirname(__FILE__), 'fixtures', 'locales'))
5
+
2
6
  SimpleCov.start do
3
7
  add_filter '/spec/'
4
8
  end
5
9
 
6
- def msgcmp_present?
10
+ def cmd_present?(cmd)
7
11
  # Try to call out to msgcmp, if it doesn't error, we have the tool
8
- `msgcmp`
12
+ `#{cmd} --version`
9
13
  return true
10
14
  rescue IOError
11
15
  return false
12
16
  end
17
+
18
+ def msgcmp_present?
19
+ cmd_present?('msgcmp')
20
+ end
21
+
22
+ def msginit_present?
23
+ cmd_present?('msginit')
24
+ end
25
+
26
+ def msgmerge_present?
27
+ cmd_present?('msgmerge')
28
+ end
29
+
30
+ def with_captured_stdout
31
+ old_stdout = $stdout
32
+ $stdout = StringIO.new('', 'w')
33
+ yield
34
+ $stdout.string
35
+ ensure
36
+ $stdout = old_stdout
37
+ 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.21'
4
+ version: '0.23'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-07 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_gettext
@@ -201,25 +201,32 @@ extra_rdoc_files: []
201
201
  files:
202
202
  - LICENSE
203
203
  - README.md
204
+ - lib/generate_metadata_pot.rb
204
205
  - lib/gettext-setup.rb
205
206
  - lib/gettext-setup/gettext_setup.rb
207
+ - lib/gettext-setup/metadata_pot.rb
208
+ - lib/gettext-setup/pot.rb
206
209
  - lib/tasks/gettext.rake
207
- - lib/tasks/task_helper.rb
210
+ - lib/templates/metadata.pot.erb
208
211
  - locales/config-sample.yaml
209
- - spec/fixtures/alt_locales/alt_locales.pot
210
- - spec/fixtures/alt_locales/config.yaml
211
- - spec/fixtures/alt_locales/jp/alt_locales.po
212
+ - spec/fixtures/fixture_locales/config.yaml
213
+ - spec/fixtures/fixture_locales/fixture_locales.pot
214
+ - spec/fixtures/fixture_locales/jp/fixture_locales.po
215
+ - spec/fixtures/fixture_locales/test_strings.rb
212
216
  - spec/fixtures/locales/config.yaml
213
217
  - spec/fixtures/locales/de/sinatra-i18n.po
214
218
  - spec/fixtures/locales/sinatra-i18n.pot
215
- - spec/fixtures/pot_update/add.pot
216
- - spec/fixtures/pot_update/change.pot
217
- - spec/fixtures/pot_update/non_string_changes.pot
218
- - spec/fixtures/pot_update/old.pot
219
- - spec/fixtures/pot_update/remove.pot
219
+ - spec/fixtures/spec_locales/config.yaml
220
+ - spec/fixtures/spec_locales/sinatra-i18n.pot
221
+ - spec/fixtures/string_changes/add.pot
222
+ - spec/fixtures/string_changes/change.pot
223
+ - spec/fixtures/string_changes/non_string_changes.pot
224
+ - spec/fixtures/string_changes/old.pot
225
+ - spec/fixtures/string_changes/remove.pot
220
226
  - spec/lib/gettext_setup_spec.rb
227
+ - spec/lib/metadata_pot_spec.rb
228
+ - spec/lib/pot_spec.rb
221
229
  - spec/spec_helper.rb
222
- - spec/tasks/update_pot_spec.rb
223
230
  homepage: https://github.com/puppetlabs/gettext-setup-gem
224
231
  licenses:
225
232
  - Apache-2.0
@@ -240,22 +247,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
247
  version: '0'
241
248
  requirements: []
242
249
  rubyforge_project:
243
- rubygems_version: 2.5.2
250
+ rubygems_version: 2.5.1
244
251
  signing_key:
245
252
  specification_version: 4
246
253
  summary: A gem to ease internationalization with fast_gettext
247
254
  test_files:
248
- - spec/fixtures/alt_locales/alt_locales.pot
249
- - spec/fixtures/alt_locales/config.yaml
250
- - spec/fixtures/alt_locales/jp/alt_locales.po
255
+ - spec/fixtures/fixture_locales/config.yaml
256
+ - spec/fixtures/fixture_locales/fixture_locales.pot
257
+ - spec/fixtures/fixture_locales/jp/fixture_locales.po
258
+ - spec/fixtures/fixture_locales/test_strings.rb
251
259
  - spec/fixtures/locales/config.yaml
252
260
  - spec/fixtures/locales/de/sinatra-i18n.po
253
261
  - spec/fixtures/locales/sinatra-i18n.pot
254
- - spec/fixtures/pot_update/add.pot
255
- - spec/fixtures/pot_update/change.pot
256
- - spec/fixtures/pot_update/non_string_changes.pot
257
- - spec/fixtures/pot_update/old.pot
258
- - spec/fixtures/pot_update/remove.pot
262
+ - spec/fixtures/spec_locales/config.yaml
263
+ - spec/fixtures/spec_locales/sinatra-i18n.pot
264
+ - spec/fixtures/string_changes/add.pot
265
+ - spec/fixtures/string_changes/change.pot
266
+ - spec/fixtures/string_changes/non_string_changes.pot
267
+ - spec/fixtures/string_changes/old.pot
268
+ - spec/fixtures/string_changes/remove.pot
259
269
  - spec/lib/gettext_setup_spec.rb
270
+ - spec/lib/metadata_pot_spec.rb
271
+ - spec/lib/pot_spec.rb
260
272
  - spec/spec_helper.rb
261
- - spec/tasks/update_pot_spec.rb
273
+ has_rdoc:
@@ -1,58 +0,0 @@
1
- require 'open3'
2
-
3
- def locale_path
4
- GettextSetup.locales_path
5
- end
6
-
7
- def text_domain
8
- FastGettext.text_domain
9
- end
10
-
11
- def files_to_translate
12
- files = GettextSetup.config['source_files'].map do |p|
13
- Dir.glob(p)
14
- end.flatten
15
- # check for optional list of files to exclude from string
16
- # extraction
17
- exclusions = (GettextSetup.config['exclude_files'] || []).map do |p|
18
- Dir.glob(p)
19
- end.flatten
20
-
21
- # if file is a directory, take it out of the array. directories
22
- # cause rxgettext to error out.
23
- (files - exclusions).reject { |file| File.directory?(file) }
24
- end
25
-
26
- def pot_file_path
27
- File.join(locale_path, GettextSetup.config['project_name'] + '.pot')
28
- end
29
-
30
- def generate_new_pot
31
- config = GettextSetup.config
32
- package_name = config['package_name']
33
- project_name = config['project_name']
34
- bugs_address = config['bugs_address']
35
- copyright_holder = config['copyright_holder']
36
- # Done this way to allow the user to enter an empty string in the config.
37
- comments_tag = config.key?('comments_tag') ? config['comments_tag'] : 'TRANSLATORS'
38
- version = `git describe`
39
- system("rxgettext -o locales/#{project_name}.pot --no-wrap --sort-by-file " \
40
- "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
41
- "--package-name '#{package_name}' " \
42
- "--package-version '#{version}' " \
43
- "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
44
- files_to_translate.join(' '))
45
- end
46
-
47
- def string_changes?(old_pot, new_pot)
48
- # Warnings will be in another language if locale is not set to en_US
49
- _, stderr, status = Open3.capture3("LANG=en_US msgcmp --use-untranslated '#{old_pot}' '#{new_pot}'")
50
- if status.exitstatus == 1 || /this message is not used/.match(stderr) || /this message is used but not defined/.match(stderr)
51
- return true
52
- end
53
- return false
54
- rescue IOError
55
- # probably means msgcmp is not present on the system
56
- # so return true to be on the safe side
57
- return true
58
- end
@@ -1,25 +0,0 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) 2016 Puppet Labs, LLC.
3
- # This file is distributed under the same license as the Sinatra i18n demo package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: alt_locales init-11-ga532a06\n"
10
- "\n"
11
- "Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
12
- "POT-Creation-Date: 2016-06-07 17:38-0500\n"
13
- "PO-Revision-Date: 2016-06-07 17:38-0500\n"
14
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15
- "Language-Team: LANGUAGE <LL@li.org>\n"
16
- "Language: \n"
17
- "MIME-Version: 1.0\n"
18
- "Content-Type: text/plain; charset=UTF-8\n"
19
- "Content-Transfer-Encoding: 8bit\n"
20
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
21
-
22
- #. GettextSetup.initialize(File::join(File::dirname(File::dirname(__FILE__)), 'fixtures'))
23
- #: ../../lib/gettext_setup_spec.rb:25
24
- msgid "Hello, world!"
25
- msgstr ""
@@ -1,28 +0,0 @@
1
- require 'rspec/expectations'
2
- require_relative '../spec_helper.rb'
3
-
4
- require_relative '../../lib/tasks/task_helper.rb'
5
-
6
- describe 'string_changes?', if: msgcmp_present? do
7
- old_pot = File.absolute_path('../fixtures/pot_update/old.pot', File.dirname(__FILE__))
8
-
9
- it 'should detect string addition' do
10
- new_pot = File.absolute_path('../fixtures/pot_update/add.pot', File.dirname(__FILE__))
11
- expect(string_changes?(old_pot, new_pot)).to eq(true)
12
- end
13
-
14
- it 'should detect string removal' do
15
- new_pot = File.absolute_path('../fixtures/pot_update/remove.pot', File.dirname(__FILE__))
16
- expect(string_changes?(old_pot, new_pot)).to eq(true)
17
- end
18
-
19
- it 'should detect string changes' do
20
- new_pot = File.absolute_path('../fixtures/pot_update/change.pot', File.dirname(__FILE__))
21
- expect(string_changes?(old_pot, new_pot)).to eq(true)
22
- end
23
-
24
- it 'should not detect non-string changes' do
25
- new_pot = File.absolute_path('../fixtures/pot_update/non_string_changes.pot', File.dirname(__FILE__))
26
- expect(string_changes?(old_pot, new_pot)).to eq(false)
27
- end
28
- end