haml-magic-translations 4.0.3 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,16 +85,18 @@ In order to extract translatable strings and merge with existing translation,
85
85
  this gem provides an Haml parser for GetText::Tools::XGetText. This requires
86
86
  gettext >= 2.3 to be available.
87
87
 
88
- You can either use it directly or through the provided Rake task. Here's an
89
- example on how to use the later:
88
+ With gettext >= 3, Rake tasks can be defined as follow:
90
89
 
91
- Haml::MagicTranslations::Tasks::UpdatePoFiles.new do |t|
92
- t.text_domain = 'my_project'
93
- t.files = Dir.glob("views/**/*.{rb,haml}") << "lib/my_project.rb"
94
- t.app_version = 'my_project 0.1'
90
+ require 'gettext/tools/task'
91
+ require 'haml/magic_translations/xgettext/haml_parser'
92
+
93
+ GetText::Tools::XGetText.add_parser(Haml::MagicTranslations::XGetText::HamlParser)
94
+ GetText::Tools::Task.define do |task|
95
+ task.spec = Gem::Specification.load('coquelicot.gemspec')
96
+ task.files = Dir.glob('views/**/*.{rb,haml}') << 'lib/my_project.rb'
95
97
  end
96
98
 
97
- This will add a +update_pofiles+ task that will update PO files that can be
99
+ This will add a +gettext:po:update+ task that will update PO files that can be
98
100
  found in the +po+ directory.
99
101
 
100
102
  === Copyrights
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.3
1
+ 4.1.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{haml-magic-translations}
8
- s.version = "4.0.3"
8
+ s.version = "4.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kriss Kowalik", "potager.org"]
12
- s.date = %q{2014-05-05}
12
+ s.date = %q{2014-05-06}
13
13
  s.description = %q{This plugin provides "magical translations" in your .haml files. What does it
14
14
  mean? It's mean that all your raw texts in templates will be automatically
15
15
  translated by GetText, FastGettext or Gettext backend from I18n. No more
@@ -210,6 +210,7 @@ module Haml
210
210
  context 'with I18n as backend' do
211
211
  before(:each) do
212
212
  Haml::MagicTranslations.enable :i18n
213
+ I18n.config.enforce_available_locales = false
213
214
  I18n.locale = :pl
214
215
  I18n.load_path += Dir[File.join(File.dirname(__FILE__), "../locales/*.po")]
215
216
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-magic-translations
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-05-05 00:00:00.000000000 Z
13
+ date: 2014-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
@@ -162,9 +162,7 @@ files:
162
162
  - init.rb
163
163
  - lib/haml-magic-translations.rb
164
164
  - lib/haml/magic_translations.rb
165
- - lib/haml/magic_translations/tasks.rb
166
165
  - lib/haml/magic_translations/xgettext/haml_parser.rb
167
- - spec/haml/magic_translations/tasks_spec.rb
168
166
  - spec/haml/magic_translations/xgettext/haml_parser_spec.rb
169
167
  - spec/haml/magic_translations_spec.rb
170
168
  - spec/locales/en.po
@@ -1,83 +0,0 @@
1
- # -*- coding: UTF-8 -*-
2
-
3
- require 'rake'
4
- require 'rake/tasklib'
5
- require 'gettext'
6
- require 'gettext/tools'
7
- require 'gettext/tools/xgettext'
8
-
9
- require 'haml/magic_translations/xgettext/haml_parser'
10
-
11
- module Haml::MagicTranslations::Tasks # :nodoc:
12
- # Rake task to generate and update PO files for a project using
13
- # Haml::MagicTranslations
14
- #
15
- # === Example
16
- #
17
- # Rakefile excerpt:
18
- #
19
- # Haml::MagicTranslations::Tasks::UpdatePoFiles.new do |t|
20
- # t.text_domain = 'my_project'
21
- # t.files = Dir.glob("views/**/*.{rb,haml}") << "lib/my_project.rb"
22
- # t.app_version = 'my_project 0.1'
23
- # end
24
- #
25
- # Updating PO files in the ++po++ directory will be done by issuing:
26
- #
27
- # rake update_pofiles
28
- #
29
- class UpdatePoFiles < ::Rake::TaskLib
30
- # The name of the task
31
- attr_accessor :name
32
-
33
- # the textdomain name (see GetText.update_pofiles)
34
- attr_accessor :text_domain
35
-
36
- # an Array of target files, that should be parsed for messages
37
- attr_accessor :files
38
-
39
- # the application information which appears "Project-Id-Version: #app_version" in the pot/po-files
40
- attr_accessor :app_version
41
-
42
- # update files only for one language - the language specified by this option
43
- attr_accessor :lang
44
-
45
- # the root directory of po-files
46
- attr_accessor :po_root
47
-
48
- # an array with the options, passed through to the gnu msgmerge tool
49
- #
50
- # Symbols are automatically translated to options with dashes,
51
- # example: ++[:no_wrap, :no_fuzzy_matching, :sort_output]++ translated to
52
- # ++--no-fuzzy-matching --sort-output++.
53
- attr_accessor :msgmerge
54
-
55
- # true to show verbose messages. default is false
56
- attr_accessor :verbose
57
-
58
- def initialize(name = :update_pofiles)
59
- @name = name
60
-
61
- yield self if block_given?
62
-
63
- define
64
- end
65
-
66
- protected
67
-
68
- def define
69
- desc "Update PO files"
70
- task(name) do
71
- [ :text_domain, :files, :app_version ].each do |opt|
72
- abort "`#{opt}` needs to be set." if send(opt).nil?
73
- end
74
- options = {}
75
- [ :lang, :po_root, :verbose ].each do |opt|
76
- options[opt] = send(opt) if send(opt)
77
- end
78
- GetText::Tools::XGetText.add_parser(Haml::MagicTranslations::XGetText::HamlParser)
79
- GetText.update_pofiles(text_domain, files, app_version, options)
80
- end
81
- end
82
- end
83
- end
@@ -1,105 +0,0 @@
1
- # -*- coding: UTF-8 -*-
2
-
3
- require 'spec_helper'
4
- require 'haml/magic_translations/tasks'
5
- require 'gettext/tools/xgettext'
6
-
7
- module Haml::MagicTranslations::Tasks
8
- describe UpdatePoFiles do
9
- before do
10
- ::Rake.application.clear
11
- end
12
-
13
- def run
14
- ::Rake.application.tasks[0].invoke
15
- end
16
-
17
- context 'with text_domain is not set' do
18
- let(:task) { UpdatePoFiles.new }
19
- before do
20
- task.files = [ 'test' ]
21
- task.app_version = 'test 1.0'
22
- # silence abort message
23
- STDERR.stub(:write)
24
- end
25
- it 'should abort' do
26
- expect { run }.to raise_error(SystemExit)
27
- end
28
- end
29
-
30
- context 'with files is not set' do
31
- let(:task) { UpdatePoFiles.new }
32
- before do
33
- task.text_domain = 'test'
34
- task.app_version = 'test 1.0'
35
- # silence abort message
36
- STDERR.stub(:write)
37
- end
38
- it 'should abort' do
39
- expect { run }.to raise_error(SystemExit)
40
- end
41
- end
42
-
43
- context 'with app_version is not set' do
44
- let(:task) { UpdatePoFiles.new }
45
- before do
46
- task.text_domain = 'test'
47
- task.files = [ 'test' ]
48
- # silence abort message
49
- STDERR.stub(:write)
50
- end
51
- it 'should abort' do
52
- expect { run }.to raise_error(SystemExit)
53
- end
54
- end
55
-
56
- context 'with text_domain, files and app_version set' do
57
- let (:task) { UpdatePoFiles.new }
58
- before(:each) do
59
- task.text_domain = 'test'
60
- task.files = [ 'test' ]
61
- task.app_version = 'test 1.0'
62
- end
63
- it 'should call update_pofiles' do
64
- expect(GetText).to receive(:update_pofiles).with(
65
- task.text_domain, task.files, task.app_version, {})
66
- run
67
- end
68
- it 'should add a parser for ".haml" files to XGetText' do
69
- allow(GetText).to receive(:update_pofiles)
70
- expect(GetText::Tools::XGetText).to receive(:add_parser) do |haml_parser|
71
- expect(haml_parser).to respond_to(:parse)
72
- expect(haml_parser).to be_a_target('example.haml')
73
- end
74
- run
75
- end
76
- context 'with lang set' do
77
- it 'should pass lang in options' do
78
- task.lang = 'pl'
79
- allow(GetText).to receive(:update_pofiles).with(
80
- task.text_domain, task.files, task.app_version,
81
- hash_including(:lang => task.lang))
82
- run
83
- end
84
- end
85
- context 'with po_root set' do
86
- it 'should pass po_root in options' do
87
- task.po_root = 'test/po'
88
- expect(GetText).to receive(:update_pofiles).with(
89
- task.text_domain, task.files, task.app_version,
90
- hash_including(:po_root => task.po_root))
91
- run
92
- end
93
- end
94
- context 'with verbose set' do
95
- it 'should pass verbose in options' do
96
- task.verbose = true
97
- expect(GetText).to receive(:update_pofiles).with(
98
- task.text_domain, task.files, task.app_version,
99
- hash_including(:verbose => task.verbose))
100
- run
101
- end
102
- end
103
- end
104
- end
105
- end