gettext_test_log 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +26 -0
- data/Rakefile +20 -0
- data/Readme.md +69 -0
- data/VERSION +1 -0
- data/gettext_test_log.gemspec +42 -0
- data/init.rb +1 -0
- data/lib/gettext_test_log.rb +67 -0
- data/lib/gettext_test_log/fast_gettext_stub.rb +15 -0
- data/spec/gettext_test_log_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -0
- data/tasks/gettext_test_log.rake +6 -0
- metadata +78 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.9.2)
|
11
|
+
rspec (2.6.0)
|
12
|
+
rspec-core (~> 2.6.0)
|
13
|
+
rspec-expectations (~> 2.6.0)
|
14
|
+
rspec-mocks (~> 2.6.0)
|
15
|
+
rspec-core (2.6.4)
|
16
|
+
rspec-expectations (2.6.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.6.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
jeweler
|
25
|
+
rake
|
26
|
+
rspec (~> 2)
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
task :default do
|
4
|
+
sh "bundle exec rspec spec"
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
gem.name = "gettext_test_log"
|
11
|
+
gem.summary = "Logs all gettext translations during test execution, to a GetText readable format"
|
12
|
+
gem.email = "grosser.michael@gmail.com"
|
13
|
+
gem.homepage = "http://github.com/grosser/#{gem.name}"
|
14
|
+
gem.authors = ["Michael Grosser"]
|
15
|
+
end
|
16
|
+
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
|
20
|
+
end
|
data/Readme.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
Problem
|
2
|
+
=======
|
3
|
+
- Finding all translations by parsing is impossible for dynamic calls
|
4
|
+
- often even static calls are not found
|
5
|
+
- some file formats do not have a gettext parser
|
6
|
+
|
7
|
+
Solution
|
8
|
+
========
|
9
|
+
- log all translations during test execution
|
10
|
+
- write them to an parseable temp file
|
11
|
+
- use gettext:find / gettext:pack as usual
|
12
|
+
- missing translation = missing test, write tests!
|
13
|
+
|
14
|
+
This will only work with [FastGettext](http://github.com/grosser/fast_gettext) and RSpec for now!
|
15
|
+
|
16
|
+
Install
|
17
|
+
=======
|
18
|
+
- `rails plugin install git://github.com/grosser/gettext_test_log.git `
|
19
|
+
- Gem: `gem install gettext_test_log`
|
20
|
+
|
21
|
+
Usage
|
22
|
+
=====
|
23
|
+
rake gettext:test_log
|
24
|
+
|
25
|
+
Optionally copy+modify task with options:
|
26
|
+
:exclude_msgids_in_po_files=>[
|
27
|
+
'some_po_file_that_contains_translations_you_do_not_need.po'
|
28
|
+
]
|
29
|
+
|
30
|
+
Add to your spec_helper:
|
31
|
+
#spec/spec_helper.rb
|
32
|
+
GettextTestLog::activate_test_logging
|
33
|
+
|
34
|
+
Run:
|
35
|
+
rake gettext:test_log
|
36
|
+
rake gettext:find #find new translations
|
37
|
+
#fill newly found translations
|
38
|
+
rake gettext:pack #write translations
|
39
|
+
|
40
|
+
Examples output
|
41
|
+
===============
|
42
|
+
#locale/testlog_phrases.rb
|
43
|
+
_("Add to favorites")
|
44
|
+
_("Added a subtitle to %{name}")
|
45
|
+
_("Additional Information")
|
46
|
+
_("Address")
|
47
|
+
...
|
48
|
+
|
49
|
+
Unwanted translations
|
50
|
+
=====================
|
51
|
+
When using gettext_i18n_rails, most of the columns of a model will be translated during model tests
|
52
|
+
this can be annoying since normally no user will see them.
|
53
|
+
To disable this, add to `spec/spec_helper.rb` :
|
54
|
+
class ActiveRecord::Base
|
55
|
+
def self.human_attribute_name(attr)
|
56
|
+
attr.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
TODO
|
61
|
+
====
|
62
|
+
- needs tests... :(
|
63
|
+
- make compatible with GetText and FastGettext at the same time ?
|
64
|
+
|
65
|
+
Author
|
66
|
+
======
|
67
|
+
[Michael Grosser](http://grosser.it)<br/>
|
68
|
+
michael@grosser.it<br/>
|
69
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gettext_test_log}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Grosser"]
|
12
|
+
s.date = %q{2011-09-23}
|
13
|
+
s.email = %q{grosser.michael@gmail.com}
|
14
|
+
s.files = [
|
15
|
+
"Gemfile",
|
16
|
+
"Gemfile.lock",
|
17
|
+
"Rakefile",
|
18
|
+
"Readme.md",
|
19
|
+
"VERSION",
|
20
|
+
"gettext_test_log.gemspec",
|
21
|
+
"init.rb",
|
22
|
+
"lib/gettext_test_log.rb",
|
23
|
+
"lib/gettext_test_log/fast_gettext_stub.rb",
|
24
|
+
"spec/gettext_test_log_spec.rb",
|
25
|
+
"spec/spec_helper.rb",
|
26
|
+
"tasks/gettext_test_log.rake"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/grosser/gettext_test_log}
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.6.2}
|
31
|
+
s.summary = %q{Logs all gettext translations during test execution, to a GetText readable format}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
37
|
+
else
|
38
|
+
end
|
39
|
+
else
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'gettext_test_log' if Rails.env.test?
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module GettextTestLog
|
2
|
+
extend self
|
3
|
+
SEPERATOR = "\nNEXT-WORD\n"
|
4
|
+
|
5
|
+
# write to a given file, which msgids where found
|
6
|
+
# in the `rake updatepo` recogniseable format _("msgid")
|
7
|
+
def write_test_log(storage_file,options={})
|
8
|
+
messages = messages_from_test_run
|
9
|
+
if excluded = options[:exclude_msgids_in_po_files]
|
10
|
+
messages -= msgids_in_po_files(excluded)
|
11
|
+
end
|
12
|
+
store_messages(messages,storage_file)
|
13
|
+
end
|
14
|
+
|
15
|
+
# call this inside your spec_helper.rb
|
16
|
+
# to activate test message storage
|
17
|
+
def activate_test_logging
|
18
|
+
if ENV['LOG_GETTEXT']
|
19
|
+
require 'gettext_test_log/fast_gettext_stub'
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
#TODO only call after the 'last' test was executed
|
22
|
+
config.after(:all) do
|
23
|
+
File.open(ENV['LOG_GETTEXT'],'w') do |f|
|
24
|
+
f.puts FastGettext::Translation::TRANSLATIONS_USED * SEPERATOR
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def messages_from_test_run
|
34
|
+
logfile = 'tmp_gettext_test_log.txt'
|
35
|
+
run_tests(logfile)
|
36
|
+
ids = used_msgids(logfile)
|
37
|
+
`rm #{logfile}`
|
38
|
+
ids
|
39
|
+
end
|
40
|
+
|
41
|
+
def used_msgids(logfile)
|
42
|
+
File.read(logfile).split(/#{SEPERATOR}/m).map(&:strip).reject(&:blank?).uniq
|
43
|
+
end
|
44
|
+
|
45
|
+
def run_tests(logfile)
|
46
|
+
ENV['LOG_GETTEXT']=logfile
|
47
|
+
Rake::Task["spec"].invoke rescue nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def msgids_in_po_files(files)
|
51
|
+
[*files].map{|file| messages_from_po_file(file).keys}.flatten
|
52
|
+
end
|
53
|
+
|
54
|
+
#returns a hash of all msgid => msgstr
|
55
|
+
def messages_from_po_file(file)
|
56
|
+
require 'fast_gettext/po_file'
|
57
|
+
FastGettext::PoFile.conver_to_mo(file).instance_variable_get('@data')
|
58
|
+
end
|
59
|
+
|
60
|
+
def store_messages(messages,file)
|
61
|
+
File.open(file,'w') do |f|
|
62
|
+
f.puts "#GENERATED FILE DO NOT MODIFY"
|
63
|
+
f.puts messages.uniq.sort.map{|message| %Q[_("#{message}")].gsub("\n","\\n")} * "\n"
|
64
|
+
f.puts "#GENERATED FILE DO NOT MODIFY"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module FastGettext::Translation
|
2
|
+
TRANSLATIONS_USED = []
|
3
|
+
|
4
|
+
def __with_log(x)
|
5
|
+
TRANSLATIONS_USED << x
|
6
|
+
__without_log(x)
|
7
|
+
end
|
8
|
+
alias_method_chain :_, :log
|
9
|
+
|
10
|
+
def s__with_log(x)
|
11
|
+
TRANSLATIONS_USED << x
|
12
|
+
s__without_log(x)
|
13
|
+
end
|
14
|
+
alias_method_chain :s_, :log
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gettext_test_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Michael Grosser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-23 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: grosser.michael@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- Gemfile
|
32
|
+
- Gemfile.lock
|
33
|
+
- Rakefile
|
34
|
+
- Readme.md
|
35
|
+
- VERSION
|
36
|
+
- gettext_test_log.gemspec
|
37
|
+
- init.rb
|
38
|
+
- lib/gettext_test_log.rb
|
39
|
+
- lib/gettext_test_log/fast_gettext_stub.rb
|
40
|
+
- spec/gettext_test_log_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
- tasks/gettext_test_log.rake
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/grosser/gettext_test_log
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.6.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Logs all gettext translations during test execution, to a GetText readable format
|
77
|
+
test_files: []
|
78
|
+
|