Hello community,
here is the log from the commit of package rubygem-gettext-setup for openSUSE:Factory checked in at 2017-06-08 15:02:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-gettext-setup (Old)
and /work/SRC/openSUSE:Factory/.rubygem-gettext-setup.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-gettext-setup"
Thu Jun 8 15:02:03 2017 rev:10 rq:499981 version:0.25
Changes:
--------
--- /work/SRC/openSUSE:Factory/rubygem-gettext-setup/rubygem-gettext-setup.changes 2017-04-20 20:58:38.018771150 +0200
+++ /work/SRC/openSUSE:Factory/.rubygem-gettext-setup.new/rubygem-gettext-setup.changes 2017-06-08 15:02:04.530878128 +0200
@@ -1,0 +2,12 @@
+Wed May 31 07:18:40 UTC 2017 - coolo@suse.com
+
+- updated to version 0.25
+ no changelog found
+
+-------------------------------------------------------------------
+Tue May 23 09:54:04 UTC 2017 - coolo@suse.com
+
+- updated to version 0.24
+ no changelog found
+
+-------------------------------------------------------------------
Old:
----
gettext-setup-0.21.gem
New:
----
gettext-setup-0.25.gem
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ rubygem-gettext-setup.spec ++++++
--- /var/tmp/diff_new_pack.TErhfK/_old 2017-06-08 15:02:05.470745485 +0200
+++ /var/tmp/diff_new_pack.TErhfK/_new 2017-06-08 15:02:05.474744921 +0200
@@ -24,7 +24,7 @@
#
Name: rubygem-gettext-setup
-Version: 0.21
+Version: 0.25
Release: 0
%define mod_name gettext-setup
%define mod_full_name %{mod_name}-%{version}
++++++ gettext-setup-0.21.gem -> gettext-setup-0.25.gem ++++++
++++ 1916 lines of diff (skipped)
++++ retrying with extended exclude list
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/README.md new/README.md
--- old/README.md 2017-04-08 00:27:08.000000000 +0200
+++ new/README.md 2017-05-30 20:09:42.000000000 +0200
@@ -36,11 +36,11 @@
`GettextSetup.initialize(File.absolute_path('locales', File.dirname(__FILE__)))`
(Note that the second line may require modification to find the `locales` directory.
1. For client-side applications, add this line:
- `FastGettext.locale = GettextSetup.negotiate_locale(GettextSetup.candidate_locales)`
+ `GettextSetup.negotiate_locale!(GettextSetup.candidate_locales)`
1. For server-side applications, add these lines:
```
before do
- FastGettext.locale = GettextSetup.negotiate_locale(env["HTTP_ACCEPT_LANGUAGE"])
+ GettextSetup.negotiate_locale!(env["HTTP_ACCEPT_LANGUAGE"])
end
```
Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/gettext-setup/gettext_setup.rb new/lib/gettext-setup/gettext_setup.rb
--- old/lib/gettext-setup/gettext_setup.rb 2017-04-08 00:27:08.000000000 +0200
+++ new/lib/gettext-setup/gettext_setup.rb 2017-05-30 20:09:42.000000000 +0200
@@ -5,6 +5,12 @@
require 'locale'
module GettextSetup
+ class NoConfigFoundError < RuntimeError
+ def initialize(path)
+ super("No config.yaml found! (searching: #{path})")
+ end
+ end
+
@config = nil
@translation_repositories = {}
FastGettext.default_available_locales = []
@@ -16,8 +22,10 @@
# - if using .mo files, an LC_MESSAGES dir in each language dir, with the .mo file in it
# valid `options` fields:
# :file_format - one of the supported backends for fast_gettext (e.g. :po, :mo, :yaml, etc.)
- def self.initialize(locales_path, options = {})
+ def self.initialize(locales_path = 'locales', options = {})
config_path = File.absolute_path('config.yaml', locales_path)
+ File.exist?(config_path) || raise(NoConfigFoundError, config_path)
+
@config = YAML.load_file(config_path)['gettext']
@locales_path = locales_path
@@ -41,6 +49,11 @@
Locale.set_default(default_locale)
end
+ def self.config?
+ raise NoConfigFoundError, File.join(locales_path, 'config.yaml') unless @config
+ @config
+ end
+
def self.add_repository_to_chain(project_name, options)
repository = FastGettext::TranslationRepository.build(project_name,
path: locales_path,
@@ -50,7 +63,7 @@
end
def self.locales_path
- @locales_path
+ @locales_path ||= File.join(Dir.pwd, 'locales')
end
def self.config
@@ -113,4 +126,9 @@
default_locale
end
end
+
+ # Negotiates and sets the locale based on an accept language header.
+ def self.negotiate_locale!(accept_header)
+ FastGettext.locale = negotiate_locale(accept_header)
+ end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/gettext-setup/metadata_pot.rb new/lib/gettext-setup/metadata_pot.rb
--- old/lib/gettext-setup/metadata_pot.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/lib/gettext-setup/metadata_pot.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,38 @@
+# -*- encoding: utf-8 -*-
+
+require 'erb'
+require 'json'
+
+module GettextSetup
+ module MetadataPot
+ def self.metadata_path
+ File.join(GettextSetup.locales_path, GettextSetup.config['project_name'] + '_metadata.pot')
+ end
+
+ def self.template_path
+ File.join(File.dirname(__FILE__), '../templates/metadata.pot.erb')
+ end
+
+ def self.metadata(metadata_file = 'metadata.json')
+ if File.exist?(metadata_file)
+ file = open(metadata_file)
+ json = file.read
+ JSON.parse(json)
+ else
+ {}
+ end
+ end
+
+ def self.pot_string(metadata)
+ b = binding.freeze
+ # Uses `metadata`
+ ERB.new(File.read(template_path)).result(b)
+ end
+
+ def self.generate_metadata_pot(pot_metadata = metadata, path = metadata_path)
+ open(path, 'w') do |f|
+ f << pot_string(pot_metadata)
+ end
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/gettext-setup/pot.rb new/lib/gettext-setup/pot.rb
--- old/lib/gettext-setup/pot.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/lib/gettext-setup/pot.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,142 @@
+# -*- encoding: utf-8 -*-
+
+require 'open3'
+require 'English'
+
+module GettextSetup
+ module Pot
+ def self.text_domain
+ FastGettext.text_domain
+ end
+
+ def self.files_to_translate
+ files = (GettextSetup.config['source_files'] || []).map do |p|
+ Dir.glob(p)
+ end.flatten
+ # check for optional list of files to exclude from string
+ # extraction
+ exclusions = (GettextSetup.config['exclude_files'] || []).map do |p|
+ Dir.glob(p)
+ end.flatten
+
+ # if file is a directory, take it out of the array. directories
+ # cause rxgettext to error out.
+ (files - exclusions).reject { |file| File.directory?(file) }
+ end
+
+ def self.pot_file_path
+ return if GettextSetup.locales_path.nil?
+ return if GettextSetup.config['project_name'].nil?
+ File.join(GettextSetup.locales_path, GettextSetup.config['project_name'] + '.pot')
+ end
+
+ def self.po_file_path(language)
+ return if GettextSetup.locales_path.nil?
+ return if GettextSetup.config['project_name'].nil?
+ return if language.nil?
+ File.join(GettextSetup.locales_path, language, GettextSetup.config['project_name'] + '.po')
+ end
+
+ def self.string_changes?(old_pot, new_pot)
+ # Warnings will be in another language if locale is not set to en_US
+ _, stderr, status = Open3.capture3("LANG=en_US msgcmp --use-untranslated '#{old_pot}' '#{new_pot}'")
+ if status.exitstatus == 1 || /this message is not used/.match(stderr) || /this message is used but not defined/.match(stderr)
+ return true
+ end
+ return false
+ rescue IOError
+ # probably means msgcmp is not present on the system
+ # so return true to be on the safe side
+ return true
+ end
+
+ def self.generate_new_pot(locales_path = GettextSetup.locales_path, path = nil)
+ GettextSetup.initialize(locales_path)
+ path ||= pot_file_path
+ config = GettextSetup.config
+ package_name = config['package_name']
+ bugs_address = config['bugs_address']
+ copyright_holder = config['copyright_holder']
+ # Done this way to allow the user to enter an empty string in the config.
+ comments_tag = config.key?('comments_tag') ? config['comments_tag'] : 'TRANSLATORS'
+ version = `git describe`
+ system("rxgettext -o #{path} --no-wrap --sort-by-file " \
+ "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
+ "--package-name '#{package_name}' " \
+ "--package-version '#{version}' " \
+ "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
+ files_to_translate.join(' '))
+ $CHILD_STATUS.success?
+ end
+
+ def self.generate_new_po(language, locales_path = GettextSetup.locales_path,
+ pot_file = nil, po_file = nil)
+ GettextSetup.initialize(locales_path)
+ pot_file ||= GettextSetup::Pot.pot_file_path
+ po_file ||= GettextSetup::Pot.po_file_path(language)
+
+ language ||= ENV['LANGUAGE']
+
+ # Let's do some pre-verification of the environment.
+ if language.nil?
+ puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'"
+ return
+ end
+
+ language_path = File.dirname(po_file)
+ FileUtils.mkdir_p(language_path)
+
+ if File.exist?(po_file)
+ cmd = "msgmerge -U #{po_file} #{pot_file}"
+ _, _, _, wait = Open3.popen3(cmd)
+ exitstatus = wait.value
+ if exitstatus.success?
+ puts "PO file #{po_file} merged"
+ true
+ else
+ puts 'PO file merge failed'
+ false
+ end
+ else
+ cmd = "msginit --no-translator -l #{language} -o #{po_file} -i #{pot_file}"
+ _, _, _, wait = Open3.popen3(cmd)
+ exitstatus = wait.value
+ if exitstatus.success?
+ puts "PO file #{po_file} created"
+ true
+ else
+ puts 'PO file creation failed'
+ false
+ end
+ end
+ end
+
+ def self.update_pot(locales_path = GettextSetup.locales_path, path = nil)
+ GettextSetup.initialize(locales_path)
+ path ||= pot_file_path
+
+ if !File.exist? path
+ puts 'No existing POT file, generating new'
+ result = GettextSetup::Pot.generate_new_pot(locales_path, path)
+ puts "POT file #{path} has been generated" if result
+ result
+ else
+ old_pot = path + '.old'
+ File.rename(path, old_pot)
+ result = GettextSetup::Pot.generate_new_pot(locales_path, path)
+ if !result
+ puts 'POT creation failed'
+ result
+ elsif GettextSetup::Pot.string_changes?(old_pot, path)
+ puts 'String changes detected, replacing with updated POT file'
+ File.delete(old_pot)
+ true
+ else
+ puts 'No string changes detected, keeping old POT file'
+ File.rename(old_pot, path)
+ true
+ end
+ end
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/gettext-setup.rb new/lib/gettext-setup.rb
--- old/lib/gettext-setup.rb 2017-04-08 00:27:08.000000000 +0200
+++ new/lib/gettext-setup.rb 2017-05-30 20:09:42.000000000 +0200
@@ -1 +1,3 @@
require 'gettext-setup/gettext_setup'
+require 'gettext-setup/metadata_pot'
+require 'gettext-setup/pot'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/tasks/gettext.rake new/lib/tasks/gettext.rake
--- old/lib/tasks/gettext.rake 2017-04-08 00:27:08.000000000 +0200
+++ new/lib/tasks/gettext.rake 2017-05-30 20:09:42.000000000 +0200
@@ -1,57 +1,57 @@
-# require 'bundler'
-# puts File.absolute_path('Gemfile', Dir.pwd)
-# Bundler.read_file(File.absolute_path('Gemfile', Dir.pwd))
-#
+# -*- encoding: utf-8 -*-
+
require_relative '../gettext-setup/gettext_setup'
-require_relative 'task_helper.rb'
-#
-# GettextSetup.initialize(File.absolute_path('locales', Dir.pwd))
+require_relative '../gettext-setup/pot'
+require_relative '../gettext-setup/metadata_pot'
namespace :gettext do
desc 'Generate a new POT file and replace old if strings changed'
+
task :update_pot do
- if !File.exist? pot_file_path
- puts 'No existing POT file, generating new'
- generate_new_pot
- else
- old_pot = pot_file_path + '.old'
- File.rename(pot_file_path, old_pot)
- generate_new_pot
- if string_changes?(old_pot, pot_file_path)
- File.delete(old_pot)
- puts 'String changes detected, replacing with updated POT file'
- else
- puts 'No string changes detected, keeping old POT file'
- File.rename(old_pot, pot_file_path)
- end
+ begin
+ result = GettextSetup::Pot.update_pot
+ exit 1 unless result
+ rescue GettextSetup::NoConfigFoundError => e
+ puts e.message
+ exit 1
end
end
desc 'Generate POT file'
task :pot do
- generate_new_pot
- puts "POT file #{pot_file_path} has been generated"
+ begin
+ result = GettextSetup::Pot.generate_new_pot
+ if result
+ puts "POT file #{GettextSetup::Pot.pot_file_path} has been generated"
+ else
+ exit 1
+ end
+ rescue GettextSetup::NoConfigFoundError => e
+ puts e.message
+ end
end
- desc 'Update PO file for a specific language'
- task :po, [:language] do |_, args|
- language = args.language || ENV['LANGUAGE']
-
- # Let's do some pre-verification of the environment.
- if language.nil?
- puts "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'"
- next
+ desc 'Generate POT file for metadata'
+ task :metadata_pot do
+ begin
+ result = GettextSetup::MetadataPot.generate_metadata_pot
+ if result
+ puts "POT metadata file #{GettextSetup::MetadataPot.metadata_path} has been generated"
+ else
+ exit 1
+ end
+ rescue GettextSetup::NoConfigFoundError => e
+ puts e.message
end
+ end
- language_path = File.join(locale_path, language)
- mkdir_p(language_path)
-
- po_file_path = File.join(language_path,
- GettextSetup.config['project_name'] + '.po')
- if File.exist?(po_file_path)
- system("msgmerge -U #{po_file_path} #{pot_file_path}")
- else
- system("msginit --no-translator -l #{language} -o #{po_file_path} -i #{pot_file_path}")
+ desc 'Update PO file for a specific language'
+ task :po, [:language] do |_, args|
+ begin
+ result = GettextSetup::Pot.generate_new_po(args.language)
+ exit 1 unless result
+ rescue GettextSetup::NoConfigFoundError => e
+ puts e.message
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/tasks/task_helper.rb new/lib/tasks/task_helper.rb
--- old/lib/tasks/task_helper.rb 2017-04-08 00:27:08.000000000 +0200
+++ new/lib/tasks/task_helper.rb 1970-01-01 01:00:00.000000000 +0100
@@ -1,58 +0,0 @@
-require 'open3'
-
-def locale_path
- GettextSetup.locales_path
-end
-
-def text_domain
- FastGettext.text_domain
-end
-
-def files_to_translate
- files = GettextSetup.config['source_files'].map do |p|
- Dir.glob(p)
- end.flatten
- # check for optional list of files to exclude from string
- # extraction
- exclusions = (GettextSetup.config['exclude_files'] || []).map do |p|
- Dir.glob(p)
- end.flatten
-
- # if file is a directory, take it out of the array. directories
- # cause rxgettext to error out.
- (files - exclusions).reject { |file| File.directory?(file) }
-end
-
-def pot_file_path
- File.join(locale_path, GettextSetup.config['project_name'] + '.pot')
-end
-
-def generate_new_pot
- config = GettextSetup.config
- package_name = config['package_name']
- project_name = config['project_name']
- bugs_address = config['bugs_address']
- copyright_holder = config['copyright_holder']
- # Done this way to allow the user to enter an empty string in the config.
- comments_tag = config.key?('comments_tag') ? config['comments_tag'] : 'TRANSLATORS'
- version = `git describe`
- system("rxgettext -o locales/#{project_name}.pot --no-wrap --sort-by-file " \
- "--add-comments#{comments_tag.to_s == '' ? '' : '=' + comments_tag} --msgid-bugs-address '#{bugs_address}' " \
- "--package-name '#{package_name}' " \
- "--package-version '#{version}' " \
- "--copyright-holder='#{copyright_holder}' --copyright-year=#{Time.now.year} " +
- files_to_translate.join(' '))
-end
-
-def string_changes?(old_pot, new_pot)
- # Warnings will be in another language if locale is not set to en_US
- _, stderr, status = Open3.capture3("LANG=en_US msgcmp --use-untranslated '#{old_pot}' '#{new_pot}'")
- if status.exitstatus == 1 || /this message is not used/.match(stderr) || /this message is used but not defined/.match(stderr)
- return true
- end
- return false
-rescue IOError
- # probably means msgcmp is not present on the system
- # so return true to be on the safe side
- return true
-end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/lib/templates/metadata.pot.erb new/lib/templates/metadata.pot.erb
--- old/lib/templates/metadata.pot.erb 1970-01-01 01:00:00.000000000 +0100
+++ new/lib/templates/metadata.pot.erb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,23 @@
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To:\n"
+"POT-Creation-Date: <%= DateTime.now %>\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Translate Toolkit 2.0.0\n"<% if metadata.key?('summary') %>
+#. metadata.json
+#: .summary
+msgid "<%= metadata['summary']%>"
+msgstr ""<% end %><% if metadata.key?('description')%>
+#. metadata.json
+#: .description
+msgid "<%= metadata['description']%>"
+msgstr ""
+<% end %>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/metadata new/metadata
--- old/metadata 2017-04-08 00:27:08.000000000 +0200
+++ new/metadata 2017-05-30 20:09:42.000000000 +0200
@@ -1,14 +1,14 @@
--- !ruby/object:Gem::Specification
name: gettext-setup
version: !ruby/object:Gem::Version
- version: '0.21'
+ version: '0.25'
platform: ruby
authors:
- Puppet
autorequire:
bindir: bin
cert_chain: []
-date: 2017-04-07 00:00:00.000000000 Z
+date: 2017-05-30 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: fast_gettext
@@ -203,23 +203,33 @@
- README.md
- lib/gettext-setup.rb
- lib/gettext-setup/gettext_setup.rb
+- lib/gettext-setup/metadata_pot.rb
+- lib/gettext-setup/pot.rb
- lib/tasks/gettext.rake
-- lib/tasks/task_helper.rb
+- lib/templates/metadata.pot.erb
- locales/config-sample.yaml
-- spec/fixtures/alt_locales/alt_locales.pot
-- spec/fixtures/alt_locales/config.yaml
-- spec/fixtures/alt_locales/jp/alt_locales.po
+- spec/fixtures/fixture_locales/config.yaml
+- spec/fixtures/fixture_locales/fixture_locales.pot
+- spec/fixtures/fixture_locales/jp/fixture_locales.po
+- spec/fixtures/fixture_locales/test_strings.rb
- spec/fixtures/locales/config.yaml
- spec/fixtures/locales/de/sinatra-i18n.po
- spec/fixtures/locales/sinatra-i18n.pot
-- spec/fixtures/pot_update/add.pot
-- spec/fixtures/pot_update/change.pot
-- spec/fixtures/pot_update/non_string_changes.pot
-- spec/fixtures/pot_update/old.pot
-- spec/fixtures/pot_update/remove.pot
-- spec/lib/gettext_setup_spec.rb
+- spec/fixtures/spec_locales/config.yaml
+- spec/fixtures/spec_locales/sinatra-i18n.pot
+- spec/fixtures/string_changes/add.pot
+- spec/fixtures/string_changes/change.pot
+- spec/fixtures/string_changes/non_string_changes.pot
+- spec/fixtures/string_changes/old.pot
+- spec/fixtures/string_changes/remove.pot
+- spec/fixtures/tmp_locales/config.yaml
+- spec/fixtures/tmp_locales/de/sinatra-i18n.po
+- spec/fixtures/tmp_locales/sinatra-i18n.pot
+- spec/lib/gettext-setup/gettext_setup_spec.rb
+- spec/lib/gettext-setup/metadata_pot_spec.rb
+- spec/lib/gettext-setup/pot_spec.rb
+- spec/lib/tasks/gettext_rake_spec.rb
- spec/spec_helper.rb
-- spec/tasks/update_pot_spec.rb
homepage: https://github.com/puppetlabs/gettext-setup-gem
licenses:
- Apache-2.0
@@ -240,22 +250,30 @@
version: '0'
requirements: []
rubyforge_project:
-rubygems_version: 2.5.2
+rubygems_version: 2.2.2
signing_key:
specification_version: 4
summary: A gem to ease internationalization with fast_gettext
test_files:
-- spec/fixtures/alt_locales/alt_locales.pot
-- spec/fixtures/alt_locales/config.yaml
-- spec/fixtures/alt_locales/jp/alt_locales.po
+- spec/fixtures/fixture_locales/config.yaml
+- spec/fixtures/fixture_locales/fixture_locales.pot
+- spec/fixtures/fixture_locales/jp/fixture_locales.po
+- spec/fixtures/fixture_locales/test_strings.rb
- spec/fixtures/locales/config.yaml
- spec/fixtures/locales/de/sinatra-i18n.po
- spec/fixtures/locales/sinatra-i18n.pot
-- spec/fixtures/pot_update/add.pot
-- spec/fixtures/pot_update/change.pot
-- spec/fixtures/pot_update/non_string_changes.pot
-- spec/fixtures/pot_update/old.pot
-- spec/fixtures/pot_update/remove.pot
-- spec/lib/gettext_setup_spec.rb
+- spec/fixtures/spec_locales/config.yaml
+- spec/fixtures/spec_locales/sinatra-i18n.pot
+- spec/fixtures/string_changes/add.pot
+- spec/fixtures/string_changes/change.pot
+- spec/fixtures/string_changes/non_string_changes.pot
+- spec/fixtures/string_changes/old.pot
+- spec/fixtures/string_changes/remove.pot
+- spec/fixtures/tmp_locales/config.yaml
+- spec/fixtures/tmp_locales/de/sinatra-i18n.po
+- spec/fixtures/tmp_locales/sinatra-i18n.pot
+- spec/lib/gettext-setup/gettext_setup_spec.rb
+- spec/lib/gettext-setup/metadata_pot_spec.rb
+- spec/lib/gettext-setup/pot_spec.rb
+- spec/lib/tasks/gettext_rake_spec.rb
- spec/spec_helper.rb
-- spec/tasks/update_pot_spec.rb
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/alt_locales/config.yaml new/spec/fixtures/alt_locales/config.yaml
--- old/spec/fixtures/alt_locales/config.yaml 2017-04-08 00:27:08.000000000 +0200
+++ new/spec/fixtures/alt_locales/config.yaml 1970-01-01 01:00:00.000000000 +0100
@@ -1,22 +0,0 @@
----
-# This is the project-specific configuration file for setting up
-# fast_gettext for your project.
-gettext:
- # This is used for the name of the .pot and .po files; they will be
- # called .pot?
- project_name: 'alt_locales'
- # This is used in comments in the .pot and .po files to indicate what
- # project the files belong to and should bea little more desctiptive than
- #
- package_name: alt_locales
- # The locale that the default messages in the .pot file are in
- default_locale: en
- # The email used for sending bug reports.
- bugs_address: docs@puppetlabs.com
- # The holder of the copyright.
- copyright_holder: Puppet Labs, LLC.
- # Patterns for +Dir.glob+ used to find all files that might contain
- # translatable content, relative to the project root directory
- source_files:
- - 'test_translation.rb'
- - '../lib/**/*.rb'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/alt_locales/jp/alt_locales.po new/spec/fixtures/alt_locales/jp/alt_locales.po
--- old/spec/fixtures/alt_locales/jp/alt_locales.po 2017-04-08 00:27:08.000000000 +0200
+++ new/spec/fixtures/alt_locales/jp/alt_locales.po 1970-01-01 01:00:00.000000000 +0100
@@ -1,23 +0,0 @@
-# German translations for Sinatra i18n demo package.
-# Copyright (C) 2016 Puppet Labs, LLC.
-# This file is distributed under the same license as the Sinatra i18n demo package.
-# Automatically generated, 2016.
-#
-msgid ""
-msgstr ""
-"Project-Id-Version: Sinatra i18n demo \n"
-"Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
-"POT-Creation-Date: 2016-04-05 10:39-0700\n"
-"PO-Revision-Date: 2016-02-26 18:21-0800\n"
-"Last-Translator: Automatically generated\n"
-"Language-Team: none\n"
-"Language: jp\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-
-#: ../app.rb:14
-msgid "Hello, world!"
-msgstr "こんにちは世界"
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/fixture_locales/config.yaml new/spec/fixtures/fixture_locales/config.yaml
--- old/spec/fixtures/fixture_locales/config.yaml 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/fixtures/fixture_locales/config.yaml 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,21 @@
+---
+# This is the project-specific configuration file for setting up
+# fast_gettext for your project.
+gettext:
+ # This is used for the name of the .pot and .po files; they will be
+ # called .pot?
+ project_name: 'fixture_locales'
+ # This is used in comments in the .pot and .po files to indicate what
+ # project the files belong to and should bea little more desctiptive than
+ #
+ package_name: Fixture locales
+ # The locale that the default messages in the .pot file are in
+ default_locale: en
+ # The email used for sending bug reports.
+ bugs_address: docs@puppetlabs.com
+ # The holder of the copyright.
+ copyright_holder: Puppet, LLC.
+ # Patterns for +Dir.glob+ used to find all files that might contain
+ # translatable content, relative to the project root directory
+ source_files:
+ - 'spec/fixtures/fixture_locales/*.rb'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/fixture_locales/jp/fixture_locales.po new/spec/fixtures/fixture_locales/jp/fixture_locales.po
--- old/spec/fixtures/fixture_locales/jp/fixture_locales.po 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/fixtures/fixture_locales/jp/fixture_locales.po 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,23 @@
+# German translations for Sinatra i18n demo package.
+# Copyright (C) 2016 Puppet Labs, LLC.
+# This file is distributed under the same license as the Sinatra i18n demo package.
+# Automatically generated, 2016.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Sinatra i18n demo \n"
+"Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
+"POT-Creation-Date: 2016-04-05 10:39-0700\n"
+"PO-Revision-Date: 2016-02-26 18:21-0800\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"Language: jp\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: ../app.rb:14
+msgid "Hello, world!"
+msgstr "こんにちは世界"
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/fixture_locales/test_strings.rb new/spec/fixtures/fixture_locales/test_strings.rb
--- old/spec/fixtures/fixture_locales/test_strings.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/fixtures/fixture_locales/test_strings.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1 @@
+_('Hello, world!')
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/locales/config.yaml new/spec/fixtures/locales/config.yaml
--- old/spec/fixtures/locales/config.yaml 2017-04-08 00:27:08.000000000 +0200
+++ new/spec/fixtures/locales/config.yaml 2017-05-30 20:09:42.000000000 +0200
@@ -18,5 +18,5 @@
# Patterns for +Dir.glob+ used to find all files that might contain
# translatable content, relative to the project root directory
source_files:
- - 'test_translation.rb'
- - '../lib/**/*.rb'
+ - 'lib/**/*.rb'
+ - 'spec/**/*.rb'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/spec_locales/config.yaml new/spec/fixtures/spec_locales/config.yaml
--- old/spec/fixtures/spec_locales/config.yaml 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/fixtures/spec_locales/config.yaml 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,21 @@
+---
+# This is the project-specific configuration file for setting up
+# fast_gettext for your project.
+gettext:
+ # This is used for the name of the .pot and .po files; they will be
+ # called .pot?
+ project_name: 'sinatra-i18n'
+ # This is used in comments in the .pot and .po files to indicate what
+ # project the files belong to and should bea little more desctiptive than
+ #
+ package_name: Sinatra i18n demo
+ # The locale that the default messages in the .pot file are in
+ default_locale: en
+ # The email used for sending bug reports.
+ bugs_address: docs@puppetlabs.com
+ # The holder of the copyright.
+ copyright_holder: Puppet Labs, LLC.
+ # Patterns for +Dir.glob+ used to find all files that might contain
+ # translatable content, relative to the project root directory
+ source_files:
+ - 'spec/**/*.rb'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/tmp_locales/config.yaml new/spec/fixtures/tmp_locales/config.yaml
--- old/spec/fixtures/tmp_locales/config.yaml 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/fixtures/tmp_locales/config.yaml 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,22 @@
+---
+# This is the project-specific configuration file for setting up
+# fast_gettext for your project.
+gettext:
+ # This is used for the name of the .pot and .po files; they will be
+ # called .pot?
+ project_name: 'sinatra-i18n'
+ # This is used in comments in the .pot and .po files to indicate what
+ # project the files belong to and should bea little more desctiptive than
+ #
+ package_name: Sinatra i18n demo
+ # The locale that the default messages in the .pot file are in
+ default_locale: en
+ # The email used for sending bug reports.
+ bugs_address: docs@puppetlabs.com
+ # The holder of the copyright.
+ copyright_holder: Puppet Labs, LLC.
+ # Patterns for +Dir.glob+ used to find all files that might contain
+ # translatable content, relative to the project root directory
+ source_files:
+ - 'lib/**/*.rb'
+ - 'spec/**/*.rb'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/fixtures/tmp_locales/de/sinatra-i18n.po new/spec/fixtures/tmp_locales/de/sinatra-i18n.po
--- old/spec/fixtures/tmp_locales/de/sinatra-i18n.po 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/fixtures/tmp_locales/de/sinatra-i18n.po 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,23 @@
+# German translations for Sinatra i18n demo package.
+# Copyright (C) 2016 Puppet Labs, LLC.
+# This file is distributed under the same license as the Sinatra i18n demo package.
+# Automatically generated, 2016.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Sinatra i18n demo \n"
+"Report-Msgid-Bugs-To: docs@puppetlabs.com\n"
+"POT-Creation-Date: 2016-04-05 10:39-0700\n"
+"PO-Revision-Date: 2016-02-26 18:21-0800\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: ../app.rb:14
+msgid "Hello, world!"
+msgstr "Hallo, Welt!"
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/lib/gettext-setup/gettext_setup_spec.rb new/spec/lib/gettext-setup/gettext_setup_spec.rb
--- old/spec/lib/gettext-setup/gettext_setup_spec.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/lib/gettext-setup/gettext_setup_spec.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,119 @@
+require 'rspec/expectations'
+require_relative '../../spec_helper'
+
+require_relative '../../../lib/gettext-setup'
+
+describe GettextSetup do
+ locales_path = File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/locales'))
+ fixture_locales_path = File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/fixture_locales'))
+
+ before(:each) do
+ GettextSetup.initialize(locales_path)
+ end
+ let(:config) do
+ GettextSetup.config
+ end
+ context 'initialize' do
+ it 'sets up correctly' do
+ expect(GettextSetup.locales_path).to match(/\/spec\/fixtures/)
+ expect(config['project_name']).to eq('sinatra-i18n')
+ expect(config['package_name']).to eq('Sinatra i18n demo')
+ expect(config['default_locale']).to eq('en')
+ expect(respond_to?(:_)).to eq(true)
+ end
+ end
+ context 'negotiate_locale' do
+ it 'negotiates correctly' do
+ FastGettext.locale = GettextSetup.negotiate_locale('de')
+ expect(FastGettext.locale).to eq('de')
+ expect(_('Hello, world!')).to eq('Hallo, Welt!')
+ end
+ it 'chooses the default locale when no match is found' do
+ expect(GettextSetup.negotiate_locale('no-match')).to eq(config['default_locale'])
+ end
+ it 'chooses the language with the highest q value' do
+ expect(GettextSetup.negotiate_locale('en;q=1, de;q=2')).to eq('de')
+ expect(GettextSetup.negotiate_locale('en;q=1, de;q=0')).to eq('en')
+ end
+ it 'chooses the first value when q values are equal' do
+ expect(GettextSetup.negotiate_locale('de;q=1, en;q=1')).to eq('de')
+ end
+ end
+ context 'negotiate_locale!' do
+ it 'sets the locale' do
+ GettextSetup.negotiate_locale!('de')
+ expect(FastGettext.locale).to eq('de')
+ expect(_('Hello, world!')).to eq('Hallo, Welt!')
+ GettextSetup.negotiate_locale!('en')
+ expect(FastGettext.locale).to eq('en')
+ expect(_('Hello, world!')).to eq('Hello, world!')
+ end
+ end
+ context 'setting default_locale' do
+ before :each do
+ GettextSetup.default_locale = 'en'
+ end
+ it 'allows setting the default locale' do
+ expect(GettextSetup.default_locale).to eq('en')
+ GettextSetup.default_locale = 'de'
+ expect(GettextSetup.default_locale).to eq('de')
+ end
+ end
+ context 'clear' do
+ it 'can clear the locale' do
+ expect(GettextSetup.default_locale).to eq('en')
+ expect(GettextSetup.candidate_locales).to include('en')
+ GettextSetup.clear
+ begin
+ old_locale = ENV['LANG']
+ ENV['LANG'] = 'de_DE'
+ expect(GettextSetup.candidate_locales).to eq('de_DE,de,en')
+ ensure
+ ENV['LANG'] = old_locale
+ end
+ end
+ end
+ context 'multiple locales' do
+ # locales/ loads the de locale and fixture_locales/ loads the jp locale
+ before(:all) do
+ GettextSetup.initialize(fixture_locales_path)
+ end
+ it 'can aggregate locales across projects' do
+ expect(FastGettext.default_available_locales).to include('en')
+ expect(FastGettext.default_available_locales).to include('de')
+ expect(FastGettext.default_available_locales).to include('jp')
+ end
+ it 'can switch to loaded locale' do
+ FastGettext.locale = GettextSetup.negotiate_locale('de,en')
+ expect(FastGettext.locale).to eq('de')
+ FastGettext.locale = GettextSetup.negotiate_locale('jp')
+ expect(FastGettext.locale).to eq('jp')
+ end
+ end
+ context 'translation repository chain' do
+ before(:all) do
+ GettextSetup.initialize(fixture_locales_path)
+ end
+ it 'chain is not nil' do
+ expect(GettextSetup.translation_repositories).not_to be_nil
+ end
+ it 'can translate without switching text domains' do
+ FastGettext.locale = 'de'
+ expect(_('Hello, world!')).to eq('Hallo, Welt!')
+ FastGettext.locale = 'jp'
+ expect(_('Hello, world!')).to eq('こんにちは世界')
+ end
+ it 'does not allow duplicate repositories' do
+ GettextSetup.initialize(fixture_locales_path)
+ repos = GettextSetup.translation_repositories
+ expect(repos.select { |k, _| k == 'fixture_locales' }.size).to eq(1)
+ end
+ it 'does allow multiple unique domains' do
+ GettextSetup.initialize(locales_path)
+ repos = GettextSetup.translation_repositories
+ expect(repos.size == 2)
+ expect(repos.select { |k, _| k == 'fixture_locales' }.size).to eq(1)
+ expect(repos.select { |k, _| k == 'sinatra-i18n' }.size).to eq(1)
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/lib/gettext-setup/metadata_pot_spec.rb new/spec/lib/gettext-setup/metadata_pot_spec.rb
--- old/spec/lib/gettext-setup/metadata_pot_spec.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/lib/gettext-setup/metadata_pot_spec.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,61 @@
+require 'rspec/expectations'
+require 'tmpdir'
+require_relative '../../spec_helper'
+
+require_relative '../../../lib/gettext-setup'
+
+describe GettextSetup::MetadataPot do
+ before(:each) do
+ GettextSetup.initialize(File.absolute_path(File.join(File.dirname(__FILE__), '../../fixtures/locales')))
+ end
+ context '#metadata_path' do
+ it 'finds the right metadata path' do
+ expect(GettextSetup::MetadataPot.metadata_path).to match(/sinatra-i18n_metadata\.pot/)
+ end
+ end
+ context '#pot_string' do
+ it 'generates a reasonable POT string' do
+ expect(GettextSetup::MetadataPot.pot_string({})).to match(/Last-Translator: FULL NAME /)
+ end
+ it 'includes summary when provided' do
+ metadata = { 'summary' => 'abc' }
+ expect(GettextSetup::MetadataPot.pot_string(metadata)).to match(/msgid "abc"/)
+ end
+ it 'includes summary when provided' do
+ metadata = { 'description' => 'def' }
+ expect(GettextSetup::MetadataPot.pot_string(metadata)).to match(/msgid "def"/)
+ end
+ it 'includes both summary and description when provided' do
+ metadata = { 'summary' => 'abc', 'description' => 'def' }
+ result = expect(GettextSetup::MetadataPot.pot_string(metadata))
+ result.to match(/msgid "def"/)
+ result.to match(/msgid "abc"/)
+ end
+ end
+ context '#load_metadata' do
+ it 'loads metadata correctly' do
+ Dir.mktmpdir do |dir|
+ file = File.join(dir, 'metadata.json')
+ File.open(file, 'w') { |f| f.write('{"description":"abcdef", "summary":"ghi"}') }
+ metadata = GettextSetup::MetadataPot.metadata(File.join(dir, 'metadata.json').to_s)
+ expect(metadata).to eq('description' => 'abcdef', 'summary' => 'ghi')
+ end
+ end
+ it 'uses an empty hash if no metadata.json is found' do
+ metadata = GettextSetup::MetadataPot.metadata(File.join(Dir.mktmpdir, 'metadata.json').to_s)
+ expect(metadata).to eq({})
+ end
+ end
+ context '#generate_metadata_pot' do
+ it 'works with everything supplied' do
+ dir = Dir.mktmpdir
+ file = File.join(dir, 'metadata.pot')
+ metadata = { 'description' => 'abc', 'summary' => 'def' }
+ GettextSetup::MetadataPot.generate_metadata_pot(metadata,
+ file)
+ contents = File.read(file)
+ expect(contents).to match(/msgid "abc"/)
+ expect(contents).to match(/msgid "def"/)
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/lib/gettext-setup/pot_spec.rb new/spec/lib/gettext-setup/pot_spec.rb
--- old/spec/lib/gettext-setup/pot_spec.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/lib/gettext-setup/pot_spec.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,147 @@
+require 'rspec/expectations'
+require 'tmpdir'
+require_relative '../../spec_helper.rb'
+
+require_relative '../../../lib/gettext-setup'
+describe GettextSetup::Pot do
+ NoConfigFoundError = GettextSetup::NoConfigFoundError
+
+ def fixture_locales_path
+ File.join(File.dirname(__FILE__), '../../fixtures/fixture_locales')
+ end
+
+ def spec_locales_path
+ File.join(File.dirname(__FILE__), '../../fixtures/spec_locales')
+ end
+
+ def locales_path
+ File.join(File.dirname(__FILE__), '../../fixtures/locales')
+ end
+
+ describe 'string_changes?', if: msgcmp_present? do
+ old_pot = File.absolute_path('../../fixtures/string_changes/old.pot', File.dirname(__FILE__))
+
+ it 'should detect string addition' do
+ new_pot = File.absolute_path('../../fixtures/string_changes/add.pot', File.dirname(__FILE__))
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
+ end
+
+ it 'should detect string removal' do
+ new_pot = File.absolute_path('../../fixtures/string_changes/remove.pot', File.dirname(__FILE__))
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
+ end
+
+ it 'should detect string changes' do
+ new_pot = File.absolute_path('../../fixtures/string_changes/change.pot', File.dirname(__FILE__))
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(true)
+ end
+
+ it 'should not detect non-string changes' do
+ new_pot = File.absolute_path('../../fixtures/string_changes/non_string_changes.pot', File.dirname(__FILE__))
+ expect(GettextSetup::Pot.string_changes?(old_pot, new_pot)).to eq(false)
+ end
+ end
+
+ context 'generate_new_pot' do
+ it "fails when GettextSetup can't find a config.yaml" do
+ path = File.join(Dir.mktmpdir, 'empty.pot')
+ expect { GettextSetup::Pot.generate_new_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
+ end
+ it 'builds a POT file' do
+ path = File.join(Dir.mktmpdir, 'new.pot')
+ expect do
+ GettextSetup::Pot.generate_new_pot(fixture_locales_path, path)
+ end.to output('').to_stdout # STDOUT is determined in `update_pot`.
+ contents = File.read(path)
+ expect(contents).to match(/Fixture locales/)
+ expect(contents).to match(/docs@puppetlabs.com/)
+ expect(contents).to match(/Puppet, LLC/)
+ expect(contents).to match(/test_strings.rb:1/)
+ end
+ end
+
+ context 'generate_new_po' do
+ it "fails when GettextSetup can't find a config.yaml" do
+ path = File.join(Dir.mktmpdir, 'fails.pot')
+ po_path = File.join(Dir.mktmpdir, 'fails.po')
+ expect { GettextSetup::Pot.generate_new_po('ja', Dir.mktmpdir, path, po_path) }.to raise_error(NoConfigFoundError)
+ end
+ it 'complains when no language is supplied' do
+ result = "You need to specify the language to add. Either 'LANGUAGE=eo rake gettext:po' or 'rake gettext:po[LANGUAGE]'\n"
+ expect do
+ GettextSetup::Pot.generate_new_po(nil, fixture_locales_path, Dir.mktmpdir, Dir.mktmpdir)
+ end.to output(result).to_stdout
+ end
+ it 'generates new PO file', if: msginit_present? do
+ po_path = File.join(Dir.mktmpdir, 'aa', 'tmp.po')
+ pot_path = File.join(locales_path, 'sinatra-i18n.pot')
+
+ expect do
+ GettextSetup::Pot.generate_new_po('aa', locales_path, pot_path, po_path)
+ end.to output("PO file #{po_path} created\n").to_stdout
+ end
+ it 'merges PO files', if: [msginit_present?, msgmerge_present?] do
+ _('merged-po-file')
+ po_path = File.join(Dir.mktmpdir, 'aa', 'tmp.po')
+ pot_path = GettextSetup::Pot.pot_file_path
+
+ expect do
+ GettextSetup::Pot.generate_new_po('aa', fixture_locales_path, pot_path, po_path)
+ end.to output("PO file #{po_path} created\n").to_stdout
+ contents = File.read(po_path)
+ expect(contents).to match(/msgid "Hello, world!"/)
+
+ new_pot_path = File.join(spec_locales_path, 'sinatra-i18n.pot')
+ expect do
+ GettextSetup::Pot.generate_new_po('aa', spec_locales_path, new_pot_path, po_path)
+ end.to output("PO file #{po_path} merged\n").to_stdout
+ new_contents = File.read(po_path)
+ expect(new_contents).to match(/merged-po-file/)
+ end
+ end
+
+ context 'update_pot' do
+ it "fails when GettextSetup can't find a config.yaml" do
+ path = File.join(Dir.mktmpdir, 'fail-update.pot')
+ expect { GettextSetup::Pot.update_pot(Dir.mktmpdir, path) }.to raise_error(NoConfigFoundError)
+ end
+ it 'creates POT when absent' do
+ _('no-pot-file')
+ path = File.join(Dir.mktmpdir, 'some-pot.pot')
+ expect do
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
+ end.to output("No existing POT file, generating new\nPOT file #{path} has been generated\n").to_stdout
+ contents = File.read(path)
+ expect(contents).to match(/msgid "no-pot-file"/)
+ end
+ it 'updates POT when something changes', if: [msginit_present?, msgmerge_present?] do
+ _('some-spec-only-string')
+ path = File.join(Dir.mktmpdir, 'some-pot.pot')
+ expect do
+ GettextSetup::Pot.update_pot(fixture_locales_path, path)
+ end.to output("No existing POT file, generating new\nPOT file #{path} has been generated\n").to_stdout
+ contents = File.read(path)
+ expect(contents).to match(/Language-Team: LANGUAGE /)
+ expect(contents).not_to match(/some-spec-only-string/)
+ expect do
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
+ end.to output("String changes detected, replacing with updated POT file\n").to_stdout
+ new_contents = File.read(path)
+ expect(new_contents).to match(/some-spec-only-string/)
+ end
+ it "doesn't update the POT when nothing changes", if: [msginit_present?, msgcmp_present?] do
+ _('unchanged-string')
+ path = File.join(Dir.mktmpdir, 'some-pot.pot')
+ expect do
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
+ end.to output("No existing POT file, generating new\nPOT file #{path} has been generated\n").to_stdout
+ contents = File.read(path)
+ expect(contents).to match(/unchanged-string/)
+ expect do
+ GettextSetup::Pot.update_pot(spec_locales_path, path)
+ end.to output("No string changes detected, keeping old POT file\n").to_stdout
+ new_contents = File.read(path)
+ expect(new_contents).to eq(contents)
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/lib/gettext_setup_spec.rb new/spec/lib/gettext_setup_spec.rb
--- old/spec/lib/gettext_setup_spec.rb 2017-04-08 00:27:08.000000000 +0200
+++ new/spec/lib/gettext_setup_spec.rb 1970-01-01 01:00:00.000000000 +0100
@@ -1,107 +0,0 @@
-require 'rspec/expectations'
-require_relative '../spec_helper'
-
-require_relative '../../lib/gettext-setup'
-
-describe GettextSetup do
- before(:each) do
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'locales'))
- end
- let(:config) do
- GettextSetup.config
- end
- context 'initialize' do
- it 'sets up correctly' do
- # GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures'))
- expect(GettextSetup.locales_path).to match(/\/spec\/fixtures/)
- expect(config['project_name']).to eq('sinatra-i18n')
- expect(config['package_name']).to eq('Sinatra i18n demo')
- expect(config['default_locale']).to eq('en')
- expect(respond_to?(:_)).to eq(true)
- end
- end
- context 'negotiate_locale' do
- it 'negotiates correctly' do
- FastGettext.locale = GettextSetup.negotiate_locale('de')
- expect(FastGettext.locale).to eq('de')
- expect(_('Hello, world!')).to eq('Hallo, Welt!')
- end
- it 'chooses the default locale when no match is found' do
- expect(GettextSetup.negotiate_locale('no-match')).to eq(config['default_locale'])
- end
- it 'chooses the language with the highest q value' do
- expect(GettextSetup.negotiate_locale('en;q=1, de;q=2')).to eq('de')
- expect(GettextSetup.negotiate_locale('en;q=1, de;q=0')).to eq('en')
- end
- it 'chooses the first value when q values are equal' do
- expect(GettextSetup.negotiate_locale('de;q=1, en;q=1')).to eq('de')
- end
- end
- context 'setting default_locale' do
- before :each do
- GettextSetup.default_locale = 'en'
- end
- it 'allows setting the default locale' do
- expect(GettextSetup.default_locale).to eq('en')
- GettextSetup.default_locale = 'de'
- expect(GettextSetup.default_locale).to eq('de')
- end
- end
- context 'clear' do
- it 'can clear the locale' do
- expect(GettextSetup.default_locale).to eq('en')
- expect(GettextSetup.candidate_locales).to include('en')
- GettextSetup.clear
- begin
- old_locale = ENV['LANG']
- ENV['LANG'] = 'de_DE'
- expect(GettextSetup.candidate_locales).to eq('de_DE,de,en')
- ensure
- ENV['LANG'] = old_locale
- end
- end
- end
- context 'multiple locales' do
- # locales/ loads the de locale and alt_locales/ loads the jp locale
- before(:all) do
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'alt_locales'))
- end
- it 'can aggregate locales across projects' do
- expect(FastGettext.default_available_locales).to include('en')
- expect(FastGettext.default_available_locales).to include('de')
- expect(FastGettext.default_available_locales).to include('jp')
- end
- it 'can switch to loaded locale' do
- FastGettext.locale = GettextSetup.negotiate_locale('de,en')
- expect(FastGettext.locale).to eq('de')
- FastGettext.locale = GettextSetup.negotiate_locale('jp')
- expect(FastGettext.locale).to eq('jp')
- end
- end
- context 'translation repository chain' do
- before(:all) do
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'alt_locales'))
- end
- it 'chain is not nil' do
- expect(GettextSetup.translation_repositories).not_to be_nil
- end
- it 'can translate without switching text domains' do
- FastGettext.locale = 'de'
- expect(_('Hello, world!')).to eq('Hallo, Welt!')
- FastGettext.locale = 'jp'
- expect(_('Hello, world!')).to eq('こんにちは世界')
- end
- it 'does not allow duplicate repositories' do
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'alt_locales'))
- repos = GettextSetup.translation_repositories
- expect(repos.select { |k, _| k == 'alt_locales' }.size).to eq(1)
- end
- it 'does allow multiple unique domains' do
- GettextSetup.initialize(File.join(File.dirname(File.dirname(__FILE__)), 'fixtures', 'locales'))
- repos = GettextSetup.translation_repositories
- expect(repos.size == 2)
- expect(repos.select { |k, _| k == 'alt_locales' }.size).to eq(1)
- expect(repos.select { |k, _| k == 'sinatra-i18n' }.size).to eq(1)
- end
- end
-end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/lib/tasks/gettext_rake_spec.rb new/spec/lib/tasks/gettext_rake_spec.rb
--- old/spec/lib/tasks/gettext_rake_spec.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/spec/lib/tasks/gettext_rake_spec.rb 2017-05-30 20:09:42.000000000 +0200
@@ -0,0 +1,103 @@
+require 'rspec/expectations'
+require 'rake'
+require_relative '../../spec_helper.rb'
+
+load File.expand_path('../../../../lib/tasks/gettext.rake', __FILE__)
+
+describe 'gettext.rake' do
+ locales = File.expand_path('../../fixtures/locales', File.dirname(__FILE__))
+ tmp_locales = File.expand_path('../../fixtures/tmp_locales', File.dirname(__FILE__))
+ fixture_locales = File.expand_path('../../fixtures/fixture_locales', File.dirname(__FILE__))
+ tmp_pot_path = File.expand_path('sinatra-i18n.pot', tmp_locales)
+
+ before :each do
+ FileUtils.rm_r(tmp_locales, force: true)
+ FileUtils.cp_r(locales, tmp_locales)
+ end
+ after :each do
+ GettextSetup.clear
+ Rake::Task.tasks.each(&:reenable)
+ end
+ around :each do |test|
+ # Since we have `exit 1` in these rake tasks, we need to explicitly tell
+ # rspec that any unexpected errors aren't expected. Otherwise, if a
+ # SystemExit error is thrown, it just doesn't finish running the rest of
+ # the tests and considers the suite passing...
+ expect { test.run }.not_to raise_error
+ end
+ context Rake::Task['gettext:pot'] do
+ it 'outputs correctly' do
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to output(/POT file .+\/spec\/fixtures\/tmp_locales\/sinatra-i18n.pot has been generated/).to_stdout
+ end
+ it 'exits 1 on error' do
+ allow(GettextSetup::Pot).to receive(:generate_new_pot).and_return(false)
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to raise_error(SystemExit)
+ end
+ end
+ context Rake::Task['gettext:metadata_pot'] do
+ it 'outputs correctly' do
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to output(/POT metadata file .+sinatra-i18n_metadata.pot has been generated/).to_stdout
+ end
+ it 'exits 1 on error' do
+ allow(GettextSetup::MetadataPot).to receive(:generate_metadata_pot).and_return(false)
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to raise_error(SystemExit)
+ end
+ end
+ context Rake::Task['gettext:po'] do
+ it 'outputs correctly' do
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke('de')
+ end.to output(/PO file .+de\/sinatra-i18n.po merged/).to_stdout
+ end
+ it 'exits 1 on error' do
+ allow(GettextSetup::Pot).to receive(:generate_new_po).with('de').and_return(false)
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke('de')
+ end.to raise_error(SystemExit)
+ end
+ end
+ context Rake::Task['gettext:update_pot'] do
+ it 'does not update the POT when no changes are detected' do
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to output(/No string changes detected, keeping old POT file/).to_stdout
+ end
+ it 'can create a new POT' do
+ FileUtils.rm(tmp_pot_path)
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to output(/No existing POT file, generating new\nPOT file .+sinatra-i18n.pot has been generated/).to_stdout
+ end
+ it 'can update the POT' do
+ fixture_locales_pot = File.expand_path('fixture_locales.pot', fixture_locales)
+ FileUtils.cp(fixture_locales_pot, tmp_pot_path)
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to output(/String changes detected, replacing with updated POT file/).to_stdout
+ end
+ it 'exits 1 upon error' do
+ allow(GettextSetup::Pot).to receive(:update_pot).and_return(false)
+ expect do
+ GettextSetup.initialize(tmp_locales)
+ subject.invoke
+ end.to raise_error(SystemExit)
+ end
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/spec_helper.rb new/spec/spec_helper.rb
--- old/spec/spec_helper.rb 2017-04-08 00:27:08.000000000 +0200
+++ new/spec/spec_helper.rb 2017-05-30 20:09:42.000000000 +0200
@@ -1,12 +1,28 @@
require 'simplecov'
+require_relative '../lib/gettext-setup'
+
+GettextSetup.initialize(File.join(File.dirname(__FILE__), 'fixtures', 'locales'))
+
SimpleCov.start do
add_filter '/spec/'
end
-def msgcmp_present?
+def cmd_present?(cmd)
# Try to call out to msgcmp, if it doesn't error, we have the tool
- `msgcmp`
+ `#{cmd} --version`
return true
rescue IOError
return false
end
+
+def msgcmp_present?
+ cmd_present?('msgcmp')
+end
+
+def msginit_present?
+ cmd_present?('msginit')
+end
+
+def msgmerge_present?
+ cmd_present?('msgmerge')
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' --exclude Makefile.in --exclude configure --exclude config.guess --exclude '*.pot' --exclude mkinstalldirs --exclude aclocal.m4 --exclude config.sub --exclude depcomp --exclude install-sh --exclude ltmain.sh old/spec/tasks/update_pot_spec.rb new/spec/tasks/update_pot_spec.rb
--- old/spec/tasks/update_pot_spec.rb 2017-04-08 00:27:08.000000000 +0200
+++ new/spec/tasks/update_pot_spec.rb 1970-01-01 01:00:00.000000000 +0100
@@ -1,28 +0,0 @@
-require 'rspec/expectations'
-require_relative '../spec_helper.rb'
-
-require_relative '../../lib/tasks/task_helper.rb'
-
-describe 'string_changes?', if: msgcmp_present? do
- old_pot = File.absolute_path('../fixtures/pot_update/old.pot', File.dirname(__FILE__))
-
- it 'should detect string addition' do
- new_pot = File.absolute_path('../fixtures/pot_update/add.pot', File.dirname(__FILE__))
- expect(string_changes?(old_pot, new_pot)).to eq(true)
- end
-
- it 'should detect string removal' do
- new_pot = File.absolute_path('../fixtures/pot_update/remove.pot', File.dirname(__FILE__))
- expect(string_changes?(old_pot, new_pot)).to eq(true)
- end
-
- it 'should detect string changes' do
- new_pot = File.absolute_path('../fixtures/pot_update/change.pot', File.dirname(__FILE__))
- expect(string_changes?(old_pot, new_pot)).to eq(true)
- end
-
- it 'should not detect non-string changes' do
- new_pot = File.absolute_path('../fixtures/pot_update/non_string_changes.pot', File.dirname(__FILE__))
- expect(string_changes?(old_pot, new_pot)).to eq(false)
- end
-end