haml-magic-translations 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  This plugin provides "magical translations" in your .haml files. What does it
4
4
  mean? It's mean that all your raw texts in templates will be automatically
5
- translated by GetText, FastGettext or Gettext backend from I18n. No more
5
+ translated by GetText, FastGettext or Gettext backend from I18n. No more
6
6
  complicated translation keys and ugly translation methods in views. Now you can
7
- only write in your language, nothing more. At the end of your work you can easy
8
- find all phrases to translate and generate .po files for it. This type of files
9
- are also more readable and easier to translate, thanks to it you save your
7
+ only write in your language, nothing more. At the end of your work you can easy
8
+ find all phrases to translate and generate .po files for it. This type of files
9
+ are also more readable and easier to translate, thanks to it you save your
10
10
  time with translations.
11
11
 
12
12
  === Installation
@@ -14,76 +14,79 @@ time with translations.
14
14
  You can install haml-magic-translations directly from rubygems:
15
15
 
16
16
  gem install haml-magic-translations
17
-
17
+
18
18
  ...or as Ruby on Rails plugin:
19
19
 
20
20
  script/plugin install git://github.com/kriss/haml-magic-translations
21
21
  or
22
- rails plugin install git://github.com/kriss/haml-magic-translations
22
+ rails plugin install git://github.com/kriss/haml-magic-translations
23
23
 
24
24
  === Gettings started with Gettext
25
25
 
26
- To use automatical translations you have to using new I18n with Gettext backend,
26
+ To use automatical translations you have to using new I18n with Gettext backend,
27
27
  GetText or FastGettext, properly installed and configured. To enable plugin
28
28
  you have to do following things:
29
29
 
30
30
  Haml::MagicTranslations.enable(:i18n) # this backend is used by default
31
-
31
+
32
32
  Available backends are +:i18n+, +:gettext+ and +:fast_gettext+
33
33
 
34
34
  Now you have to add path to all your .po files with locales. Eg. for i18n backend
35
- it will be something like:
36
-
35
+ it will be something like:
36
+
37
37
  I18n.load_path += Dir["path/to/your/locales/*.{po}")]
38
-
38
+
39
39
  And that's all. Now you can enjoy automatically translations in your .haml files!
40
40
 
41
41
  === Examples
42
42
 
43
- Now you can write what you want, and at the end of work you
43
+ Now you can write what you want, and at the end of work you
44
44
  will easy found all phrases to translate. Check out following example:
45
45
 
46
46
  %p This is my simple dummy text.
47
47
  %p And more lorem ipsum...
48
48
  %p= link_to _("This will be also translated"), "#"
49
-
50
- Those translations are allso allowing you to use standard Haml interpolation.
51
- You can easy write:
52
-
49
+
50
+ Those translations are allso allowing you to use standard Haml interpolation.
51
+ You can easy write:
52
+
53
53
  %p This is my text with #{"interpolation".upcase}... Great, isn't it?
54
54
  %p
55
55
  This multiline string
56
56
  Will be also translated
57
-
57
+
58
58
  And text from codes above will be stored in .po files as:
59
59
 
60
60
  # File test1.haml, line 1
61
61
  msgid "This is my simple dummy text"
62
62
  msgstr "This is my dummy translation of dummy text"
63
-
63
+
64
64
  # File test2.haml, line 1
65
65
  msgid "This is my text with %s... Great, isn't it?"
66
66
  msgstr "Next one %s translation!"
67
-
67
+
68
68
  # File test4.haml, line 3
69
69
  msgid "This multiline string"
70
70
  msgstr ""
71
-
71
+
72
72
  # File test2.haml, line 4
73
73
  msgid "Will be also translated"
74
74
  msgstr ""
75
-
76
- Notice that in multiline strings each line is translated separatelly.
77
-
75
+
76
+ Notice that in multiline strings each line is translated separatelly.
77
+
78
78
  Generator for .po files also includes information where your phrases are placed
79
- in filesystem. Thanks to it you don't forget about any even small word to
80
- translate.
79
+ in filesystem. Thanks to it you don't forget about any even small word to
80
+ translate.
81
81
 
82
82
  === Extracting strings and merging translations
83
83
 
84
84
  In order to extract translatable strings and merge with existing translation,
85
- this gem provides an Haml parser for RGetText. You can either use it directly
86
- or through the provided Rake task. Here's an example on how to use the later:
85
+ this gem provides an Haml parser for GetText::Tools::XGetText. This requires
86
+ gettext >= 2.3 to be available.
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:
87
90
 
88
91
  Haml::MagicTranslations::Tasks::UpdatePoFiles.new do |t|
89
92
  t.text_domain = 'my_project'
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ time with translations.
20
20
  gem.authors = ["Kriss Kowalik", "potager.org"]
21
21
  gem.add_dependency "haml", "~> 3.1"
22
22
  gem.add_development_dependency "actionpack"
23
- gem.add_development_dependency "gettext"
23
+ gem.add_development_dependency "gettext", ">= 2.3"
24
24
  gem.add_development_dependency "fast_gettext"
25
25
  gem.add_development_dependency "rspec", ">= 2"
26
26
  gem.add_development_dependency "rdoc", ">= 2.4.2"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.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 = "0.4.0"
8
+ s.version = "0.5.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{2013-03-15}
12
+ s.date = %q{2013-03-21}
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
@@ -33,10 +33,10 @@ time with translations.
33
33
  "init.rb",
34
34
  "lib/haml-magic-translations.rb",
35
35
  "lib/haml/magic_translations.rb",
36
- "lib/haml/magic_translations/rgettext/haml_parser.rb",
37
36
  "lib/haml/magic_translations/tasks.rb",
38
- "spec/haml/magic_translations/rgettext/haml_parser_spec.rb",
37
+ "lib/haml/magic_translations/xgettext/haml_parser.rb",
39
38
  "spec/haml/magic_translations/tasks_spec.rb",
39
+ "spec/haml/magic_translations/xgettext/haml_parser_spec.rb",
40
40
  "spec/haml/magic_translations_spec.rb",
41
41
  "spec/locales/en.po",
42
42
  "spec/locales/pl.po",
@@ -44,17 +44,16 @@ time with translations.
44
44
  ]
45
45
  s.homepage = %q{http://github.com/potager/haml-magic-translations}
46
46
  s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.3.7}
47
+ s.rubygems_version = %q{1.8.23}
48
48
  s.summary = %q{Provides automaticaly translations in haml templates}
49
49
 
50
50
  if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
51
  s.specification_version = 3
53
52
 
54
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
54
  s.add_runtime_dependency(%q<haml>, ["~> 3.1"])
56
55
  s.add_development_dependency(%q<actionpack>, [">= 0"])
57
- s.add_development_dependency(%q<gettext>, [">= 0"])
56
+ s.add_development_dependency(%q<gettext>, [">= 2.3"])
58
57
  s.add_development_dependency(%q<fast_gettext>, [">= 0"])
59
58
  s.add_development_dependency(%q<rspec>, [">= 2"])
60
59
  s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
@@ -62,7 +61,7 @@ time with translations.
62
61
  else
63
62
  s.add_dependency(%q<haml>, ["~> 3.1"])
64
63
  s.add_dependency(%q<actionpack>, [">= 0"])
65
- s.add_dependency(%q<gettext>, [">= 0"])
64
+ s.add_dependency(%q<gettext>, [">= 2.3"])
66
65
  s.add_dependency(%q<fast_gettext>, [">= 0"])
67
66
  s.add_dependency(%q<rspec>, [">= 2"])
68
67
  s.add_dependency(%q<rdoc>, [">= 2.4.2"])
@@ -71,7 +70,7 @@ time with translations.
71
70
  else
72
71
  s.add_dependency(%q<haml>, ["~> 3.1"])
73
72
  s.add_dependency(%q<actionpack>, [">= 0"])
74
- s.add_dependency(%q<gettext>, [">= 0"])
73
+ s.add_dependency(%q<gettext>, [">= 2.3"])
75
74
  s.add_dependency(%q<fast_gettext>, [">= 0"])
76
75
  s.add_dependency(%q<rspec>, [">= 2"])
77
76
  s.add_dependency(%q<rdoc>, [">= 2.4.2"])
@@ -4,9 +4,9 @@ require 'rake'
4
4
  require 'rake/tasklib'
5
5
  require 'gettext'
6
6
  require 'gettext/tools'
7
- require 'gettext/tools/rgettext'
7
+ require 'gettext/tools/xgettext'
8
8
 
9
- require 'haml/magic_translations/rgettext/haml_parser'
9
+ require 'haml/magic_translations/xgettext/haml_parser'
10
10
 
11
11
  module Haml::MagicTranslations::Tasks # :nodoc:
12
12
  # Rake task to generate and update PO files for a project using
@@ -75,7 +75,7 @@ module Haml::MagicTranslations::Tasks # :nodoc:
75
75
  [ :lang, :po_root, :verbose ].each do |opt|
76
76
  options[opt] = send(opt) if send(opt)
77
77
  end
78
- GetText::RGetText.add_parser(Haml::MagicTranslations::RGetText::HamlParser)
78
+ GetText::Tools::XGetText.add_parser(Haml::MagicTranslations::XGetText::HamlParser)
79
79
  GetText.update_pofiles(text_domain, files, app_version, options)
80
80
  end
81
81
  end
@@ -4,12 +4,12 @@ require 'json'
4
4
  require 'haml'
5
5
  require 'haml/magic_translations'
6
6
 
7
- module Haml::MagicTranslations::RGetText # :nodoc:
8
- # RGetText parser for Haml files
7
+ module Haml::MagicTranslations::XGetText # :nodoc:
8
+ # XGetText parser for Haml files
9
9
  #
10
10
  # === Example
11
11
  #
12
- # GetText::RGetText.add_parser(Haml::MagicTranslations::RGetText::HamlParser)
12
+ # GetText::Tools::XGetText.add_parser(Haml::MagicTranslations::XGetText::HamlParser)
13
13
  # GetText.update_pofiles(text_domain, files, app_version, options)
14
14
  #
15
15
  module HamlParser
@@ -19,7 +19,7 @@ module Haml::MagicTranslations::RGetText # :nodoc:
19
19
  File.extname(file) == '.haml'
20
20
  end
21
21
 
22
- def parse(file, ary = []) # :nodoc:
22
+ def parse(file) # :nodoc:
23
23
  Parser.new(file).parse
24
24
  end
25
25
 
@@ -37,15 +37,15 @@ module Haml::MagicTranslations::RGetText # :nodoc:
37
37
  end
38
38
 
39
39
  def parse
40
- Haml::Engine.send(:include, RGetTextEngine)
40
+ Haml::Engine.send(:include, XGetTextEngine)
41
41
  engine = Haml::Engine.new(
42
42
  content, :filename => @file,
43
- :rgettext => true,
43
+ :xgettext => true,
44
44
  :magic_translations => false).targets
45
45
  end
46
46
  end
47
47
 
48
- module RGetTextEngine # :nodoc:all
48
+ module XGetTextEngine # :nodoc:all
49
49
  def add_target(text, lineno = @node.line)
50
50
  @targets = {} if @targets.nil?
51
51
  unless text.empty?
@@ -71,7 +71,7 @@ module Haml::MagicTranslations::RGetText # :nodoc:
71
71
  #
72
72
  # So let's hook in the parser, just for this specific case.
73
73
  def parse_tag(line)
74
- return super unless self.options[:rgettext]
74
+ return super unless self.options[:xgettext]
75
75
 
76
76
  tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
77
77
  nuke_inner_whitespace, action, value, last_line = super(line)
@@ -91,29 +91,29 @@ module Haml::MagicTranslations::RGetText # :nodoc:
91
91
  end
92
92
 
93
93
  def compile_plain
94
- return super unless self.options[:rgettext]
94
+ return super unless self.options[:xgettext]
95
95
 
96
96
  add_target(@node.value[:text])
97
97
  end
98
98
 
99
99
  def compile_doctype
100
- return super unless self.options[:rgettext]
100
+ return super unless self.options[:xgettext]
101
101
  end
102
102
 
103
103
  def compile_script
104
- return super unless self.options[:rgettext]
104
+ return super unless self.options[:xgettext]
105
105
 
106
106
  yield if block_given?
107
107
  end
108
108
 
109
109
  def compile_silent_script
110
- return super unless self.options[:rgettext]
110
+ return super unless self.options[:xgettext]
111
111
 
112
112
  yield if block_given?
113
113
  end
114
114
 
115
115
  def compile_tag
116
- return super unless self.options[:rgettext]
116
+ return super unless self.options[:xgettext]
117
117
 
118
118
  # handle explicit translations in attributes
119
119
  @node.value[:attributes_hashes].each do |hash_string|
@@ -126,11 +126,11 @@ module Haml::MagicTranslations::RGetText # :nodoc:
126
126
  end
127
127
 
128
128
  def compile_filter
129
- return super unless self.options[:rgettext]
129
+ return super unless self.options[:xgettext]
130
130
 
131
131
  case @node.value[:name]
132
132
  when 'markdown', 'maruku'
133
- add_target(@node.value[:text].rstrip.gsub(/\n/, '\n'))
133
+ add_target(@node.value[:text].rstrip)
134
134
  when 'javascript'
135
135
  lineno = 0
136
136
  @node.value[:text].split(/\r\n|\r|\n/).each do |line|
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'haml/magic_translations/tasks'
5
- require 'gettext/tools/rgettext'
5
+ require 'gettext/tools/xgettext'
6
6
 
7
7
  module Haml::MagicTranslations::Tasks
8
8
  describe UpdatePoFiles do
@@ -65,9 +65,9 @@ module Haml::MagicTranslations::Tasks
65
65
  task.text_domain, task.files, task.app_version, {})
66
66
  run
67
67
  end
68
- it 'should add a parser for ".haml" files to RGetText' do
68
+ it 'should add a parser for ".haml" files to XGetText' do
69
69
  GetText.stub!(:update_pofiles)
70
- GetText::RGetText.should_receive(:add_parser) do |haml_parser|
70
+ GetText::Tools::XGetText.should_receive(:add_parser) do |haml_parser|
71
71
  haml_parser.should respond_to(:parse)
72
72
  haml_parser.should be_a_target('example.haml')
73
73
  end
@@ -1,9 +1,9 @@
1
1
  # -*- coding: UTF-8 -*-
2
2
 
3
3
  require 'spec_helper'
4
- require 'haml/magic_translations/rgettext/haml_parser'
4
+ require 'haml/magic_translations/xgettext/haml_parser'
5
5
 
6
- module Haml::MagicTranslations::RGetText
6
+ module Haml::MagicTranslations::XGetText
7
7
  describe HamlParser do
8
8
  describe '.target?' do
9
9
  subject { HamlParser }
@@ -192,7 +192,7 @@ module Haml::MagicTranslations::RGetText
192
192
  HAML
193
193
  end
194
194
  it 'should properly add it to translations' do
195
- should == [["First paragraph\\n\\nSecond paragraph", '(haml):1']]
195
+ should == [["First paragraph\n\nSecond paragraph", '(haml):1']]
196
196
  end
197
197
  end
198
198
  context 'after extracting translations' do
@@ -221,7 +221,7 @@ module Haml
221
221
  lang = File.basename(src).gsub(/\.po$/, '')
222
222
  dest = File.join(tmpdir, lang, 'LC_MESSAGES', 'test.mo')
223
223
  FileUtils.mkdir_p(File.dirname(dest))
224
- GetText.rmsgfmt(src, dest)
224
+ GetText::Tools::MsgFmt.run(src, '-o', dest)
225
225
  end
226
226
  Haml::MagicTranslations.enable :gettext
227
227
  GetText.bindtextdomain 'test', :path => tmpdir
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: 0.4.0
4
+ version: 0.5.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: 2013-03-15 00:00:00.000000000 Z
13
+ date: 2013-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.3'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: '2.3'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: fast_gettext
65
65
  requirement: !ruby/object:Gem::Requirement
@@ -146,10 +146,10 @@ files:
146
146
  - init.rb
147
147
  - lib/haml-magic-translations.rb
148
148
  - lib/haml/magic_translations.rb
149
- - lib/haml/magic_translations/rgettext/haml_parser.rb
150
149
  - lib/haml/magic_translations/tasks.rb
151
- - spec/haml/magic_translations/rgettext/haml_parser_spec.rb
150
+ - lib/haml/magic_translations/xgettext/haml_parser.rb
152
151
  - spec/haml/magic_translations/tasks_spec.rb
152
+ - spec/haml/magic_translations/xgettext/haml_parser_spec.rb
153
153
  - spec/haml/magic_translations_spec.rb
154
154
  - spec/locales/en.po
155
155
  - spec/locales/pl.po