haml-magic-translations 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +84 -0
- data/Rakefile +58 -0
- data/TODO +3 -0
- data/VERSION +1 -0
- data/haml-magic-translations.gemspec +71 -0
- data/init.rb +1 -0
- data/lib/haml-magic-translations.rb +3 -0
- data/lib/haml/magic_translations.rb +137 -0
- data/spec/locales/en.po +7 -0
- data/spec/locales/pl.po +16 -0
- data/spec/magic_translations_spec.rb +68 -0
- data/spec/spec_helper.rb +18 -0
- metadata +126 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Kriss Kowalik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
== Magic Translations
|
2
|
+
|
3
|
+
This plugin provides "magical translations" in your .haml files. What does it
|
4
|
+
mean? It's mean that all your raw texts in templates will be automatically
|
5
|
+
translated by Gettext backend from I18n. No more complicated translation keys
|
6
|
+
and ugly translation methods in views. Now you can only write in your language,
|
7
|
+
nothing more. At the end of your work you can easy find all phrases to translate
|
8
|
+
and generate .po files for it. This type of files are also more readable and
|
9
|
+
easier to translate, thanks to it you save your time with translations.
|
10
|
+
|
11
|
+
=== Installation
|
12
|
+
|
13
|
+
You can install haml-magic-translations directly from rubygems:
|
14
|
+
|
15
|
+
gem install haml-magic-translations
|
16
|
+
|
17
|
+
...or as Ruby on Rails plugin:
|
18
|
+
|
19
|
+
script/plugin install git://github.com/kriss/haml-magic-translations
|
20
|
+
or
|
21
|
+
rails plugin install git://github.com/kriss/haml-magic-translations
|
22
|
+
|
23
|
+
=== Gettings started with Gettext
|
24
|
+
|
25
|
+
To use automatical translations you have to using new I18n with Gettext backend.
|
26
|
+
Magic translations plugin will automatically enable it for you, so you have to
|
27
|
+
only define somewhere you path to .po files with your translations.
|
28
|
+
|
29
|
+
I18n.load_path += Dir["path/to/your/locales/*.{po}")]
|
30
|
+
|
31
|
+
=== Time for translations
|
32
|
+
|
33
|
+
When gem is installed, then magic translations are enabled by default. But when
|
34
|
+
somehow you will not be able to use it, set one of Haml options - `:magic_translations`
|
35
|
+
|
36
|
+
Haml::Template.options[:magic_translations] = true
|
37
|
+
|
38
|
+
And that's all.
|
39
|
+
|
40
|
+
=== Examples
|
41
|
+
|
42
|
+
Now you can write what you want, and at the end of work you
|
43
|
+
will easy found all phrases to translate. Check out following example:
|
44
|
+
|
45
|
+
%p This is my simple dummy text.
|
46
|
+
%p And more lorem ipsum...
|
47
|
+
%p= link_to _("This will be also translated"), "#"
|
48
|
+
|
49
|
+
Those translations are allso allowing you to use standard Haml interpolation.
|
50
|
+
You can easy write:
|
51
|
+
|
52
|
+
%p This is my text with #{"interpolation".upcase}... Great, isn't it?
|
53
|
+
%p
|
54
|
+
This multiline string
|
55
|
+
Will be also translated
|
56
|
+
|
57
|
+
And text from codes above will be stored in .po files as:
|
58
|
+
|
59
|
+
# File test1.haml, line 1
|
60
|
+
msgid "This is my simple dummy text"
|
61
|
+
msgstr "This is my dummy translation of dummy text"
|
62
|
+
|
63
|
+
# File test2.haml, line 1
|
64
|
+
msgid "This is my text with %s... Great, isn't it?"
|
65
|
+
msgstr "Next one %s translation!"
|
66
|
+
|
67
|
+
# File test4.haml, line 3
|
68
|
+
msgid "This multiline string"
|
69
|
+
msgstr ""
|
70
|
+
|
71
|
+
# File test2.haml, line 4
|
72
|
+
msgid "Will be also translated"
|
73
|
+
msgstr ""
|
74
|
+
|
75
|
+
Notice that in multiline strings each line is translated separatelly.
|
76
|
+
|
77
|
+
Generator for .po files also includes information where your phrases are placed
|
78
|
+
in filesystem. Thanks to it you don't forget about any even small word to
|
79
|
+
translate.
|
80
|
+
|
81
|
+
=== Copyrights
|
82
|
+
|
83
|
+
Kriss Kowalik (kriss.kowalik@gmail.com)
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "haml-magic-translations"
|
7
|
+
gem.summary = "Provides automaticaly translations in haml templates"
|
8
|
+
gem.description = <<-DESCR
|
9
|
+
This plugin provides "magical translations" in your .haml files. What does it
|
10
|
+
mean? It's mean that all your raw texts in templates will be automatically
|
11
|
+
translated by Gettext backend from I18n. No more complicated translation keys
|
12
|
+
and ugly translation methods in views. Now you can only write in your language,
|
13
|
+
nothing more. At the end of your work you can easy find all phrases to translate
|
14
|
+
and generate .po files for it. This type of files are also more readable and
|
15
|
+
easier to translate, thanks to it you save your time with translations.
|
16
|
+
DESCR
|
17
|
+
gem.email = "kriss.kowalik@gmail.com"
|
18
|
+
gem.homepage = "http://github.com/kriss/haml-magic-translations"
|
19
|
+
gem.authors = ["Kriss Kowalik"]
|
20
|
+
gem.add_development_dependency "haml", ">= 3.0.0"
|
21
|
+
gem.add_development_dependency "i18n", ">= 0.4.1"
|
22
|
+
gem.add_development_dependency "gettext", ">= 2.0.0"
|
23
|
+
end
|
24
|
+
Jeweler::GemcutterTasks.new
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'spec/rake/spectask'
|
30
|
+
require 'rake/rdoctask'
|
31
|
+
|
32
|
+
desc 'Default: run specs.'
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
desc 'Run the specs'
|
36
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
37
|
+
t.spec_files = Dir['spec/**/*_spec.rb']
|
38
|
+
t.spec_opts = %w(-fs --color)
|
39
|
+
end
|
40
|
+
|
41
|
+
namespace :spec do
|
42
|
+
desc "Run all specs with RCov"
|
43
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
44
|
+
t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
|
45
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
46
|
+
t.rcov = true
|
47
|
+
t.rcov_opts = ['--exclude', 'spec,/Users/']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Generate documentation for the simple_navigation plugin.'
|
52
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = 'SimpleNavigation'
|
55
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
56
|
+
rdoc.rdoc_files.include('README')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{haml-magic-translations}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kriss Kowalik"]
|
12
|
+
s.date = %q{2010-07-21}
|
13
|
+
s.description = %q{This plugin provides "magical translations" in your .haml files. What does it
|
14
|
+
mean? It's mean that all your raw texts in templates will be automatically
|
15
|
+
translated by Gettext backend from I18n. No more complicated translation keys
|
16
|
+
and ugly translation methods in views. Now you can only write in your language,
|
17
|
+
nothing more. At the end of your work you can easy find all phrases to translate
|
18
|
+
and generate .po files for it. This type of files are also more readable and
|
19
|
+
easier to translate, thanks to it you save your time with translations.
|
20
|
+
}
|
21
|
+
s.email = %q{kriss.kowalik@gmail.com}
|
22
|
+
s.extra_rdoc_files = [
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"TODO"
|
26
|
+
]
|
27
|
+
s.files = [
|
28
|
+
"LICENSE",
|
29
|
+
"README.rdoc",
|
30
|
+
"Rakefile",
|
31
|
+
"TODO",
|
32
|
+
"VERSION",
|
33
|
+
"haml-magic-translations.gemspec",
|
34
|
+
"init.rb",
|
35
|
+
"lib/haml-magic-translations.rb",
|
36
|
+
"lib/haml/magic_translations.rb",
|
37
|
+
"spec/locales/en.po",
|
38
|
+
"spec/locales/pl.po",
|
39
|
+
"spec/magic_translations_spec.rb",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/kriss/haml-magic-translations}
|
43
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.6}
|
46
|
+
s.summary = %q{Provides automaticaly translations in haml templates}
|
47
|
+
s.test_files = [
|
48
|
+
"spec/spec_helper.rb",
|
49
|
+
"spec/magic_translations_spec.rb"
|
50
|
+
]
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<haml>, [">= 3.0.0"])
|
58
|
+
s.add_development_dependency(%q<i18n>, [">= 0.4.1"])
|
59
|
+
s.add_development_dependency(%q<gettext>, [">= 2.0.0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<haml>, [">= 3.0.0"])
|
62
|
+
s.add_dependency(%q<i18n>, [">= 0.4.1"])
|
63
|
+
s.add_dependency(%q<gettext>, [">= 2.0.0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<haml>, [">= 3.0.0"])
|
67
|
+
s.add_dependency(%q<i18n>, [">= 0.4.1"])
|
68
|
+
s.add_dependency(%q<gettext>, [">= 2.0.0"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'haml-magic-translations'
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'haml'
|
2
|
+
require 'haml/template'
|
3
|
+
|
4
|
+
require 'i18n'
|
5
|
+
require 'i18n/backend/gettext'
|
6
|
+
require 'i18n/gettext/helpers'
|
7
|
+
|
8
|
+
##
|
9
|
+
# This plugin provides "magical translations" in your .haml files. What does it
|
10
|
+
# mean? It's mean that all your raw texts in templates will be automatically
|
11
|
+
# translated by Gettext backend from I18n. No more complicated translation keys
|
12
|
+
# and ugly translation methods in views. Now you can only write in your language,
|
13
|
+
# nothing more. At the end of your work you can easy find all phrases to translate
|
14
|
+
# and generate .po files for it. This type of files are also more readable and
|
15
|
+
# easier to translate, thanks to it you save your time with translations.
|
16
|
+
#
|
17
|
+
# === Examples
|
18
|
+
#
|
19
|
+
# Now you can write what you want, and at the end of work you
|
20
|
+
# will easy found all phrases to translate. Check out following example:
|
21
|
+
#
|
22
|
+
# %p This is my simple dummy text.
|
23
|
+
# %p And more lorem ipsum...
|
24
|
+
# %p= link_to _("This will be also translated"), "#"
|
25
|
+
#
|
26
|
+
# Those translations are allso allowing you to use standard Haml interpolation.
|
27
|
+
# You can easy write:
|
28
|
+
#
|
29
|
+
# %p This is my text with #{"interpolation".upcase}... Great, isn't it?
|
30
|
+
#
|
31
|
+
# And text from codes above will be stored in .po files as:
|
32
|
+
#
|
33
|
+
# # File test1.haml, line 1
|
34
|
+
# msgid "This is my simple dummy text"
|
35
|
+
# msgstr "This is my dummy translation of dummy text"
|
36
|
+
#
|
37
|
+
# # File test2.haml, line 1
|
38
|
+
# msgid "This is my text with %s... Great, isn't it?"
|
39
|
+
# msgstr "Next one %s translation!"
|
40
|
+
#
|
41
|
+
# Generator for .po files also includes information where your phrases are placed
|
42
|
+
# in filesystem. Thanks to it you don't forget about any even small word to
|
43
|
+
# translate.
|
44
|
+
#
|
45
|
+
module Haml::MagicTranslations
|
46
|
+
# Overriden function that parses Haml tags. Injects gettext call for all plain
|
47
|
+
# text lines.
|
48
|
+
def parse_tag(line)
|
49
|
+
tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
50
|
+
nuke_inner_whitespace, action, value, last_line = super(line)
|
51
|
+
|
52
|
+
magic_translations = self.options[:magic_translations]
|
53
|
+
magic_translations = Haml::Template.options[:magic_translations] if magic_translations.nil?
|
54
|
+
|
55
|
+
if magic_translations
|
56
|
+
unless action && action != '!' || action == '!' && value[0] == '=' || value.empty?
|
57
|
+
value, interpolation_arguments = prepare_i18n_interpolation(value)
|
58
|
+
value = "\#{_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\}\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
[tag_name, attributes, attributes_hashes, object_ref, nuke_outer_whitespace,
|
62
|
+
nuke_inner_whitespace, action, value, last_line]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Magical translations will be also used for plain text.
|
66
|
+
def push_plain(text, options = {})
|
67
|
+
if block_opened?
|
68
|
+
raise SyntaxError.new("Illegal nesting: nesting within plain text is illegal.", @next_line.index)
|
69
|
+
end
|
70
|
+
|
71
|
+
options[:magic_translations] = self.options[:magic_translations] if options[:magic_translations].nil?
|
72
|
+
options[:magic_translations] = Haml::Template.options[:magic_translations] if options[:magic_translations].nil?
|
73
|
+
|
74
|
+
if options[:magic_translations]
|
75
|
+
value, interpolation_arguments = prepare_i18n_interpolation(text,
|
76
|
+
:escape_html => options[:escape_html])
|
77
|
+
value = "_('#{value.gsub(/'/, "\\\\'")}') % #{interpolation_arguments}\n"
|
78
|
+
push_script(value, :escape_html => false)
|
79
|
+
else
|
80
|
+
if contains_interpolation?(text)
|
81
|
+
options[:escape_html] = self.options[:escape_html] if options[:escape_html].nil?
|
82
|
+
push_script(
|
83
|
+
unescape_interpolation(text, :escape_html => options[:escape_html]),
|
84
|
+
:escape_html => false)
|
85
|
+
else
|
86
|
+
push_text text
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# It discovers all fragments of code embeded in text and replacing with
|
92
|
+
# simple string interpolation parameters.
|
93
|
+
#
|
94
|
+
# ==== Example:
|
95
|
+
#
|
96
|
+
# Following line...
|
97
|
+
#
|
98
|
+
# %p This is some #{'Interpolated'.upcase'} text
|
99
|
+
#
|
100
|
+
# ... will be translated to:
|
101
|
+
#
|
102
|
+
# [ "This is some %s text", "['Interpolated'.upcase]" ]
|
103
|
+
#
|
104
|
+
def prepare_i18n_interpolation(str, opts = {})
|
105
|
+
args = []
|
106
|
+
res = ''
|
107
|
+
str = str.
|
108
|
+
gsub(/\n/, '\n').
|
109
|
+
gsub(/\r/, '\r').
|
110
|
+
gsub(/\#/, '\#').
|
111
|
+
gsub(/\"/, '\"').
|
112
|
+
gsub(/\\/, '\\\\')
|
113
|
+
|
114
|
+
rest = Haml::Shared.handle_interpolation '"' + str + '"' do |scan|
|
115
|
+
escapes = (scan[2].size - 1) / 2
|
116
|
+
res << scan.matched[0...-3 - escapes]
|
117
|
+
if escapes % 2 == 1
|
118
|
+
res << '#{'
|
119
|
+
else
|
120
|
+
content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
|
121
|
+
content = "Haml::Helpers.html_escape(#{content.to_s})" if opts[:escape_html]
|
122
|
+
args << content
|
123
|
+
res << '%s'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
value = res+rest.gsub(/\\(.)/, '\1').chomp
|
127
|
+
value = value[1..-2] unless value.blank?
|
128
|
+
args = "[#{args.join(', ')}]"
|
129
|
+
[value, args]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Gettext)
|
134
|
+
Haml::Engine.send(:include, Haml::MagicTranslations)
|
135
|
+
Haml::Helpers.send(:include, I18n::Gettext::Helpers)
|
136
|
+
Haml::Template.options[:magic_translations] = true
|
137
|
+
|
data/spec/locales/en.po
ADDED
data/spec/locales/pl.po
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
msgid "Magic translations works!"
|
3
|
+
msgstr "Magiczne tłumaczenie działa!"
|
4
|
+
|
5
|
+
msgid "Here with interpolation, and everything thanks to %s and %s"
|
6
|
+
msgstr "A tutaj razem z interpolacją, a to wszystko dzięki połączeniu %s i %s"
|
7
|
+
|
8
|
+
msgid "Now we will check multiline strings,"
|
9
|
+
msgstr "Kolejny wieloliniowy tekst,"
|
10
|
+
|
11
|
+
msgid "which should be also translated,"
|
12
|
+
msgstr "który powinien zostać przetłumaczony,"
|
13
|
+
|
14
|
+
msgid "with interpolation %s"
|
15
|
+
msgstr "interpolacja %s też działa!"
|
16
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper.rb')
|
2
|
+
|
3
|
+
def render(text, options = {}, &block)
|
4
|
+
scope = options.delete(:scope) || Object.new
|
5
|
+
locals = options.delete(:locals) || {}
|
6
|
+
Haml::Engine.new(text, options).to_html(scope, locals, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Haml magic translations' do
|
10
|
+
|
11
|
+
it 'should allow to set :magic_translations option in Haml::Template' do
|
12
|
+
Haml::Template.options.key?(:magic_translations).should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should translate text using existing locales' do
|
16
|
+
Haml::Template.options[:magic_translations] = true
|
17
|
+
I18n.locale = :pl
|
18
|
+
<<HTML.should == render(<<HAML)
|
19
|
+
<p>Magiczne tłumaczenie działa!</p>
|
20
|
+
<p>A tutaj razem z interpolacją, a to wszystko dzięki połączeniu I18n i GetText</p>
|
21
|
+
HTML
|
22
|
+
%p Magic translations works!
|
23
|
+
%p Here with interpolation, and everything thanks to \#{I18n.name} and \#{GetText.name}
|
24
|
+
HAML
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should leave text without changes when translation was not found' do
|
28
|
+
Haml::Template.options[:magic_translations] = true
|
29
|
+
I18n.locale = :en
|
30
|
+
<<HTML.should == render(<<HAML)
|
31
|
+
<p>Magic translations works!</p>
|
32
|
+
<p>And this one does not exist</p>
|
33
|
+
<p>Here with interpolation, and everything thanks to I18n and GetText</p>
|
34
|
+
HTML
|
35
|
+
%p Magic translations works!
|
36
|
+
%p And this one does not exist
|
37
|
+
%p Here with interpolation, and everything thanks to \#{I18n.name} and \#{GetText.name}
|
38
|
+
HAML
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should translate text with multiline plain text' do
|
42
|
+
Haml::Template.options[:magic_translations] = true
|
43
|
+
I18n.locale = :pl
|
44
|
+
<<HTML.should == render(<<HAML)
|
45
|
+
<p>Magiczne tłumaczenie działa!</p>
|
46
|
+
<p>
|
47
|
+
Kolejny wieloliniowy tekst,
|
48
|
+
który powinien zostać przetłumaczony,
|
49
|
+
interpolacja INTERPOLATION też działa!
|
50
|
+
</p>
|
51
|
+
HTML
|
52
|
+
%p Magic translations works!
|
53
|
+
%p
|
54
|
+
Now we will check multiline strings,
|
55
|
+
which should be also translated,
|
56
|
+
with interpolation \#{'Interpolation'.upcase}
|
57
|
+
HAML
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should leave text without changes when :magic_translations option is off' do
|
61
|
+
Haml::Template.options[:magic_translations] = false
|
62
|
+
<<HTML.should == render(<<HAML)
|
63
|
+
<p>Text without changes</p>
|
64
|
+
HTML
|
65
|
+
%p Text without changes
|
66
|
+
HAML
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
$:.unshift File.dirname(__FILE__)
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), '../lib')
|
7
|
+
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_view'
|
10
|
+
|
11
|
+
require 'haml/magic_translations'
|
12
|
+
|
13
|
+
Haml::Template.options[:ugly] = false
|
14
|
+
Haml::Template.options[:format] = :xhtml
|
15
|
+
|
16
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Gettext)
|
17
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), "locales/*.{po}")]
|
18
|
+
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haml-magic-translations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kriss Kowalik
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-21 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: haml
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 3.0.0
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: i18n
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 4
|
44
|
+
- 1
|
45
|
+
version: 0.4.1
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: gettext
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
version: 2.0.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: |
|
63
|
+
This plugin provides "magical translations" in your .haml files. What does it
|
64
|
+
mean? It's mean that all your raw texts in templates will be automatically
|
65
|
+
translated by Gettext backend from I18n. No more complicated translation keys
|
66
|
+
and ugly translation methods in views. Now you can only write in your language,
|
67
|
+
nothing more. At the end of your work you can easy find all phrases to translate
|
68
|
+
and generate .po files for it. This type of files are also more readable and
|
69
|
+
easier to translate, thanks to it you save your time with translations.
|
70
|
+
|
71
|
+
email: kriss.kowalik@gmail.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files:
|
77
|
+
- LICENSE
|
78
|
+
- README.rdoc
|
79
|
+
- TODO
|
80
|
+
files:
|
81
|
+
- LICENSE
|
82
|
+
- README.rdoc
|
83
|
+
- Rakefile
|
84
|
+
- TODO
|
85
|
+
- VERSION
|
86
|
+
- haml-magic-translations.gemspec
|
87
|
+
- init.rb
|
88
|
+
- lib/haml-magic-translations.rb
|
89
|
+
- lib/haml/magic_translations.rb
|
90
|
+
- spec/locales/en.po
|
91
|
+
- spec/locales/pl.po
|
92
|
+
- spec/magic_translations_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://github.com/kriss/haml-magic-translations
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options:
|
100
|
+
- --charset=UTF-8
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 1.3.6
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: Provides automaticaly translations in haml templates
|
124
|
+
test_files:
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- spec/magic_translations_spec.rb
|