i18n_screwdriver 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config CHANGED
@@ -1,2 +1,2 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
1
+ --- {}
2
+
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2
data/Gemfile CHANGED
@@ -1,10 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "actionpack", ">= 3.0.0"
4
-
5
- group :development do
6
- gem "shoulda", ">= 0"
7
- gem "bundler", "~> 1.0.0"
8
- gem "jeweler", "~> 1.5.1"
9
- gem "rcov", ">= 0"
10
- end
3
+ # Specify your gem's dependencies in datatrans.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,47 +1,101 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ i18n_screwdriver (0.4.0)
5
+ rails (>= 3.0.0)
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
4
- abstract (1.0.0)
5
- actionpack (3.0.3)
6
- activemodel (= 3.0.3)
7
- activesupport (= 3.0.3)
8
- builder (~> 2.1.2)
9
- erubis (~> 2.6.6)
10
- i18n (~> 0.4)
11
- rack (~> 1.2.1)
12
- rack-mount (~> 0.6.13)
13
- rack-test (~> 0.5.6)
14
- tzinfo (~> 0.3.23)
15
- activemodel (3.0.3)
16
- activesupport (= 3.0.3)
17
- builder (~> 2.1.2)
18
- i18n (~> 0.4)
19
- activesupport (3.0.3)
20
- builder (2.1.2)
21
- erubis (2.6.6)
22
- abstract (>= 1.0.0)
23
- git (1.2.5)
24
- i18n (0.4.2)
25
- jeweler (1.5.1)
26
- bundler (~> 1.0.0)
27
- git (>= 1.2.5)
28
- rake
29
- rack (1.2.1)
30
- rack-mount (0.6.13)
10
+ actionmailer (3.1.1)
11
+ actionpack (= 3.1.1)
12
+ mail (~> 2.3.0)
13
+ actionpack (3.1.1)
14
+ activemodel (= 3.1.1)
15
+ activesupport (= 3.1.1)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.2)
20
+ rack-cache (~> 1.1)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.2)
24
+ activemodel (3.1.1)
25
+ activesupport (= 3.1.1)
26
+ builder (~> 3.0.0)
27
+ i18n (~> 0.6)
28
+ activerecord (3.1.1)
29
+ activemodel (= 3.1.1)
30
+ activesupport (= 3.1.1)
31
+ arel (~> 2.2.1)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.1.1)
34
+ activemodel (= 3.1.1)
35
+ activesupport (= 3.1.1)
36
+ activesupport (3.1.1)
37
+ multi_json (~> 1.0)
38
+ arel (2.2.1)
39
+ builder (3.0.0)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.7.0)
42
+ hike (1.2.1)
43
+ i18n (0.6.0)
44
+ mail (2.3.0)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.16)
49
+ multi_json (1.0.3)
50
+ polyglot (0.3.2)
51
+ rack (1.3.4)
52
+ rack-cache (1.1)
53
+ rack (>= 0.4)
54
+ rack-mount (0.8.3)
31
55
  rack (>= 1.0.0)
32
- rack-test (0.5.6)
56
+ rack-ssl (1.3.2)
57
+ rack
58
+ rack-test (0.6.1)
33
59
  rack (>= 1.0)
34
- rake (0.8.7)
35
- rcov (0.9.9)
36
- shoulda (2.11.3)
37
- tzinfo (0.3.23)
60
+ rails (3.1.1)
61
+ actionmailer (= 3.1.1)
62
+ actionpack (= 3.1.1)
63
+ activerecord (= 3.1.1)
64
+ activeresource (= 3.1.1)
65
+ activesupport (= 3.1.1)
66
+ bundler (~> 1.0)
67
+ railties (= 3.1.1)
68
+ railties (3.1.1)
69
+ actionpack (= 3.1.1)
70
+ activesupport (= 3.1.1)
71
+ rack-ssl (~> 1.3.2)
72
+ rake (>= 0.8.7)
73
+ rdoc (~> 3.4)
74
+ thor (~> 0.14.6)
75
+ rake (0.9.2)
76
+ rdoc (3.9.4)
77
+ rspec (2.6.0)
78
+ rspec-core (~> 2.6.0)
79
+ rspec-expectations (~> 2.6.0)
80
+ rspec-mocks (~> 2.6.0)
81
+ rspec-core (2.6.4)
82
+ rspec-expectations (2.6.0)
83
+ diff-lcs (~> 1.1.2)
84
+ rspec-mocks (2.6.0)
85
+ sprockets (2.0.2)
86
+ hike (~> 1.2)
87
+ rack (~> 1.0)
88
+ tilt (!= 1.3.0, ~> 1.1)
89
+ thor (0.14.6)
90
+ tilt (1.3.3)
91
+ treetop (1.4.10)
92
+ polyglot
93
+ polyglot (>= 0.3.1)
94
+ tzinfo (0.3.30)
38
95
 
39
96
  PLATFORMS
40
97
  ruby
41
98
 
42
99
  DEPENDENCIES
43
- actionpack (>= 3.0.0)
44
- bundler (~> 1.0.0)
45
- jeweler (~> 1.5.1)
46
- rcov
47
- shoulda
100
+ i18n_screwdriver!
101
+ rspec
data/README.rdoc CHANGED
@@ -20,8 +20,8 @@ Then run the generator that copies the translation rake task to your application
20
20
 
21
21
  Set these constants to make i18n screwdriver aware of the languages you are using
22
22
 
23
- APPLICATION_LANGUAGES = ['de', 'en, 'fr', 'it']
24
23
  DEFAULT_LANGUAGE = 'de'
24
+ FOREIGN_LANGUAGES = ['en, 'fr', 'it']
25
25
 
26
26
  In your views, helpers and controllers use the convenient underscore helper method for all your translations
27
27
 
@@ -41,9 +41,8 @@ It gets recreated everytime you run the tasks - edit those translations in your
41
41
 
42
42
  == Next steps
43
43
 
44
- * fix drawback that multiple translations on the same name are currently not recognized, happens very well with options for select tags
44
+ * fix drawback that multiple translations on the same line are currently not recognized, happens very well with options for select tags
45
45
  * also recognize model validation error messages
46
- * DRY the code
47
46
  * test more
48
47
  * use ruby_parser instead of regex
49
48
  * support interpolation like "my name is #{user.full_name} and I am living in #{user.location}"
@@ -60,4 +59,4 @@ It gets recreated everytime you run the tasks - edit those translations in your
60
59
 
61
60
  == Copyright
62
61
 
63
- Copyright (c) 2010 Tobias Miesel. Released unter the MIT license.
62
+ Copyright (c) 2010-2011 Tobias Miesel. Released unter the MIT license.
data/Rakefile CHANGED
@@ -1,46 +1 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "i18n_screwdriver"
8
- gem.homepage = "http://github.com/agileapplications/i18n_screwdriver"
9
- gem.license = "MIT"
10
- gem.summary = %Q{make translating with rails i18n fun again}
11
- gem.email = "agileapplications@gmail.com"
12
- gem.authors = ["Tobias Miesel"]
13
- gem.add_development_dependency "shoulda", ">= 0"
14
- gem.add_dependency "actionpack", ">= 3.0.0"
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
27
-
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- task :test => :check_dependencies
36
- task :default => :test
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "i18n_screwdriver #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
1
+ require 'bundler/gem_tasks'
@@ -1,72 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{i18n_screwdriver}
8
- s.version = "0.3.0"
5
+ s.name = "i18n_screwdriver"
6
+ s.version = "0.4.0"
7
+ s.authors = ["Tobias Miesel"]
8
+ s.email = ["agileapplications@gmail.com"]
9
+ s.homepage = "http://github.com/agileapplications/i18n_screwdriver"
10
+ s.summary = %q{make translating with rails i18n fun again}
11
+ s.description = %q{make translating with rails i18n fun again}
9
12
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Tobias Miesel"]
12
- s.date = %q{2010-11-23}
13
- s.email = %q{agileapplications@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README.rdoc"
16
- ]
17
- s.files = [
18
- ".bundle/config",
19
- "Gemfile",
20
- "Gemfile.lock",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "i18n_screwdriver.gemspec",
25
- "lib/generators/screwdriver_generator.rb",
26
- "lib/i18n_screwdriver.rb",
27
- "lib/tasks/i18n.rake",
28
- "test/helper.rb",
29
- "test/test_i18n_screwdriver.rb"
30
- ]
31
- s.homepage = %q{http://github.com/agileapplications/i18n_screwdriver}
32
- s.licenses = ["MIT"]
33
- s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{make translating with rails i18n fun again}
36
- s.test_files = [
37
- "test/helper.rb",
38
- "test/test_i18n_screwdriver.rb"
39
- ]
40
-
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
13
+ s.rubyforge_project = "i18n_screwdriver"
44
14
 
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
47
- s.add_development_dependency(%q<shoulda>, [">= 0"])
48
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
50
- s.add_development_dependency(%q<rcov>, [">= 0"])
51
- s.add_development_dependency(%q<shoulda>, [">= 0"])
52
- s.add_runtime_dependency(%q<actionpack>, [">= 3.0.0"])
53
- else
54
- s.add_dependency(%q<actionpack>, [">= 3.0.0"])
55
- s.add_dependency(%q<shoulda>, [">= 0"])
56
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
58
- s.add_dependency(%q<rcov>, [">= 0"])
59
- s.add_dependency(%q<shoulda>, [">= 0"])
60
- s.add_dependency(%q<actionpack>, [">= 3.0.0"])
61
- end
62
- else
63
- s.add_dependency(%q<actionpack>, [">= 3.0.0"])
64
- s.add_dependency(%q<shoulda>, [">= 0"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
67
- s.add_dependency(%q<rcov>, [">= 0"])
68
- s.add_dependency(%q<shoulda>, [">= 0"])
69
- s.add_dependency(%q<actionpack>, [">= 3.0.0"])
70
- end
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'rails', '>= 3.0.0'
21
+ s.add_development_dependency 'rspec'
71
22
  end
72
-
@@ -0,0 +1,119 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Screwdriver
5
+ class Scanner
6
+
7
+ PATH_TO_LOCALES = "config/locales/"
8
+ LOCALE_PREFIX = "application"
9
+
10
+ def initialize
11
+ raise "ERROR: FOREIGN_LANGUAGES is not defined" unless defined? FOREIGN_LANGUAGES
12
+ raise "ERROR: DEFAULT_LANGUAGE is not defined" unless defined? DEFAULT_LANGUAGE
13
+
14
+ @translations = {}
15
+ end
16
+
17
+ def run
18
+ scan_files
19
+ write_translation_file(@translations, DEFAULT_LANGUAGE)
20
+
21
+ FOREIGN_LANGUAGES.each do |language|
22
+ update_translations(language)
23
+ end
24
+
25
+ puts "#{@translations.keys.length} unique translations found"
26
+ end
27
+
28
+ def translate(language)
29
+ file_name = PATH_TO_LOCALES + LOCALE_PREFIX + ".#{language}.yml"
30
+ raise "File #{file_name} not found!" unless File.exists?(file_name)
31
+ existing_translations = YAML.load_file(file_name)[language]
32
+
33
+ existing_translations.each do |key, translation|
34
+ if translation.length == 0
35
+ puts "> #{key}"
36
+ input = STDIN.gets.chomp
37
+ if input == ":q"
38
+ break
39
+ else
40
+ existing_translations[key] = input
41
+ end
42
+ end
43
+ end
44
+
45
+ write_translation_file(existing_translations, language)
46
+ end
47
+
48
+
49
+ private
50
+
51
+ def update_translations(language)
52
+ existing_translations = {}
53
+ file_name = PATH_TO_LOCALES + LOCALE_PREFIX + ".#{language}.yml"
54
+ existing_translations = YAML.load_file(file_name) if File.exists?(file_name)
55
+
56
+ syncronize_translations(existing_translations)
57
+ write_translation_file(existing_translations, language)
58
+ end
59
+
60
+ def syncronize_translations(existing_translations)
61
+ @translations.each_key do |key|
62
+ existing_translations[key] = "" unless existing_translations.has_key?(key)
63
+ end
64
+ existing_translations
65
+ end
66
+
67
+ def scan_files
68
+ Dir.glob("**/*.{haml,erb,slim,rb}").each do |file_name|
69
+ scan_file(file_name)
70
+ end
71
+ end
72
+
73
+ def scan_file(file_name)
74
+ File.open(file_name) do |file|
75
+ file.each do |line|
76
+ @translations.merge!(extract_translation(line))
77
+ end
78
+ end
79
+ end
80
+
81
+ def extract_translation(line)
82
+ {}.tap do |hash|
83
+ if line =~ /_\("([^"]+)"\)/
84
+ hash[translation_to_key($1)] = $1
85
+ elsif line =~ /_\('([^']+)'\)/
86
+ hash[translation_to_key($1)] = $1
87
+ end
88
+ end
89
+ end
90
+
91
+ def sorted_translations(translations)
92
+ translations.keys.sort do |a, b|
93
+ a.downcase <=> b.downcase
94
+ end.each do |key|
95
+ yield key, translations[key]
96
+ end
97
+ end
98
+
99
+ def translation_to_key(translation)
100
+ translation.gsub(/\./, '')
101
+ end
102
+
103
+ def remove_translation(key)
104
+ @translations.delete(key) #unless translations.has_key?(key)
105
+ end
106
+
107
+ def write_translation_file(translations, language)
108
+ File.open("config/locales/application.#{language}.yml", "w") do |file|
109
+ file.puts "# use rake task i18n:update to update this file"
110
+ file.puts
111
+ file.puts "\"#{language}\":"
112
+ sorted_translations(translations) do |key, translation|
113
+ file.puts " \"#{key}\": \"#{translation}\""
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -1,3 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require 'action_view'
4
+ require 'action_controller'
5
+ require 'i18n/screwdriver/scanner'
6
+
1
7
  module I18n
2
8
  module Screwdriver
3
9
  def self.included(klass)
@@ -8,7 +14,14 @@ module I18n
8
14
  def _(translation)
9
15
  # the . is a special character in rails i18n - we have to strip it
10
16
  translation_without_dot = translation.gsub(/\./, '').strip
11
- t("#{translation_without_dot}")
17
+ translated = I18n.translate(translation_without_dot)
18
+
19
+ if defined?(Rails) && Rails.env.development? && translated.start_with?('translation missing')
20
+ # TODO: add translation with key to all translation files
21
+ # so that rake task is obsolete - instant feedback!
22
+ end
23
+
24
+ translated
12
25
  end
13
26
  end
14
27
  end
@@ -16,3 +29,5 @@ end
16
29
 
17
30
  ActionView::Base.send :include, I18n::Screwdriver
18
31
  ActionController::Base.send :include, I18n::Screwdriver
32
+ ActionController::IntegrationTest.send :include, I18n::Screwdriver
33
+ ActionController::TestCase.send :include, I18n::Screwdriver
data/lib/tasks/i18n.rake CHANGED
@@ -1,101 +1,14 @@
1
1
  namespace :i18n do
2
- desc 'find all translations in views, helpers and controllers'
2
+ desc 'update translation files'
3
3
  task :update => :environment do
4
-
5
- translations = {}
6
- raise "ERROR: APPLICATION_LANGUAGES = ['de', 'en', ...] is not defined - define it in your initializers" unless defined? APPLICATION_LANGUAGES
7
- raise "ERROR: DEFAULT_LANGUAGE = '??' is not defined - define it in your initializers" unless defined? DEFAULT_LANGUAGE
8
-
9
- # parse all view files for translations - removed ones get removed from
10
- # the i18n translation yml's automatically
11
- Dir.glob("**/*.{haml,erb}").each do |file|
12
- scan_for_translations(file, translations)
13
- end
14
-
15
- # also check helper files and controllers
16
- Dir.glob("**/*{_helper,_controller}.rb").each do |file|
17
- scan_for_translations(file, translations)
18
- end
19
-
20
- # rewrite default language file with updated translations
21
- puts "found #{translations.keys.size} unique translations"
22
- write_translation_file(DEFAULT_LANGUAGE, translations)
23
-
24
- # write a file for each foreign language
25
- (APPLICATION_LANGUAGES - [DEFAULT_LANGUAGE]).each do |language|
26
- # load foreign language file in temp hash
27
- if File.exists?("config/locales/application.#{language}.yml")
28
- existing_translations = YAML.load_file("config/locales/application.#{language}.yml")
29
- existing_translations = existing_translations[language]
30
- else
31
- existing_translations = { language => {} }
32
- end
33
-
34
- # delete removed translations from hash
35
- existing_translations.each_key do |key|
36
- existing_translations.delete(key) unless translations.has_key?(key)
37
- end
38
-
39
- # add new keys with empty translation to hash
40
- translations.each_key do |key|
41
- existing_translations[key] = "TRANSLATION_MISSING" unless existing_translations.has_key?(key)
42
- end
43
- write_translation_file(language, existing_translations)
44
- end
4
+ I18n::Screwdriver::Scanner.new.run
45
5
  end
46
-
6
+
47
7
  desc 'translate foreign language file line by line'
48
8
  task :translate => :environment do
49
- raise "ERROR: usage: TRANSLATE=de rake i18n:translate" unless ENV['TRANSLATE']
50
- language = ENV['TRANSLATE']
51
- if File.exists?("config/locales/application.#{language}.yml")
52
- existing_translations = YAML.load_file("config/locales/application.#{language}.yml")
53
- existing_translations = existing_translations[language]
54
- puts "Translating #{existing_translations.keys.size} entries to <#{language}> (enter :q to save and quit):"
55
- existing_translations.keys.sort.each do |key|
56
- if ["TRANSLATION_MISSING", ""].include?(existing_translations[key])
57
- puts "> #{key}"
58
- input = STDIN.gets.chomp
59
- if input == ":q"
60
- break
61
- else
62
- existing_translations[key] = input
63
- end
64
- end
65
- end
66
-
67
- puts "Schreiben der Datei config/locales/application.#{language}.yml"
68
- write_translation_file(language, existing_translations)
69
- else
70
- puts "ERROR: No translation file in config/locales/application.#{language}.yml"
71
- puts "Choosen language is invalid or you did not run rake i18n:update yet"
72
- end
73
- end
74
-
75
- def write_translation_file(language, translations)
76
- file = File.open("config/locales/application.#{language}.yml", "w")
77
- file.puts "# use rake task i18n:update to generate this file"
78
- file.puts
79
- file.puts "\"#{language}\":"
80
- translations.keys.sort do |a, b|
81
- a.downcase <=> b.downcase
82
- end.each do |key|
83
- file.puts " \"#{key}\": \"#{translations[key]}\""
84
- end
85
- file.close
86
- end
87
-
88
- def scan_for_translations(file, translations)
89
- File.open(file) do |io|
90
- io.each do |line|
91
- if line =~ /_\("([^"]+)"\)/
92
- value = $1
93
- translations[$1.gsub(/\./, '').strip] = value.strip
94
- elsif line =~ /_\('([^']+)'\)/
95
- value = $1
96
- translations[$1.gsub(/\./, '').strip] = value.strip
97
- end
98
- end
99
- end
9
+ language = ENV['TRANSLATE'] || FOREIGN_LANGUAGES.first
10
+ raise "ERROR: usage: TRANSLATE=de rake i18n:translate" unless language
11
+
12
+ I18n::Screwdriver::Scanner.new.translate(language)
100
13
  end
101
14
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe I18n::Screwdriver do
4
+
5
+ describe "translation helper" do
6
+ it "removes dots from translation string" do
7
+ _("my.new.translation").should == "translation missing: en.mynewtranslation"
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe I18n::Screwdriver::Scanner do
4
+
5
+ before do
6
+ @scanner = I18n::Screwdriver::Scanner.new
7
+ end
8
+
9
+ describe "extract_translation" do
10
+ it "returns an empty hash when no translation was found" do
11
+ @scanner.send(:extract_translation, 'hello world').should == {}
12
+ end
13
+
14
+ it "returns a filled hash when translation was found" do
15
+ @scanner.send(:extract_translation, '_("hello world")').should == {
16
+ 'hello world' => 'hello world'
17
+ }
18
+
19
+ @scanner.send(:extract_translation, '_("Going out today.")').should == {
20
+ 'Going out today' => 'Going out today.'
21
+ }
22
+
23
+ @scanner.send(:extract_translation, '_(".a.b.c.d.e")').should == {
24
+ 'abcde' => '.a.b.c.d.e'
25
+ }
26
+ end
27
+ end
28
+
29
+ describe "translation_to_key" do
30
+ it "removes all dots" do
31
+ @scanner.send(:translation_to_key, 'Good morning.').should == 'Good morning'
32
+ end
33
+ end
34
+
35
+ describe "sorted_translations" do
36
+ it "returns all translations sorted" do
37
+ #@scanner.send(:sorted_translations) do |key, translation|
38
+ # puts " \"#{key}\": \"#{translation}\""
39
+ #end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'i18n_screwdriver'
5
+
6
+ DEFAULT_LANGUAGE = 'de'
7
+ FOREIGN_LANGUAGES = ['en']
8
+
9
+ RSpec.configure do |config|
10
+
11
+ config.include I18n::Screwdriver
12
+
13
+ end
metadata CHANGED
@@ -1,184 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: i18n_screwdriver
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tobias Miesel
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-11-23 00:00:00 +01:00
12
+ date: 2011-10-12 00:00:00.000000000 +02:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- type: :runtime
23
- prerelease: false
24
- name: actionpack
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &70219571521460 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 7
31
- segments:
32
- - 3
33
- - 0
34
- - 0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
35
22
  version: 3.0.0
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- type: :development
39
- prerelease: false
40
- name: shoulda
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
52
- type: :development
53
- prerelease: false
54
- name: bundler
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
58
- - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 23
61
- segments:
62
- - 1
63
- - 0
64
- - 0
65
- version: 1.0.0
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
- type: :development
69
- prerelease: false
70
- name: jeweler
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ~>
75
- - !ruby/object:Gem::Version
76
- hash: 1
77
- segments:
78
- - 1
79
- - 5
80
- - 1
81
- version: 1.5.1
82
- requirement: *id004
83
- - !ruby/object:Gem::Dependency
84
- type: :development
23
+ type: :runtime
85
24
  prerelease: false
86
- name: rcov
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
25
+ version_requirements: *70219571521460
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &70219571520880 !ruby/object:Gem::Requirement
88
29
  none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
96
- requirement: *id005
97
- - !ruby/object:Gem::Dependency
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
98
34
  type: :development
99
35
  prerelease: false
100
- name: shoulda
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
102
- none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
108
- - 0
109
- version: "0"
110
- requirement: *id006
111
- - !ruby/object:Gem::Dependency
112
- type: :runtime
113
- prerelease: false
114
- name: actionpack
115
- version_requirements: &id007 !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 7
121
- segments:
122
- - 3
123
- - 0
124
- - 0
125
- version: 3.0.0
126
- requirement: *id007
127
- description:
128
- email: agileapplications@gmail.com
36
+ version_requirements: *70219571520880
37
+ description: make translating with rails i18n fun again
38
+ email:
39
+ - agileapplications@gmail.com
129
40
  executables: []
130
-
131
41
  extensions: []
132
-
133
- extra_rdoc_files:
134
- - README.rdoc
135
- files:
42
+ extra_rdoc_files: []
43
+ files:
136
44
  - .bundle/config
45
+ - .gitignore
46
+ - .rvmrc
137
47
  - Gemfile
138
48
  - Gemfile.lock
139
49
  - README.rdoc
140
50
  - Rakefile
141
- - VERSION
142
51
  - i18n_screwdriver.gemspec
143
52
  - lib/generators/screwdriver_generator.rb
53
+ - lib/i18n/screwdriver/scanner.rb
144
54
  - lib/i18n_screwdriver.rb
145
55
  - lib/tasks/i18n.rake
146
- - test/helper.rb
147
- - test/test_i18n_screwdriver.rb
56
+ - spec/libraries/i18n_screwdriver_spec.rb
57
+ - spec/libraries/scanner_spec.rb
58
+ - spec/spec_helper.rb
148
59
  has_rdoc: true
149
60
  homepage: http://github.com/agileapplications/i18n_screwdriver
150
- licenses:
151
- - MIT
61
+ licenses: []
152
62
  post_install_message:
153
63
  rdoc_options: []
154
-
155
- require_paths:
64
+ require_paths:
156
65
  - lib
157
- required_ruby_version: !ruby/object:Gem::Requirement
66
+ required_ruby_version: !ruby/object:Gem::Requirement
158
67
  none: false
159
- requirements:
160
- - - ">="
161
- - !ruby/object:Gem::Version
162
- hash: 3
163
- segments:
164
- - 0
165
- version: "0"
166
- required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
73
  none: false
168
- requirements:
169
- - - ">="
170
- - !ruby/object:Gem::Version
171
- hash: 3
172
- segments:
173
- - 0
174
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
175
78
  requirements: []
176
-
177
- rubyforge_project:
178
- rubygems_version: 1.3.7
79
+ rubyforge_project: i18n_screwdriver
80
+ rubygems_version: 1.6.2
179
81
  signing_key:
180
82
  specification_version: 3
181
83
  summary: make translating with rails i18n fun again
182
- test_files:
183
- - test/helper.rb
184
- - test/test_i18n_screwdriver.rb
84
+ test_files:
85
+ - spec/libraries/i18n_screwdriver_spec.rb
86
+ - spec/libraries/scanner_spec.rb
87
+ - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.0
data/test/helper.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
- require 'action_controller'
13
- require 'action_view'
14
-
15
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
- $LOAD_PATH.unshift(File.dirname(__FILE__))
17
- require 'i18n_screwdriver'
18
-
19
- class Test::Unit::TestCase
20
- include I18n::Screwdriver
21
- include ActionView::Helpers
22
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestI18nScrewdriver < Test::Unit::TestCase
4
- should "remove dots from translation string" do
5
- assert_equal "<span class=\"translation_missing\">en, mynewtranslation</span>", _("my.new.translation")
6
- end
7
- end