i18n_screwdriver 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.bundle/config +2 -2
- data/Gemfile +8 -2
- data/Gemfile.lock +37 -91
- data/README.rdoc +12 -6
- data/Rakefile +46 -1
- data/VERSION +1 -0
- data/i18n_screwdriver.gemspec +66 -16
- data/lib/i18n_screwdriver.rb +1 -14
- data/lib/tasks/i18n.rake +93 -7
- data/test/helper.rb +22 -0
- data/test/test_i18n_screwdriver.rb +7 -0
- metadata +149 -52
- data/.gitignore +0 -21
- data/.rvmrc +0 -1
- data/lib/i18n/screwdriver/scanner.rb +0 -119
- data/spec/libraries/i18n_screwdriver_spec.rb +0 -11
- data/spec/libraries/scanner_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -13
data/.bundle/config
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
---
|
2
|
-
|
1
|
+
---
|
2
|
+
BUNDLE_DISABLE_SHARED_GEMS: "1"
|
data/Gemfile
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
|
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
|
data/Gemfile.lock
CHANGED
@@ -1,101 +1,47 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
i18n_screwdriver (0.4.0)
|
5
|
-
rails (>= 3.0.0)
|
6
|
-
|
7
1
|
GEM
|
8
2
|
remote: http://rubygems.org/
|
9
3
|
specs:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rack (~>
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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)
|
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)
|
55
31
|
rack (>= 1.0.0)
|
56
|
-
rack-
|
57
|
-
rack
|
58
|
-
rack-test (0.6.1)
|
32
|
+
rack-test (0.5.6)
|
59
33
|
rack (>= 1.0)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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)
|
34
|
+
rake (0.8.7)
|
35
|
+
rcov (0.9.9)
|
36
|
+
shoulda (2.11.3)
|
37
|
+
tzinfo (0.3.23)
|
95
38
|
|
96
39
|
PLATFORMS
|
97
40
|
ruby
|
98
41
|
|
99
42
|
DEPENDENCIES
|
100
|
-
|
101
|
-
|
43
|
+
actionpack (>= 3.0.0)
|
44
|
+
bundler (~> 1.0.0)
|
45
|
+
jeweler (~> 1.5.1)
|
46
|
+
rcov
|
47
|
+
shoulda
|
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
|
-
|
24
|
-
|
23
|
+
APPLICATION_LANGUAGES = [['Deutsch', 'de'], ['English', 'en'], ...]
|
24
|
+
DEFAULT_LANGUAGE = ['Deutsch', 'de']
|
25
25
|
|
26
26
|
In your views, helpers and controllers use the convenient underscore helper method for all your translations
|
27
27
|
|
@@ -33,17 +33,23 @@ for each of your APPLICATION_LANGUAGES.
|
|
33
33
|
|
34
34
|
rake i18n:update
|
35
35
|
|
36
|
-
The
|
36
|
+
The second one lets you translate your application.<lang>.yml file line by line. Of course
|
37
37
|
you can edit the application.<lang>.yml file itself - but dont do that for your default language file.
|
38
38
|
It gets recreated everytime you run the tasks - edit those translations in your views e.g. itself.
|
39
39
|
|
40
40
|
TRANSLATE=en rake i18n:translate
|
41
41
|
|
42
|
+
== Test Helpers
|
43
|
+
|
44
|
+
In your tests (functionals and integration) you can use the same translation helper
|
45
|
+
|
46
|
+
_("your translation")
|
47
|
+
|
42
48
|
== Next steps
|
43
49
|
|
44
|
-
* fix drawback that multiple translations on the same line are currently not recognized, happens very well with options for select tags
|
45
50
|
* also recognize model validation error messages
|
46
|
-
*
|
51
|
+
* DRY the code
|
52
|
+
* test more (= test at all)
|
47
53
|
* use ruby_parser instead of regex
|
48
54
|
* support interpolation like "my name is #{user.full_name} and I am living in #{user.location}"
|
49
55
|
|
@@ -59,4 +65,4 @@ It gets recreated everytime you run the tasks - edit those translations in your
|
|
59
65
|
|
60
66
|
== Copyright
|
61
67
|
|
62
|
-
Copyright (c) 2010
|
68
|
+
Copyright (c) 2010 Tobias Miesel. Released unter the MIT license.
|
data/Rakefile
CHANGED
@@ -1 +1,46 @@
|
|
1
|
-
require '
|
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
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/i18n_screwdriver.gemspec
CHANGED
@@ -1,22 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
5
|
|
4
6
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
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}
|
7
|
+
s.name = %q{i18n_screwdriver}
|
8
|
+
s.version = "0.5.0"
|
12
9
|
|
13
|
-
s.
|
14
|
-
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
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"]
|
18
33
|
s.require_paths = ["lib"]
|
19
|
-
|
20
|
-
s.
|
21
|
-
s.
|
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
|
44
|
+
|
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
|
22
71
|
end
|
72
|
+
|
data/lib/i18n_screwdriver.rb
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'action_view'
|
4
|
-
require 'action_controller'
|
5
|
-
require 'i18n/screwdriver/scanner'
|
6
|
-
|
7
1
|
module I18n
|
8
2
|
module Screwdriver
|
9
3
|
def self.included(klass)
|
@@ -14,14 +8,7 @@ module I18n
|
|
14
8
|
def _(translation)
|
15
9
|
# the . is a special character in rails i18n - we have to strip it
|
16
10
|
translation_without_dot = translation.gsub(/\./, '').strip
|
17
|
-
|
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
|
11
|
+
I18n.translate("#{translation_without_dot}")
|
25
12
|
end
|
26
13
|
end
|
27
14
|
end
|
data/lib/tasks/i18n.rake
CHANGED
@@ -1,14 +1,100 @@
|
|
1
1
|
namespace :i18n do
|
2
|
-
desc '
|
2
|
+
desc 'find all translations in views, helpers and controllers'
|
3
3
|
task :update => :environment do
|
4
|
-
|
4
|
+
|
5
|
+
translations = {}
|
6
|
+
raise "ERROR: APPLICATION_LANGUAGES = [['Deutsch', 'de'], ['English', 'en'], ...] is not defined - define it in your initializers" unless defined? APPLICATION_LANGUAGES
|
7
|
+
raise "ERROR: DEFAULT_LANGUAGE = ['Deutsch', 'de'] e.g. 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[1], 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[1]}.yml")
|
28
|
+
existing_translations = YAML.load_file("config/locales/application.#{language[1]}.yml")
|
29
|
+
existing_translations = existing_translations[language[1]]
|
30
|
+
else
|
31
|
+
existing_translations = { language[1] => {} }
|
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[1], existing_translations)
|
44
|
+
end
|
5
45
|
end
|
6
|
-
|
46
|
+
|
7
47
|
desc 'translate foreign language file line by line'
|
8
48
|
task :translate => :environment do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
+
line.scan(/_\("([^"]+)"\)/) do |match|
|
92
|
+
translations[match.first.gsub(/\./, '').strip] = match.first.strip
|
93
|
+
end
|
94
|
+
line.scan(/_\('([^']+)'\)/) do |match|
|
95
|
+
translations[match.first.gsub(/\./, '').strip] = match.first.strip
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
13
99
|
end
|
14
100
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
metadata
CHANGED
@@ -1,87 +1,184 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_screwdriver
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Tobias Miesel
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
17
|
+
|
18
|
+
date: 2010-11-23 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
|
17
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
name: actionpack
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
18
26
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 7
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 0
|
22
35
|
version: 3.0.0
|
23
|
-
|
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
|
24
69
|
prerelease: false
|
25
|
-
|
26
|
-
|
27
|
-
name: rspec
|
28
|
-
requirement: &70219571520880 !ruby/object:Gem::Requirement
|
70
|
+
name: jeweler
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
29
72
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
|
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
|
34
84
|
type: :development
|
35
85
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
86
|
+
name: rcov
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
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
|
98
|
+
type: :development
|
99
|
+
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
|
40
129
|
executables: []
|
130
|
+
|
41
131
|
extensions: []
|
42
|
-
|
43
|
-
|
132
|
+
|
133
|
+
extra_rdoc_files:
|
134
|
+
- README.rdoc
|
135
|
+
files:
|
44
136
|
- .bundle/config
|
45
|
-
- .gitignore
|
46
|
-
- .rvmrc
|
47
137
|
- Gemfile
|
48
138
|
- Gemfile.lock
|
49
139
|
- README.rdoc
|
50
140
|
- Rakefile
|
141
|
+
- VERSION
|
51
142
|
- i18n_screwdriver.gemspec
|
52
143
|
- lib/generators/screwdriver_generator.rb
|
53
|
-
- lib/i18n/screwdriver/scanner.rb
|
54
144
|
- lib/i18n_screwdriver.rb
|
55
145
|
- lib/tasks/i18n.rake
|
56
|
-
-
|
57
|
-
-
|
58
|
-
- spec/spec_helper.rb
|
146
|
+
- test/helper.rb
|
147
|
+
- test/test_i18n_screwdriver.rb
|
59
148
|
has_rdoc: true
|
60
149
|
homepage: http://github.com/agileapplications/i18n_screwdriver
|
61
|
-
licenses:
|
150
|
+
licenses:
|
151
|
+
- MIT
|
62
152
|
post_install_message:
|
63
153
|
rdoc_options: []
|
64
|
-
|
154
|
+
|
155
|
+
require_paths:
|
65
156
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
158
|
none: false
|
68
|
-
requirements:
|
69
|
-
- -
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
72
|
-
|
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
|
73
167
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
hash: 3
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
78
175
|
requirements: []
|
79
|
-
|
80
|
-
|
176
|
+
|
177
|
+
rubyforge_project:
|
178
|
+
rubygems_version: 1.3.7
|
81
179
|
signing_key:
|
82
180
|
specification_version: 3
|
83
181
|
summary: make translating with rails i18n fun again
|
84
|
-
test_files:
|
85
|
-
-
|
86
|
-
-
|
87
|
-
- spec/spec_helper.rb
|
182
|
+
test_files:
|
183
|
+
- test/helper.rb
|
184
|
+
- test/test_i18n_screwdriver.rb
|
data/.gitignore
DELETED
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.2
|
@@ -1,119 +0,0 @@
|
|
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,43 +0,0 @@
|
|
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
|