emipair-merb_global 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/.gitignore +9 -0
  2. data/CONTRIBUTORS +6 -0
  3. data/HISTORY +34 -0
  4. data/LICENSE +21 -0
  5. data/README +4 -0
  6. data/README.markdown +179 -0
  7. data/Rakefile +65 -0
  8. data/TODO +4 -0
  9. data/VERSION +1 -0
  10. data/activerecord_generators/translations_migration/USAGE +4 -0
  11. data/activerecord_generators/translations_migration/templates/translations_migration.erb +30 -0
  12. data/activerecord_generators/translations_migration/translations_migration_generator.rb +31 -0
  13. data/benchmarks/database1.rb +174 -0
  14. data/examples/active_record_example/README.txt +9 -0
  15. data/examples/active_record_example/application.rb +5 -0
  16. data/examples/active_record_example/config/database.yml +9 -0
  17. data/examples/active_record_example/config/framework.rb +5 -0
  18. data/examples/active_record_example/config/init.rb +24 -0
  19. data/examples/active_record_example/config/plugins.yml +3 -0
  20. data/examples/data_mapper_example/README.txt +9 -0
  21. data/examples/data_mapper_example/application.rb +5 -0
  22. data/examples/data_mapper_example/config/database.yml +9 -0
  23. data/examples/data_mapper_example/config/framework.rb +5 -0
  24. data/examples/data_mapper_example/config/init.rb +24 -0
  25. data/examples/data_mapper_example/config/plugins.yml +3 -0
  26. data/examples/database.sql +28 -0
  27. data/examples/gettext_example/README.txt +9 -0
  28. data/examples/gettext_example/application.rb +8 -0
  29. data/examples/gettext_example/config/framework.rb +5 -0
  30. data/examples/gettext_example/config/init.rb +24 -0
  31. data/examples/gettext_example/config/plugins.yml +4 -0
  32. data/examples/gettext_example/locale/merbapp.pot +21 -0
  33. data/examples/gettext_example/locale/pl/LC_MESSAGES/merbapp.mo +0 -0
  34. data/examples/gettext_example/locale/pl.po +23 -0
  35. data/examples/mock_example/README.txt +9 -0
  36. data/examples/mock_example/application.rb +5 -0
  37. data/examples/mock_example/config/framework.rb +5 -0
  38. data/examples/mock_example/config/init.rb +23 -0
  39. data/examples/mock_example/config/plugins.yml +3 -0
  40. data/examples/sequel_example/README.txt +9 -0
  41. data/examples/sequel_example/application.rb +5 -0
  42. data/examples/sequel_example/config/database.yml +9 -0
  43. data/examples/sequel_example/config/framework.rb +5 -0
  44. data/examples/sequel_example/config/init.rb +24 -0
  45. data/examples/sequel_example/config/plugins.yml +3 -0
  46. data/examples/yaml_example/README.txt +9 -0
  47. data/examples/yaml_example/application.rb +5 -0
  48. data/examples/yaml_example/config/framework.rb +5 -0
  49. data/examples/yaml_example/config/init.rb +24 -0
  50. data/examples/yaml_example/config/plugins.yml +4 -0
  51. data/examples/yaml_example/locale/en.yaml +2 -0
  52. data/examples/yaml_example/locale/pl.yaml +2 -0
  53. data/lib/merb_global/base.rb +157 -0
  54. data/lib/merb_global/config.rb +36 -0
  55. data/lib/merb_global/controller.rb +40 -0
  56. data/lib/merb_global/date_providers/fork.rb +37 -0
  57. data/lib/merb_global/date_providers.rb +47 -0
  58. data/lib/merb_global/locale.rb +164 -0
  59. data/lib/merb_global/merbrake.rb +37 -0
  60. data/lib/merb_global/message_providers/active_record.rb +113 -0
  61. data/lib/merb_global/message_providers/data_mapper.rb +113 -0
  62. data/lib/merb_global/message_providers/gettext.rb +125 -0
  63. data/lib/merb_global/message_providers/gettext.treetop +60 -0
  64. data/lib/merb_global/message_providers/mock.rb +17 -0
  65. data/lib/merb_global/message_providers/sequel.rb +99 -0
  66. data/lib/merb_global/message_providers/yaml.rb +105 -0
  67. data/lib/merb_global/message_providers.rb +146 -0
  68. data/lib/merb_global/numeric_providers/fork.rb +37 -0
  69. data/lib/merb_global/numeric_providers/java.rb +15 -0
  70. data/lib/merb_global/numeric_providers.rb +48 -0
  71. data/lib/merb_global/plural.rb +20 -0
  72. data/lib/merb_global/plural.treetop +267 -0
  73. data/lib/merb_global/providers.rb +40 -0
  74. data/lib/merb_global.rb +8 -0
  75. data/sequel_generators/translations_migration/USAGE +4 -0
  76. data/sequel_generators/translations_migration/templates/translations_migration.erb +28 -0
  77. data/sequel_generators/translations_migration/translations_migration_generator.rb +32 -0
  78. data/spec/base_spec.rb +124 -0
  79. data/spec/controller_spec.rb +95 -0
  80. data/spec/date_providers_spec.rb +82 -0
  81. data/spec/locale/merbapp.pot +26 -0
  82. data/spec/locale/pl/LC_MESSAGES/merbapp.mo +0 -0
  83. data/spec/locale/pl.po +27 -0
  84. data/spec/locale/pl.yaml +8 -0
  85. data/spec/message_providers/active_record_spec.rb +192 -0
  86. data/spec/message_providers/data_mapper_spec.rb +124 -0
  87. data/spec/message_providers/gettext_spec.rb +77 -0
  88. data/spec/message_providers/mock_spec.rb +27 -0
  89. data/spec/message_providers/sequel_spec.rb +185 -0
  90. data/spec/message_providers/yaml_spec.rb +64 -0
  91. data/spec/message_providers_spec.rb +186 -0
  92. data/spec/numeric_providers_spec.rb +82 -0
  93. data/spec/plural_spec.rb +23 -0
  94. data/spec/providers_spec.rb +60 -0
  95. data/spec/spec_helper.rb +36 -0
  96. metadata +183 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ coverage
3
+ doc
4
+ log
5
+ pkg
6
+ pkg/*
7
+ tmp/
8
+ tmp/*
9
+ *.db
data/CONTRIBUTORS ADDED
@@ -0,0 +1,6 @@
1
+ Contributors
2
+ ============
3
+
4
+ * Alex Coles, alex at alexcolesportfolio dot com
5
+ * Maciej Piechotka, uzytkownik2 at gmail dot com
6
+ * Pavel Kunc
data/HISTORY ADDED
@@ -0,0 +1,34 @@
1
+ === 0.0.7
2
+ * More consistent configuration of supported languages
3
+ * JRuby Numeric provider
4
+ * Some small fixes
5
+
6
+ === 0.0.6
7
+ * Introduction of Locale object
8
+ * Change of MessageProviders interface
9
+ * Per-environment configuration
10
+
11
+ === 0.0.5
12
+ * Handles lang_REGION as lang
13
+ * Renamed providers into message providers and translate_to into localize
14
+ * Added support for localization of dates and numbers
15
+ * Updated specs
16
+
17
+ === 0.0.4
18
+ * Changed database format (to allow importing/exporting)
19
+ * Added importing/exporting (EXPERIMENTAL)
20
+
21
+ === 0.0.3
22
+ * New Plural engine
23
+
24
+ === 0.0.2
25
+ * Added language customisation
26
+ * Support for auto-choose of language
27
+ * Support for DataMapper 0.9 (removed for 0.3)
28
+ * Developed examples
29
+ * Clean-up of code
30
+ * Minor other improvements
31
+
32
+ === 0.0.1
33
+ * Basic support for 'view' translation
34
+ * Auto-guess of language on base of Accept-Language header
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2008 Alex Coles, Ikonoklastik Productions
2
+ Maciej Piechotka
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,4 @@
1
+ = merb_global
2
+ == Localization (L10n) and Internationalization (i18n) support for the Merb MVC Framework
3
+
4
+ Please see README.markdown.
data/README.markdown ADDED
@@ -0,0 +1,179 @@
1
+ MerbGlobal README
2
+ =================
3
+
4
+ A plugin for the Merb framework providing Localization (L10n) and
5
+ Internationalization (i18n) support.
6
+
7
+ merb\_global will have the following feature set:
8
+
9
+ * support for model (content) localization
10
+ - by default, localization stored in the database
11
+ - with DataMapper (targeted 0.1)
12
+ - with ActiveRecord (targeted 0.2)
13
+ - with Sequel ORM
14
+ - and, with a choice of strategies in each case:
15
+ - single-table (c.f. globalize RoR plugin)
16
+
17
+ |title |varchar(100)|
18
+ |title_de|varchar(100)|
19
+ |title_fr|varchar(100)|
20
+
21
+ - joined-table for unlimited localizations (c.f. Symfony PHP)
22
+ - or, alternatively localizations can be stored outside of the domain
23
+ model, UI Strings.
24
+
25
+ * support for view (UI String) localization
26
+ - choice of providers (po, yaml, database)
27
+
28
+ Merb::Plugins.config[:merb_global] = {
29
+ #:message_provider => "po", # default
30
+ :message_provider => 'yaml'
31
+ #:message_provider => active_record
32
+ #:message_provider => data_mapper
33
+ #:message_provider => sequel
34
+ }
35
+
36
+ - for JRuby, wrapper allowing use of .properties files.
37
+
38
+ * Extract, update for PO/POT files
39
+ * Currency, Date and Language Helpers
40
+ - stored either in the database, or for JRuby, wrappers around
41
+ built-in functionality provided by java.util.Currency, java.util.Locale
42
+
43
+ * support for localization of Merb generated code
44
+ * support for non-English Inflectors.
45
+
46
+ Developer ReadMe
47
+ ----------------
48
+
49
+ **REQUEST** : Your development support is very much appreciated. Please
50
+ contact us below if you're interested in lending a hand with the development
51
+ of this project.
52
+
53
+ Getting the Source
54
+ ------------------
55
+
56
+ Performing a git clone on either of the following repositories will get you
57
+ the latest source:
58
+
59
+ git clone git://github.com/myabc/merb_global.git
60
+ git clone git://gitorious.org/merb_global/mainline.git (on gitorious)
61
+
62
+ The following additional mirrors are available:
63
+
64
+ git://repo.or.cz/merb_global.git
65
+ http://repo.or.cz/r/merb_global.git
66
+
67
+ Installation and Setup
68
+ ----------------------
69
+
70
+ Dependencies:
71
+ sudo gem install gettext
72
+
73
+ Installing MerbGlobal
74
+ rake gem
75
+ sudo gem install pkg/merb_global-0.0.1.gem
76
+
77
+ Configuration options
78
+ ---------------------
79
+
80
+ MerbGlobal is possible to configure with:
81
+
82
+ Merb::Plugins.config[:merb_global] = {
83
+ :message_provider => 'gettext'
84
+ ...
85
+ }
86
+
87
+ in init.rb or using plugins.yml file:
88
+
89
+ :merb_global:
90
+ :message_provider: gettext
91
+ ...
92
+
93
+ Configuration options:
94
+
95
+ * :message_provider
96
+
97
+ What message provider we want to use.
98
+
99
+ Values: gettext, yaml, sequel, active\_record, data\_mapper
100
+ Default: gettext
101
+
102
+ * :date_provider
103
+
104
+ What date provider we want to use.
105
+
106
+ Values: fork
107
+ Default: fork
108
+
109
+ * :numeric_providers
110
+
111
+ What numeric provider we want to use.
112
+
113
+ Values: fork
114
+ Default: fork
115
+
116
+ * :flat
117
+
118
+ Are we running merb-flat or normal merb?
119
+
120
+ Values: true/false
121
+ Default: false
122
+
123
+ * :localedir
124
+
125
+ Define directory where translations are stored.
126
+
127
+ If :flat is set to true than MerbGlobal will search in #{Merb.root}+'locale'. If :flat is false than in #{Merb.root}+:localedir. When :flat is false and :localedir configuration is not defined the default will be #{Merb.root}+'app/locale'.
128
+
129
+ * :gettext => :domain
130
+
131
+ Name of the text domain. Which is basically name of the GetText MO file without .mo extension.
132
+
133
+ Default: merbapp
134
+
135
+ ##Configuration examples
136
+
137
+ Follwing configuraiton in plugins.yml:
138
+
139
+ :merb_global:
140
+ :provider: gettext
141
+ :flat: false
142
+ :localedir: locale
143
+ :gettext:
144
+ :domain: messages
145
+
146
+ will make MerbGlobal to search translations in following places:
147
+
148
+ #{Merb.root}/locale/#{language}/LC_MESSAGES/messages.mo
149
+ #{Merb.root}/locale/#{language}/messages.mo
150
+
151
+ Where #{language} is string which defines language such as cs\_CZ, en\_GB or just cs, en.
152
+
153
+ No configuration will look at:
154
+
155
+ #{Merb.root}/app/locale/#{language}/LC_MESSAGES/merbapp.mo
156
+ #{Merb.root}/app/locale/#{language}/merbapp.mo
157
+
158
+ Licensing and Copyright
159
+ -----------------------
160
+
161
+ MerbGlobal is released under an **MIT License**. Copyright information, as
162
+ well as a copy of the License may be found in the LICENSE file.
163
+
164
+ Support
165
+ -------
166
+
167
+ **WARNING REPEATED** : MerbGlobal at an early stage of its development.
168
+ You should not use this code unless you're reasonably secure with both Ruby
169
+ and Merb. That said, _please do get involved!_
170
+
171
+ Your best sources for support are currently the wiki, IRC or our mailing
172
+ list:
173
+
174
+ * **MerbGlobal Wiki**: <http://trac.ikonoklastik.com/merb_global/>
175
+ * **MerbGlobal mailing list**: <http://groups.google.com/group/merb_global>
176
+ * **MerbGlobal homepage**: _coming soon_
177
+ * Contact the developers directly:
178
+ - <alex@alexcolesportfolio.com> | myabc on #datamapper, #merb IRC
179
+ - <uzytkownik2@gmail.com> | <xmpp:uzytkownik@jid.pl>
data/Rakefile ADDED
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+
5
+ PLUGIN = "emipair-merb_global"
6
+ NAME = "emipair-merb_global"
7
+ GEM_VERSION = "0.0.7"
8
+ AUTHORS = ["Matt Kent", "Ryan Dy"]
9
+ EMAIL = "eng@emimusic.com"
10
+ HOMEPAGE = "http://trac.ikonoklastik.com/merb_global/"
11
+ SUMMARY = "Localization (L10n) and Internationalization (i18n) support for the Merb MVC Framework"
12
+
13
+ begin
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = NAME
17
+ gemspec.summary = SUMMARY
18
+ gemspec.description = gemspec.summary
19
+ gemspec.email = EMAIL
20
+ gemspec.homepage = HOMEPAGE
21
+ gemspec.authors = AUTHORS
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
25
+ end
26
+
27
+ desc "Install merb_global"
28
+ task :install => [:package] do
29
+ sh %{gem install pkg/#{NAME}-#{GEM_VERSION}}
30
+ end
31
+
32
+ Rake::RDocTask.new do |rd|
33
+ rd.rdoc_dir = "doc"
34
+ rd.rdoc_files.include "lib/**/*.rb"
35
+ end
36
+
37
+ desc "Creates database for examples"
38
+ task :populate_db do
39
+ require 'fileutils'
40
+ pwd = File.dirname __FILE__
41
+ db = "#{pwd}/examples/database.db"
42
+ sh %{sqlite3 #{db} < #{pwd}/examples/database.sql}
43
+ FileUtils.cp db, "#{pwd}/examples/active_record_example/database.db"
44
+ FileUtils.cp db, "#{pwd}/examples/data_mapper_example/database.db"
45
+ FileUtils.cp db, "#{pwd}/examples/sequel_example/database.db"
46
+ end
47
+ task "pkg/#{NAME}-#{GEM_VERSION}" => [:populate_db]
48
+
49
+ require 'spec/rake/spectask'
50
+
51
+ desc "Run all specs"
52
+ Spec::Rake::SpecTask.new('specs') do |st|
53
+ st.libs = ['lib', 'spec']
54
+ st.spec_files = FileList['spec/**/*_spec.rb']
55
+ st.spec_opts = ['--format specdoc', '--color']
56
+ end
57
+
58
+ desc "Run rcov"
59
+ Spec::Rake::SpecTask.new('rcov') do |rct|
60
+ rct.libs = ['lib', 'spec']
61
+ rct.rcov = true
62
+ rct.rcov_opts = ['-x gems', '-x usr', '-x spec']
63
+ rct.spec_files = FileList['spec/**/*.rb']
64
+ rct.spec_opts = ['--format specdoc', '--color']
65
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ = TODO
2
+
3
+ Please see http://trac.ikonoklastik.com/merb_global/ for the MerbGlobal issue
4
+ tracker.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,4 @@
1
+ Description:
2
+
3
+
4
+ Usage:
@@ -0,0 +1,30 @@
1
+ #<% if false %>
2
+ class Merb::Global::MessageProviders::ActiveRecord
3
+ #<% end %>
4
+ class AddTranslationsMigration < ActiveRecord::Migration
5
+ def self.up
6
+ create_table :merb_global_languages do |t|
7
+ t.string :name, :limit => 16
8
+ t.integer :nplural
9
+ t.string :plural, :size => 128
10
+ end
11
+ add_index :merb_global_languages, :name, :unique => true
12
+ create_table :merb_global_translations,
13
+ :id => false, :primary_key => [:language_id,
14
+ :msgid_hash,
15
+ :msgstr_index] do |t|
16
+ t.integer :language_id, :null => false
17
+ t.text :msgid, :null => false
18
+ t.text :msgid_plural
19
+ t.text :msgstr, :null => false
20
+ t.integer :msgstr_index, :null => true
21
+ end
22
+ end
23
+ def self.down
24
+ drop_table :merb_global_languages
25
+ drop_table :merb_global_translations
26
+ end
27
+ end
28
+ #<% if false %>
29
+ end
30
+ #<% end %>
@@ -0,0 +1,31 @@
1
+ class TranslationMigrationGenerator < Merb::GeneratorBase
2
+ protected :banner
3
+
4
+ def initialize runtime_args, runtime_options = {}
5
+ runtime_args.push ''
6
+ super
7
+ @name = 'translations'
8
+ end
9
+
10
+ def mainfest
11
+ record do |m|
12
+ m.directory 'schema/migrations'
13
+ highest_migration = Dir[Dir.pwd+'/schema/migrations/*'].map do |f|
14
+ File.basename(f) =~ /^(\d+)/
15
+ $1
16
+ end.max
17
+ filename = format '%03d_%s', (highest_migration.to_i+1), @name.snake_case
18
+ m.template 'translation_migration.erb',
19
+ "schema/migrations/#{filename}.rb"
20
+ puts banner
21
+ end
22
+ end
23
+
24
+ def banner
25
+ <<-EOS
26
+ A migration to add translation tables to your database has been created.
27
+ Run 'rake sequel:db:migrate' to add the translations migration to your database.
28
+
29
+ EOS
30
+ end
31
+ end
@@ -0,0 +1,174 @@
1
+ require 'sequel'
2
+ require 'benchmark'
3
+
4
+ DB = Sequel.connect ARGV[0]
5
+
6
+ DB.create_table! :languages1 do
7
+ primary_key :id
8
+ varchar :name, :size => 16, :unique => true
9
+ varchar :plural, :size => 128
10
+ end
11
+
12
+ DB.create_table! :translations1 do
13
+ primary_key [:language_id, :msgid_hash, :msgstr_index]
14
+ foreign_key :language_id, :languages1, :null => false
15
+ integer :msgid_hash, :null => false
16
+ text :msgstr, :null => false
17
+ integer :msgstr_index
18
+ end
19
+
20
+ DB.create_table! :languages2 do
21
+ primary_key :id
22
+ varchar :name, :size => 16, :unique => true
23
+ varchar :plural, :size => 128
24
+ end
25
+
26
+ DB.create_table! :translations2 do
27
+ primary_key [:language_id, :msgid, :msgstr_index]
28
+ foreign_key :language_id, :languages2, :null => false
29
+ text :msgid, :null => false
30
+ text :msgstr, :null => false
31
+ integer :msgstr_index
32
+ end
33
+
34
+ DB.create_table! :languages3 do
35
+ primary_key :id
36
+ varchar :name, :size => 16, :unique => true
37
+ varchar :plural, :size => 128
38
+ end
39
+
40
+ drop_table :original3 rescue nil
41
+ DB << "CREATE TABLE original3 (id INTEGER PRIMARY KEY, msgid TEXT)"
42
+
43
+ DB.create_table! :translations3 do
44
+ primary_key [:language_id, :original_id, :msgstr_index]
45
+ foreign_key :language_id, :languages3, :null => false
46
+ foreign_key :original_id, :original3, :null => false
47
+ text :msgstr, :null => false
48
+ integer :msgstr_index
49
+ end
50
+
51
+ $chars = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
52
+ def rand_string size
53
+ (0...size).collect { $chars[Kernel.rand($chars.length)] }.join
54
+ end
55
+
56
+ $original = []
57
+ 128.times { $original << rand_string(32) }
58
+ $original.sort!.uniq!
59
+ $translations = {}
60
+ $plurals = {}
61
+ 3.times do
62
+ lang_name = rand_string(2)
63
+ $translations[lang_name] = lang = {}
64
+ $plurals[lang_name] = rand_string(8)
65
+ $original.each do |orig|
66
+ lang[orig] = rand_string(32)
67
+ end
68
+ end
69
+
70
+ $languages = $plurals.keys
71
+ def rand_language
72
+ $languages[Kernel.rand($languages.length)]
73
+ end
74
+
75
+ def rand_original
76
+ $original[Kernel.rand($original.length)]
77
+ end
78
+
79
+ puts 'Export'
80
+ Benchmark.bm(22) do |bm|
81
+ bm.report('Original 0.0.3:') do
82
+ $translations.each do |lang, trans|
83
+ lang_id = (DB[:languages1] << {:name => lang, :plural => $plurals[lang]})
84
+ trans.each do |original, translation|
85
+ DB[:translations1] << {
86
+ :language_id => lang_id,
87
+ :msgid_hash => original.hash,
88
+ :msgstr => translation
89
+ }
90
+ end
91
+ end
92
+ end
93
+ bm.report('With string inside:') do
94
+ $translations.each do |lang, trans|
95
+ lang_id = (DB[:languages2] << {:name => lang, :plural => $plurals[lang]})
96
+ trans.each do |original, translation|
97
+ DB[:translations2] << {
98
+ :language_id => lang_id,
99
+ :msgid => original,
100
+ :msgstr => translation
101
+ }
102
+ end
103
+ end
104
+ end
105
+ bm.report('With separate strings:') do
106
+ $original.each do |original|
107
+ DB[:original3] << {:id => original.hash, :msgid => original}
108
+ end
109
+ $translations.each do |lang, trans|
110
+ lang_id = (DB[:languages3] << {:name => lang, :plural => $plurals[lang]})
111
+ trans.each do |original, translation|
112
+ DB[:translations3] << {
113
+ :language_id => lang_id,
114
+ :original_id => original.hash,
115
+ :msgstr => translation
116
+ }
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ $search = (0...1024).collect {[rand_language, rand_original]}
123
+
124
+ puts ''
125
+ puts 'Searching'
126
+ Benchmark.bm(22) do |bm|
127
+ bm.report('Original 0.0.3:') do
128
+ $search.each do |arr|
129
+ _lang, _orig = *arr
130
+ lang = DB[:languages1].filter(:name => _lang).first[:id]
131
+ trans = DB[:translations1].filter(:language_id => lang,
132
+ :msgid_hash => _orig.hash,
133
+ :msgstr_index => nil).first[:msgstr]
134
+ end
135
+ end
136
+ bm.report('With string inside:') do
137
+ $search.each do |arr|
138
+ _lang, _orig = *arr
139
+ lang = DB[:languages2].filter(:name => _lang).first[:id]
140
+ trans = DB[:translations2].filter(:language_id => lang,
141
+ :msgid => _orig,
142
+ :msgstr_index => nil).first[:msgstr]
143
+ end
144
+ end
145
+ bm.report('With separate strings:') do
146
+ $search.each do |arr|
147
+ _lang, _orig = *arr
148
+ lang = DB[:languages3].filter(:name => _lang).first[:id]
149
+ trans = DB[:translations3].filter(:language_id => lang,
150
+ :original_id => _orig.hash,
151
+ :msgstr_index => nil).first[:msgstr]
152
+ end
153
+ end
154
+ end
155
+
156
+ puts ''
157
+ puts 'Import'
158
+ Benchmark.bm(22) do |bm|
159
+ bm.report('With string inside:') do
160
+ DB[:languages2].each do |lang|
161
+ DB[:translations2].each do |trans|
162
+ [lang[:name], trans[:msgid], trans[:msgstr], trans[:msgstr_index]]
163
+ end
164
+ end
165
+ end
166
+ bm.report('With separate strings:') do
167
+ DB[:languages3].each do |lang|
168
+ DB[:translations3].each do |trans|
169
+ orig = DB[:original3].filter(:id => trans[:original_id]).first[:msgid]
170
+ [lang[:name], orig, trans[:msgstr], trans[:msgstr_index]]
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,9 @@
1
+ Merb Flat
2
+ ==============
3
+
4
+ An example of a small Merb application. Uses a single views directory and one
5
+ controller file.
6
+
7
+ Start with
8
+
9
+ merb
@@ -0,0 +1,5 @@
1
+ class ActiveRecordExample < Merb::Controller
2
+ def index
3
+ _('Hi! Hello world!')
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ :development: &defaults
2
+ :adapter: sqlite3
3
+ :database: database.db
4
+
5
+ :test:
6
+ <<: *defaults
7
+
8
+ :production:
9
+ <<: *defaults
@@ -0,0 +1,5 @@
1
+ Merb::Config[:framework] = {
2
+ :application => 'application.rb',
3
+ :view => 'views',
4
+ :config => 'config'
5
+ }
@@ -0,0 +1,24 @@
1
+ # Load the merb_global from current tree
2
+ Gem.clear_paths
3
+ Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
4
+ $LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
5
+
6
+ Merb::Router.prepare do |r|
7
+ r.match('/').to(:controller => 'active_record_example', :action =>'index')
8
+ end
9
+
10
+ use_orm :activerecord
11
+ dependency 'merb_global'
12
+
13
+ Merb::Config.use { |c|
14
+ c[:environment] = 'production',
15
+ c[:framework] = {},
16
+ c[:log_level] = 'debug',
17
+ c[:use_mutex] = false,
18
+ c[:session_store] = 'cookie',
19
+ c[:session_id_key] = '_session_id',
20
+ c[:session_secret_key] = '779c710d6a7b90faf17cba97c156fc133a9884c9',
21
+ c[:exception_details] = true,
22
+ c[:reload_classes] = true,
23
+ c[:reload_time] = 0.5
24
+ }
@@ -0,0 +1,3 @@
1
+ :merb_global:
2
+ :message_provider: active_record
3
+ :locales: ['en', 'pl']
@@ -0,0 +1,9 @@
1
+ Merb Flat
2
+ ==============
3
+
4
+ An example of a small Merb application. Uses a single views directory and one
5
+ controller file.
6
+
7
+ Start with
8
+
9
+ merb
@@ -0,0 +1,5 @@
1
+ class DataMapperExample < Merb::Controller
2
+ def index
3
+ _('Hi! Hello world!')
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ :development: &defaults
2
+ :adapter: sqlite3
3
+ :database: database.db
4
+
5
+ :test:
6
+ <<: *defaults
7
+
8
+ :production:
9
+ <<: *defaults
@@ -0,0 +1,5 @@
1
+ Merb::Config[:framework] = {
2
+ :application => 'application.rb',
3
+ :view => 'views',
4
+ :config => 'config'
5
+ }