fast_gettext 0.5.10 → 0.5.11
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/Gemfile +9 -0
- data/Gemfile.lock +43 -0
- data/Rakefile +9 -8
- data/{README.markdown → Readme.md} +7 -7
- data/VERSION +1 -1
- data/fast_gettext.gemspec +95 -99
- data/lib/fast_gettext.rb +7 -2
- data/lib/fast_gettext/storage.rb +4 -4
- data/lib/fast_gettext/translation.rb +4 -4
- data/spec/aa_unconfigued_spec.rb +1 -1
- data/spec/fast_gettext/mo_file_spec.rb +1 -1
- data/spec/fast_gettext/storage_spec.rb +45 -24
- data/spec/fast_gettext/translation_repository/base_spec.rb +1 -1
- data/spec/fast_gettext/translation_repository/chain_spec.rb +1 -1
- data/spec/fast_gettext/translation_repository/db_spec.rb +1 -1
- data/spec/fast_gettext/translation_repository/logger_spec.rb +1 -1
- data/spec/fast_gettext/translation_repository/mo_spec.rb +1 -1
- data/spec/fast_gettext/translation_repository/po_spec.rb +1 -1
- data/spec/fast_gettext/translation_repository/yaml_spec.rb +2 -2
- data/spec/fast_gettext/translation_repository_spec.rb +1 -1
- data/spec/fast_gettext/translation_spec.rb +1 -1
- data/spec/fast_gettext/vendor/iconv_spec.rb +1 -0
- data/spec/fast_gettext/vendor/string_spec.rb +1 -1
- data/spec/fast_gettext_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +28 -22
- data/.gitignore +0 -2
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.3)
|
5
|
+
activesupport (= 3.0.3)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.4)
|
8
|
+
activerecord (3.0.3)
|
9
|
+
activemodel (= 3.0.3)
|
10
|
+
activesupport (= 3.0.3)
|
11
|
+
arel (~> 2.0.2)
|
12
|
+
tzinfo (~> 0.3.23)
|
13
|
+
activesupport (3.0.3)
|
14
|
+
arel (2.0.7)
|
15
|
+
builder (2.1.2)
|
16
|
+
diff-lcs (1.1.2)
|
17
|
+
git (1.2.5)
|
18
|
+
i18n (0.5.0)
|
19
|
+
jeweler (1.5.2)
|
20
|
+
bundler (~> 1.0.0)
|
21
|
+
git (>= 1.2.5)
|
22
|
+
rake
|
23
|
+
rake (0.8.7)
|
24
|
+
rspec (2.5.0)
|
25
|
+
rspec-core (~> 2.5.0)
|
26
|
+
rspec-expectations (~> 2.5.0)
|
27
|
+
rspec-mocks (~> 2.5.0)
|
28
|
+
rspec-core (2.5.1)
|
29
|
+
rspec-expectations (2.5.0)
|
30
|
+
diff-lcs (~> 1.1.2)
|
31
|
+
rspec-mocks (2.5.0)
|
32
|
+
sqlite3 (1.3.3)
|
33
|
+
tzinfo (0.3.24)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
activerecord
|
40
|
+
jeweler
|
41
|
+
rake
|
42
|
+
rspec (~> 2)
|
43
|
+
sqlite3
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
task :default => :spec
|
2
|
-
require
|
3
|
-
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
4
|
+
t.rspec_opts = '--backtrace --color'
|
5
|
+
end
|
4
6
|
|
5
7
|
task :benchmark do
|
6
8
|
puts "Running on #{RUBY}"
|
@@ -17,16 +19,15 @@ end
|
|
17
19
|
|
18
20
|
begin
|
19
21
|
require 'jeweler'
|
20
|
-
project_name = 'fast_gettext'
|
21
22
|
Jeweler::Tasks.new do |gem|
|
22
|
-
gem.name =
|
23
|
-
gem.summary = "A simple, fast and threadsafe implementation of GetText"
|
24
|
-
gem.email = "
|
25
|
-
gem.homepage = "http://github.com/grosser/#{
|
23
|
+
gem.name = 'fast_gettext'
|
24
|
+
gem.summary = "A simple, fast, memory-efficient and threadsafe implementation of GetText"
|
25
|
+
gem.email = "michael@grosser.it"
|
26
|
+
gem.homepage = "http://github.com/grosser/#{gem.name}"
|
26
27
|
gem.authors = ["Michael Grosser"]
|
27
28
|
end
|
28
29
|
|
29
30
|
Jeweler::GemcutterTasks.new
|
30
31
|
rescue LoadError
|
31
32
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
32
|
-
end
|
33
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
FastGettext
|
2
2
|
===========
|
3
|
-
GetText but 3.5 x faster, 560 x less memory, simple, clean namespace (7 vs 34) and threadsave!
|
3
|
+
GetText but 3.5 x faster, 560 x less memory, simple, clean namespace (7 vs 34) and threadsave!
|
4
4
|
|
5
5
|
It supports multiple backends (.mo, .po, .yml files, Database(ActiveRecor + any other), Chain, Loggers) and can easily be extended.
|
6
6
|
|
@@ -59,7 +59,7 @@ Or yaml files (use I18n syntax/indentation)
|
|
59
59
|
FastGettext.add_text_domain('my_app',:path=>'config/locales', :type=>:yaml)
|
60
60
|
|
61
61
|
Or database (scaleable, good for many locales/translators)
|
62
|
-
# db access is cached <-> only first lookup hits the db
|
62
|
+
# db access is cached <-> only first lookup hits the db
|
63
63
|
require "fast_gettext/translation_repository/db"
|
64
64
|
FastGettext::TranslationRepository::Db.require_models #load and include default models
|
65
65
|
FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey)
|
@@ -90,7 +90,7 @@ Use the [original GetText](http://github.com/mutoh/gettext) to create and manage
|
|
90
90
|
(Work on a po/mo parser & reader that is easier to use has started, contributions welcome @ [pomo](http://github.com/grosser/pomo) )
|
91
91
|
|
92
92
|
###Database
|
93
|
-
[Example migration for ActiveRecord](http://github.com/grosser/fast_gettext/blob/master/examples/db/migration.rb)
|
93
|
+
[Example migration for ActiveRecord](http://github.com/grosser/fast_gettext/blob/master/examples/db/migration.rb)<br/>
|
94
94
|
The default plural seperator is `||||` but you may overwrite it (or suggest a better one..).
|
95
95
|
|
96
96
|
This is usable with any model DataMapper/Sequel or any other(non-database) backend, the only thing you need to do is respond to the self.translation(key, locale) call.
|
@@ -100,7 +100,7 @@ To manage translations via a Web GUI, use a [Rails application and the translati
|
|
100
100
|
|
101
101
|
Rails
|
102
102
|
=======================
|
103
|
-
Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup
|
103
|
+
Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup.<br/>
|
104
104
|
Try the [translation_db_engine](http://github.com/grosser/translation_db_engine), to manage your translations in a db.
|
105
105
|
|
106
106
|
Setting `available_locales`,`text_domain` or `locale` will not work inside the `evironment.rb`,
|
@@ -195,6 +195,6 @@ Mo/Po-file parsing from Masao Mutoh, see vendor/README
|
|
195
195
|
- [J. Pablo Fernández](http://pupeno.com)
|
196
196
|
- Rudolf Gavlas
|
197
197
|
|
198
|
-
[Michael Grosser](http://
|
199
|
-
|
200
|
-
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
198
|
+
[Michael Grosser](http://grosser.it)<br/>
|
199
|
+
michael@grosser.it<br/>
|
200
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.11
|
data/fast_gettext.gemspec
CHANGED
@@ -1,122 +1,118 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fast_gettext}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{
|
13
|
-
s.email = %q{
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.markdown"
|
16
|
-
]
|
12
|
+
s.date = %q{2011-02-27}
|
13
|
+
s.email = %q{michael@grosser.it}
|
17
14
|
s.files = [
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
15
|
+
"CHANGELOG",
|
16
|
+
"Gemfile",
|
17
|
+
"Gemfile.lock",
|
18
|
+
"Rakefile",
|
19
|
+
"Readme.md",
|
20
|
+
"VERSION",
|
21
|
+
"benchmark/base.rb",
|
22
|
+
"benchmark/baseline.rb",
|
23
|
+
"benchmark/fast_gettext.rb",
|
24
|
+
"benchmark/i18n_simple.rb",
|
25
|
+
"benchmark/ideal.rb",
|
26
|
+
"benchmark/locale/de.yml",
|
27
|
+
"benchmark/locale/de/LC_MESSAGES/large.mo",
|
28
|
+
"benchmark/misc/threadsave.rb",
|
29
|
+
"benchmark/namespace/fast_gettext.rb",
|
30
|
+
"benchmark/namespace/original.rb",
|
31
|
+
"benchmark/original.rb",
|
32
|
+
"examples/db/migration.rb",
|
33
|
+
"examples/missing_translation_logger.rb",
|
34
|
+
"fast_gettext.gemspec",
|
35
|
+
"lib/fast_gettext.rb",
|
36
|
+
"lib/fast_gettext/VERSION",
|
37
|
+
"lib/fast_gettext/mo_file.rb",
|
38
|
+
"lib/fast_gettext/po_file.rb",
|
39
|
+
"lib/fast_gettext/storage.rb",
|
40
|
+
"lib/fast_gettext/translation.rb",
|
41
|
+
"lib/fast_gettext/translation_repository.rb",
|
42
|
+
"lib/fast_gettext/translation_repository/base.rb",
|
43
|
+
"lib/fast_gettext/translation_repository/chain.rb",
|
44
|
+
"lib/fast_gettext/translation_repository/db.rb",
|
45
|
+
"lib/fast_gettext/translation_repository/db_models/translation_key.rb",
|
46
|
+
"lib/fast_gettext/translation_repository/db_models/translation_text.rb",
|
47
|
+
"lib/fast_gettext/translation_repository/logger.rb",
|
48
|
+
"lib/fast_gettext/translation_repository/mo.rb",
|
49
|
+
"lib/fast_gettext/translation_repository/po.rb",
|
50
|
+
"lib/fast_gettext/translation_repository/yaml.rb",
|
51
|
+
"lib/fast_gettext/vendor/README.rdoc",
|
52
|
+
"lib/fast_gettext/vendor/empty.mo",
|
53
|
+
"lib/fast_gettext/vendor/iconv.rb",
|
54
|
+
"lib/fast_gettext/vendor/mofile.rb",
|
55
|
+
"lib/fast_gettext/vendor/poparser.rb",
|
56
|
+
"lib/fast_gettext/vendor/string.rb",
|
57
|
+
"spec/aa_unconfigued_spec.rb",
|
58
|
+
"spec/fast_gettext/mo_file_spec.rb",
|
59
|
+
"spec/fast_gettext/storage_spec.rb",
|
60
|
+
"spec/fast_gettext/translation_repository/base_spec.rb",
|
61
|
+
"spec/fast_gettext/translation_repository/chain_spec.rb",
|
62
|
+
"spec/fast_gettext/translation_repository/db_spec.rb",
|
63
|
+
"spec/fast_gettext/translation_repository/logger_spec.rb",
|
64
|
+
"spec/fast_gettext/translation_repository/mo_spec.rb",
|
65
|
+
"spec/fast_gettext/translation_repository/po_spec.rb",
|
66
|
+
"spec/fast_gettext/translation_repository/yaml_spec.rb",
|
67
|
+
"spec/fast_gettext/translation_repository_spec.rb",
|
68
|
+
"spec/fast_gettext/translation_spec.rb",
|
69
|
+
"spec/fast_gettext/vendor/fake_load_path/iconv.rb",
|
70
|
+
"spec/fast_gettext/vendor/iconv_spec.rb",
|
71
|
+
"spec/fast_gettext/vendor/string_spec.rb",
|
72
|
+
"spec/fast_gettext_spec.rb",
|
73
|
+
"spec/fuzzy_locale/de/test.po",
|
74
|
+
"spec/locale/de/LC_MESSAGES/test.mo",
|
75
|
+
"spec/locale/de/test.po",
|
76
|
+
"spec/locale/en/LC_MESSAGES/plural_test.mo",
|
77
|
+
"spec/locale/en/LC_MESSAGES/test.mo",
|
78
|
+
"spec/locale/en/plural_test.po",
|
79
|
+
"spec/locale/en/test.po",
|
80
|
+
"spec/locale/yaml/de.yml",
|
81
|
+
"spec/locale/yaml/en.yml",
|
82
|
+
"spec/locale/yaml/notfound.yml",
|
83
|
+
"spec/obsolete_locale/de/test.po",
|
84
|
+
"spec/spec_helper.rb"
|
87
85
|
]
|
88
86
|
s.homepage = %q{http://github.com/grosser/fast_gettext}
|
89
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
90
87
|
s.require_paths = ["lib"]
|
91
|
-
s.rubygems_version = %q{1.
|
92
|
-
s.summary = %q{A simple, fast and threadsafe implementation of GetText}
|
88
|
+
s.rubygems_version = %q{1.4.2}
|
89
|
+
s.summary = %q{A simple, fast, memory-efficient and threadsafe implementation of GetText}
|
93
90
|
s.test_files = [
|
91
|
+
"examples/db/migration.rb",
|
92
|
+
"examples/missing_translation_logger.rb",
|
94
93
|
"spec/aa_unconfigued_spec.rb",
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
"examples/db/migration.rb",
|
112
|
-
"examples/missing_translation_logger.rb"
|
94
|
+
"spec/fast_gettext/mo_file_spec.rb",
|
95
|
+
"spec/fast_gettext/storage_spec.rb",
|
96
|
+
"spec/fast_gettext/translation_repository/base_spec.rb",
|
97
|
+
"spec/fast_gettext/translation_repository/chain_spec.rb",
|
98
|
+
"spec/fast_gettext/translation_repository/db_spec.rb",
|
99
|
+
"spec/fast_gettext/translation_repository/logger_spec.rb",
|
100
|
+
"spec/fast_gettext/translation_repository/mo_spec.rb",
|
101
|
+
"spec/fast_gettext/translation_repository/po_spec.rb",
|
102
|
+
"spec/fast_gettext/translation_repository/yaml_spec.rb",
|
103
|
+
"spec/fast_gettext/translation_repository_spec.rb",
|
104
|
+
"spec/fast_gettext/translation_spec.rb",
|
105
|
+
"spec/fast_gettext/vendor/fake_load_path/iconv.rb",
|
106
|
+
"spec/fast_gettext/vendor/iconv_spec.rb",
|
107
|
+
"spec/fast_gettext/vendor/string_spec.rb",
|
108
|
+
"spec/fast_gettext_spec.rb",
|
109
|
+
"spec/spec_helper.rb"
|
113
110
|
]
|
114
111
|
|
115
112
|
if s.respond_to? :specification_version then
|
116
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
117
113
|
s.specification_version = 3
|
118
114
|
|
119
|
-
if Gem::Version.new(Gem::
|
115
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
120
116
|
else
|
121
117
|
end
|
122
118
|
else
|
data/lib/fast_gettext.rb
CHANGED
@@ -10,9 +10,9 @@ module FastGettext
|
|
10
10
|
|
11
11
|
VERSION = File.read( File.join(File.dirname(__FILE__), 'fast_gettext', 'VERSION') ).strip
|
12
12
|
LOCALE_REX = /^[a-z]{2}$|^[a-z]{2}_[A-Z]{2}$/
|
13
|
-
|
13
|
+
NAMESPACE_SEPARATOR = '|'
|
14
14
|
|
15
|
-
# users should not include FastGettext, since this would
|
15
|
+
# users should not include FastGettext, since this would contaminate their namespace
|
16
16
|
# rather use
|
17
17
|
# FastGettext.locale = ..
|
18
18
|
# FastGettext.text_domain = ..
|
@@ -27,4 +27,9 @@ module FastGettext
|
|
27
27
|
def add_text_domain(name,options)
|
28
28
|
translation_repositories[name] = TranslationRepository.build(name,options)
|
29
29
|
end
|
30
|
+
|
31
|
+
# some repositories know where to store their locales
|
32
|
+
def locale_path
|
33
|
+
translation_repositories[text_domain].instance_variable_get(:@options)[:path]
|
34
|
+
end
|
30
35
|
end
|
data/lib/fast_gettext/storage.rb
CHANGED
@@ -59,7 +59,7 @@ module FastGettext
|
|
59
59
|
|
60
60
|
|
61
61
|
# if overwritten by user( FastGettext.pluralisation_rule = xxx) use it,
|
62
|
-
# otherwise fall back to repo or to default lambda
|
62
|
+
# otherwise fall back to repo or to default lambda
|
63
63
|
def pluralisation_rule
|
64
64
|
Thread.current[:fast_gettext_pluralisation_rule] || current_repository.pluralisation_rule || lambda{|i| i!=1}
|
65
65
|
end
|
@@ -122,7 +122,7 @@ module FastGettext
|
|
122
122
|
self.locale = new_locale
|
123
123
|
locale
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
@@default_locale = nil
|
127
127
|
def default_locale=(new_locale)
|
128
128
|
@@default_locale = best_locale_in(new_locale)
|
@@ -149,7 +149,7 @@ module FastGettext
|
|
149
149
|
#turn off translation if none was defined to disable all resulting errors
|
150
150
|
def silence_errors
|
151
151
|
require 'fast_gettext/translation_repository/base'
|
152
|
-
translation_repositories[text_domain]
|
152
|
+
translation_repositories[text_domain] ||= TranslationRepository::Base.new('x', :path => 'locale')
|
153
153
|
end
|
154
154
|
|
155
155
|
private
|
@@ -189,4 +189,4 @@ module FastGettext
|
|
189
189
|
self.current_cache = caches[text_domain][locale]
|
190
190
|
end
|
191
191
|
end
|
192
|
-
end
|
192
|
+
end
|
@@ -35,9 +35,9 @@ module FastGettext
|
|
35
35
|
|
36
36
|
#translate, but discard namespace if nothing was found
|
37
37
|
# Car|Tire -> Tire if no translation could be found
|
38
|
-
def s_(key,
|
38
|
+
def s_(key,separator=nil)
|
39
39
|
translation = FastGettext.cached_find(key) and return translation
|
40
|
-
key.split(
|
40
|
+
key.split(separator||NAMESPACE_SEPARATOR).last
|
41
41
|
end
|
42
42
|
|
43
43
|
#tell gettext: this string need translation (will be found during parsing)
|
@@ -51,7 +51,7 @@ module FastGettext
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def ns_(*args)
|
54
|
-
n_(*args).split(
|
54
|
+
n_(*args).split(NAMESPACE_SEPARATOR).last
|
55
55
|
end
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
data/spec/aa_unconfigued_spec.rb
CHANGED
@@ -1,33 +1,47 @@
|
|
1
|
-
require 'spec/spec_helper'
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
2
|
|
3
3
|
describe 'Storage' do
|
4
4
|
include FastGettext::Storage
|
5
5
|
|
6
6
|
before do
|
7
7
|
#reset everything to nil
|
8
|
-
self.
|
8
|
+
self.default_available_locales = nil
|
9
9
|
self.default_text_domain = nil
|
10
10
|
self.default_locale = nil
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
self.available_locales = nil
|
12
|
+
self.text_domain = 'xxx'
|
13
|
+
send(:_locale=, nil)#nil is not allowed to be set...
|
14
|
+
|
15
|
+
# fake a simple text-domain
|
16
|
+
translation_repositories[text_domain] = FastGettext::TranslationRepository::Base.new('x')
|
17
|
+
|
18
|
+
default_locale.should == nil
|
19
|
+
default_available_locales.should == nil
|
20
|
+
available_locales.should == nil
|
14
21
|
locale.should == 'en'
|
22
|
+
text_domain.should == 'xxx'
|
15
23
|
end
|
16
24
|
|
17
|
-
def thread_save(method,
|
18
|
-
send("#{method}=",
|
25
|
+
def thread_save(method, value_a, value_b)
|
26
|
+
send("#{method}=",value_a)
|
19
27
|
|
20
28
|
# mess around with other threads
|
21
29
|
100.times do
|
22
|
-
Thread.new {FastGettext.send("#{method}=",
|
30
|
+
Thread.new {FastGettext.send("#{method}=",value_b)}
|
23
31
|
end
|
24
|
-
|
25
|
-
|
32
|
+
sleep 0.1 # Ruby 1.9 cannot switch threads fat enough <-> spec fails without this WTF!
|
33
|
+
|
34
|
+
!!(send(method) == value_a)
|
26
35
|
end
|
27
36
|
|
28
|
-
{
|
37
|
+
{
|
38
|
+
:locale=>['de','en'],
|
39
|
+
:available_locales=>[['de'],['en']],
|
40
|
+
:text_domain=>['xx','yy'],
|
41
|
+
:pluralisation_rule=>[lambda{|x|x==4},lambda{|x|x==1}]
|
42
|
+
}.each do |method, (value_a, value_b)|
|
29
43
|
it "stores #{method} thread-save" do
|
30
|
-
thread_save(method,
|
44
|
+
thread_save(method, value_a, value_b).should == true
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
@@ -50,7 +64,7 @@ describe 'Storage' do
|
|
50
64
|
|
51
65
|
describe :default_locale do
|
52
66
|
it "stores default_locale non-thread-safe" do
|
53
|
-
thread_save(:default_locale, 'de').should == false
|
67
|
+
thread_save(:default_locale, 'de', 'en').should == false
|
54
68
|
end
|
55
69
|
|
56
70
|
it "does not overwrite locale" do
|
@@ -79,7 +93,7 @@ describe 'Storage' do
|
|
79
93
|
|
80
94
|
describe :default_text_domain do
|
81
95
|
it "stores default_text_domain non-thread-safe" do
|
82
|
-
thread_save(:default_text_domain, 'xx').should == false
|
96
|
+
thread_save(:default_text_domain, 'xx', 'en').should == false
|
83
97
|
end
|
84
98
|
|
85
99
|
it "uses default_text_domain when text_domain is not set" do
|
@@ -96,12 +110,8 @@ describe 'Storage' do
|
|
96
110
|
end
|
97
111
|
|
98
112
|
describe :default_available_locales do
|
99
|
-
after do
|
100
|
-
self.default_available_locales = nil
|
101
|
-
end
|
102
|
-
|
103
113
|
it "stores default_available_locales non-thread-safe" do
|
104
|
-
thread_save(:default_available_locales, 'xx').should == false
|
114
|
+
thread_save(:default_available_locales, ['xx'], ['yy']).should == false
|
105
115
|
end
|
106
116
|
|
107
117
|
it "converts locales to s" do
|
@@ -196,21 +206,32 @@ describe 'Storage' do
|
|
196
206
|
|
197
207
|
describe :silence_errors do
|
198
208
|
before do
|
199
|
-
|
209
|
+
self.text_domain = rand(99999).to_s
|
200
210
|
end
|
201
211
|
|
202
212
|
it "raises when a textdomain was empty" do
|
203
|
-
begin
|
213
|
+
begin
|
204
214
|
FastGettext._('x')
|
205
|
-
|
215
|
+
raise 'NOPE!'
|
206
216
|
rescue FastGettext::Storage::NoTextDomainConfigured
|
207
217
|
end
|
208
218
|
end
|
209
219
|
|
210
|
-
it "can silence
|
220
|
+
it "can silence errors" do
|
211
221
|
FastGettext.silence_errors
|
212
222
|
FastGettext._('x').should == 'x'
|
213
223
|
end
|
224
|
+
|
225
|
+
it "does not overwrite existing textdomain" do
|
226
|
+
self.translation_repositories[FastGettext.text_domain] = 1
|
227
|
+
FastGettext.silence_errors
|
228
|
+
self.translation_repositories[FastGettext.text_domain].should == 1
|
229
|
+
end
|
230
|
+
|
231
|
+
it "has ./locale as locale path when silenced" do
|
232
|
+
FastGettext.silence_errors
|
233
|
+
FastGettext.locale_path.should == 'locale'
|
234
|
+
end
|
214
235
|
end
|
215
236
|
|
216
237
|
describe :current_cache do
|
@@ -310,4 +331,4 @@ describe 'Storage' do
|
|
310
331
|
FastGettext::Storage::NoTextDomainConfigured.new('xxx').to_s.should =~ /xxx/
|
311
332
|
end
|
312
333
|
end
|
313
|
-
end
|
334
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'spec/spec_helper'
|
1
|
+
require File.expand_path('spec/spec_helper')
|
2
2
|
|
3
3
|
describe 'FastGettext::TranslationRepository::Yaml' do
|
4
4
|
before do
|
@@ -47,7 +47,7 @@ describe 'FastGettext::TranslationRepository::Yaml' do
|
|
47
47
|
4.times do |i|
|
48
48
|
it "can be used to do wanky pluralisation rules #{i}" do
|
49
49
|
FastGettext.stub!(:current_repository).and_return @rep
|
50
|
-
@rep.stub!(:pluralisation_rule).and_return lambda{i}
|
50
|
+
@rep.stub!(:pluralisation_rule).and_return lambda{|x| i}
|
51
51
|
FastGettext.n_('cars.silly',1).should == i.to_s # cars.silly translations are 0,1,2,3
|
52
52
|
end
|
53
53
|
end
|
data/spec/fast_gettext_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
|
|
4
4
|
require 'fast_gettext'
|
5
5
|
|
6
6
|
# ---- revert to defaults
|
7
|
-
|
7
|
+
RSpec.configure do |config|
|
8
8
|
config.before :all do
|
9
9
|
FastGettext.locale = 'de'
|
10
10
|
FastGettext.available_locales = nil
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_gettext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
9
|
+
- 11
|
10
|
+
version: 0.5.11
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Grosser
|
@@ -14,23 +15,24 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-02-27 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
21
22
|
description:
|
22
|
-
email:
|
23
|
+
email: michael@grosser.it
|
23
24
|
executables: []
|
24
25
|
|
25
26
|
extensions: []
|
26
27
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
29
30
|
files:
|
30
|
-
- .gitignore
|
31
31
|
- CHANGELOG
|
32
|
-
-
|
32
|
+
- Gemfile
|
33
|
+
- Gemfile.lock
|
33
34
|
- Rakefile
|
35
|
+
- Readme.md
|
34
36
|
- VERSION
|
35
37
|
- benchmark/base.rb
|
36
38
|
- benchmark/baseline.rb
|
@@ -101,48 +103,52 @@ homepage: http://github.com/grosser/fast_gettext
|
|
101
103
|
licenses: []
|
102
104
|
|
103
105
|
post_install_message:
|
104
|
-
rdoc_options:
|
105
|
-
|
106
|
+
rdoc_options: []
|
107
|
+
|
106
108
|
require_paths:
|
107
109
|
- lib
|
108
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
109
112
|
requirements:
|
110
113
|
- - ">="
|
111
114
|
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
112
116
|
segments:
|
113
117
|
- 0
|
114
118
|
version: "0"
|
115
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
116
121
|
requirements:
|
117
122
|
- - ">="
|
118
123
|
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
119
125
|
segments:
|
120
126
|
- 0
|
121
127
|
version: "0"
|
122
128
|
requirements: []
|
123
129
|
|
124
130
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.4.2
|
126
132
|
signing_key:
|
127
133
|
specification_version: 3
|
128
|
-
summary: A simple, fast and threadsafe implementation of GetText
|
134
|
+
summary: A simple, fast, memory-efficient and threadsafe implementation of GetText
|
129
135
|
test_files:
|
136
|
+
- examples/db/migration.rb
|
137
|
+
- examples/missing_translation_logger.rb
|
130
138
|
- spec/aa_unconfigued_spec.rb
|
131
139
|
- spec/fast_gettext/mo_file_spec.rb
|
132
140
|
- spec/fast_gettext/storage_spec.rb
|
133
|
-
- spec/fast_gettext/translation_spec.rb
|
134
|
-
- spec/fast_gettext/translation_repository_spec.rb
|
135
141
|
- spec/fast_gettext/translation_repository/base_spec.rb
|
136
142
|
- spec/fast_gettext/translation_repository/chain_spec.rb
|
137
143
|
- spec/fast_gettext/translation_repository/db_spec.rb
|
138
|
-
- spec/fast_gettext/translation_repository/po_spec.rb
|
139
|
-
- spec/fast_gettext/translation_repository/mo_spec.rb
|
140
144
|
- spec/fast_gettext/translation_repository/logger_spec.rb
|
145
|
+
- spec/fast_gettext/translation_repository/mo_spec.rb
|
146
|
+
- spec/fast_gettext/translation_repository/po_spec.rb
|
141
147
|
- spec/fast_gettext/translation_repository/yaml_spec.rb
|
142
|
-
- spec/fast_gettext/
|
143
|
-
- spec/fast_gettext/
|
148
|
+
- spec/fast_gettext/translation_repository_spec.rb
|
149
|
+
- spec/fast_gettext/translation_spec.rb
|
144
150
|
- spec/fast_gettext/vendor/fake_load_path/iconv.rb
|
145
|
-
- spec/
|
151
|
+
- spec/fast_gettext/vendor/iconv_spec.rb
|
152
|
+
- spec/fast_gettext/vendor/string_spec.rb
|
146
153
|
- spec/fast_gettext_spec.rb
|
147
|
-
-
|
148
|
-
- examples/missing_translation_logger.rb
|
154
|
+
- spec/spec_helper.rb
|
data/.gitignore
DELETED