Commit ac389ef86e312b4bf25f76e82f02045b3886f8f3
1 parent
0b7bc84e
Exists in
master
and in
27 other branches
Now using the packaged version of fast_gettext
deleting code \o/
Showing
60 changed files
with
4 additions
and
3374 deletions
Show diff stats
Gemfile
Gemfile.lock
@@ -31,6 +31,7 @@ GEM | @@ -31,6 +31,7 @@ GEM | ||
31 | arel (3.0.2) | 31 | arel (3.0.2) |
32 | builder (3.0.0) | 32 | builder (3.0.0) |
33 | erubis (2.7.0) | 33 | erubis (2.7.0) |
34 | + fast_gettext (0.6.8) | ||
34 | hike (1.2.1) | 35 | hike (1.2.1) |
35 | i18n (0.6.0) | 36 | i18n (0.6.0) |
36 | journey (1.0.3) | 37 | journey (1.0.3) |
@@ -81,5 +82,6 @@ PLATFORMS | @@ -81,5 +82,6 @@ PLATFORMS | ||
81 | ruby | 82 | ruby |
82 | 83 | ||
83 | DEPENDENCIES | 84 | DEPENDENCIES |
85 | + fast_gettext | ||
84 | rails | 86 | rails |
85 | rake | 87 | rake |
debian/control
@@ -28,6 +28,7 @@ Depends: | @@ -28,6 +28,7 @@ Depends: | ||
28 | rake, | 28 | rake, |
29 | # This package depends on rails that conflicts with rails3 | 29 | # This package depends on rails that conflicts with rails3 |
30 | # ruby-gettext-rails, | 30 | # ruby-gettext-rails, |
31 | + ruby-fast-gettext, | ||
31 | ruby-sqlite3, | 32 | ruby-sqlite3, |
32 | ruby-pg, | 33 | ruby-pg, |
33 | ruby-rmagick, | 34 | ruby-rmagick, |
lib/fast_gettext
lib/fast_gettext.rb
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/CHANGELOG
@@ -1,6 +0,0 @@ | @@ -1,6 +0,0 @@ | ||
1 | -0.4.14 -- "" is translated as "", not as gettext meta information | ||
2 | -0.4.0 -- pluralisation_rules is no longer stored in each repository, only retrived. Added Chain and Logger repository. | ||
3 | -0.3.6 -- FastGettext.default_locale= | ||
4 | -0.3.5 -- FastGettext.default_text_domain= | ||
5 | -0.3.4 -- Exceptions are thrown, not returned when translating without text domain | ||
6 | -0.3 -- pluralisation methods accept/return n plural forms, contrary to singular/plural before | ||
7 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/README.markdown
@@ -1,196 +0,0 @@ | @@ -1,196 +0,0 @@ | ||
1 | -FastGettext | ||
2 | -=========== | ||
3 | -GetText but 3.5 x faster, 560 x less memory, simple, clean namespace (7 vs 34) and threadsave! | ||
4 | - | ||
5 | -It supports multiple backends (.mo, .po, .yml files, Database(ActiveRecor + any other), Chain, Loggers) and can easily be extended. | ||
6 | - | ||
7 | -[Example Rails application](https://github.com/grosser/gettext_i18n_rails_example) | ||
8 | - | ||
9 | -Comparison | ||
10 | -========== | ||
11 | -<table> | ||
12 | - <tr> | ||
13 | - <td></td> | ||
14 | - <td width="100">Hash</td> | ||
15 | - <td width="150">FastGettext</td> | ||
16 | - <td width="100">GetText</td> | ||
17 | - <td width="100">ActiveSupport I18n::Simple</td> | ||
18 | - </tr> | ||
19 | - <tr> | ||
20 | - <td>Speed*</td> | ||
21 | - <td>0.82s</td> | ||
22 | - <td>1.36s</td> | ||
23 | - <td>4.88s</td> | ||
24 | - <td>21.77s</td> | ||
25 | - </tr> | ||
26 | - <tr> | ||
27 | - <td>RAM*</td> | ||
28 | - <td>4K</td> | ||
29 | - <td>8K</td> | ||
30 | - <td>4480K</td> | ||
31 | - <td>10100K</td> | ||
32 | - </tr> | ||
33 | - <tr> | ||
34 | - <td>Included backends</td> | ||
35 | - <td></td> | ||
36 | - <td>db, yml, mo, po, logger, chain</td> | ||
37 | - <td>mo</td> | ||
38 | - <td>yml</td> | ||
39 | - </tr> | ||
40 | -</table> | ||
41 | -<small>*50.000 translations with ruby enterprise 1.8.6 through `rake benchmark`</small> | ||
42 | - | ||
43 | -Setup | ||
44 | -===== | ||
45 | -### 1. Install | ||
46 | - sudo gem install fast_gettext | ||
47 | - | ||
48 | -### 2. Add a translation repository | ||
49 | - | ||
50 | -From mo files (traditional/default) | ||
51 | - FastGettext.add_text_domain('my_app',:path=>'locale') | ||
52 | - | ||
53 | -Or po files (less maintenance than mo) | ||
54 | - FastGettext.add_text_domain('my_app',:path=>'locale', :type=>:po) | ||
55 | - | ||
56 | -Or yaml files (use I18n syntax/indentation) | ||
57 | - FastGettext.add_text_domain('my_app',:path=>'config/locales', :type=>:yaml) | ||
58 | - | ||
59 | -Or database (scaleable, good for many locales/translators) | ||
60 | - # db access is cached <-> only first lookup hits the db | ||
61 | - require "fast_gettext/translation_repository/db" | ||
62 | - include FastGettext::TranslationRepository::Db.require_models #load and include default models | ||
63 | - FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey) | ||
64 | - | ||
65 | -### 3. Choose text domain and locale for translation | ||
66 | -Do this once in every Thread. (e.g. Rails -> ApplicationController) | ||
67 | - FastGettext.text_domain = 'my_app' | ||
68 | - FastGettext.available_locales = ['de','en','fr','en_US','en_UK'] # only allow these locales to be set (optional) | ||
69 | - FastGettext.locale = 'de' | ||
70 | - | ||
71 | -### 4. Start translating | ||
72 | - include FastGettext::Translation | ||
73 | - _('Car') == 'Auto' | ||
74 | - _('not-found') == 'not-found' | ||
75 | - s_('Namespace|no-found') == 'not-found' | ||
76 | - n_('Axis','Axis',3) == 'Achsen' #German plural of Axis | ||
77 | - | ||
78 | - | ||
79 | -Managing translations | ||
80 | -============ | ||
81 | -### mo/po-files | ||
82 | -Generate .po or .mo files using GetText parser (example tasks at [gettext_i18n_rails](http://github.com/grosser/gettext_i18n_rails)) | ||
83 | - | ||
84 | -Tell Gettext where your .mo or .po files lie, e.g. for locale/de/my_app.po and locale/de/LC_MESSAGES/my_app.mo | ||
85 | - FastGettext.add_text_domain('my_app',:path=>'locale') | ||
86 | - | ||
87 | -Use the [original GetText](http://github.com/mutoh/gettext) to create and manage po/mo-files. | ||
88 | -(Work on a po/mo parser & reader that is easier to use has started, contributions welcome @ [pomo](http://github.com/grosser/pomo) ) | ||
89 | - | ||
90 | -###Database | ||
91 | -[Example migration for ActiveRecord](http://github.com/grosser/fast_gettext/blob/master/examples/db/migration.rb) | ||
92 | -The default plural seperator is `||||` but you may overwrite it (or suggest a better one..). | ||
93 | - | ||
94 | -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. | ||
95 | -If you want to use your own models, have a look at the [default models](http://github.com/grosser/fast_gettext/tree/master/lib/fast_gettext/translation_repository/db_models) to see what you want/need to implement. | ||
96 | - | ||
97 | -To manage translations via a Web GUI, use a [Rails application and the translation_db_engine](http://github.com/grosser/translation_db_engine) | ||
98 | - | ||
99 | -Rails | ||
100 | -======================= | ||
101 | -Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup. | ||
102 | -Try the [translation_db_engine](http://github.com/grosser/translation_db_engine), to manage your translations in a db. | ||
103 | - | ||
104 | -Setting `available_locales`,`text_domain` or `locale` will not work inside the `evironment.rb`, | ||
105 | -since it runs in a different thread then e.g. controllers, so set them inside your application_controller. | ||
106 | - | ||
107 | - #environment.rb after initializers | ||
108 | - Object.send(:include,FastGettext::Translation) | ||
109 | - FastGettext.add_text_domain('accounting',:path=>'locale') | ||
110 | - FastGettext.add_text_domain('frontend',:path=>'locale') | ||
111 | - ... | ||
112 | - | ||
113 | - #application_controller.rb | ||
114 | - class ApplicationController ... | ||
115 | - include FastGettext::Translation | ||
116 | - before_filter :set_locale | ||
117 | - def set_locale | ||
118 | - FastGettext.available_locales = ['de','en',...] | ||
119 | - FastGettext.text_domain = 'frontend' | ||
120 | - session[:locale] = I18n.locale = FastGettext.set_locale(params[:locale] || session[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') | ||
121 | - end | ||
122 | - | ||
123 | - | ||
124 | -Advanced features | ||
125 | -================= | ||
126 | -###Abnormal pluralisation | ||
127 | -Pluralisation rules can be set directly via a lambda (see specs/), or by using the Gettext | ||
128 | -plural definition (see spec/locale/en/test_plural.po or [Plural expressions for all languages](http://translate.sourceforge.net/wiki/l10n/pluralforms). | ||
129 | - | ||
130 | - | ||
131 | -###default_text_domain | ||
132 | -If you only use one text domain, setting `FastGettext.default_text_domain = 'app'` | ||
133 | -is sufficient and no more `text_domain=` is needed | ||
134 | - | ||
135 | -###default_locale | ||
136 | -If the simple rule of "first `availble_locale` or 'en'" is not suficcient for you, set `FastGettext.default_locale = 'de'`. | ||
137 | - | ||
138 | -###default_available_locales | ||
139 | -Fallback when no available_locales are set | ||
140 | - | ||
141 | -###Chains | ||
142 | -You can use any number of repositories to find a translation. Simply add them to a chain and when | ||
143 | -the first cannot translate a given key, the next is asked and so forth. | ||
144 | - repos = [ | ||
145 | - FastGettext::TranslationRepository.build('new', :path=>'....'), | ||
146 | - FastGettext::TranslationRepository.build('old', :path=>'....') | ||
147 | - ] | ||
148 | - FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos | ||
149 | - | ||
150 | -###Logger | ||
151 | -When you want to know which keys could not be translated or were used, add a Logger to a Chain: | ||
152 | - repos = [ | ||
153 | - FastGettext::TranslationRepository.build('app', :path=>'....') | ||
154 | - FastGettext::TranslationRepository.build('logger', :type=>:logger, :callback=>lamda{|key_or_array_of_ids| ... }), | ||
155 | - } | ||
156 | - FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos | ||
157 | -If the Logger is in position #1 it will see all translations, if it is in position #2 it will only see the unfound. | ||
158 | -Unfound may not always mean missing, if you chose not to translate a word because the key is a good translation, it will appear nevertheless. | ||
159 | -A lambda or anything that responds to `call` will do as callback. A good starting point may be `examples/missing_translations_logger.rb`. | ||
160 | - | ||
161 | -###Plugins | ||
162 | -Want a xml version ? | ||
163 | -Write your own TranslationRepository! | ||
164 | - #fast_gettext/translation_repository/xxx.rb | ||
165 | - module FastGettext | ||
166 | - module TranslationRepository | ||
167 | - class Wtf | ||
168 | - define initialize(name,options), [key], plural(*keys) and | ||
169 | - either inherit from TranslationRepository::Base or define available_locales and pluralisation_rule | ||
170 | - end | ||
171 | - end | ||
172 | - end | ||
173 | - | ||
174 | - | ||
175 | -FAQ | ||
176 | -=== | ||
177 | - - [Problems with ActiveRecord messages?](http://wiki.github.com/grosser/fast_gettext/activerecord) | ||
178 | - | ||
179 | - | ||
180 | -TODO | ||
181 | -==== | ||
182 | - - YML backend that reads ActiveSupport::I18n files | ||
183 | - - any ideas ? :D | ||
184 | - | ||
185 | -Author | ||
186 | -====== | ||
187 | -Mo/Po-file parsing from Masao Mutoh, see vendor/README | ||
188 | - | ||
189 | -###Contributors | ||
190 | - - [geekq](http://www.innoq.com/blog/vd) | ||
191 | - - [Matt Sanford](http://blog.mzsanford.com) | ||
192 | - - Rudolf Gavlas | ||
193 | - | ||
194 | -[Michael Grosser](http://pragmatig.wordpress.com) | ||
195 | -grosser.michael@gmail.com | ||
196 | -Hereby placed under public domain, do what you want, just do not hold me accountable... |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/Rakefile
@@ -1,32 +0,0 @@ | @@ -1,32 +0,0 @@ | ||
1 | -task :default => :spec | ||
2 | -require 'spec/rake/spectask' | ||
3 | -Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']} | ||
4 | - | ||
5 | -task :benchmark do | ||
6 | - puts "Running on #{RUBY}" | ||
7 | - %w[baseline ideal fast_gettext original i18n_simple].each do |bench| | ||
8 | - puts `ruby benchmark/#{bench}.rb` | ||
9 | - puts "" | ||
10 | - end | ||
11 | -end | ||
12 | - | ||
13 | -task :namespaces do | ||
14 | - puts `ruby benchmark/namespace/original.rb` | ||
15 | - puts `ruby benchmark/namespace/fast_gettext.rb` | ||
16 | -end | ||
17 | - | ||
18 | -begin | ||
19 | - require 'jeweler' | ||
20 | - project_name = 'fast_gettext' | ||
21 | - Jeweler::Tasks.new do |gem| | ||
22 | - gem.name = project_name | ||
23 | - gem.summary = "A simple, fast and threadsafe implementation of GetText" | ||
24 | - gem.email = "grosser.michael@gmail.com" | ||
25 | - gem.homepage = "http://github.com/grosser/#{project_name}" | ||
26 | - gem.authors = ["Michael Grosser"] | ||
27 | - end | ||
28 | - | ||
29 | - Jeweler::GemcutterTasks.new | ||
30 | -rescue LoadError | ||
31 | - puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler" | ||
32 | -end | ||
33 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/VERSION
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/base.rb
@@ -1,42 +0,0 @@ | @@ -1,42 +0,0 @@ | ||
1 | -require 'rubygems' | ||
2 | -require 'benchmark' | ||
3 | - | ||
4 | -RUNS = 50_0000 | ||
5 | -DEFAULTS = {:memory=>0} | ||
6 | - | ||
7 | -def locale_folder(domain) | ||
8 | - path = case domain | ||
9 | - when 'test' then File.join(File.expand_path(File.dirname(__FILE__)),'..','spec','locale') | ||
10 | - when 'large' then File.join(File.expand_path(File.dirname(__FILE__)),'locale') | ||
11 | - end | ||
12 | - | ||
13 | - mo = File.join(path,'de','LC_MESSAGES',"#{domain}.mo") | ||
14 | - raise unless File.exist?(mo) | ||
15 | - path | ||
16 | -end | ||
17 | - | ||
18 | -def results_test(&block) | ||
19 | - print "#{(result(&block)).to_s.strip.split(' ').first}s / #{memory}K <-> " | ||
20 | -end | ||
21 | - | ||
22 | -def results_large | ||
23 | - print "#{(result {_('login') == 'anmelden'}).to_s.strip.split(' ').first}s / #{memory}K" | ||
24 | - puts "" | ||
25 | -end | ||
26 | - | ||
27 | -def result | ||
28 | - result =Benchmark.measure do | ||
29 | - RUNS.times do | ||
30 | - raise "not translated" unless yield | ||
31 | - end | ||
32 | - end | ||
33 | - result | ||
34 | -end | ||
35 | - | ||
36 | -def memory | ||
37 | - pid = Process.pid | ||
38 | - map = `pmap -d #{pid}` | ||
39 | - map.split("\n").last.strip.squeeze(' ').split(' ')[3].to_i - DEFAULTS[:memory] | ||
40 | -end | ||
41 | - | ||
42 | -DEFAULTS[:memory] = memory + 4 #4 => 0 for base calls | ||
43 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/baseline.rb
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/fast_gettext.rb
@@ -1,18 +0,0 @@ | @@ -1,18 +0,0 @@ | ||
1 | -require 'benchmark/base' | ||
2 | - | ||
3 | -$LOAD_PATH.unshift 'lib' | ||
4 | -require 'fast_gettext' | ||
5 | -include FastGettext::Translation | ||
6 | - | ||
7 | -FastGettext.available_locales = ['de','en'] | ||
8 | -FastGettext.locale = 'de' | ||
9 | - | ||
10 | -puts "FastGettext:" | ||
11 | -FastGettext.add_text_domain('test',:path=>locale_folder('test')) | ||
12 | -FastGettext.text_domain = 'test' | ||
13 | -results_test{_('car') == 'Auto'} | ||
14 | - | ||
15 | -#i cannot add the large file, since its an internal applications mo file | ||
16 | -FastGettext.add_text_domain('large',:path=>locale_folder('large')) | ||
17 | -FastGettext.text_domain = 'large' | ||
18 | -results_large | ||
19 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/i18n_simple.rb
@@ -1,7 +0,0 @@ | @@ -1,7 +0,0 @@ | ||
1 | -require 'benchmark/base' | ||
2 | -require 'activesupport' | ||
3 | -I18n.backend = I18n::Backend::Simple.new | ||
4 | -I18n.load_path = ['benchmark/locale/de.yml'] | ||
5 | -I18n.locale = :de | ||
6 | -puts "ActiveSupport I18n::Backend::Simple :" | ||
7 | -results_test{I18n.translate('activerecord.models.car')=='Auto'} | ||
8 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/ideal.rb
@@ -1,24 +0,0 @@ | @@ -1,24 +0,0 @@ | ||
1 | -require 'benchmark/base' | ||
2 | - | ||
3 | -$LOAD_PATH.unshift 'lib' | ||
4 | - | ||
5 | -module FastestGettext | ||
6 | - def set_domain(folder,domain,locale) | ||
7 | - @data = {} | ||
8 | - require 'fast_gettext/vendor/mofile' | ||
9 | - FastGettext::GetText::MOFile.open(File.join(folder,locale,'LC_MESSAGES',"#{domain}.mo"), "UTF-8").each{|k,v|@data[k]=v} | ||
10 | - end | ||
11 | - def _(word) | ||
12 | - @data[word] | ||
13 | - end | ||
14 | -end | ||
15 | - | ||
16 | - | ||
17 | -include FastestGettext | ||
18 | -set_domain(locale_folder('test'),'test','de') | ||
19 | -puts "Ideal: (primitive Hash lookup)" | ||
20 | -results_test{_('car') == 'Auto'} | ||
21 | - | ||
22 | -#i cannot add the large file, since its an internal applications mo file | ||
23 | -set_domain(locale_folder('large'),'large','de') | ||
24 | -results_large |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/misc/threadsave.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -require 'benchmark' | ||
2 | -BASELINE = 0 | ||
3 | -def test | ||
4 | - result = Benchmark.measure {1_000_000.times{ yield }} | ||
5 | - result.to_s.strip.split(' ').first.to_f - BASELINE | ||
6 | -end | ||
7 | - | ||
8 | -BASELINE = (test{}) | ||
9 | -Thread.current[:library_name]={} | ||
10 | -other = "x" | ||
11 | -puts "Ruby #{VERSION}" | ||
12 | - | ||
13 | -puts "generic:" | ||
14 | -puts " Symbol: #{test{Thread.current[:library_name][:just_a_symbol]}}s" | ||
15 | -puts " String concat: #{test{Thread.current["xxxxxx"<<other.to_s]}}s" | ||
16 | -puts " String add: #{test{Thread.current["xxxxxx"+other.to_s]}}s" | ||
17 | -puts " String insert: #{test{Thread.current["xxxxxx#{other}"]}}s" | ||
18 | - | ||
19 | -puts "single:" | ||
20 | -puts " Symbol: #{test{Thread.current[:long_unique_symbol]}}s" | ||
21 | -puts " String: #{test{Thread.current["xxxxxx"]}}s" | ||
22 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/namespace/fast_gettext.rb
@@ -1,15 +0,0 @@ | @@ -1,15 +0,0 @@ | ||
1 | -#Iconv will not be defined, unless it is found -> normalize test results for users that have Iconv/those who do not have it | ||
2 | -begin;require 'iconv';rescue;LoadError;end | ||
3 | -initial = methods.count + Module.constants.count | ||
4 | - | ||
5 | -#FastGettext | ||
6 | -$LOAD_PATH.unshift File.join(File.dirname(__FILE__),'..','..','lib') | ||
7 | -require 'fast_gettext' | ||
8 | -FastGettext.locale = 'de' | ||
9 | -FastGettext.add_text_domain 'test', :path=>'spec/locale' | ||
10 | -FastGettext.text_domain = 'test' | ||
11 | -include FastGettext::Translation | ||
12 | -raise unless _('car')=='Auto' | ||
13 | - | ||
14 | -puts "FastGettext" | ||
15 | -puts methods.count + Module.constants.count - initial | ||
16 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/namespace/original.rb
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
1 | -require 'rubygems' | ||
2 | -initial = methods.count + Module.constants.count | ||
3 | - | ||
4 | -#GetText | ||
5 | -gem 'gettext', '>=2.0.0' | ||
6 | -require 'gettext' | ||
7 | -GetText.locale = 'de' | ||
8 | -GetText.bindtextdomain('test',:path=>'spec/locale') | ||
9 | -include GetText | ||
10 | -raise unless _('car') == 'Auto' | ||
11 | - | ||
12 | - | ||
13 | -puts "GetText" | ||
14 | -puts methods.count + Module.constants.count - initial | ||
15 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/benchmark/original.rb
@@ -1,19 +0,0 @@ | @@ -1,19 +0,0 @@ | ||
1 | -require 'benchmark/base' | ||
2 | - | ||
3 | -begin | ||
4 | -gem 'gettext', '>=2.0.0' | ||
5 | -rescue LoadError | ||
6 | - $LOAD_PATH.unshift 'lib' | ||
7 | -end | ||
8 | -require 'gettext' | ||
9 | -include GetText | ||
10 | - | ||
11 | -self.locale = 'de' | ||
12 | - | ||
13 | -puts "GetText #{GetText::VERSION}:" | ||
14 | -bindtextdomain('test',:path=>locale_folder('test')) | ||
15 | -results_test{_('car') == 'Auto'} | ||
16 | - | ||
17 | -#i cannot add the large file, since its an internal applications mo file | ||
18 | -bindtextdomain('large',:path=>locale_folder('large')) | ||
19 | -results_large |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/examples/db/migration.rb
@@ -1,22 +0,0 @@ | @@ -1,22 +0,0 @@ | ||
1 | -class CreateTranslationTables < ActiveRecord::Migration | ||
2 | - def self.up | ||
3 | - create_table :translation_keys do |t| | ||
4 | - t.string :key, :unique=>true, :null=>false | ||
5 | - t.timestamps | ||
6 | - end | ||
7 | - add_index :translation_keys, :key #I am not sure if this helps.... | ||
8 | - | ||
9 | - create_table :translation_texts do |t| | ||
10 | - t.text :text | ||
11 | - t.string :locale | ||
12 | - t.integer :translation_key_id, :null=>false | ||
13 | - t.timestamps | ||
14 | - end | ||
15 | - add_index :translation_texts, :translation_key_id | ||
16 | - end | ||
17 | - | ||
18 | - def self.down | ||
19 | - drop_table :translation_keys | ||
20 | - drop_table :translation_texts | ||
21 | - end | ||
22 | -end | ||
23 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/examples/missing_translation_logger.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -class MissingTranslationLogger | ||
2 | - def call(unfound) | ||
3 | - logger.warn "#{FastGettext.locale}: #{unfound}" unless FastGettext.locale == 'en' | ||
4 | - end | ||
5 | - | ||
6 | - private | ||
7 | - | ||
8 | - def logger | ||
9 | - return @logger if @logger | ||
10 | - require 'logger' | ||
11 | - @logger = Logger.new("log/unfound_translations", 2, 5*(1024**2))#max 2x 5mb logfile | ||
12 | - end | ||
13 | -end | ||
14 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/fast_gettext.gemspec
@@ -1,122 +0,0 @@ | @@ -1,122 +0,0 @@ | ||
1 | -# Generated by jeweler | ||
2 | -# DO NOT EDIT THIS FILE DIRECTLY | ||
3 | -# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | ||
4 | -# -*- encoding: utf-8 -*- | ||
5 | - | ||
6 | -Gem::Specification.new do |s| | ||
7 | - s.name = %q{fast_gettext} | ||
8 | - s.version = "0.5.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{2010-01-30} | ||
13 | - s.email = %q{grosser.michael@gmail.com} | ||
14 | - s.extra_rdoc_files = [ | ||
15 | - "README.markdown" | ||
16 | - ] | ||
17 | - s.files = [ | ||
18 | - ".gitignore", | ||
19 | - "CHANGELOG", | ||
20 | - "README.markdown", | ||
21 | - "Rakefile", | ||
22 | - "VERSION", | ||
23 | - "benchmark/base.rb", | ||
24 | - "benchmark/baseline.rb", | ||
25 | - "benchmark/fast_gettext.rb", | ||
26 | - "benchmark/i18n_simple.rb", | ||
27 | - "benchmark/ideal.rb", | ||
28 | - "benchmark/locale/de.yml", | ||
29 | - "benchmark/locale/de/LC_MESSAGES/large.mo", | ||
30 | - "benchmark/misc/threadsave.rb", | ||
31 | - "benchmark/namespace/fast_gettext.rb", | ||
32 | - "benchmark/namespace/original.rb", | ||
33 | - "benchmark/original.rb", | ||
34 | - "examples/db/migration.rb", | ||
35 | - "examples/missing_translation_logger.rb", | ||
36 | - "fast_gettext.gemspec", | ||
37 | - "lib/fast_gettext.rb", | ||
38 | - "lib/fast_gettext/mo_file.rb", | ||
39 | - "lib/fast_gettext/po_file.rb", | ||
40 | - "lib/fast_gettext/storage.rb", | ||
41 | - "lib/fast_gettext/translation.rb", | ||
42 | - "lib/fast_gettext/translation_repository.rb", | ||
43 | - "lib/fast_gettext/translation_repository/base.rb", | ||
44 | - "lib/fast_gettext/translation_repository/chain.rb", | ||
45 | - "lib/fast_gettext/translation_repository/db.rb", | ||
46 | - "lib/fast_gettext/translation_repository/db_models/translation_key.rb", | ||
47 | - "lib/fast_gettext/translation_repository/db_models/translation_text.rb", | ||
48 | - "lib/fast_gettext/translation_repository/logger.rb", | ||
49 | - "lib/fast_gettext/translation_repository/mo.rb", | ||
50 | - "lib/fast_gettext/translation_repository/po.rb", | ||
51 | - "lib/fast_gettext/translation_repository/yaml.rb", | ||
52 | - "spec/aa_unconfigued_spec.rb", | ||
53 | - "spec/fast_gettext/mo_file_spec.rb", | ||
54 | - "spec/fast_gettext/storage_spec.rb", | ||
55 | - "spec/fast_gettext/translation_repository/base_spec.rb", | ||
56 | - "spec/fast_gettext/translation_repository/chain_spec.rb", | ||
57 | - "spec/fast_gettext/translation_repository/db_spec.rb", | ||
58 | - "spec/fast_gettext/translation_repository/logger_spec.rb", | ||
59 | - "spec/fast_gettext/translation_repository/mo_spec.rb", | ||
60 | - "spec/fast_gettext/translation_repository/po_spec.rb", | ||
61 | - "spec/fast_gettext/translation_repository/yaml_spec.rb", | ||
62 | - "spec/fast_gettext/translation_repository_spec.rb", | ||
63 | - "spec/fast_gettext/translation_spec.rb", | ||
64 | - "spec/fast_gettext_spec.rb", | ||
65 | - "spec/locale/de/LC_MESSAGES/test.mo", | ||
66 | - "spec/locale/de/test.po", | ||
67 | - "spec/locale/en/LC_MESSAGES/plural_test.mo", | ||
68 | - "spec/locale/en/LC_MESSAGES/test.mo", | ||
69 | - "spec/locale/en/plural_test.po", | ||
70 | - "spec/locale/en/test.po", | ||
71 | - "spec/locale/yaml/de.yml", | ||
72 | - "spec/locale/yaml/en.yml", | ||
73 | - "spec/locale/yaml/notfound.yml", | ||
74 | - "spec/spec_helper.rb", | ||
75 | - "spec/vendor/fake_load_path/iconv.rb", | ||
76 | - "spec/vendor/iconv_spec.rb", | ||
77 | - "spec/vendor/string_spec.rb", | ||
78 | - "vendor/README.rdoc", | ||
79 | - "vendor/empty.mo", | ||
80 | - "vendor/iconv.rb", | ||
81 | - "vendor/mofile.rb", | ||
82 | - "vendor/poparser.rb", | ||
83 | - "vendor/string.rb" | ||
84 | - ] | ||
85 | - s.homepage = %q{http://github.com/grosser/fast_gettext} | ||
86 | - s.rdoc_options = ["--charset=UTF-8"] | ||
87 | - s.require_paths = ["lib"] | ||
88 | - s.rubygems_version = %q{1.3.5} | ||
89 | - s.summary = %q{A simple, fast and threadsafe implementation of GetText} | ||
90 | - s.test_files = [ | ||
91 | - "spec/spec_helper.rb", | ||
92 | - "spec/aa_unconfigued_spec.rb", | ||
93 | - "spec/vendor/fake_load_path/iconv.rb", | ||
94 | - "spec/vendor/iconv_spec.rb", | ||
95 | - "spec/vendor/string_spec.rb", | ||
96 | - "spec/fast_gettext_spec.rb", | ||
97 | - "spec/fast_gettext/translation_repository_spec.rb", | ||
98 | - "spec/fast_gettext/translation_repository/mo_spec.rb", | ||
99 | - "spec/fast_gettext/translation_repository/db_spec.rb", | ||
100 | - "spec/fast_gettext/translation_repository/yaml_spec.rb", | ||
101 | - "spec/fast_gettext/translation_repository/logger_spec.rb", | ||
102 | - "spec/fast_gettext/translation_repository/base_spec.rb", | ||
103 | - "spec/fast_gettext/translation_repository/po_spec.rb", | ||
104 | - "spec/fast_gettext/translation_repository/chain_spec.rb", | ||
105 | - "spec/fast_gettext/translation_spec.rb", | ||
106 | - "spec/fast_gettext/mo_file_spec.rb", | ||
107 | - "spec/fast_gettext/storage_spec.rb", | ||
108 | - "examples/missing_translation_logger.rb", | ||
109 | - "examples/db/migration.rb" | ||
110 | - ] | ||
111 | - | ||
112 | - if s.respond_to? :specification_version then | ||
113 | - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
114 | - s.specification_version = 3 | ||
115 | - | ||
116 | - if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then | ||
117 | - else | ||
118 | - end | ||
119 | - else | ||
120 | - end | ||
121 | -end | ||
122 | - |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext.rb
@@ -1,30 +0,0 @@ | @@ -1,30 +0,0 @@ | ||
1 | -require 'fast_gettext/mo_file' | ||
2 | -require 'fast_gettext/storage' | ||
3 | -require 'fast_gettext/translation' | ||
4 | -require 'fast_gettext/translation_repository' | ||
5 | -require 'fast_gettext/vendor/string' | ||
6 | - | ||
7 | -module FastGettext | ||
8 | - include FastGettext::Storage | ||
9 | - extend self | ||
10 | - | ||
11 | - VERSION = File.read( File.join(File.dirname(__FILE__), 'fast_gettext', 'VERSION') ).strip | ||
12 | - LOCALE_REX = /^[a-z]{2}$|^[a-z]{2}_[A-Z]{2}$/ | ||
13 | - NAMESPACE_SEPERATOR = '|' | ||
14 | - | ||
15 | - # users should not include FastGettext, since this would conterminate their namespace | ||
16 | - # rather use | ||
17 | - # FastGettext.locale = .. | ||
18 | - # FastGettext.text_domain = .. | ||
19 | - # and | ||
20 | - # include FastGettext::Translation | ||
21 | - FastGettext::Translation.public_instance_methods.each do |method| | ||
22 | - define_method method do |*args| | ||
23 | - Translation.send(method,*args) | ||
24 | - end | ||
25 | - end | ||
26 | - | ||
27 | - def add_text_domain(name,options) | ||
28 | - translation_repositories[name] = TranslationRepository.build(name,options) | ||
29 | - end | ||
30 | -end |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/VERSION
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -0.5.1 |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/mo_file.rb
@@ -1,67 +0,0 @@ | @@ -1,67 +0,0 @@ | ||
1 | -require 'fast_gettext/vendor/mofile' | ||
2 | -module FastGettext | ||
3 | - # Responsibility: | ||
4 | - # - abstract mo files for Mo Repository | ||
5 | - class MoFile | ||
6 | - PLURAL_SEPERATOR = "\000" | ||
7 | - | ||
8 | - # file => path or FastGettext::GetText::MOFile | ||
9 | - def initialize(file) | ||
10 | - if file.is_a? FastGettext::GetText::MOFile | ||
11 | - @data = file | ||
12 | - else | ||
13 | - @data = FastGettext::GetText::MOFile.open(file, "UTF-8") | ||
14 | - end | ||
15 | - make_singular_and_plural_available | ||
16 | - end | ||
17 | - | ||
18 | - def [](key) | ||
19 | - @data[key] | ||
20 | - end | ||
21 | - | ||
22 | - #returns the plural forms or all singular translations that where found | ||
23 | - def plural(*msgids) | ||
24 | - translations = plural_translations(msgids) | ||
25 | - return translations unless translations.empty? | ||
26 | - msgids.map{|msgid| self[msgid] || msgid} #try to translate each id | ||
27 | - end | ||
28 | - | ||
29 | - def pluralisation_rule | ||
30 | - #gettext uses 0 as default rule, which would turn off all pluralisation, very clever... | ||
31 | - #additionally parsing fails when directly accessing po files, so this line was taken from gettext/mofile | ||
32 | - (@data['']||'').split("\n").each do |line| | ||
33 | - return lambda{|n|eval($2)} if /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line | ||
34 | - end | ||
35 | - nil | ||
36 | - end | ||
37 | - | ||
38 | - def self.empty | ||
39 | - MoFile.new(File.join(File.dirname(__FILE__),'vendor','empty.mo')) | ||
40 | - end | ||
41 | - | ||
42 | - private | ||
43 | - | ||
44 | - #(if plural==singular, prefer singular) | ||
45 | - def make_singular_and_plural_available | ||
46 | - data = {} | ||
47 | - @data.each do |key,translation| | ||
48 | - next unless key.include? PLURAL_SEPERATOR | ||
49 | - singular, plural = split_plurals(key) | ||
50 | - translation = split_plurals(translation) | ||
51 | - data[singular] ||= translation[0] | ||
52 | - data[plural] ||= translation[1] | ||
53 | - end | ||
54 | - @data.merge!(data){|key,old,new| old} | ||
55 | - end | ||
56 | - | ||
57 | - def split_plurals(singular_plural) | ||
58 | - singular_plural.split(PLURAL_SEPERATOR) | ||
59 | - end | ||
60 | - | ||
61 | - # Car, Cars => [Auto,Autos] or [] | ||
62 | - def plural_translations(msgids) | ||
63 | - plurals = self[msgids*PLURAL_SEPERATOR] | ||
64 | - if plurals then split_plurals(plurals) else [] end | ||
65 | - end | ||
66 | - end | ||
67 | -end |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/po_file.rb
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
1 | -require 'fast_gettext/mo_file' | ||
2 | -module FastGettext | ||
3 | - # Responsibility: | ||
4 | - # - abstract po files for Po Repository | ||
5 | - # TODO refactor... | ||
6 | - class PoFile | ||
7 | - def self.to_mo_file(file) | ||
8 | - require 'fast_gettext/vendor/poparser' | ||
9 | - mo_file = FastGettext::GetText::MOFile.new | ||
10 | - FastGettext::GetText::PoParser.new.parse(File.read(file),mo_file) | ||
11 | - MoFile.new(mo_file) | ||
12 | - end | ||
13 | - end | ||
14 | -end |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/storage.rb
@@ -1,188 +0,0 @@ | @@ -1,188 +0,0 @@ | ||
1 | -module FastGettext | ||
2 | - # Responsibility: | ||
3 | - # - store data threadsave | ||
4 | - # - provide error messages when repositories are unconfigured | ||
5 | - # - accept/reject locales that are set by the user | ||
6 | - module Storage | ||
7 | - class NoTextDomainConfigured < RuntimeError | ||
8 | - def to_s | ||
9 | - "Current textdomain (#{FastGettext.text_domain.inspect}) was not added, use FastGettext.add_text_domain !" | ||
10 | - end | ||
11 | - end | ||
12 | - | ||
13 | - [:available_locales, :_locale, :text_domain, :pluralisation_rule].each do |method_name| | ||
14 | - key = "fast_gettext_#{method_name}".to_sym | ||
15 | - define_method method_name do | ||
16 | - Thread.current[key] | ||
17 | - end | ||
18 | - | ||
19 | - define_method "#{method_name}=" do |value| | ||
20 | - Thread.current[key]=value | ||
21 | - update_current_cache | ||
22 | - end | ||
23 | - end | ||
24 | - private :_locale, :_locale= | ||
25 | - | ||
26 | - | ||
27 | - def available_locales | ||
28 | - Thread.current[:fast_gettext_available_locales] || default_available_locales | ||
29 | - end | ||
30 | - | ||
31 | - # == cattr_accessor :default_available_locales | ||
32 | - @@default_available_locales = nil | ||
33 | - def default_available_locales=(avail_locales) | ||
34 | - @@default_available_locales = avail_locales | ||
35 | - update_current_cache | ||
36 | - end | ||
37 | - | ||
38 | - def default_available_locales | ||
39 | - @@default_available_locales | ||
40 | - end | ||
41 | - | ||
42 | - | ||
43 | - def text_domain | ||
44 | - Thread.current[:fast_gettext_text_domain] || default_text_domain | ||
45 | - end | ||
46 | - | ||
47 | - # == cattr_accessor :default_text_domain | ||
48 | - @@default_text_domain = nil | ||
49 | - def default_text_domain=(domain) | ||
50 | - @@default_text_domain = domain | ||
51 | - update_current_cache | ||
52 | - end | ||
53 | - | ||
54 | - def default_text_domain | ||
55 | - @@default_text_domain | ||
56 | - end | ||
57 | - | ||
58 | - | ||
59 | - def pluralisation_rule | ||
60 | - Thread.current[:fast_gettext_pluralisation_rule] || current_repository.pluralisation_rule || lambda{|i| i!=1} | ||
61 | - end | ||
62 | - | ||
63 | - def current_cache | ||
64 | - Thread.current[:fast_gettext_current_cache] || {} | ||
65 | - end | ||
66 | - | ||
67 | - def current_cache=(cache) | ||
68 | - Thread.current[:fast_gettext_current_cache] = cache | ||
69 | - end | ||
70 | - | ||
71 | - #global, since re-parsing whole folders takes too much time... | ||
72 | - @@translation_repositories={} | ||
73 | - def translation_repositories | ||
74 | - @@translation_repositories | ||
75 | - end | ||
76 | - | ||
77 | - # used to speedup simple translations, does not work for pluralisation | ||
78 | - # caches[text_domain][locale][key]=translation | ||
79 | - @@caches={} | ||
80 | - def caches | ||
81 | - @@caches | ||
82 | - end | ||
83 | - | ||
84 | - def current_repository | ||
85 | - translation_repositories[text_domain] || raise(NoTextDomainConfigured) | ||
86 | - end | ||
87 | - | ||
88 | - def key_exist?(key) | ||
89 | - !!(cached_find key) | ||
90 | - end | ||
91 | - | ||
92 | - def cached_find(key) | ||
93 | - translation = current_cache[key] | ||
94 | - return translation if translation or translation == false #found or was not found before | ||
95 | - current_cache[key] = current_repository[key] || false | ||
96 | - end | ||
97 | - | ||
98 | - def cached_plural_find(*keys) | ||
99 | - key = '||||' + keys * '||||' | ||
100 | - translation = current_cache[key] | ||
101 | - return translation if translation or translation == false #found or was not found before | ||
102 | - current_cache[key] = current_repository.plural(*keys) || false | ||
103 | - end | ||
104 | - | ||
105 | - def locale | ||
106 | - _locale || ( default_locale || (available_locales||[]).first || 'en' ) | ||
107 | - end | ||
108 | - | ||
109 | - def locale=(new_locale) | ||
110 | - new_locale = best_locale_in(new_locale) | ||
111 | - self._locale = new_locale if new_locale | ||
112 | - end | ||
113 | - | ||
114 | - # for chaining: puts set_locale('xx') == 'xx' ? 'applied' : 'rejected' | ||
115 | - # returns the current locale, not the one that was supplied | ||
116 | - # like locale=(), whoes behavior cannot be changed | ||
117 | - def set_locale(new_locale) | ||
118 | - self.locale = new_locale | ||
119 | - locale | ||
120 | - end | ||
121 | - | ||
122 | - @@default_locale = nil | ||
123 | - def default_locale=(new_locale) | ||
124 | - @@default_locale = best_locale_in(new_locale) | ||
125 | - update_current_cache | ||
126 | - end | ||
127 | - | ||
128 | - def default_locale | ||
129 | - @@default_locale | ||
130 | - end | ||
131 | - | ||
132 | - #Opera: de-DE,de;q=0.9,en;q=0.8 | ||
133 | - #Firefox de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 | ||
134 | - #IE6/7 de | ||
135 | - #nil if nothing matches | ||
136 | - def best_locale_in(locales) | ||
137 | - formatted_sorted_locales(locales).each do |candidate| | ||
138 | - return candidate if not available_locales | ||
139 | - return candidate if available_locales.include?(candidate) | ||
140 | - return candidate[0..1] if available_locales.include?(candidate[0..1])#available locales include a langauge | ||
141 | - end | ||
142 | - return nil#nothing found im sorry :P | ||
143 | - end | ||
144 | - | ||
145 | - #turn off translation if none was defined to disable all resulting errors | ||
146 | - def silence_errors | ||
147 | - require 'fast_gettext/translation_repository/base' | ||
148 | - translation_repositories[text_domain] = TranslationRepository::Base.new('x') | ||
149 | - end | ||
150 | - | ||
151 | - private | ||
152 | - | ||
153 | - # de-de,DE-CH;q=0.9 -> ['de_DE','de_CH'] | ||
154 | - def formatted_sorted_locales(locales) | ||
155 | - found = weighted_locales(locales).reject{|x|x.empty?}.sort_by{|l|l.last}.reverse #sort them by weight which is the last entry | ||
156 | - found.flatten.map{|l| format_locale(l)} | ||
157 | - end | ||
158 | - | ||
159 | - #split the locale and seperate it into different languages | ||
160 | - #de-de,de;q=0.9,en;q=0.8 => [['de-de','de','0.5'], ['en','0.8']] | ||
161 | - def weighted_locales(locales) | ||
162 | - locales = locales.to_s.gsub(/\s/,'') | ||
163 | - found = [[]] | ||
164 | - locales.split(',').each do |part| | ||
165 | - if part =~ /;q=/ #contains language and weight ? | ||
166 | - found.last << part.split(/;q=/) | ||
167 | - found.last.flatten! | ||
168 | - found << [] | ||
169 | - else | ||
170 | - found.last << part | ||
171 | - end | ||
172 | - end | ||
173 | - found | ||
174 | - end | ||
175 | - | ||
176 | - #de-de -> de_DE | ||
177 | - def format_locale(locale) | ||
178 | - locale.sub(/^([a-zA-Z]{2})[-_]([a-zA-Z]{2})$/){$1.downcase+'_'+$2.upcase} | ||
179 | - end | ||
180 | - | ||
181 | - def update_current_cache | ||
182 | - caches[text_domain] ||= {} | ||
183 | - caches[text_domain][locale] ||= {} | ||
184 | - caches[text_domain][locale][""] = false #ignore gettext meta key when translating | ||
185 | - self.current_cache = caches[text_domain][locale] | ||
186 | - end | ||
187 | - end | ||
188 | -end | ||
189 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation.rb
@@ -1,53 +0,0 @@ | @@ -1,53 +0,0 @@ | ||
1 | -module FastGettext | ||
2 | - # this module should be included | ||
3 | - # Responsibility: | ||
4 | - # - direct translation queries to the current repository | ||
5 | - # - handle untranslated values | ||
6 | - # - understand / enforce namespaces | ||
7 | - # - decide which plural form is used | ||
8 | - module Translation | ||
9 | - extend self | ||
10 | - | ||
11 | - #make it usable in class definition, e.g. | ||
12 | - # class Y | ||
13 | - # include FastGettext::Translation | ||
14 | - # @@x = _('y') | ||
15 | - # end | ||
16 | - def self.included(klas) #:nodoc: | ||
17 | - klas.extend self | ||
18 | - end | ||
19 | - | ||
20 | - def _(key) | ||
21 | - FastGettext.cached_find(key) or key | ||
22 | - end | ||
23 | - | ||
24 | - #translate pluralized | ||
25 | - # some languages have up to 4 plural forms... | ||
26 | - # n_(singular, plural, plural form 2, ..., count) | ||
27 | - # n_('apple','apples',3) | ||
28 | - def n_(*keys) | ||
29 | - count = keys.pop | ||
30 | - translations = FastGettext.cached_plural_find *keys | ||
31 | - selected = FastGettext.pluralisation_rule.call(count) | ||
32 | - selected = selected ? 1 : 0 unless selected.is_a? Numeric #convert booleans to numbers | ||
33 | - translations[selected] || keys[selected] || keys.last | ||
34 | - end | ||
35 | - | ||
36 | - #translate, but discard namespace if nothing was found | ||
37 | - # Car|Tire -> Tire if no translation could be found | ||
38 | - def s_(key,seperator=nil) | ||
39 | - translation = FastGettext.cached_find(key) and return translation | ||
40 | - key.split(seperator||NAMESPACE_SEPERATOR).last | ||
41 | - end | ||
42 | - | ||
43 | - #tell gettext: this string need translation (will be found during parsing) | ||
44 | - def N_(translate) | ||
45 | - translate | ||
46 | - end | ||
47 | - | ||
48 | - #tell gettext: this string need translation (will be found during parsing) | ||
49 | - def Nn_(*keys) | ||
50 | - keys | ||
51 | - end | ||
52 | - end | ||
53 | -end | ||
54 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -module FastGettext | ||
2 | - # Responsibility: | ||
3 | - # - decide which repository to choose from given input | ||
4 | - module TranslationRepository | ||
5 | - extend self | ||
6 | - | ||
7 | - # only single-word types supported atm (mytype works, MyType will not) | ||
8 | - def build(name, options) | ||
9 | - type = options[:type] || :mo | ||
10 | - class_name = type.to_s.capitalize | ||
11 | - unless FastGettext::TranslationRepository.constants.map{|c|c.to_s}.include?(class_name) | ||
12 | - require "fast_gettext/translation_repository/#{type}" | ||
13 | - end | ||
14 | - eval(class_name).new(name,options) | ||
15 | - end | ||
16 | - end | ||
17 | -end | ||
18 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/base.rb
@@ -1,49 +0,0 @@ | @@ -1,49 +0,0 @@ | ||
1 | -module FastGettext | ||
2 | - module TranslationRepository | ||
3 | - # Responsibility: | ||
4 | - # - base for all repositories | ||
5 | - # - fallback as empty repository, that cannot translate anything but does not crash | ||
6 | - class Base | ||
7 | - def initialize(name,options={}) | ||
8 | - @name = name | ||
9 | - @options = options | ||
10 | - end | ||
11 | - | ||
12 | - def pluralisation_rule | ||
13 | - nil | ||
14 | - end | ||
15 | - | ||
16 | - def available_locales | ||
17 | - [] | ||
18 | - end | ||
19 | - | ||
20 | - def [](key) | ||
21 | - current_translations[key] | ||
22 | - end | ||
23 | - | ||
24 | - def plural(*keys) | ||
25 | - current_translations.plural(*keys) | ||
26 | - end | ||
27 | - | ||
28 | - protected | ||
29 | - | ||
30 | - def current_translations | ||
31 | - MoFile.empty | ||
32 | - end | ||
33 | - | ||
34 | - def find_files_in_locale_folders(relative_file_path,path) | ||
35 | - path ||= "locale" | ||
36 | - raise "path #{path} cound not be found!" unless File.exist?(path) | ||
37 | - | ||
38 | - @files = {} | ||
39 | - Dir[File.join(path,'*')].each do |locale_folder| | ||
40 | - next unless File.basename(locale_folder) =~ LOCALE_REX | ||
41 | - file = File.join(locale_folder,relative_file_path) | ||
42 | - next unless File.exist? file | ||
43 | - locale = File.basename(locale_folder) | ||
44 | - @files[locale] = yield(locale,file) | ||
45 | - end | ||
46 | - end | ||
47 | - end | ||
48 | - end | ||
49 | -end | ||
50 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/chain.rb
@@ -1,43 +0,0 @@ | @@ -1,43 +0,0 @@ | ||
1 | -require 'fast_gettext/translation_repository/base' | ||
2 | - | ||
3 | -module FastGettext | ||
4 | - module TranslationRepository | ||
5 | - # Responsibility: | ||
6 | - # - delegate calls to members of the chain in turn | ||
7 | - #TODO cache should be expired after a repo was added | ||
8 | - class Chain < Base | ||
9 | - attr_accessor :chain | ||
10 | - | ||
11 | - def initialize(name,options={}) | ||
12 | - super | ||
13 | - self.chain = options[:chain] | ||
14 | - end | ||
15 | - | ||
16 | - def available_locales | ||
17 | - chain.map{|c|c.available_locales}.flatten.uniq | ||
18 | - end | ||
19 | - | ||
20 | - def pluralisation_rule | ||
21 | - chain.each do |c| | ||
22 | - result = c.pluralisation_rule and return result | ||
23 | - end | ||
24 | - nil | ||
25 | - end | ||
26 | - | ||
27 | - def [](key) | ||
28 | - chain.each do |c| | ||
29 | - result = c[key] and return result | ||
30 | - end | ||
31 | - nil | ||
32 | - end | ||
33 | - | ||
34 | - def plural(*keys) | ||
35 | - chain.each do |c| | ||
36 | - result = c.plural(*keys) | ||
37 | - return result unless result.compact.empty? | ||
38 | - end | ||
39 | - [] | ||
40 | - end | ||
41 | - end | ||
42 | - end | ||
43 | -end | ||
44 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/db.rb
@@ -1,57 +0,0 @@ | @@ -1,57 +0,0 @@ | ||
1 | -require 'active_record' | ||
2 | -module FastGettext | ||
3 | - module TranslationRepository | ||
4 | - # Responsibility: | ||
5 | - # - provide access to translations in database through a database abstraction | ||
6 | - # | ||
7 | - # Options: | ||
8 | - # :model => Model that represents your keys | ||
9 | - # you can either use the models supplied under db/, extend them or build your own | ||
10 | - # only constraints: | ||
11 | - # key: find_by_key, translations | ||
12 | - # translation: text, locale | ||
13 | - class Db | ||
14 | - def initialize(name,options={}) | ||
15 | - @model = options[:model] | ||
16 | - end | ||
17 | - | ||
18 | - @@seperator = '||||' # string that seperates multiple plurals | ||
19 | - def self.seperator=(sep);@@seperator = sep;end | ||
20 | - def self.seperator;@@seperator;end | ||
21 | - | ||
22 | - def available_locales | ||
23 | - if @model.respond_to? :available_locales | ||
24 | - @model.available_locales || [] | ||
25 | - else | ||
26 | - [] | ||
27 | - end | ||
28 | - end | ||
29 | - | ||
30 | - def pluralisation_rule | ||
31 | - if @model.respond_to? :pluralsation_rule | ||
32 | - @model.pluralsation_rule | ||
33 | - else | ||
34 | - nil | ||
35 | - end | ||
36 | - end | ||
37 | - | ||
38 | - def [](key) | ||
39 | - @model.translation(key, FastGettext.locale) | ||
40 | - end | ||
41 | - | ||
42 | - def plural(*args) | ||
43 | - if translation = @model.translation(args*self.class.seperator, FastGettext.locale) | ||
44 | - translation.to_s.split(self.class.seperator) | ||
45 | - else | ||
46 | - [] | ||
47 | - end | ||
48 | - end | ||
49 | - | ||
50 | - def self.require_models | ||
51 | - require 'fast_gettext/translation_repository/db_models/translation_key' | ||
52 | - require 'fast_gettext/translation_repository/db_models/translation_text' | ||
53 | - FastGettext::TranslationRepository::DbModels | ||
54 | - end | ||
55 | - end | ||
56 | - end | ||
57 | -end | ||
58 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/db_models/translation_key.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -module FastGettext::TranslationRepository | ||
2 | - module DbModels | ||
3 | - class TranslationKey < ActiveRecord::Base | ||
4 | - has_many :translations, :class_name=>'TranslationText' | ||
5 | - accepts_nested_attributes_for :translations, :allow_destroy => true | ||
6 | - | ||
7 | - validates_uniqueness_of :key | ||
8 | - validates_presence_of :key | ||
9 | - | ||
10 | - def self.translation(key, locale) | ||
11 | - return unless translation_key = find_by_key(key) | ||
12 | - return unless translation_text = translation_key.translations.find_by_locale(locale) | ||
13 | - translation_text.text | ||
14 | - end | ||
15 | - | ||
16 | - def self.available_locales | ||
17 | - @@available_locales ||= TranslationText.count(:group=>:locale).keys.sort | ||
18 | - end | ||
19 | - | ||
20 | - #this is only for ActiveSupport to get polymorphic_url FastGettext::... namespace free | ||
21 | - def self.model_name | ||
22 | - ActiveSupport::ModelName.new('TranslationKey') | ||
23 | - end | ||
24 | - end | ||
25 | - end | ||
26 | -end | ||
27 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/db_models/translation_text.rb
@@ -1,9 +0,0 @@ | @@ -1,9 +0,0 @@ | ||
1 | -module FastGettext::TranslationRepository | ||
2 | - module DbModels | ||
3 | - class TranslationText < ActiveRecord::Base | ||
4 | - belongs_to :key, :class_name=>'TranslationKey' | ||
5 | - validates_presence_of :locale | ||
6 | - validates_uniqueness_of :locale, :scope=>:translation_key_id | ||
7 | - end | ||
8 | - end | ||
9 | -end | ||
10 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/logger.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -require 'fast_gettext/translation_repository/base' | ||
2 | - | ||
3 | -module FastGettext | ||
4 | - module TranslationRepository | ||
5 | - # This should be used in a TranslationRepository::Chain, so tat untranslated keys can be found | ||
6 | - # Responsibility: | ||
7 | - # - log every translation call | ||
8 | - class Logger < Base | ||
9 | - attr_accessor :callback | ||
10 | - | ||
11 | - def initialize(name,options={}) | ||
12 | - super | ||
13 | - self.callback = options[:callback] | ||
14 | - end | ||
15 | - | ||
16 | - def [](key) | ||
17 | - callback.call(key) | ||
18 | - nil | ||
19 | - end | ||
20 | - | ||
21 | - def plural(*keys) | ||
22 | - callback.call(keys) | ||
23 | - [] | ||
24 | - end | ||
25 | - end | ||
26 | - end | ||
27 | -end | ||
28 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/mo.rb
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -require 'fast_gettext/translation_repository/base' | ||
2 | -module FastGettext | ||
3 | - module TranslationRepository | ||
4 | - # Responsibility: | ||
5 | - # - find and store mo files | ||
6 | - # - provide access to translations in mo files | ||
7 | - class Mo < Base | ||
8 | - def initialize(name,options={}) | ||
9 | - find_and_store_files(name,options) | ||
10 | - super | ||
11 | - end | ||
12 | - | ||
13 | - def available_locales | ||
14 | - @files.keys | ||
15 | - end | ||
16 | - | ||
17 | - def pluralisation_rule | ||
18 | - current_translations.pluralisation_rule | ||
19 | - end | ||
20 | - | ||
21 | - protected | ||
22 | - | ||
23 | - def find_and_store_files(name,options) | ||
24 | - # parse all .mo files with the right name, that sit in locale/LC_MESSAGES folders | ||
25 | - find_files_in_locale_folders(File.join('LC_MESSAGES',"#{name}.mo"), options[:path]) do |locale,file| | ||
26 | - @files[locale] = MoFile.new(file) | ||
27 | - end | ||
28 | - end | ||
29 | - | ||
30 | - def current_translations | ||
31 | - @files[FastGettext.locale] || MoFile.empty | ||
32 | - end | ||
33 | - end | ||
34 | - end | ||
35 | -end | ||
36 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/po.rb
@@ -1,18 +0,0 @@ | @@ -1,18 +0,0 @@ | ||
1 | -require 'fast_gettext/translation_repository/base' | ||
2 | -require 'fast_gettext/translation_repository/mo' | ||
3 | -module FastGettext | ||
4 | - module TranslationRepository | ||
5 | - # Responsibility: | ||
6 | - # - find and store po files | ||
7 | - # - provide access to translations in po files | ||
8 | - class Po < Mo | ||
9 | - protected | ||
10 | - def find_and_store_files(name,options) | ||
11 | - require 'fast_gettext/po_file' | ||
12 | - find_files_in_locale_folders("#{name}.po",options[:path]) do |locale,file| | ||
13 | - @files[locale] = PoFile.to_mo_file(file) | ||
14 | - end | ||
15 | - end | ||
16 | - end | ||
17 | - end | ||
18 | -end | ||
19 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/translation_repository/yaml.rb
@@ -1,72 +0,0 @@ | @@ -1,72 +0,0 @@ | ||
1 | -require 'fast_gettext/translation_repository/base' | ||
2 | -require 'yaml' | ||
3 | - | ||
4 | -module FastGettext | ||
5 | - module TranslationRepository | ||
6 | - # Responsibility: | ||
7 | - # - find and store yaml files | ||
8 | - # - provide access to translations in yaml files | ||
9 | - class Yaml < Base | ||
10 | - def initialize(name,options={}) | ||
11 | - find_and_store_files(options) | ||
12 | - super | ||
13 | - end | ||
14 | - | ||
15 | - def available_locales | ||
16 | - @files.keys | ||
17 | - end | ||
18 | - | ||
19 | - def plural(*keys) | ||
20 | - ['one', 'other', 'plural2', 'plural3'].map do |name| | ||
21 | - self[yaml_dot_notation(keys.first, name)] | ||
22 | - end | ||
23 | - end | ||
24 | - | ||
25 | - def pluralisation_rule | ||
26 | - self['pluralisation_rule'] ? lambda{|n| eval(self['pluralisation_rule']) } : nil | ||
27 | - end | ||
28 | - | ||
29 | - protected | ||
30 | - | ||
31 | - MAX_FIND_DEPTH = 10 | ||
32 | - | ||
33 | - def find_and_store_files(options) | ||
34 | - @files = {} | ||
35 | - path = options[:path] || 'config/locales' | ||
36 | - Dir["#{path}/??.yml"].each do |yaml_file| | ||
37 | - locale = yaml_file.match(/([a-z]{2})\.yml$/)[1] | ||
38 | - @files[locale] = load_yaml(yaml_file, locale) | ||
39 | - end | ||
40 | - end | ||
41 | - | ||
42 | - def current_translations | ||
43 | - @files[FastGettext.locale] || super | ||
44 | - end | ||
45 | - | ||
46 | - # Given a yaml file return a hash of key -> translation | ||
47 | - def load_yaml(file, locale) | ||
48 | - yaml = YAML.load_file(file) | ||
49 | - yaml_hash_to_dot_notation(yaml[locale]) | ||
50 | - end | ||
51 | - | ||
52 | - def yaml_hash_to_dot_notation(yaml_hash) | ||
53 | - add_yaml_key({}, nil, yaml_hash) | ||
54 | - end | ||
55 | - | ||
56 | - def add_yaml_key(result, prefix, hash) | ||
57 | - hash.each_pair do |key, value| | ||
58 | - if value.kind_of?(Hash) | ||
59 | - add_yaml_key(result, yaml_dot_notation(prefix, key), value) | ||
60 | - else | ||
61 | - result[yaml_dot_notation(prefix, key)] = value | ||
62 | - end | ||
63 | - end | ||
64 | - result | ||
65 | - end | ||
66 | - | ||
67 | - def yaml_dot_notation(a,b) | ||
68 | - a ? "#{a}.#{b}" : b | ||
69 | - end | ||
70 | - end | ||
71 | - end | ||
72 | -end | ||
73 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/vendor/README.rdoc
@@ -1,236 +0,0 @@ | @@ -1,236 +0,0 @@ | ||
1 | -= Ruby-GetText-Package | ||
2 | - | ||
3 | -Ruby-GetText-Package is a Localization(L10n) library and tool | ||
4 | -which is modeled after the GNU gettext package. | ||
5 | - | ||
6 | -This library translates original messages to localized | ||
7 | -messages using client-side locale information(environment | ||
8 | -variable or CGI variable). | ||
9 | - | ||
10 | -The tools for developers support creating, useing, and modifying | ||
11 | -localized message files(message catalogs). | ||
12 | - | ||
13 | -((*Rails*)) | ||
14 | -Rails support has been removed. | ||
15 | -Rails / ActiveRecord specific code now lives in gettext_rails and gettext_activerecord. | ||
16 | - | ||
17 | -== Website | ||
18 | -* homepage[http://www.yotabanana.com/hiki/ruby-gettext.html] | ||
19 | -* on rubyforge[http://gettext/rubyforge.org/] | ||
20 | -* on github[http://github.com/gettext/] | ||
21 | - | ||
22 | -== Features | ||
23 | -* Simple APIs(similar to GNU gettext) | ||
24 | - | ||
25 | -* rgettext creates po-files from | ||
26 | - * ruby scripts | ||
27 | - * glade-2 XML file(.glade) | ||
28 | - * ERB file(.rhtml, .erb) | ||
29 | - * Anything (with your own parsers) | ||
30 | - * The po-files are compatible to GNU gettext. | ||
31 | - | ||
32 | -* rmsgfmt creates a mo-file from a po-file. | ||
33 | - The mo-file is compatible to GNU gettext(msgfmt). | ||
34 | - | ||
35 | -* textdomain's scope is adapt to ruby class/module mechanism. | ||
36 | - * A class/module can have plural textdomains. | ||
37 | - * a message is looked up in its class/module and ancestors. | ||
38 | - | ||
39 | -* CGI support (gettext/cgi) | ||
40 | - * Locale is retrieved from client informations | ||
41 | - (HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, QUERY_STRING(lang), Cookies(lang)). | ||
42 | - | ||
43 | -* String%() is extended to use named argument such as <tt>%{foo}" %{:foo => 1}</tt>. | ||
44 | - Notes that Ruby-1.9.x supports this format by itself. | ||
45 | - | ||
46 | -== Requirements | ||
47 | -* {Ruby 1.8.3 or later}[http://www.ruby-lang.org] | ||
48 | -* {Rubygems}[http://www.rubygems.org/] | ||
49 | -* {locale gem}[http://rubyforge.org/projects/locale/] | ||
50 | - * $ gem install locale | ||
51 | -* (for development only) | ||
52 | - * {GNU gettext 0.10.35 or later}[http://www.gnu.org/software/gettext/gettext.html] | ||
53 | - * {Racc-1.4.3 or later}[http://www.ruby-lang.org/raa/list.rhtml?name=racc] | ||
54 | - * (for compiling src/rmsgfmt.ry only) | ||
55 | - | ||
56 | -== Install | ||
57 | -* Uninstall old gettext if exists. | ||
58 | - (sudo/su on POSIX system) | ||
59 | - gem uninstall gettext | ||
60 | - | ||
61 | -* gem | ||
62 | - #from github (edge/unstable) | ||
63 | - (sudo/su on POSIX system) | ||
64 | - gem install locale | ||
65 | - gem install mutoh-gettext -s http://gems.github.com/ | ||
66 | - | ||
67 | - #from rubyforge (stable) | ||
68 | - (sudo/su on POSIX system) | ||
69 | - gem install locale | ||
70 | - gem install gettext | ||
71 | - | ||
72 | -* download tar-ball | ||
73 | - # De-Compress archive and enter its top directory. | ||
74 | - (sudo/su on POSIX system) | ||
75 | - ruby setup.rb | ||
76 | - | ||
77 | -You can also install files in your favorite directory by | ||
78 | -supplying setup.rb some options. Try <tt>ruby setup.rb --help</tt>. | ||
79 | - | ||
80 | -== Usage | ||
81 | -===Translation | ||
82 | -- _: Basic translation method | ||
83 | - Translates the message. | ||
84 | - _("Hello") | ||
85 | - | ||
86 | -The gettext methods comes in 3 combinable flavors | ||
87 | -- n: Pluralized | ||
88 | - Returns singular or plural form, depending on how many you have. | ||
89 | - n_("Apple", "%{num} Apples", 3) | ||
90 | - n_(["Apple", "%{num} Apples"], 3) | ||
91 | - | ||
92 | -- p: context aware | ||
93 | - A context is a prefix to your translation, usefull when one word has different meanings, depending on its context. | ||
94 | - p_("Printer","Open") <=> p_("File","Open") | ||
95 | - is the same as s_("Printer|Open") <=> s_("File|Open") | ||
96 | - | ||
97 | -- s: without context | ||
98 | - If a translation could not be found, return the msgid without context. | ||
99 | - s_("Printer|Open") => "Öffnen" #translation found | ||
100 | - s_("Printer|Open") => "Open" #translation not found | ||
101 | - | ||
102 | -- combinations | ||
103 | - np_("Fruit", "Apple", "%{num} Apples", 3) | ||
104 | - ns_("Fruit|Apple","%{num} Apples", 3) | ||
105 | - | ||
106 | - np_(["Fruit","Apple","%{num} Apples"], 3) | ||
107 | - ns_(["Fruit|Apple","%{num} Apples"], 3) | ||
108 | - | ||
109 | -- N_, Nn_: Makes dynamic translation messages readable for the gettext parser. | ||
110 | - <tt>_(fruit)</tt> cannot be understood by the gettext parser. To help the parser find all your translations, | ||
111 | - you can add <tt>fruit = N_("Apple")</tt> which does not translate, but tells the parser: "Apple" needs translation. | ||
112 | - | ||
113 | - fruit = N_("Apple") # same as fruit = "Apple" | ||
114 | - _(fruit) # does a normal translation | ||
115 | - | ||
116 | - fruits = Nn_("Apple", "%{num} Apples") | ||
117 | - n_(fruits, 3) | ||
118 | - | ||
119 | -=== Locale / Domain | ||
120 | -GetText stores the locale your are using | ||
121 | - GetText.locale = "en_US" # translate into english from now on | ||
122 | - GetText.locale # => en_US | ||
123 | -Or | ||
124 | - include GetText | ||
125 | - set_locale "en_US" | ||
126 | - | ||
127 | -Each locale can have different sets of translations (text domains) (e.g. Financial terms + Human-resource terms) | ||
128 | - GetText.bindtextdomain('financial') | ||
129 | -Or | ||
130 | - include GetText | ||
131 | - bindtextdomain('financial') | ||
132 | - | ||
133 | -For more details and options, have a look at the samples folder or | ||
134 | -consult the tutorial[http://www.yotabanana.com/hiki/ruby-gettext-howto.html]. | ||
135 | - | ||
136 | - | ||
137 | -== License | ||
138 | -This program is licenced under the same licence as Ruby. | ||
139 | -(See the file 'COPYING'.) | ||
140 | - | ||
141 | -* mofile.rb | ||
142 | - * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp> | ||
143 | - * Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp> | ||
144 | - | ||
145 | -* gettext.rb | ||
146 | - * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp> | ||
147 | - * Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp> | ||
148 | - | ||
149 | -* rgettext | ||
150 | - * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp> | ||
151 | - * Copyright (C) 2001,2002 Yasushi Shoji <yashi at atmark-techno.com> | ||
152 | - | ||
153 | -* setup.rb | ||
154 | - * Copyright (C) 2000-2005 Minero Aoki <aamine at loveruby.net> | ||
155 | - * This file is released under LGPL. See the top of the install.rb. | ||
156 | - | ||
157 | -* Others | ||
158 | - * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp> | ||
159 | - | ||
160 | - | ||
161 | -== Translators | ||
162 | -* Bosnian(bs) - Sanjin Sehic <saserr at gmail.com> | ||
163 | -* Bulgarian(bg) - Sava Chankov <sava.chankov at gmail.com> | ||
164 | -* Catalan(ca) - Ramon Salvadó <rsalvado at gnuine.com> | ||
165 | -* Chinese(Simplified)(zh_CN) | ||
166 | - * Yang Bob <bob.yang.dev at gmail.com> (current) | ||
167 | - * Yingfeng <blogyingfeng at gmail.com> | ||
168 | -* Chinese(Traditional)(zh_TW) | ||
169 | - * Yang Bob <bob.yang.dev at gmail.com> (current) | ||
170 | - * LIN CHUNG-YI <xmarsh at gmail.com> | ||
171 | -* Croatian(hr) - Sanjin Sehic <saserr at gmail.com> | ||
172 | -* Czech(cs) - Karel Miarka <kajism at yahoo.com> | ||
173 | -* Dutch(nl) - Menno Jonkers <ruby-gettext at jonkers.com> | ||
174 | -* Esperanto(eo) - Malte Milatz <malte at gmx-topmail.de> | ||
175 | -* Estonian(et) - Erkki Eilonen <erkki at itech.ee> | ||
176 | -* French(fr) | ||
177 | - * Vincent Isambart <vincent.isambart at gmail.com> (current) | ||
178 | - * David Sulc <davidsulc at gmail.com> | ||
179 | - * Laurent Sansonetti <laurent.sansonetti at gmail.com> | ||
180 | -* German(de) | ||
181 | - * Patrick Lenz <patrick at limited-overload.de> (current) | ||
182 | - * Detlef Reichl <detlef.reichl at gmx.org> | ||
183 | - * Sven Herzberg <herzi at abi02.de> | ||
184 | - * Sascha Ebach <se at digitale-wertschoepfung.de> | ||
185 | -* Greek(el) - Vassilis Rizopoulos <damphyr at gmx.net> | ||
186 | -* Hungarian(hu) - Tamás Tompa <tompata at gmail.com> | ||
187 | -* Italian(it) | ||
188 | - * Marco Lazzeri <marco.lazzeri at gmail.com> | ||
189 | - * Gabriele Renzi <surrender_it at yahoo.it> | ||
190 | -* Japanese(ja) - Masao Mutoh <mutoh at highway.ne.jp> | ||
191 | -* Korean(ko) - Gyoung-Yoon Noh <nohmad at gmail.com> | ||
192 | -* Latvian(lv) - Aivars Akots <aivars.akots at gmail.com> | ||
193 | -* Norwegian(nb) - Runar Ingebrigtsen <runar at mopo.no> | ||
194 | -* Portuguese(Brazil)(pt_BR) | ||
195 | - * Antonio S. de A. Terceiro <terceiro at softwarelivre.org> (current) | ||
196 | - * Joao Pedrosa <joaopedrosa at gmail.com> | ||
197 | -* Russian(ru) - Yuri Kozlov <kozlov.y at gmail.com> | ||
198 | -* Serbian(sr) - Slobodan Paunović" <slobodan.paunovic at gmail.com> | ||
199 | -* Spanish(es) | ||
200 | - * David Espada <davinci at escomposlinux.org> (current) | ||
201 | - * David Moreno Garza <damog at damog.net> | ||
202 | -* Swedish(sv) - Nikolai Weibull <mailing-lists.ruby-talk at rawuncut.elitemail.org> | ||
203 | -* Ukrainian(ua) - Alex Rootoff <rootoff at pisem.net> | ||
204 | -* Vietnamese(vi) - Ngoc Dao Thanh <ngocdaothanh at gmail.com> | ||
205 | - | ||
206 | -== Status of translations | ||
207 | -* Bosnian(bs) - 1.90.0 (old) | ||
208 | -* Bulgarian(bg) - 2.0.0pre1 (new) | ||
209 | -* Catalan(ca) - 2.0.0pre1 | ||
210 | -* Croatian(hr) - 1.90.0 (old) | ||
211 | -* Chinese(zh_CN) - 2.0.0pre1 | ||
212 | -* Chinese(zh_TW) - 2.0.0pre1 | ||
213 | -* Czech(cs) - 1.9.0 (old) | ||
214 | -* Dutch(nl) - 1.90.0 (old) | ||
215 | -* English(default) - 1.90.0 (old) | ||
216 | -* Esperanto(eo) - 2.0.0pre1 | ||
217 | -* Estonian(et) - 2.0.0pre1 | ||
218 | -* French(fr) - 2.0.0pre1 | ||
219 | -* German(de) - 2.0.0pre1 | ||
220 | -* Greek(el) - 2.0.0pre1 | ||
221 | -* Hungarian(hu) - 2.0.0pre1 | ||
222 | -* Italian(it) - 1.6.0 (old) | ||
223 | -* Japanese(ja) - 2.0.0pre1 | ||
224 | -* Korean(ko) - 1.9.0 (old) | ||
225 | -* Latvian(lv) - 2.0.0pre1 (new) | ||
226 | -* Norwegian(nb) - 2.0.0pre1 | ||
227 | -* Portuguese(Brazil)(pt_BR) - 2.0.0pre1 | ||
228 | -* Russian(ru) - 2.0.0pre1 | ||
229 | -* Serbian(sr) - 1.91.0 (old) | ||
230 | -* Spanish(es) - 2.0.0pre1 | ||
231 | -* Swedish(sv) - 0.8.0 (too much old) | ||
232 | -* Ukrainian(ua) - 2.0.0pre1 | ||
233 | -* Vietnamese(vi) - 2.0.0pre1 | ||
234 | - | ||
235 | -== Maintainer | ||
236 | -Masao Mutoh <mutoh at highway.ne.jp> |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/vendor/empty.mo
No preview for this file type
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/vendor/iconv.rb
@@ -1,107 +0,0 @@ | @@ -1,107 +0,0 @@ | ||
1 | -=begin | ||
2 | - iconv.rb - Pseudo Iconv class. Supports Iconv.iconv, Iconv.conv. | ||
3 | - | ||
4 | - For Matz Ruby: | ||
5 | - If you don't have iconv but glib2, this library uses glib2 iconv functions. | ||
6 | - | ||
7 | - For JRuby: | ||
8 | - Use Java String class to convert strings. | ||
9 | - | ||
10 | - Copyright (C) 2004-2007 Masao Mutoh | ||
11 | - | ||
12 | - You may redistribute it and/or modify it under the same | ||
13 | - license terms as Ruby. | ||
14 | - | ||
15 | - $Id: iconv.rb,v 1.6 2007/11/08 14:21:22 mutoh Exp $ | ||
16 | -=end | ||
17 | - | ||
18 | -#Modifications | ||
19 | -#wrapped inside FastGettext namespace to reduce conflic | ||
20 | - | ||
21 | -begin | ||
22 | - require 'iconv' | ||
23 | -rescue LoadError | ||
24 | - # Provides Iconv.iconv which normally is provided through Ruby/GLib(1) functions. | ||
25 | - # This library is required for 'gettext'. | ||
26 | - # If you require 'gettext/iconv', it tries to call Ruby/GLib function | ||
27 | - # when it doesn't find original Iconv class(iconv.so) it adds a pseudo class. | ||
28 | - # | ||
29 | - # One-click Ruby Installer for Win32 hadn’t had iconv and there hadn’t been a way to install iconv.so itself for Win32. | ||
30 | - # And JRuby hadn’t had Iconv. | ||
31 | - # I’ve not checked them currently, but if they’ve supported iconv now, we don’t need this anymore... | ||
32 | - # | ||
33 | - # (1) Ruby/GLib is a module which is provided from Ruby-GNOME2 Project. | ||
34 | - # You can get binaries for Win32(One-Click Ruby Installer). | ||
35 | - # <URL: http://ruby-gnome2.sourceforge.jp/> | ||
36 | - module FastGettext | ||
37 | - class Iconv2 | ||
38 | - module Failure; end | ||
39 | - class InvalidEncoding < ArgumentError; include Failure; end | ||
40 | - class IllegalSequence < ArgumentError; include Failure; end | ||
41 | - class InvalidCharacter < ArgumentError; include Failure; end | ||
42 | - | ||
43 | - if RUBY_PLATFORM =~ /java/ | ||
44 | - def self.conv(to, from, str) | ||
45 | - raise InvalidCharacter, "the 3rd argument is nil" unless str | ||
46 | - begin | ||
47 | - str = java.lang.String.new(str.unpack("C*").to_java(:byte), from) | ||
48 | - str.getBytes(to).to_ary.pack("C*") | ||
49 | - rescue java.io.UnsupportedEncodingException | ||
50 | - raise InvalidEncoding | ||
51 | - end | ||
52 | - end | ||
53 | - else | ||
54 | - begin | ||
55 | - require 'glib2' | ||
56 | - | ||
57 | - def self.check_glib_version?(major, minor, micro) # :nodoc: | ||
58 | - (GLib::BINDING_VERSION[0] > major || | ||
59 | - (GLib::BINDING_VERSION[0] == major && | ||
60 | - GLib::BINDING_VERSION[1] > minor) || | ||
61 | - (GLib::BINDING_VERSION[0] == major && | ||
62 | - GLib::BINDING_VERSION[1] == minor && | ||
63 | - GLib::BINDING_VERSION[2] >= micro)) | ||
64 | - end | ||
65 | - | ||
66 | - if check_glib_version?(0, 11, 0) | ||
67 | - # This is a function equivalent of Iconv.iconv. | ||
68 | - # * to: encoding name for destination | ||
69 | - # * from: encoding name for source | ||
70 | - # * str: strings to be converted | ||
71 | - # * Returns: Returns an Array of converted strings. | ||
72 | - def self.conv(to, from, str) | ||
73 | - begin | ||
74 | - GLib.convert(str, to, from) | ||
75 | - rescue GLib::ConvertError => e | ||
76 | - case e.code | ||
77 | - when GLib::ConvertError::NO_CONVERSION | ||
78 | - raise InvalidEncoding.new(str) | ||
79 | - when GLib::ConvertError::ILLEGAL_SEQUENCE | ||
80 | - raise IllegalSequence.new(str) | ||
81 | - else | ||
82 | - raise InvalidCharacter.new(str) | ||
83 | - end | ||
84 | - end | ||
85 | - end | ||
86 | - else | ||
87 | - def self.conv(to, from, str) # :nodoc: | ||
88 | - begin | ||
89 | - GLib.convert(str, to, from) | ||
90 | - rescue | ||
91 | - raise IllegalSequence.new(str) | ||
92 | - end | ||
93 | - end | ||
94 | - end | ||
95 | - rescue LoadError | ||
96 | - def self.conv(to, from, str) # :nodoc: | ||
97 | - warn "Iconv was not found." if $DEBUG | ||
98 | - str | ||
99 | - end | ||
100 | - end | ||
101 | - end | ||
102 | - def self.iconv(to, from, str) | ||
103 | - conv(to, from, str).split(//) | ||
104 | - end | ||
105 | - end | ||
106 | - end | ||
107 | -end | ||
108 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/vendor/mofile.rb
@@ -1,296 +0,0 @@ | @@ -1,296 +0,0 @@ | ||
1 | -=begin | ||
2 | - mofile.rb - A simple class for operating GNU MO file. | ||
3 | - | ||
4 | - Copyright (C) 2003-2008 Masao Mutoh | ||
5 | - Copyright (C) 2002 Masahiro Sakai, Masao Mutoh | ||
6 | - Copyright (C) 2001 Masahiro Sakai | ||
7 | - | ||
8 | - Masahiro Sakai <s01397ms at sfc.keio.ac.jp> | ||
9 | - Masao Mutoh <mutoh at highway.ne.jp> | ||
10 | - | ||
11 | - You can redistribute this file and/or modify it under the same term | ||
12 | - of Ruby. License of Ruby is included with Ruby distribution in | ||
13 | - the file "README". | ||
14 | - | ||
15 | - $Id: mo.rb,v 1.10 2008/06/17 16:40:52 mutoh Exp $ | ||
16 | -=end | ||
17 | - | ||
18 | -require 'iconv' | ||
19 | -require 'stringio' | ||
20 | - | ||
21 | -#Modifications: | ||
22 | -# use Iconv or FastGettext::Icvon | ||
23 | - | ||
24 | -module FastGettext | ||
25 | - module GetText | ||
26 | - class MOFile < Hash | ||
27 | - class InvalidFormat < RuntimeError; end; | ||
28 | - | ||
29 | - attr_reader :filename | ||
30 | - | ||
31 | - Header = Struct.new(:magic, | ||
32 | - :revision, | ||
33 | - :nstrings, | ||
34 | - :orig_table_offset, | ||
35 | - :translated_table_offset, | ||
36 | - :hash_table_size, | ||
37 | - :hash_table_offset) | ||
38 | - | ||
39 | - # The following are only used in .mo files | ||
40 | - # with minor revision >= 1. | ||
41 | - class HeaderRev1 < Header | ||
42 | - attr_accessor :n_sysdep_segments, | ||
43 | - :sysdep_segments_offset, | ||
44 | - :n_sysdep_strings, | ||
45 | - :orig_sysdep_tab_offset, | ||
46 | - :trans_sysdep_tab_offset | ||
47 | - end | ||
48 | - | ||
49 | - MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde" | ||
50 | - MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95" | ||
51 | - | ||
52 | - def self.open(arg = nil, output_charset = nil) | ||
53 | - result = self.new(output_charset) | ||
54 | - result.load(arg) | ||
55 | - end | ||
56 | - | ||
57 | - def initialize(output_charset = nil) | ||
58 | - @filename = nil | ||
59 | - @last_modified = nil | ||
60 | - @little_endian = true | ||
61 | - @output_charset = output_charset | ||
62 | - super() | ||
63 | - end | ||
64 | - | ||
65 | - def update! | ||
66 | - if FileTest.exist?(@filename) | ||
67 | - st = File.stat(@filename) | ||
68 | - load(@filename) unless (@last_modified == [st.ctime, st.mtime]) | ||
69 | - else | ||
70 | - warn "#{@filename} was lost." if $DEBUG | ||
71 | - clear | ||
72 | - end | ||
73 | - self | ||
74 | - end | ||
75 | - | ||
76 | - def load(arg) | ||
77 | - if arg.kind_of? String | ||
78 | - begin | ||
79 | - st = File.stat(arg) | ||
80 | - @last_modified = [st.ctime, st.mtime] | ||
81 | - rescue Exception | ||
82 | - end | ||
83 | - load_from_file(arg) | ||
84 | - else | ||
85 | - load_from_stream(arg) | ||
86 | - end | ||
87 | - @filename = arg | ||
88 | - self | ||
89 | - end | ||
90 | - | ||
91 | - def load_from_stream(io) | ||
92 | - magic = io.read(4) | ||
93 | - case magic | ||
94 | - when MAGIC_BIG_ENDIAN | ||
95 | - @little_endian = false | ||
96 | - when MAGIC_LITTLE_ENDIAN | ||
97 | - @little_endian = true | ||
98 | - else | ||
99 | - raise InvalidFormat.new(sprintf("Unknown signature %s", magic.dump)) | ||
100 | - end | ||
101 | - | ||
102 | - endian_type6 = @little_endian ? 'V6' : 'N6' | ||
103 | - endian_type_astr = @little_endian ? 'V*' : 'N*' | ||
104 | - | ||
105 | - header = HeaderRev1.new(magic, *(io.read(4 * 6).unpack(endian_type6))) | ||
106 | - | ||
107 | - if header.revision == 1 | ||
108 | - # FIXME: It doesn't support sysdep correctly. | ||
109 | - header.n_sysdep_segments = io.read(4).unpack(endian_type6) | ||
110 | - header.sysdep_segments_offset = io.read(4).unpack(endian_type6) | ||
111 | - header.n_sysdep_strings = io.read(4).unpack(endian_type6) | ||
112 | - header.orig_sysdep_tab_offset = io.read(4).unpack(endian_type6) | ||
113 | - header.trans_sysdep_tab_offset = io.read(4).unpack(endian_type6) | ||
114 | - elsif header.revision > 1 | ||
115 | - raise InvalidFormat.new(sprintf("file format revision %d isn't supported", header.revision)) | ||
116 | - end | ||
117 | - io.pos = header.orig_table_offset | ||
118 | - orig_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr) | ||
119 | - | ||
120 | - io.pos = header.translated_table_offset | ||
121 | - trans_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr) | ||
122 | - | ||
123 | - original_strings = Array.new(header.nstrings) | ||
124 | - for i in 0...header.nstrings | ||
125 | - io.pos = orig_table_data[i * 2 + 1] | ||
126 | - original_strings[i] = io.read(orig_table_data[i * 2 + 0]) | ||
127 | - end | ||
128 | - | ||
129 | - clear | ||
130 | - for i in 0...header.nstrings | ||
131 | - io.pos = trans_table_data[i * 2 + 1] | ||
132 | - str = io.read(trans_table_data[i * 2 + 0]) | ||
133 | - | ||
134 | - if (! original_strings[i]) || original_strings[i] == "" | ||
135 | - if str | ||
136 | - @charset = nil | ||
137 | - @nplurals = nil | ||
138 | - @plural = nil | ||
139 | - str.each_line{|line| | ||
140 | - if /^Content-Type:/i =~ line and /charset=((?:\w|-)+)/i =~ line | ||
141 | - @charset = $1 | ||
142 | - elsif /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line | ||
143 | - @nplurals = $1 | ||
144 | - @plural = $2 | ||
145 | - end | ||
146 | - break if @charset and @nplurals | ||
147 | - } | ||
148 | - @nplurals = "1" unless @nplurals | ||
149 | - @plural = "0" unless @plural | ||
150 | - end | ||
151 | - else | ||
152 | - if @output_charset | ||
153 | - begin | ||
154 | - iconv = Iconv || FastGettext::Iconv | ||
155 | - str = iconv.conv(@output_charset, @charset, str) if @charset | ||
156 | - rescue iconv::Failure | ||
157 | - if $DEBUG | ||
158 | - warn "@charset = ", @charset | ||
159 | - warn"@output_charset = ", @output_charset | ||
160 | - warn "msgid = ", original_strings[i] | ||
161 | - warn "msgstr = ", str | ||
162 | - end | ||
163 | - end | ||
164 | - end | ||
165 | - end | ||
166 | - self[original_strings[i]] = str.freeze | ||
167 | - end | ||
168 | - self | ||
169 | - end | ||
170 | - | ||
171 | - # Is this number a prime number ? | ||
172 | - # http://apidock.com/ruby/Prime | ||
173 | - def prime?(number) | ||
174 | - ('1' * number) !~ /^1?$|^(11+?)\1+$/ | ||
175 | - end | ||
176 | - | ||
177 | - def next_prime(seed) | ||
178 | - require 'mathn' | ||
179 | - prime = Prime.new | ||
180 | - while current = prime.succ | ||
181 | - return current if current > seed | ||
182 | - end | ||
183 | - end | ||
184 | - | ||
185 | - # From gettext-0.12.1/gettext-runtime/intl/hash-string.h | ||
186 | - # Defines the so called `hashpjw' function by P.J. Weinberger | ||
187 | - # [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, | ||
188 | - # 1986, 1987 Bell Telephone Laboratories, Inc.] | ||
189 | - HASHWORDBITS = 32 | ||
190 | - def hash_string(str) | ||
191 | - hval = 0 | ||
192 | - i = 0 | ||
193 | - str.each_byte do |b| | ||
194 | - break if b == '\0' | ||
195 | - hval <<= 4 | ||
196 | - hval += b.to_i | ||
197 | - g = hval & (0xf << (HASHWORDBITS - 4)) | ||
198 | - if (g != 0) | ||
199 | - hval ^= g >> (HASHWORDBITS - 8) | ||
200 | - hval ^= g | ||
201 | - end | ||
202 | - end | ||
203 | - hval | ||
204 | - end | ||
205 | - | ||
206 | - def save_to_stream(io) | ||
207 | - #Save data as little endian format. | ||
208 | - header_size = 4 * 7 | ||
209 | - table_size = 4 * 2 * size | ||
210 | - | ||
211 | - hash_table_size = next_prime((size * 4) / 3) | ||
212 | - hash_table_size = 3 if hash_table_size <= 2 | ||
213 | - header = Header.new( | ||
214 | - MAGIC_LITTLE_ENDIAN, # magic | ||
215 | - 0, # revision | ||
216 | - size, # nstrings | ||
217 | - header_size, # orig_table_offset | ||
218 | - header_size + table_size, # translated_table_offset | ||
219 | - hash_table_size, # hash_table_size | ||
220 | - header_size + table_size * 2 # hash_table_offset | ||
221 | - ) | ||
222 | - io.write(header.to_a.pack('a4V*')) | ||
223 | - | ||
224 | - ary = to_a | ||
225 | - ary.sort!{|a, b| a[0] <=> b[0]} # sort by original string | ||
226 | - | ||
227 | - pos = header.hash_table_size * 4 + header.hash_table_offset | ||
228 | - | ||
229 | - orig_table_data = Array.new() | ||
230 | - ary.each{|item, _| | ||
231 | - orig_table_data.push(item.size) | ||
232 | - orig_table_data.push(pos) | ||
233 | - pos += item.size + 1 # +1 is <NUL> | ||
234 | - } | ||
235 | - io.write(orig_table_data.pack('V*')) | ||
236 | - | ||
237 | - trans_table_data = Array.new() | ||
238 | - ary.each{|_, item| | ||
239 | - trans_table_data.push(item.size) | ||
240 | - trans_table_data.push(pos) | ||
241 | - pos += item.size + 1 # +1 is <NUL> | ||
242 | - } | ||
243 | - io.write(trans_table_data.pack('V*')) | ||
244 | - | ||
245 | - hash_tab = Array.new(hash_table_size) | ||
246 | - j = 0 | ||
247 | - ary[0...size].each {|key, _| | ||
248 | - hash_val = hash_string(key) | ||
249 | - idx = hash_val % hash_table_size | ||
250 | - if hash_tab[idx] != nil | ||
251 | - incr = 1 + (hash_val % (hash_table_size - 2)) | ||
252 | - begin | ||
253 | - if (idx >= hash_table_size - incr) | ||
254 | - idx -= hash_table_size - incr | ||
255 | - else | ||
256 | - idx += incr | ||
257 | - end | ||
258 | - end until (hash_tab[idx] == nil) | ||
259 | - end | ||
260 | - hash_tab[idx] = j + 1 | ||
261 | - j += 1 | ||
262 | - } | ||
263 | - hash_tab.collect!{|i| i ? i : 0} | ||
264 | - | ||
265 | - io.write(hash_tab.pack('V*')) | ||
266 | - | ||
267 | - ary.each{|item, _| io.write(item); io.write("\0") } | ||
268 | - ary.each{|_, item| io.write(item); io.write("\0") } | ||
269 | - | ||
270 | - self | ||
271 | - end | ||
272 | - | ||
273 | - def load_from_file(filename) | ||
274 | - @filename = filename | ||
275 | - begin | ||
276 | - File.open(filename, 'rb'){|f| load_from_stream(f)} | ||
277 | - rescue => e | ||
278 | - e.set_backtrace("File: #{@filename}") | ||
279 | - raise e | ||
280 | - end | ||
281 | - end | ||
282 | - | ||
283 | - def save_to_file(filename) | ||
284 | - File.open(filename, 'wb'){|f| save_to_stream(f)} | ||
285 | - end | ||
286 | - | ||
287 | - def set_comment(msgid_or_sym, comment) | ||
288 | - #Do nothing | ||
289 | - end | ||
290 | - | ||
291 | - | ||
292 | - attr_accessor :little_endian, :path, :last_modified | ||
293 | - attr_reader :charset, :nplurals, :plural | ||
294 | - end | ||
295 | - end | ||
296 | -end | ||
297 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/vendor/poparser.rb
@@ -1,331 +0,0 @@ | @@ -1,331 +0,0 @@ | ||
1 | -=begin | ||
2 | - poparser.rb - Generate a .mo | ||
3 | - | ||
4 | - Copyright (C) 2003-2009 Masao Mutoh <mutoh at highway.ne.jp> | ||
5 | - | ||
6 | - You may redistribute it and/or modify it under the same | ||
7 | - license terms as Ruby. | ||
8 | -=end | ||
9 | - | ||
10 | -#MODIFIED | ||
11 | -# removed include GetText etc | ||
12 | -# added stub translation method _(x) | ||
13 | -require 'racc/parser' | ||
14 | - | ||
15 | -module FastGettext | ||
16 | -module GetText | ||
17 | - | ||
18 | - class PoParser < Racc::Parser | ||
19 | - | ||
20 | - def _(x) | ||
21 | - x | ||
22 | - end | ||
23 | - | ||
24 | -module_eval <<'..end src/poparser.ry modeval..id7a99570e05', 'src/poparser.ry', 108 | ||
25 | - def unescape(orig) | ||
26 | - ret = orig.gsub(/\\n/, "\n") | ||
27 | - ret.gsub!(/\\t/, "\t") | ||
28 | - ret.gsub!(/\\r/, "\r") | ||
29 | - ret.gsub!(/\\"/, "\"") | ||
30 | - ret | ||
31 | - end | ||
32 | - | ||
33 | - def parse(str, data, ignore_fuzzy = true) | ||
34 | - @comments = [] | ||
35 | - @data = data | ||
36 | - @fuzzy = false | ||
37 | - @msgctxt = "" | ||
38 | - $ignore_fuzzy = ignore_fuzzy | ||
39 | - | ||
40 | - str.strip! | ||
41 | - @q = [] | ||
42 | - until str.empty? do | ||
43 | - case str | ||
44 | - when /\A\s+/ | ||
45 | - str = $' | ||
46 | - when /\Amsgctxt/ | ||
47 | - @q.push [:MSGCTXT, $&] | ||
48 | - str = $' | ||
49 | - when /\Amsgid_plural/ | ||
50 | - @q.push [:MSGID_PLURAL, $&] | ||
51 | - str = $' | ||
52 | - when /\Amsgid/ | ||
53 | - @q.push [:MSGID, $&] | ||
54 | - str = $' | ||
55 | - when /\Amsgstr/ | ||
56 | - @q.push [:MSGSTR, $&] | ||
57 | - str = $' | ||
58 | - when /\A\[(\d+)\]/ | ||
59 | - @q.push [:PLURAL_NUM, $1] | ||
60 | - str = $' | ||
61 | - when /\A\#~(.*)/ | ||
62 | - $stderr.print _("Warning: obsolete msgid exists.\n") | ||
63 | - $stderr.print " #{$&}\n" | ||
64 | - @q.push [:COMMENT, $&] | ||
65 | - str = $' | ||
66 | - when /\A\#(.*)/ | ||
67 | - @q.push [:COMMENT, $&] | ||
68 | - str = $' | ||
69 | - when /\A\"(.*)\"/ | ||
70 | - @q.push [:STRING, $1] | ||
71 | - str = $' | ||
72 | - else | ||
73 | - #c = str[0,1] | ||
74 | - #@q.push [:STRING, c] | ||
75 | - str = str[1..-1] | ||
76 | - end | ||
77 | - end | ||
78 | - @q.push [false, '$end'] | ||
79 | - if $DEBUG | ||
80 | - @q.each do |a,b| | ||
81 | - puts "[#{a}, #{b}]" | ||
82 | - end | ||
83 | - end | ||
84 | - @yydebug = true if $DEBUG | ||
85 | - do_parse | ||
86 | - | ||
87 | - if @comments.size > 0 | ||
88 | - @data.set_comment(:last, @comments.join("\n")) | ||
89 | - end | ||
90 | - @data | ||
91 | - end | ||
92 | - | ||
93 | - def next_token | ||
94 | - @q.shift | ||
95 | - end | ||
96 | - | ||
97 | - def on_message(msgid, msgstr) | ||
98 | - if msgstr.size > 0 | ||
99 | - @data[msgid] = msgstr | ||
100 | - @data.set_comment(msgid, @comments.join("\n")) | ||
101 | - end | ||
102 | - @comments.clear | ||
103 | - @msgctxt = "" | ||
104 | - end | ||
105 | - | ||
106 | - def on_comment(comment) | ||
107 | - @fuzzy = true if (/fuzzy/ =~ comment) | ||
108 | - @comments << comment | ||
109 | - end | ||
110 | - | ||
111 | - | ||
112 | -..end src/poparser.ry modeval..id7a99570e05 | ||
113 | - | ||
114 | -##### racc 1.4.5 generates ### | ||
115 | - | ||
116 | -racc_reduce_table = [ | ||
117 | - 0, 0, :racc_error, | ||
118 | - 0, 10, :_reduce_none, | ||
119 | - 2, 10, :_reduce_none, | ||
120 | - 2, 10, :_reduce_none, | ||
121 | - 2, 10, :_reduce_none, | ||
122 | - 2, 12, :_reduce_5, | ||
123 | - 1, 13, :_reduce_none, | ||
124 | - 1, 13, :_reduce_none, | ||
125 | - 4, 15, :_reduce_8, | ||
126 | - 5, 16, :_reduce_9, | ||
127 | - 2, 17, :_reduce_10, | ||
128 | - 1, 17, :_reduce_none, | ||
129 | - 3, 18, :_reduce_12, | ||
130 | - 1, 11, :_reduce_13, | ||
131 | - 2, 14, :_reduce_14, | ||
132 | - 1, 14, :_reduce_15 ] | ||
133 | - | ||
134 | -racc_reduce_n = 16 | ||
135 | - | ||
136 | -racc_shift_n = 26 | ||
137 | - | ||
138 | -racc_action_table = [ | ||
139 | - 3, 13, 5, 7, 9, 15, 16, 17, 20, 17, | ||
140 | - 13, 17, 13, 13, 11, 17, 23, 20, 13, 17 ] | ||
141 | - | ||
142 | -racc_action_check = [ | ||
143 | - 1, 16, 1, 1, 1, 12, 12, 12, 18, 18, | ||
144 | - 7, 14, 15, 9, 3, 19, 20, 21, 23, 25 ] | ||
145 | - | ||
146 | -racc_action_pointer = [ | ||
147 | - nil, 0, nil, 14, nil, nil, nil, 3, nil, 6, | ||
148 | - nil, nil, 0, nil, 4, 5, -6, nil, 2, 8, | ||
149 | - 8, 11, nil, 11, nil, 12 ] | ||
150 | - | ||
151 | -racc_action_default = [ | ||
152 | - -1, -16, -2, -16, -3, -13, -4, -16, -6, -16, | ||
153 | - -7, 26, -16, -15, -5, -16, -16, -14, -16, -8, | ||
154 | - -16, -9, -11, -16, -10, -12 ] | ||
155 | - | ||
156 | -racc_goto_table = [ | ||
157 | - 12, 22, 14, 4, 24, 6, 2, 8, 18, 19, | ||
158 | - 10, 21, 1, nil, nil, nil, 25 ] | ||
159 | - | ||
160 | -racc_goto_check = [ | ||
161 | - 5, 9, 5, 3, 9, 4, 2, 6, 5, 5, | ||
162 | - 7, 8, 1, nil, nil, nil, 5 ] | ||
163 | - | ||
164 | -racc_goto_pointer = [ | ||
165 | - nil, 12, 5, 2, 4, -7, 6, 9, -7, -17 ] | ||
166 | - | ||
167 | -racc_goto_default = [ | ||
168 | - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ] | ||
169 | - | ||
170 | -racc_token_table = { | ||
171 | - false => 0, | ||
172 | - Object.new => 1, | ||
173 | - :COMMENT => 2, | ||
174 | - :MSGID => 3, | ||
175 | - :MSGCTXT => 4, | ||
176 | - :MSGID_PLURAL => 5, | ||
177 | - :MSGSTR => 6, | ||
178 | - :STRING => 7, | ||
179 | - :PLURAL_NUM => 8 } | ||
180 | - | ||
181 | -racc_use_result_var = true | ||
182 | - | ||
183 | -racc_nt_base = 9 | ||
184 | - | ||
185 | -Racc_arg = [ | ||
186 | - racc_action_table, | ||
187 | - racc_action_check, | ||
188 | - racc_action_default, | ||
189 | - racc_action_pointer, | ||
190 | - racc_goto_table, | ||
191 | - racc_goto_check, | ||
192 | - racc_goto_default, | ||
193 | - racc_goto_pointer, | ||
194 | - racc_nt_base, | ||
195 | - racc_reduce_table, | ||
196 | - racc_token_table, | ||
197 | - racc_shift_n, | ||
198 | - racc_reduce_n, | ||
199 | - racc_use_result_var ] | ||
200 | - | ||
201 | -Racc_token_to_s_table = [ | ||
202 | -'$end', | ||
203 | -'error', | ||
204 | -'COMMENT', | ||
205 | -'MSGID', | ||
206 | -'MSGCTXT', | ||
207 | -'MSGID_PLURAL', | ||
208 | -'MSGSTR', | ||
209 | -'STRING', | ||
210 | -'PLURAL_NUM', | ||
211 | -'$start', | ||
212 | -'msgfmt', | ||
213 | -'comment', | ||
214 | -'msgctxt', | ||
215 | -'message', | ||
216 | -'string_list', | ||
217 | -'single_message', | ||
218 | -'plural_message', | ||
219 | -'msgstr_plural', | ||
220 | -'msgstr_plural_line'] | ||
221 | - | ||
222 | -Racc_debug_parser = true | ||
223 | - | ||
224 | -##### racc system variables end ##### | ||
225 | - | ||
226 | - # reduce 0 omitted | ||
227 | - | ||
228 | - # reduce 1 omitted | ||
229 | - | ||
230 | - # reduce 2 omitted | ||
231 | - | ||
232 | - # reduce 3 omitted | ||
233 | - | ||
234 | - # reduce 4 omitted | ||
235 | - | ||
236 | -module_eval <<'.,.,', 'src/poparser.ry', 25 | ||
237 | - def _reduce_5( val, _values, result ) | ||
238 | - @msgctxt = unescape(val[1]) + "\004" | ||
239 | - result | ||
240 | - end | ||
241 | -.,., | ||
242 | - | ||
243 | - # reduce 6 omitted | ||
244 | - | ||
245 | - # reduce 7 omitted | ||
246 | - | ||
247 | -module_eval <<'.,.,', 'src/poparser.ry', 48 | ||
248 | - def _reduce_8( val, _values, result ) | ||
249 | - if @fuzzy and $ignore_fuzzy | ||
250 | - if val[1] != "" | ||
251 | - $stderr.print _("Warning: fuzzy message was ignored.\n") | ||
252 | - $stderr.print " msgid '#{val[1]}'\n" | ||
253 | - else | ||
254 | - on_message('', unescape(val[3])) | ||
255 | - end | ||
256 | - @fuzzy = false | ||
257 | - else | ||
258 | - on_message(@msgctxt + unescape(val[1]), unescape(val[3])) | ||
259 | - end | ||
260 | - result = "" | ||
261 | - result | ||
262 | - end | ||
263 | -.,., | ||
264 | - | ||
265 | -module_eval <<'.,.,', 'src/poparser.ry', 65 | ||
266 | - def _reduce_9( val, _values, result ) | ||
267 | - if @fuzzy and $ignore_fuzzy | ||
268 | - if val[1] != "" | ||
269 | - $stderr.print _("Warning: fuzzy message was ignored.\n") | ||
270 | - $stderr.print "msgid = '#{val[1]}\n" | ||
271 | - else | ||
272 | - on_message('', unescape(val[3])) | ||
273 | - end | ||
274 | - @fuzzy = false | ||
275 | - else | ||
276 | - on_message(@msgctxt + unescape(val[1]) + "\000" + unescape(val[3]), unescape(val[4])) | ||
277 | - end | ||
278 | - result = "" | ||
279 | - result | ||
280 | - end | ||
281 | -.,., | ||
282 | - | ||
283 | -module_eval <<'.,.,', 'src/poparser.ry', 76 | ||
284 | - def _reduce_10( val, _values, result ) | ||
285 | - if val[0].size > 0 | ||
286 | - result = val[0] + "\000" + val[1] | ||
287 | - else | ||
288 | - result = "" | ||
289 | - end | ||
290 | - result | ||
291 | - end | ||
292 | -.,., | ||
293 | - | ||
294 | - # reduce 11 omitted | ||
295 | - | ||
296 | -module_eval <<'.,.,', 'src/poparser.ry', 84 | ||
297 | - def _reduce_12( val, _values, result ) | ||
298 | - result = val[2] | ||
299 | - result | ||
300 | - end | ||
301 | -.,., | ||
302 | - | ||
303 | -module_eval <<'.,.,', 'src/poparser.ry', 91 | ||
304 | - def _reduce_13( val, _values, result ) | ||
305 | - on_comment(val[0]) | ||
306 | - result | ||
307 | - end | ||
308 | -.,., | ||
309 | - | ||
310 | -module_eval <<'.,.,', 'src/poparser.ry', 99 | ||
311 | - def _reduce_14( val, _values, result ) | ||
312 | - result = val.delete_if{|item| item == ""}.join | ||
313 | - result | ||
314 | - end | ||
315 | -.,., | ||
316 | - | ||
317 | -module_eval <<'.,.,', 'src/poparser.ry', 103 | ||
318 | - def _reduce_15( val, _values, result ) | ||
319 | - result = val[0] | ||
320 | - result | ||
321 | - end | ||
322 | -.,., | ||
323 | - | ||
324 | - def _reduce_none( val, _values, result ) | ||
325 | - result | ||
326 | - end | ||
327 | - | ||
328 | - end # class PoParser | ||
329 | - | ||
330 | -end # module GetText | ||
331 | -end | ||
332 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/lib/fast_gettext/vendor/string.rb
@@ -1,74 +0,0 @@ | @@ -1,74 +0,0 @@ | ||
1 | -#! /usr/bin/ruby | ||
2 | -=begin | ||
3 | - string.rb - Extension for String. | ||
4 | - | ||
5 | - Copyright (C) 2005,2006 Masao Mutoh | ||
6 | - | ||
7 | - You may redistribute it and/or modify it under the same | ||
8 | - license terms as Ruby. | ||
9 | -=end | ||
10 | - | ||
11 | -# Extension for String class. This feature is included in Ruby 1.9 or later. | ||
12 | -begin | ||
13 | - raise unless ("a %{x}" % {:x=>'b'}) == 'a b' | ||
14 | -rescue ArgumentError | ||
15 | - class String | ||
16 | - alias :_fast_gettext_old_format_m :% # :nodoc: | ||
17 | - | ||
18 | - PERCENT_MATCH_RE = Regexp.union( | ||
19 | - /%%/, | ||
20 | - /%\{([-\.\w]+)\}/, | ||
21 | - /%<([-\.\w]+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ | ||
22 | - ) | ||
23 | - | ||
24 | - # call-seq: | ||
25 | - # %(hash) | ||
26 | - # | ||
27 | - # Default: "%s, %s" % ["Masao", "Mutoh"] | ||
28 | - # Extended: | ||
29 | - # "%{firstname}, %{lastname}" % {:firstname=>"Masao",:lastname=>"Mutoh"} == "Masao Mutoh" | ||
30 | - # with field type such as d(decimal), f(float), ... | ||
31 | - # "%<age>d, %<weight>.1f" % {:age => 10, :weight => 43.4} == "10 43.4" | ||
32 | - # This is the recommanded way for Ruby-GetText | ||
33 | - # because the translators can understand the meanings of the keys easily. | ||
34 | - def %(args) | ||
35 | - if args.kind_of? Hash | ||
36 | - #stringify keys | ||
37 | - replace = {} | ||
38 | - args.each{|k,v|replace[k.to_s]=v} | ||
39 | - | ||
40 | - #replace occurances | ||
41 | - ret = dup | ||
42 | - ret.gsub!(PERCENT_MATCH_RE) do |match| | ||
43 | - if match == '%%' | ||
44 | - '%' | ||
45 | - elsif $1 | ||
46 | - replace.has_key?($1) ? replace[$1] : match | ||
47 | - elsif $2 | ||
48 | - replace.has_key?($2) ? sprintf("%#{$3}", replace[$2]) : match | ||
49 | - end | ||
50 | - end | ||
51 | - ret | ||
52 | - else | ||
53 | - ret = gsub(/%([{<])/, '%%\1') | ||
54 | - ret._fast_gettext_old_format_m(args) | ||
55 | - end | ||
56 | - end | ||
57 | - end | ||
58 | -end | ||
59 | - | ||
60 | -# 1.9.1 if you misspell a %{key} your whole page would blow up, no thanks... | ||
61 | -begin | ||
62 | - ("%{b}" % {:a=>'b'}) | ||
63 | -rescue KeyError | ||
64 | - class String | ||
65 | - alias :_fast_gettext_old_format_m :% | ||
66 | - def %(*args) | ||
67 | - begin | ||
68 | - _fast_gettext_old_format_m(*args) | ||
69 | - rescue KeyError | ||
70 | - self | ||
71 | - end | ||
72 | - end | ||
73 | - end | ||
74 | -end | ||
75 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/aa_unconfigued_spec.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -require File.join(File.dirname(__FILE__),'spec_helper') | ||
2 | - | ||
3 | -describe 'unconfigured' do | ||
4 | - it "gives a useful error message when trying to just translate" do | ||
5 | - FastGettext.text_domain = nil | ||
6 | - begin | ||
7 | - FastGettext._('x') | ||
8 | - "".should == "success!?" | ||
9 | - rescue FastGettext::Storage::NoTextDomainConfigured | ||
10 | - end | ||
11 | - end | ||
12 | - | ||
13 | - it "gives a useful error message when only locale was set" do | ||
14 | - FastGettext.locale = 'de' | ||
15 | - begin | ||
16 | - FastGettext._('x') | ||
17 | - "".should == "success!?" | ||
18 | - rescue FastGettext::Storage::NoTextDomainConfigured | ||
19 | - end | ||
20 | - end | ||
21 | -end | ||
22 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/mo_file_spec.rb
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','spec_helper') | ||
3 | - | ||
4 | -de_file = File.join(current_folder,'..','locale','de','LC_MESSAGES','test.mo') | ||
5 | -de = FastGettext::MoFile.new(de_file) | ||
6 | - | ||
7 | -describe FastGettext::MoFile do | ||
8 | - before :all do | ||
9 | - File.exist?(de_file).should == true | ||
10 | - end | ||
11 | - | ||
12 | - it "parses a file" do | ||
13 | - de['car'].should == 'Auto' | ||
14 | - end | ||
15 | - | ||
16 | - it "stores untranslated values as nil" do | ||
17 | - de['Car|Model'].should == nil | ||
18 | - end | ||
19 | - | ||
20 | - it "finds pluralized values" do | ||
21 | - de.plural('Axis','Axis').should == ['Achse','Achsen'] | ||
22 | - end | ||
23 | - | ||
24 | - it "returns singular translations when pluralisation could not be found" do | ||
25 | - de.plural('Axis','Axis','Axis').should == ['Achse','Achse','Achse'] | ||
26 | - end | ||
27 | - | ||
28 | - it "returns ids when not plural and singular translations could not be found" do | ||
29 | - de.plural('Axis','Axis','NOTFOUND').should == ['Achse','Achse','NOTFOUND'] | ||
30 | - end | ||
31 | - | ||
32 | - it "can access plurals through []" do | ||
33 | - de['Axis'].should == 'Achse' #singular | ||
34 | - end | ||
35 | -end | ||
36 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/storage_spec.rb
@@ -1,309 +0,0 @@ | @@ -1,309 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','spec_helper') | ||
3 | - | ||
4 | -describe 'Storage' do | ||
5 | - include FastGettext::Storage | ||
6 | - | ||
7 | - before do | ||
8 | - #reset everything to nil | ||
9 | - self.available_locales = nil | ||
10 | - self.default_text_domain = nil | ||
11 | - self.default_locale = nil | ||
12 | - send(:_locale=,nil)#nil is not allowed to be set... | ||
13 | - default_locale.should be_nil | ||
14 | - available_locales.should be_nil | ||
15 | - locale.should == 'en' | ||
16 | - end | ||
17 | - | ||
18 | - def thread_save(method, value) | ||
19 | - send("#{method}=",value) | ||
20 | - | ||
21 | - # mess around with other threads | ||
22 | - 100.times do | ||
23 | - Thread.new {FastGettext.send("#{method}=",'en')} | ||
24 | - end | ||
25 | - | ||
26 | - send(method) == value | ||
27 | - end | ||
28 | - | ||
29 | - {:locale=>'de', :available_locales=>['de'], :text_domain=>'xx', :pluralisation_rule=>lambda{|x|x==4}}.each do |method, value| | ||
30 | - it "stores #{method} thread-save" do | ||
31 | - thread_save(method, value).should == true | ||
32 | - end | ||
33 | - end | ||
34 | - | ||
35 | - it "stores translation_repositories non-thread-safe" do | ||
36 | - self.translation_repositories[:x]=1 | ||
37 | - t = Thread.new{self.translation_repositories[:x]=2} | ||
38 | - t.join | ||
39 | - self.translation_repositories[:x].should == 2 | ||
40 | - end | ||
41 | - | ||
42 | - describe :pluralisation_rule do | ||
43 | - it "defaults to singular-if-1 when it is not set" do | ||
44 | - stub!(:current_repository).and_return mock('',:pluralisation_rule=>nil) | ||
45 | - self.pluralisation_rule = nil | ||
46 | - pluralisation_rule.call(1).should == false | ||
47 | - pluralisation_rule.call(0).should == true | ||
48 | - pluralisation_rule.call(2).should == true | ||
49 | - end | ||
50 | - end | ||
51 | - | ||
52 | - describe :default_locale do | ||
53 | - it "stores default_locale non-thread-safe" do | ||
54 | - thread_save(:default_locale, 'de').should == false | ||
55 | - end | ||
56 | - | ||
57 | - it "does not overwrite locale" do | ||
58 | - self.locale = 'de' | ||
59 | - self.default_locale = 'yy' | ||
60 | - self.locale.should == 'de' | ||
61 | - end | ||
62 | - | ||
63 | - it "falls back to default if locale is missing" do | ||
64 | - self.default_locale = 'yy' | ||
65 | - self.locale.should == 'yy' | ||
66 | - end | ||
67 | - | ||
68 | - it "does not set non-available-locales as default" do | ||
69 | - self.available_locales = ['xx'] | ||
70 | - self.default_locale = 'yy' | ||
71 | - self.default_locale.should == nil | ||
72 | - end | ||
73 | - | ||
74 | - it "can set default_locale to nil" do | ||
75 | - self.default_locale = 'xx' | ||
76 | - self.default_locale = nil | ||
77 | - default_locale.should be_nil | ||
78 | - end | ||
79 | - end | ||
80 | - | ||
81 | - describe :default_text_domain do | ||
82 | - it "stores default_text_domain non-thread-safe" do | ||
83 | - thread_save(:default_text_domain, 'xx').should == false | ||
84 | - end | ||
85 | - | ||
86 | - it "uses default_text_domain when text_domain is not set" do | ||
87 | - self.text_domain = nil | ||
88 | - self.default_text_domain = 'x' | ||
89 | - text_domain.should == 'x' | ||
90 | - end | ||
91 | - | ||
92 | - it "does not use default when domain is set" do | ||
93 | - self.text_domain = 'x' | ||
94 | - self.default_text_domain = 'y' | ||
95 | - text_domain.should == 'x' | ||
96 | - end | ||
97 | - end | ||
98 | - | ||
99 | - describe :default_available_locales do | ||
100 | - after do | ||
101 | - self.default_available_locales = nil | ||
102 | - end | ||
103 | - | ||
104 | - it "stores default_available_locales non-thread-safe" do | ||
105 | - thread_save(:default_available_locales, 'xx').should == false | ||
106 | - end | ||
107 | - | ||
108 | - it "uses default_available_locales when available_locales is not set" do | ||
109 | - self.available_locales = nil | ||
110 | - self.default_available_locales = 'x' | ||
111 | - available_locales.should == 'x' | ||
112 | - end | ||
113 | - | ||
114 | - it "does not use default when available_locales is set" do | ||
115 | - self.available_locales = 'x' | ||
116 | - self.default_available_locales = 'y' | ||
117 | - available_locales.should == 'x' | ||
118 | - end | ||
119 | - end | ||
120 | - | ||
121 | - describe :locale do | ||
122 | - it "stores everything as long as available_locales is not set" do | ||
123 | - self.available_locales = nil | ||
124 | - self.locale = 'XXX' | ||
125 | - locale.should == 'XXX' | ||
126 | - end | ||
127 | - | ||
128 | - it "is en if no locale and no available_locale were set" do | ||
129 | - FastGettext.send(:_locale=,nil) | ||
130 | - self.available_locales = nil | ||
131 | - locale.should == 'en' | ||
132 | - end | ||
133 | - | ||
134 | - it "does not change the locale if locales was called with nil" do | ||
135 | - self.locale = nil | ||
136 | - locale.should == 'en' | ||
137 | - end | ||
138 | - | ||
139 | - it "is the first available_locale if one was set" do | ||
140 | - self.available_locales = ['de'] | ||
141 | - locale.should == 'de' | ||
142 | - end | ||
143 | - | ||
144 | - it "does not store a locale if it is not available" do | ||
145 | - self.available_locales = ['de'] | ||
146 | - self.locale = 'en' | ||
147 | - locale.should == 'de' | ||
148 | - end | ||
149 | - | ||
150 | - it "set_locale returns the old locale if the new could not be set" do | ||
151 | - self.locale = 'de' | ||
152 | - self.available_locales = ['de'] | ||
153 | - self.set_locale('en').should == 'de' | ||
154 | - end | ||
155 | - | ||
156 | - { | ||
157 | - 'Opera' => "de-DE,de;q=0.9,en;q=0.8", | ||
158 | - 'Firefox' => "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3", | ||
159 | - }.each do |browser,accept_language| | ||
160 | - it "sets the locale from #{browser} headers" do | ||
161 | - FastGettext.available_locales = ['de_DE','de','xx'] | ||
162 | - FastGettext.locale = 'xx' | ||
163 | - FastGettext.locale = accept_language | ||
164 | - FastGettext.locale.should == 'de_DE' | ||
165 | - end | ||
166 | - end | ||
167 | - | ||
168 | - it "sets a unimportant locale if it is the only available" do | ||
169 | - FastGettext.available_locales = ['en','xx'] | ||
170 | - FastGettext.locale = "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3" | ||
171 | - FastGettext.locale.should == 'en' | ||
172 | - end | ||
173 | - | ||
174 | - it "sets the locale with the highest wheight" do | ||
175 | - FastGettext.available_locales = ['en','de'] | ||
176 | - FastGettext.locale = "xx-us;q=0.5,de-de,de;q=0.8,en;q=0.9" | ||
177 | - FastGettext.locale.should == 'en' | ||
178 | - end | ||
179 | - | ||
180 | - it "sets the locale from languages" do | ||
181 | - FastGettext.available_locales = ['de'] | ||
182 | - FastGettext.locale = "xx-us;q=0.5,de-de;q=0.8,en-uk;q=0.9" | ||
183 | - FastGettext.locale.should == 'de' | ||
184 | - end | ||
185 | - | ||
186 | - it "sets locale from comma seperated" do | ||
187 | - FastGettext.available_locales = ['de_DE','en','xx'] | ||
188 | - FastGettext.locale = "de,de-de,en" | ||
189 | - FastGettext.locale.should == 'de_DE' | ||
190 | - end | ||
191 | - end | ||
192 | - | ||
193 | - describe :silence_errors do | ||
194 | - before do | ||
195 | - FastGettext.text_domain = 'xxx' | ||
196 | - end | ||
197 | - | ||
198 | - it "raises when a textdomain was empty" do | ||
199 | - begin | ||
200 | - FastGettext._('x') | ||
201 | - "".should == "success!?" | ||
202 | - rescue FastGettext::Storage::NoTextDomainConfigured | ||
203 | - end | ||
204 | - end | ||
205 | - | ||
206 | - it "can silence erros" do | ||
207 | - FastGettext.silence_errors | ||
208 | - FastGettext._('x').should == 'x' | ||
209 | - end | ||
210 | - end | ||
211 | - | ||
212 | - describe :current_cache do | ||
213 | - before do | ||
214 | - FastGettext.text_domain = 'xxx' | ||
215 | - FastGettext.available_locales = ['de','en'] | ||
216 | - FastGettext.locale = 'de' | ||
217 | - FastGettext.current_repository.stub!(:"[]").with('abc').and_return 'old' | ||
218 | - FastGettext.current_repository.stub!(:"[]").with('unfound').and_return nil | ||
219 | - FastGettext._('abc') | ||
220 | - FastGettext._('unfound') | ||
221 | - FastGettext.locale = 'en' | ||
222 | - end | ||
223 | - | ||
224 | - it "stores a translation seperate by locale" do | ||
225 | - FastGettext.current_cache['abc'].should == nil | ||
226 | - end | ||
227 | - | ||
228 | - it "stores a translation seperate by domain" do | ||
229 | - FastGettext.locale = 'de' | ||
230 | - FastGettext.text_domain = nil | ||
231 | - FastGettext.current_cache['abc'].should == nil | ||
232 | - end | ||
233 | - | ||
234 | - it "cache is restored through setting of default_text_domain" do | ||
235 | - FastGettext.locale = 'de' | ||
236 | - FastGettext.text_domain = nil | ||
237 | - FastGettext.default_text_domain = 'xxx' | ||
238 | - FastGettext.current_cache['abc'].should == 'old' | ||
239 | - end | ||
240 | - | ||
241 | - it "cache is restored through setting of default_locale" do | ||
242 | - FastGettext.send(:_locale=,nil)#reset locale to nil | ||
243 | - FastGettext.default_locale = 'de' | ||
244 | - FastGettext.locale.should == 'de' | ||
245 | - FastGettext.current_cache['abc'].should == 'old' | ||
246 | - end | ||
247 | - | ||
248 | - it "stores a translation permanently" do | ||
249 | - FastGettext.locale = 'de' | ||
250 | - FastGettext.current_cache['abc'].should == 'old' | ||
251 | - end | ||
252 | - | ||
253 | - it "stores a unfound translation permanently" do | ||
254 | - FastGettext.locale = 'de' | ||
255 | - FastGettext.current_cache['unfound'].should == false | ||
256 | - end | ||
257 | - end | ||
258 | - | ||
259 | - describe :key_exist? do | ||
260 | - it "does not find default keys" do | ||
261 | - FastGettext._('abcde') | ||
262 | - key_exist?('abcde').should be_false | ||
263 | - end | ||
264 | - | ||
265 | - it "finds using the current repository" do | ||
266 | - should_receive(:current_repository).and_return '1234'=>'1' | ||
267 | - key_exist?('1234').should == true | ||
268 | - end | ||
269 | - | ||
270 | - it "sets the current cache with a found result" do | ||
271 | - should_receive(:current_repository).and_return 'xxx'=>'1' | ||
272 | - key_exist?('xxx') | ||
273 | - current_cache['xxx'].should == '1' | ||
274 | - end | ||
275 | - | ||
276 | - it "does not overwrite an existing cache value" do | ||
277 | - current_cache['xxx']='xxx' | ||
278 | - stub!(:current_repository).and_return 'xxx'=>'1' | ||
279 | - key_exist?('xxx') | ||
280 | - current_cache['xxx'].should == 'xxx' | ||
281 | - end | ||
282 | - | ||
283 | - it "is false for gettext meta key" do | ||
284 | - key_exist?("").should == false | ||
285 | - end | ||
286 | - end | ||
287 | - | ||
288 | - describe :cached_find do | ||
289 | - it "is nil for gettext meta key" do | ||
290 | - cached_find("").should == false | ||
291 | - end | ||
292 | - end | ||
293 | - | ||
294 | - describe FastGettext::Storage::NoTextDomainConfigured do | ||
295 | - it "shows what to do" do | ||
296 | - FastGettext::Storage::NoTextDomainConfigured.new.to_s.should =~ /FastGettext\.add_text_domain/ | ||
297 | - end | ||
298 | - | ||
299 | - it "warns when text_domain is nil" do | ||
300 | - FastGettext.text_domain = nil | ||
301 | - FastGettext::Storage::NoTextDomainConfigured.new.to_s.should =~ /\(nil\)/ | ||
302 | - end | ||
303 | - | ||
304 | - it "shows current text_domain" do | ||
305 | - FastGettext.text_domain = 'xxx' | ||
306 | - FastGettext::Storage::NoTextDomainConfigured.new('xxx').to_s.should =~ /xxx/ | ||
307 | - end | ||
308 | - end | ||
309 | -end | ||
310 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/base_spec.rb
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | -require 'fast_gettext/translation_repository/base' | ||
4 | - | ||
5 | -describe 'FastGettext::TranslationRepository::Base' do | ||
6 | - before do | ||
7 | - @rep = FastGettext::TranslationRepository::Base.new('x') | ||
8 | - end | ||
9 | - | ||
10 | - it "can be built" do | ||
11 | - @rep.available_locales.should == [] | ||
12 | - end | ||
13 | - | ||
14 | - it "cannot translate" do | ||
15 | - @rep['car'].should == nil | ||
16 | - end | ||
17 | - | ||
18 | - it "cannot pluralize" do | ||
19 | - @rep.plural('Axis','Axis').should == ['Axis','Axis'] | ||
20 | - end | ||
21 | -end | ||
22 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/chain_spec.rb
@@ -1,82 +0,0 @@ | @@ -1,82 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | - | ||
4 | -class MockRepo | ||
5 | - def [](key)#should_receive :[] does not work so well... | ||
6 | - singular key | ||
7 | - end | ||
8 | -end | ||
9 | - | ||
10 | -describe 'FastGettext::TranslationRepository::Chain' do | ||
11 | - describe "empty chain" do | ||
12 | - before do | ||
13 | - @rep = FastGettext::TranslationRepository.build('chain', :chain=>[], :type=>:chain) | ||
14 | - end | ||
15 | - | ||
16 | - it "has no locales" do | ||
17 | - @rep.available_locales.should == [] | ||
18 | - end | ||
19 | - | ||
20 | - it "cannot translate" do | ||
21 | - @rep['car'].should == nil | ||
22 | - end | ||
23 | - | ||
24 | - it "cannot pluralize" do | ||
25 | - @rep.plural('Axis','Axis').should == [] | ||
26 | - end | ||
27 | - | ||
28 | - it "has no pluralisation rule" do | ||
29 | - @rep.pluralisation_rule.should == nil | ||
30 | - end | ||
31 | - end | ||
32 | - | ||
33 | - describe "filled chain" do | ||
34 | - before do | ||
35 | - @one = MockRepo.new | ||
36 | - @one.stub!(:singular).with('xx').and_return 'one' | ||
37 | - @two = MockRepo.new | ||
38 | - @two.stub!(:singular).with('xx').and_return 'two' | ||
39 | - @rep = FastGettext::TranslationRepository.build('chain', :chain=>[@one, @two], :type=>:chain) | ||
40 | - end | ||
41 | - | ||
42 | - describe :singular do | ||
43 | - it "uses the first repo in the chain if it responds" do | ||
44 | - @rep['xx'].should == 'one' | ||
45 | - end | ||
46 | - | ||
47 | - it "uses the second repo in the chain if the first does not respond" do | ||
48 | - @one.should_receive(:singular).and_return nil | ||
49 | - @rep['xx'].should == 'two' | ||
50 | - end | ||
51 | - end | ||
52 | - | ||
53 | - describe :plural do | ||
54 | - it "uses the first repo in the chain if it responds" do | ||
55 | - @one.should_receive(:plural).with('a','b').and_return ['A','B'] | ||
56 | - @rep.plural('a','b').should == ['A','B'] | ||
57 | - end | ||
58 | - | ||
59 | - it "uses the second repo in the chain if the first does not respond" do | ||
60 | - @one.should_receive(:plural).with('a','b').and_return [nil,nil] | ||
61 | - @two.should_receive(:plural).with('a','b').and_return ['A','B'] | ||
62 | - @rep.plural('a','b').should == ['A','B'] | ||
63 | - end | ||
64 | - end | ||
65 | - | ||
66 | - describe :available_locales do | ||
67 | - it "should be the sum of all added repositories" do | ||
68 | - @one.should_receive(:available_locales).and_return ['de'] | ||
69 | - @two.should_receive(:available_locales).and_return ['de','en'] | ||
70 | - @rep.available_locales.should == ['de','en'] | ||
71 | - end | ||
72 | - end | ||
73 | - | ||
74 | - describe :pluralisation_rule do | ||
75 | - it "chooses the first that exists" do | ||
76 | - @one.should_receive(:pluralisation_rule).and_return nil | ||
77 | - @two.should_receive(:pluralisation_rule).and_return 'x' | ||
78 | - @rep.pluralisation_rule.should == 'x' | ||
79 | - end | ||
80 | - end | ||
81 | - end | ||
82 | -end | ||
83 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/db_spec.rb
@@ -1,72 +0,0 @@ | @@ -1,72 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | - | ||
4 | -require 'active_record' | ||
5 | -require 'fast_gettext/translation_repository/db' | ||
6 | - | ||
7 | -include FastGettext::TranslationRepository::Db.require_models | ||
8 | -describe FastGettext::TranslationRepository::Db do | ||
9 | - | ||
10 | - before :all do | ||
11 | - ActiveRecord::Base.establish_connection({ | ||
12 | - :adapter => "sqlite3", | ||
13 | - :database => ":memory:" | ||
14 | - }) | ||
15 | - | ||
16 | - #create model table | ||
17 | - #TODO surpress output ? | ||
18 | - ActiveRecord::Schema.define(:version => 1) do | ||
19 | - create_table :translation_keys do |t| | ||
20 | - t.string :key, :unique=>true, :null=>false | ||
21 | - t.timestamps | ||
22 | - end | ||
23 | - create_table :translation_texts do |t| | ||
24 | - t.string :text, :locale | ||
25 | - t.integer :translation_key_id, :null=>false | ||
26 | - t.timestamps | ||
27 | - end | ||
28 | - end | ||
29 | - end | ||
30 | - | ||
31 | - before do | ||
32 | - TranslationKey.delete_all | ||
33 | - TranslationText.delete_all | ||
34 | - FastGettext.locale = 'de' | ||
35 | - @rep = FastGettext::TranslationRepository::Db.new('x', :model=>TranslationKey) | ||
36 | - end | ||
37 | - | ||
38 | - def create_translation(key, text) | ||
39 | - translation_key = TranslationKey.create!(:key=>key) | ||
40 | - TranslationText.create!(:translation_key_id=>translation_key.id, :text=>text, :locale=>'de') | ||
41 | - end | ||
42 | - | ||
43 | - it "reads locales from the db" do | ||
44 | - locales = ['de','en','es'] | ||
45 | - locales.reverse.each do |locale| | ||
46 | - TranslationText.create!(:translation_key_id=>1, :text=>'asdasd', :locale=>locale) | ||
47 | - end | ||
48 | - @rep.available_locales.should == locales | ||
49 | - end | ||
50 | - | ||
51 | - it "has no pluralisation_rule by default" do | ||
52 | - @rep.pluralisation_rule.should == nil | ||
53 | - end | ||
54 | - | ||
55 | - it "cannot translate when no models are present" do | ||
56 | - @rep['car'].should == nil | ||
57 | - end | ||
58 | - | ||
59 | - it "can translate" do | ||
60 | - create_translation 'car', 'Auto' | ||
61 | - @rep['car'].should == 'Auto' | ||
62 | - end | ||
63 | - | ||
64 | - it "cannot pluralize when no model is present" do | ||
65 | - @rep.plural('Axis','Axis').should == [] | ||
66 | - end | ||
67 | - | ||
68 | - it "can pluralize" do | ||
69 | - create_translation 'Axis||||Axis', 'Achse||||Achsen' | ||
70 | - @rep.plural('Axis','Axis').should == ['Achse','Achsen'] | ||
71 | - end | ||
72 | -end | ||
73 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/logger_spec.rb
@@ -1,41 +0,0 @@ | @@ -1,41 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | - | ||
4 | -describe 'FastGettext::TranslationRepository::Logger' do | ||
5 | - before do | ||
6 | - @callback = lambda{} | ||
7 | - @rep = FastGettext::TranslationRepository.build('test', :type=>:logger, :callback=>@callback) | ||
8 | - @rep.is_a?(FastGettext::TranslationRepository::Logger).should be_true | ||
9 | - end | ||
10 | - subject{@rep} | ||
11 | - | ||
12 | - it{ should have(0).available_locales} | ||
13 | - | ||
14 | - it "has no pluralisation_rule" do | ||
15 | - @rep.pluralisation_rule.should == nil | ||
16 | - end | ||
17 | - | ||
18 | - describe :single do | ||
19 | - it "logs every call" do | ||
20 | - @callback.should_receive(:call).with('the_key') | ||
21 | - @rep['the_key'] | ||
22 | - end | ||
23 | - | ||
24 | - it "returns nil" do | ||
25 | - @callback.should_receive(:call).with('the_key').and_return 'something' | ||
26 | - @rep['the_key'].should == nil | ||
27 | - end | ||
28 | - end | ||
29 | - | ||
30 | - describe :plural do | ||
31 | - it "logs every call" do | ||
32 | - @callback.should_receive(:call).with(['a','b']) | ||
33 | - @rep.plural('a','b') | ||
34 | - end | ||
35 | - | ||
36 | - it "returns an empty array" do | ||
37 | - @callback.should_receive(:call).with(['a','b']).and_return 'something' | ||
38 | - @rep.plural('a','b').should == [] | ||
39 | - end | ||
40 | - end | ||
41 | -end | ||
42 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/mo_spec.rb
@@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | - | ||
4 | - | ||
5 | -describe 'FastGettext::TranslationRepository::Mo' do | ||
6 | - before do | ||
7 | - @rep = FastGettext::TranslationRepository.build('test',:path=>File.join(current_folder,'..','..','locale')) | ||
8 | - @rep.is_a?(FastGettext::TranslationRepository::Mo).should be_true | ||
9 | - end | ||
10 | - | ||
11 | - it "can be built" do | ||
12 | - @rep.available_locales.sort.should == ['de','en'] | ||
13 | - end | ||
14 | - | ||
15 | - it "can translate" do | ||
16 | - FastGettext.locale = 'de' | ||
17 | - @rep['car'].should == 'Auto' | ||
18 | - end | ||
19 | - | ||
20 | - it "can pluralize" do | ||
21 | - FastGettext.locale = 'de' | ||
22 | - @rep.plural('Axis','Axis').should == ['Achse','Achsen'] | ||
23 | - end | ||
24 | - | ||
25 | - it "has access to the mo repositories pluralisation rule" do | ||
26 | - FastGettext.locale = 'en' | ||
27 | - rep = FastGettext::TranslationRepository.build('plural_test',:path=>File.join(current_folder,'..','..','locale')) | ||
28 | - rep['car'].should == 'Test'#just check it is loaded correctly | ||
29 | - rep.pluralisation_rule.call(2).should == 3 | ||
30 | - end | ||
31 | -end | ||
32 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/po_spec.rb
@@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | - | ||
4 | - | ||
5 | -describe 'FastGettext::TranslationRepository::Po' do | ||
6 | - before do | ||
7 | - @rep = FastGettext::TranslationRepository.build('test',:path=>File.join(current_folder,'..','..','locale'),:type=>:po) | ||
8 | - @rep.is_a?(FastGettext::TranslationRepository::Po).should be_true | ||
9 | - end | ||
10 | - | ||
11 | - it "can be built" do | ||
12 | - @rep.available_locales.sort.should == ['de','en'] | ||
13 | - end | ||
14 | - | ||
15 | - it "can translate" do | ||
16 | - FastGettext.locale = 'de' | ||
17 | - @rep['car'].should == 'Auto' | ||
18 | - end | ||
19 | - | ||
20 | - it "can pluralize" do | ||
21 | - FastGettext.locale = 'de' | ||
22 | - @rep.plural('Axis','Axis').should == ['Achse','Achsen'] | ||
23 | - end | ||
24 | - | ||
25 | - it "has access to the mo repositories pluralisation rule" do | ||
26 | - FastGettext.locale = 'en' | ||
27 | - rep = FastGettext::TranslationRepository.build('plural_test',:path=>File.join(current_folder,'..','..','locale'),:type=>:po) | ||
28 | - rep['car'].should == 'Test'#just check it is loaded correctly | ||
29 | - rep.pluralisation_rule.call(2).should == 3 | ||
30 | - end | ||
31 | -end | ||
32 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository/yaml_spec.rb
@@ -1,61 +0,0 @@ | @@ -1,61 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','..','spec_helper') | ||
3 | - | ||
4 | -describe 'FastGettext::TranslationRepository::Yaml' do | ||
5 | - before do | ||
6 | - @rep = FastGettext::TranslationRepository.build('test', :path => File.join(current_folder,'..', '..', 'locale', 'yaml'), :type => :yaml) | ||
7 | - @rep.is_a?(FastGettext::TranslationRepository::Yaml).should be_true | ||
8 | - FastGettext.locale = 'de' | ||
9 | - end | ||
10 | - | ||
11 | - it "can be built" do | ||
12 | - @rep.available_locales.sort.should == ['de', 'en'] | ||
13 | - end | ||
14 | - | ||
15 | - it "translates nothing when locale is unsupported" do | ||
16 | - FastGettext.locale = 'xx' | ||
17 | - @rep['simple'].should == nil | ||
18 | - end | ||
19 | - | ||
20 | - it "does not translated categories" do | ||
21 | - @rep['cars'].should == nil | ||
22 | - end | ||
23 | - | ||
24 | - it "can translate simple" do | ||
25 | - @rep['simple'].should == 'einfach' | ||
26 | - end | ||
27 | - | ||
28 | - it "can translate nested" do | ||
29 | - @rep['cars.car'].should == 'Auto' | ||
30 | - end | ||
31 | - | ||
32 | - it "can pluralize" do | ||
33 | - @rep.plural('cars.axis').should == ['Achse', 'Achsen', nil, nil] | ||
34 | - end | ||
35 | - | ||
36 | - it "handles unfound plurals with nil" do | ||
37 | - @rep.plural('cars.xxx').should == [nil, nil, nil, nil] | ||
38 | - end | ||
39 | - | ||
40 | - it "can be used to translate plural forms" do | ||
41 | - FastGettext.stub!(:current_repository).and_return @rep | ||
42 | - FastGettext.n_('cars.axis','cars.axis',2).should == 'Achsen' | ||
43 | - FastGettext.n_('cars.axis',2).should == 'Achsen' | ||
44 | - FastGettext.n_('cars.axis',1).should == 'Achse' | ||
45 | - end | ||
46 | - | ||
47 | - it "can be used to do wanky pluralisation rules" do | ||
48 | - FastGettext.stub!(:current_repository).and_return @rep | ||
49 | - 4.times do |i| | ||
50 | - @rep.stub!(:pluralisation_rule).and_return lambda{i} | ||
51 | - FastGettext.n_('cars.silly',1).should == i.to_s | ||
52 | - end | ||
53 | - end | ||
54 | - | ||
55 | - it "can use custom pluraliztion rules" do | ||
56 | - FastGettext.locale = 'en' | ||
57 | - {0 => 0, 1 => 1, 2 => 2, 3 => 0}.each do |input, expected| | ||
58 | - @rep.pluralisation_rule.call(input).should == expected | ||
59 | - end | ||
60 | - end | ||
61 | -end | ||
62 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_repository_spec.rb
@@ -1,34 +0,0 @@ | @@ -1,34 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','spec_helper') | ||
3 | - | ||
4 | -module FastGettext | ||
5 | - module TranslationRepository | ||
6 | - class Dummy | ||
7 | - attr_accessor :name, :options | ||
8 | - def initialize(name, options) | ||
9 | - @name = name | ||
10 | - @options = options | ||
11 | - end | ||
12 | - end | ||
13 | - end | ||
14 | -end | ||
15 | - | ||
16 | -describe FastGettext::TranslationRepository do | ||
17 | - describe "build" do | ||
18 | - it "auto requires class by default" do | ||
19 | - lambda { FastGettext::TranslationRepository.build('xx', { :type => 'invalid'}) }.should raise_error(LoadError) | ||
20 | - end | ||
21 | - | ||
22 | - it "can have auto-require disabled" do | ||
23 | - FastGettext::TranslationRepository.build('xx', { :type => 'dummy' }) | ||
24 | - end | ||
25 | - | ||
26 | - it "makes a new repository" do | ||
27 | - options = { :type => 'dummy', :external => true } | ||
28 | - repo = FastGettext::TranslationRepository.build('xx', options) | ||
29 | - repo.class.should == FastGettext::TranslationRepository::Dummy | ||
30 | - repo.name.should == 'xx' | ||
31 | - repo.options.should == options | ||
32 | - end | ||
33 | - end | ||
34 | -end | ||
35 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext/translation_spec.rb
@@ -1,152 +0,0 @@ | @@ -1,152 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','spec_helper') | ||
3 | - | ||
4 | -describe FastGettext::Translation do | ||
5 | - include FastGettext::Translation | ||
6 | - | ||
7 | - before do | ||
8 | - default_setup | ||
9 | - end | ||
10 | - | ||
11 | - describe "unknown locale" do | ||
12 | - before do | ||
13 | - FastGettext.available_locales = nil | ||
14 | - FastGettext.locale = 'xx' | ||
15 | - end | ||
16 | - | ||
17 | - it "does not translate" do | ||
18 | - _('car').should == 'car' | ||
19 | - end | ||
20 | - | ||
21 | - it "does not translate plurals" do | ||
22 | - n_('car','cars',2).should == 'cars' | ||
23 | - end | ||
24 | - end | ||
25 | - | ||
26 | - describe :_ do | ||
27 | - it "translates simple text" do | ||
28 | - _('car').should == 'Auto' | ||
29 | - end | ||
30 | - | ||
31 | - it "returns key if not translation was found" do | ||
32 | - _('NOT|FOUND').should == 'NOT|FOUND' | ||
33 | - end | ||
34 | - | ||
35 | - it "does not return the gettext meta information" do | ||
36 | - _('').should == '' | ||
37 | - end | ||
38 | - end | ||
39 | - | ||
40 | - describe :n_ do | ||
41 | - before do | ||
42 | - FastGettext.pluralisation_rule = nil | ||
43 | - end | ||
44 | - | ||
45 | - it "translates pluralized" do | ||
46 | - n_('Axis','Axis',1).should == 'Achse' | ||
47 | - n_('Axis','Axis',2).should == 'Achsen' | ||
48 | - n_('Axis','Axis',0).should == 'Achsen' | ||
49 | - end | ||
50 | - | ||
51 | - describe "pluralisations rules" do | ||
52 | - it "supports abstract pluralisation rules" do | ||
53 | - FastGettext.pluralisation_rule = lambda{|n|2} | ||
54 | - n_('a','b','c','d',4).should == 'c' | ||
55 | - end | ||
56 | - | ||
57 | - it "supports false as singular" do | ||
58 | - FastGettext.pluralisation_rule = lambda{|n|n!=2} | ||
59 | - n_('singular','plural','c','d',2).should == 'singular' | ||
60 | - end | ||
61 | - | ||
62 | - it "supports true as plural" do | ||
63 | - FastGettext.pluralisation_rule = lambda{|n|n==2} | ||
64 | - n_('singular','plural','c','d',2).should == 'plural' | ||
65 | - end | ||
66 | - end | ||
67 | - | ||
68 | - it "returns the appropriate key if no translation was found" do | ||
69 | - n_('NOTFOUND','NOTFOUNDs',1).should == 'NOTFOUND' | ||
70 | - n_('NOTFOUND','NOTFOUNDs',2).should == 'NOTFOUNDs' | ||
71 | - end | ||
72 | - | ||
73 | - it "returns the last key when no translation was found and keys where to short" do | ||
74 | - FastGettext.pluralisation_rule = lambda{|x|4} | ||
75 | - n_('Apple','Apples',2).should == 'Apples' | ||
76 | - end | ||
77 | - end | ||
78 | - | ||
79 | - describe :s_ do | ||
80 | - it "translates simple text" do | ||
81 | - s_('car').should == 'Auto' | ||
82 | - end | ||
83 | - | ||
84 | - it "returns cleaned key if a translation was not found" do | ||
85 | - s_("XXX|not found").should == "not found" | ||
86 | - end | ||
87 | - | ||
88 | - it "can use a custom seperator" do | ||
89 | - s_("XXX/not found",'/').should == "not found" | ||
90 | - end | ||
91 | - end | ||
92 | - | ||
93 | - describe :N_ do | ||
94 | - it "returns the key" do | ||
95 | - N_('XXXXX').should == 'XXXXX' | ||
96 | - end | ||
97 | - end | ||
98 | - | ||
99 | - describe :Nn_ do | ||
100 | - it "returns the keys as array" do | ||
101 | - Nn_('X','Y').should == ['X','Y'] | ||
102 | - end | ||
103 | - end | ||
104 | - | ||
105 | - describe :caching do | ||
106 | - describe :cache_hit do | ||
107 | - before do | ||
108 | - FastGettext.translation_repositories.replace({}) | ||
109 | - #singular cache keys | ||
110 | - FastGettext.current_cache['xxx'] = '1' | ||
111 | - | ||
112 | - #plural cache keys | ||
113 | - FastGettext.current_cache['||||xxx'] = ['1','2'] | ||
114 | - FastGettext.current_cache['||||xxx||||yyy'] = ['1','2'] | ||
115 | - end | ||
116 | - | ||
117 | - it "uses the cache when translating with _" do | ||
118 | - _('xxx').should == '1' | ||
119 | - end | ||
120 | - | ||
121 | - it "uses the cache when translating with s_" do | ||
122 | - s_('xxx').should == '1' | ||
123 | - end | ||
124 | - | ||
125 | - it "uses the cache when translating with n_" do | ||
126 | - n_('xxx','yyy',1).should == '1' | ||
127 | - end | ||
128 | - | ||
129 | - it "uses the cache when translating with n_ and single argument" do | ||
130 | - n_('xxx',1).should == '1' | ||
131 | - end | ||
132 | - end | ||
133 | - | ||
134 | - it "caches different locales seperatly" do | ||
135 | - FastGettext.locale = 'en' | ||
136 | - _('car').should == 'car' | ||
137 | - FastGettext.locale = 'de' | ||
138 | - _('car').should == 'Auto' | ||
139 | - end | ||
140 | - | ||
141 | - it "caches different textdomains seperatly" do | ||
142 | - _('car').should == 'Auto' | ||
143 | - | ||
144 | - FastGettext.translation_repositories['fake'] = {} | ||
145 | - FastGettext.text_domain = 'fake' | ||
146 | - _('car').should == 'car' | ||
147 | - | ||
148 | - FastGettext.text_domain = 'test' | ||
149 | - _('car').should == 'Auto' | ||
150 | - end | ||
151 | - end | ||
152 | -end | ||
153 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/fast_gettext_spec.rb
@@ -1,43 +0,0 @@ | @@ -1,43 +0,0 @@ | ||
1 | -require File.expand_path("spec_helper", File.dirname(__FILE__)) | ||
2 | - | ||
3 | -default_setup | ||
4 | -class IncludeTest | ||
5 | - include FastGettext::Translation | ||
6 | - @@xx = _('car') | ||
7 | - def self.ext | ||
8 | - _('car') | ||
9 | - end | ||
10 | - def inc | ||
11 | - _('car') | ||
12 | - end | ||
13 | - def self.xx | ||
14 | - @@xx | ||
15 | - end | ||
16 | -end | ||
17 | - | ||
18 | -describe FastGettext do | ||
19 | - include FastGettext | ||
20 | - before :all do | ||
21 | - default_setup | ||
22 | - end | ||
23 | - | ||
24 | - it "provides access to FastGettext::Translations methods" do | ||
25 | - FastGettext._('car').should == 'Auto' | ||
26 | - _('car').should == 'Auto' | ||
27 | - s_("XXX|not found").should == "not found" | ||
28 | - n_('Axis','Axis',1).should == 'Achse' | ||
29 | - N_('XXXXX').should == 'XXXXX' | ||
30 | - Nn_('X','Y').should == ['X','Y'] | ||
31 | - end | ||
32 | - | ||
33 | - it "is extended to a class and included into a class" do | ||
34 | - IncludeTest.ext.should == 'Auto' | ||
35 | - IncludeTest.ext.should == 'Auto' | ||
36 | - IncludeTest.new.inc.should == 'Auto' | ||
37 | - IncludeTest.xx.should == 'Auto' | ||
38 | - end | ||
39 | - | ||
40 | - it "has a VERSION" do | ||
41 | - FastGettext::VERSION.should =~ /^\d+\.\d+\.\d+$/ | ||
42 | - end | ||
43 | -end | ||
44 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/spec_helper.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -# ---- requirements | ||
2 | -require 'rubygems' | ||
3 | -$LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__)) | ||
4 | -require 'fast_gettext' | ||
5 | - | ||
6 | -# ---- revert to defaults | ||
7 | -Spec::Runner.configure do |config| | ||
8 | - config.before :all do | ||
9 | - FastGettext.locale = 'de' | ||
10 | - FastGettext.available_locales = nil | ||
11 | - end | ||
12 | -end | ||
13 | - | ||
14 | -# ---- Helpers | ||
15 | -def pending_it(text,&block) | ||
16 | - it text do | ||
17 | - pending(&block) | ||
18 | - end | ||
19 | -end | ||
20 | - | ||
21 | -def default_setup | ||
22 | - FastGettext.add_text_domain('test',:path=>File.join(File.dirname(__FILE__),'locale')) | ||
23 | - FastGettext.text_domain = 'test' | ||
24 | - FastGettext.available_locales = ['en','de'] | ||
25 | - FastGettext.locale = 'de' | ||
26 | -end | ||
27 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/vendor/fake_load_path/iconv.rb
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/vendor/iconv_spec.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -$LOAD_PATH.unshift File.expand_path("../../lib", current_folder) | ||
3 | - | ||
4 | -describe 'Iconv' do | ||
5 | - it "also works when Iconv was not found locally" do | ||
6 | - #prepare load path | ||
7 | - $LOAD_PATH.unshift File.join(current_folder,'fake_load_path') | ||
8 | - test = 1 | ||
9 | - begin | ||
10 | - require 'iconv' | ||
11 | - rescue LoadError | ||
12 | - test = 2 | ||
13 | - end | ||
14 | - test.should == 2 | ||
15 | - | ||
16 | - #load fast_gettext | ||
17 | - require 'fast_gettext' | ||
18 | - | ||
19 | - FastGettext.add_text_domain('test',:path=>File.join(File.dirname(__FILE__),'..','locale')) | ||
20 | - FastGettext.text_domain = 'test' | ||
21 | - FastGettext.available_locales = ['en','de'] | ||
22 | - FastGettext.locale = 'de' | ||
23 | - | ||
24 | - #translate | ||
25 | - FastGettext._('car').should == 'Auto' | ||
26 | - end | ||
27 | -end | ||
28 | \ No newline at end of file | 0 | \ No newline at end of file |
vendor/terceiro-fast_gettext-fe7bb09e30f7b1b5876a3b7a18fe8a254c6f59cb/spec/vendor/string_spec.rb
@@ -1,77 +0,0 @@ | @@ -1,77 +0,0 @@ | ||
1 | -current_folder = File.dirname(__FILE__) | ||
2 | -require File.join(current_folder,'..','spec_helper') | ||
3 | - | ||
4 | -#just to make sure we did not mess up while copying... | ||
5 | -describe String do | ||
6 | - it "does not translate twice" do | ||
7 | - ("%{a} %{b}" % {:a=>'%{b}',:b=>'c'}).should == '%{b} c' | ||
8 | - end | ||
9 | - | ||
10 | - describe "old % style replacement" do | ||
11 | - it "substitudes using % + Hash" do | ||
12 | - ("x%{name}y" %{:name=>'a'}).should == 'xay' | ||
13 | - end | ||
14 | - | ||
15 | - it "does not substitute after %%" do | ||
16 | - ("%%{num} oops" % {:num => 1}).should == '%{num} oops' | ||
17 | - end | ||
18 | - | ||
19 | - it "does not substitute when nothing could be found" do | ||
20 | - ("abc" % {:x=>1}).should == 'abc' | ||
21 | - end | ||
22 | - | ||
23 | - if RUBY_VERSION < '1.9' # this does not longer work in 1.9, use :"my weird string" | ||
24 | - it "sustitutes strings" do | ||
25 | - ("a%{b}c" % {'b'=>1}).should == 'a1c' | ||
26 | - end | ||
27 | - | ||
28 | - it "sustitutes strings with -" do | ||
29 | - ("a%{b-a}c" % {'b-a'=>1}).should == 'a1c' | ||
30 | - end | ||
31 | - | ||
32 | - it "sustitutes string with ." do | ||
33 | - ("a%{b.a}c" % {'b.a'=>1}).should == 'a1c' | ||
34 | - end | ||
35 | - | ||
36 | - it "sustitutes string with number" do | ||
37 | - ("a%{1}c" % {'1'=>1}).should == 'a1c' | ||
38 | - end | ||
39 | - end | ||
40 | - end | ||
41 | - | ||
42 | - describe 'old sprintf style' do | ||
43 | - it "substitudes using % + Array" do | ||
44 | - ("x%sy%s" % ['a','b']).should == 'xayb' | ||
45 | - end | ||
46 | - | ||
47 | - if RUBY_VERSION < '1.9' # this does not longer work in 1.9, ArgumentError is raised | ||
48 | - it "does not remove %{} style replacements" do | ||
49 | - ("%{name} x%sy%s" % ['a','b']).should == '%{name} xayb' | ||
50 | - end | ||
51 | - | ||
52 | - it "does not remove %<> style replacement" do | ||
53 | - ("%{name} %<num>f %s" % ['x']).should == "%{name} %<num>f x" | ||
54 | - end | ||
55 | - end | ||
56 | - end | ||
57 | - | ||
58 | - describe 'ruby 1.9 style %< replacement' do | ||
59 | - it "does not substitute after %%" do | ||
60 | - ("%%<num> oops" % {:num => 1}).should == '%<num> oops' | ||
61 | - end | ||
62 | - | ||
63 | - it "subsitutes %<something>d" do | ||
64 | - ("x%<hello>dy" % {:hello=>1}).should == 'x1y' | ||
65 | - end | ||
66 | - | ||
67 | - it "substitutes #b" do | ||
68 | - ("%<num>#b" % {:num => 1}).should == "0b1" | ||
69 | - end | ||
70 | - end | ||
71 | - | ||
72 | - if RUBY_VERSION >= '1.9' | ||
73 | - it "does not raise when key was not found" do | ||
74 | - ("%{typo} xxx" % {:something=>1}).should == "%{typo} xxx" | ||
75 | - end | ||
76 | - end | ||
77 | -end | ||
78 | \ No newline at end of file | 0 | \ No newline at end of file |