threedaymonk-l10nizer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -37,7 +37,7 @@ spec = Gem::Specification.new do |s|
37
37
  s.add_dependency("treetop", "~> 1.2.6")
38
38
  s.add_dependency("polyglot", "~> 0.2.5")
39
39
 
40
- s.add_development_dependency("shoulda")
40
+ s.add_development_dependency("thoughtbot-shoulda")
41
41
  end
42
42
 
43
43
  Rake::GemPackageTask.new(spec) do |pkg|
data/bin/l10nizer CHANGED
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "l10nizer"
3
3
  require "yaml"
4
+ require "fileutils"
5
+
6
+ Dir.chdir(ARGV.first) if ARGV.first
7
+ templates = Dir["app/views/**/*.html.erb"]
8
+ raise "Can't find any templates in app/views." unless templates.any?
4
9
 
5
10
  keygen = L10nizer::KeyGenerator.new
6
11
  l10ns = {}
7
12
 
8
- templates = Dir["app/views/**/*.html.erb"]
9
13
  templates.each do |path|
10
- keygen.namespace = path.split("/")[2 .. -2] * "_"
14
+ keygen.namespace = path.split("/")[2]
11
15
  source = File.read(path)
12
16
  l10nizer = L10nizer::Processor.new(source, keygen)
13
17
  l10ns.merge!(l10nizer.l10ns)
@@ -16,6 +20,13 @@ templates.each do |path|
16
20
  end
17
21
  end
18
22
 
23
+ l10ns = l10ns.inject({}){ |hash, (key, value)|
24
+ parts = key.split(".")
25
+ parts[0 .. -2].inject(hash){ |h, k| h[k] ||= {} }[parts.last] = value
26
+ hash
27
+ }
28
+
29
+ FileUtils.mkdir_p("config/locales")
19
30
  File.open("config/locales/l10nized.yml", "w") do |f|
20
31
  f << l10ns.to_yaml
21
32
  end
@@ -16,7 +16,7 @@ grammar HtmlErb
16
16
  end
17
17
 
18
18
  rule tag
19
- "<" (erb_eval / [^>])+ ">"
19
+ "<" (erb_control / erb_eval / [^>])+ ">"
20
20
  end
21
21
 
22
22
  rule whitespace
@@ -27,7 +27,9 @@ module L10nizer
27
27
 
28
28
  def make_safe(string)
29
29
  return nil if string.nil?
30
- string.downcase.gsub(/[^a-z0-9]+/, "_").gsub(/^_|_$/, "")[0, 40]
30
+ safe = string.downcase.gsub(/[^a-z0-9]+/, "_").gsub(/^_|_$/, "")[0, 40]
31
+ safe = "unknown" if safe.empty?
32
+ safe
31
33
  end
32
34
  end
33
35
  end
@@ -2,7 +2,7 @@ module L10nizer #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -30,6 +30,10 @@ class KeyGeneratorTest < Test::Unit::TestCase
30
30
  assert_equal "a_thing_1", @keygen.call("A thing")
31
31
  assert_equal "a_thing_2", @keygen.call("A Thing")
32
32
  end
33
+
34
+ should "generate_non_empty_keys_for_punctuation" do
35
+ assert_not_equal "", @keygen.call("<>!@#%#.,")
36
+ end
33
37
  end
34
38
 
35
39
  context "with namespacing" do
@@ -81,6 +81,12 @@ class ProcessorTest < Test::Unit::TestCase
81
81
  assert_equal html, l10nizer.reformed
82
82
  end
83
83
 
84
+ should "not try to localise control inside a tag" do
85
+ html = %{<div class="user-skills block <% unless @user.skills.any? %>blank<% end %>">}
86
+ l10nizer = L10nizer::Processor.new(html, DumbKeyGenerator.new)
87
+ assert_equal html, l10nizer.reformed
88
+ end
89
+
84
90
  context "when parsing a sample document" do
85
91
  setup do
86
92
  @html = File.read(File.join(File.dirname(__FILE__), "samples", "input.html.erb"))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threedaymonk-l10nizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-10 00:00:00 -07:00
12
+ date: 2009-07-12 00:00:00 -07:00
13
13
  default_executable: l10nizer
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 0.2.5
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
- name: shoulda
36
+ name: thoughtbot-shoulda
37
37
  type: :development
38
38
  version_requirement:
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.2.0
92
92
  signing_key:
93
- specification_version: 3
93
+ specification_version: 2
94
94
  summary: Automatically extract strings from ERB templates and replace with calls to t()
95
95
  test_files: []
96
96