merb_global 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. data/HISTORY +6 -1
  2. data/Rakefile +28 -30
  3. data/TODO +2 -1
  4. data/examples/active_record_example/README.txt +9 -0
  5. data/examples/active_record_example/application.rb +5 -0
  6. data/examples/active_record_example/config/database.yml +9 -0
  7. data/examples/active_record_example/config/framework.rb +5 -0
  8. data/examples/active_record_example/config/init.rb +24 -0
  9. data/examples/active_record_example/config/plugins.yml +3 -0
  10. data/examples/active_record_example/database.db +0 -0
  11. data/examples/active_record_example/log/merb.4000.pid +1 -0
  12. data/examples/active_record_example/log/merb.main.log +9 -0
  13. data/examples/data_mapper_example/README.txt +9 -0
  14. data/examples/data_mapper_example/application.rb +5 -0
  15. data/examples/data_mapper_example/config/database.yml +9 -0
  16. data/examples/data_mapper_example/config/framework.rb +5 -0
  17. data/examples/data_mapper_example/config/init.rb +24 -0
  18. data/examples/data_mapper_example/config/plugins.yml +3 -0
  19. data/examples/data_mapper_example/database.db +0 -0
  20. data/examples/data_mapper_example/log/dm.log +3 -0
  21. data/examples/data_mapper_example/log/merb.4000.pid +1 -0
  22. data/examples/database.db +0 -0
  23. data/examples/database.sql +28 -0
  24. data/examples/gettext_example/README.txt +9 -0
  25. data/examples/gettext_example/application.rb +8 -0
  26. data/examples/gettext_example/config/framework.rb +5 -0
  27. data/examples/gettext_example/config/init.rb +24 -0
  28. data/examples/gettext_example/config/plugins.yml +4 -0
  29. data/examples/gettext_example/locale/merbapp.pot +21 -0
  30. data/examples/gettext_example/locale/pl.po +23 -0
  31. data/examples/gettext_example/locale/pl/LC_MESSAGES/merbapp.mo +0 -0
  32. data/examples/mock_example/README.txt +9 -0
  33. data/examples/mock_example/application.rb +5 -0
  34. data/examples/mock_example/config/framework.rb +5 -0
  35. data/examples/mock_example/config/init.rb +23 -0
  36. data/examples/mock_example/config/plugins.yml +3 -0
  37. data/examples/sequel_example/README.txt +9 -0
  38. data/examples/sequel_example/application.rb +5 -0
  39. data/examples/sequel_example/config/database.yml +9 -0
  40. data/examples/sequel_example/config/framework.rb +5 -0
  41. data/examples/sequel_example/config/init.rb +24 -0
  42. data/examples/sequel_example/config/plugins.yml +3 -0
  43. data/examples/sequel_example/database.db +0 -0
  44. data/examples/yaml_example/README.txt +9 -0
  45. data/examples/yaml_example/application.rb +5 -0
  46. data/examples/yaml_example/config/framework.rb +5 -0
  47. data/examples/yaml_example/config/init.rb +24 -0
  48. data/examples/yaml_example/config/plugins.yml +4 -0
  49. data/examples/yaml_example/locale/en.yaml +2 -0
  50. data/examples/yaml_example/locale/pl.yaml +2 -0
  51. data/lib/merb_global/controller.rb +3 -29
  52. data/lib/merb_global/date_providers.rb +1 -1
  53. data/lib/merb_global/locale.rb +50 -7
  54. data/lib/merb_global/message_providers.rb +3 -29
  55. data/lib/merb_global/message_providers/active_record.rb +3 -21
  56. data/lib/merb_global/message_providers/data_mapper.rb +0 -9
  57. data/lib/merb_global/message_providers/gettext.rb +0 -15
  58. data/lib/merb_global/message_providers/mock.rb +0 -8
  59. data/lib/merb_global/message_providers/sequel.rb +0 -13
  60. data/lib/merb_global/message_providers/yaml.rb +0 -17
  61. data/lib/merb_global/numeric_providers/java.rb +15 -0
  62. data/lib/merb_global/providers.rb +1 -1
  63. metadata +70 -4
data/HISTORY CHANGED
@@ -1,7 +1,12 @@
1
+ === 0.0.7
2
+ * More consistent configuration of supported languages
3
+ * JRuby Numeric provider
4
+ * Some small fixes
5
+
1
6
  === 0.0.6
2
7
  * Introduction of Locale object
3
8
  * Change of MessageProviders interface
4
- * Per-enviroment configuration
9
+ * Per-environment configuration
5
10
 
6
11
  === 0.0.5
7
12
  * Handles lang_REGION as lang
data/Rakefile CHANGED
@@ -1,50 +1,47 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
3
  require 'rake/rdoctask'
4
- require 'spec/rake/spectask'
5
- require 'fileutils'
6
4
 
7
5
  PLUGIN = "merb_global"
8
6
  NAME = "merb_global"
9
- GEM_VERSION = "0.0.6"
7
+ GEM_VERSION = "0.0.7"
10
8
  AUTHORS = ["Alex Coles", "Maciej Piechotka"]
11
- EMAIL = "alex@alexcolesportfolio.com"
9
+ EMAIL = "merb_global@googlegroups.com"
12
10
  HOMEPAGE = "http://trac.ikonoklastik.com/merb_global/"
13
11
  SUMMARY = "Localization (L10n) and Internationalization (i18n) support for the Merb MVC Framework"
14
12
 
15
- spec = Gem::Specification.new do |s|
16
- s.name = NAME
17
- s.version = GEM_VERSION
18
- s.platform = Gem::Platform::RUBY
19
- s.summary = SUMMARY
20
- s.description = s.summary
21
- s.authors = AUTHORS
22
- s.email = EMAIL
23
- s.homepage = HOMEPAGE
24
- s.rubyforge_project = 'merb-global'
25
- s.add_dependency('merb-core', '>= 0.9.1')
26
- s.add_dependency('treetop', '>= 1.2.3') # Tested on 1.2.3
27
- s.require_path = 'lib'
28
- s.autorequire = PLUGIN
29
- s.files = %w(LICENSE README Rakefile TODO HISTORY) +
30
- Dir.glob("{lib,specs,*_generators}/**/*")
31
-
32
- # rdoc
33
- s.has_rdoc = true
34
- s.extra_rdoc_files = %w(README LICENSE TODO HISTORY)
13
+ def spec
14
+ require 'spec/rake/spectask'
15
+ Gem::Specification.new do |s|
16
+ s.name = NAME
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.summary = SUMMARY
20
+ s.description = s.summary
21
+ s.authors = AUTHORS
22
+ s.email = EMAIL
23
+ s.homepage = HOMEPAGE
24
+ s.rubyforge_project = 'merb-global'
25
+ s.add_dependency('merb-core', '>= 0.9.1')
26
+ s.add_dependency('treetop', '>= 1.2.3') # Tested on 1.2.3
27
+ s.require_path = 'lib'
28
+ s.autorequire = PLUGIN
29
+ s.files = %w(LICENSE README Rakefile TODO HISTORY) +
30
+ Dir.glob("{lib,specs,*_generators,examples}/**/*")
31
+
32
+ # rdoc
33
+ s.has_rdoc = true
34
+ s.extra_rdoc_files = %w(README LICENSE TODO HISTORY)
35
+ end
35
36
  end
36
37
 
37
- windows = (PLATFORM =~ /win32|cygwin/) rescue nil
38
-
39
- SUDO = windows ? "" : "sudo"
40
-
41
38
  Rake::GemPackageTask.new(spec) do |pkg|
42
39
  pkg.gem_spec = spec
43
40
  end
44
41
 
45
42
  desc "Install merb_global"
46
43
  task :install => [:package] do
47
- sh %{#{SUDO} gem install pkg/#{NAME}-#{GEM_VERSION}}
44
+ sh %{gem install pkg/#{NAME}-#{GEM_VERSION}}
48
45
  end
49
46
 
50
47
  Rake::RDocTask.new do |rd|
@@ -54,6 +51,7 @@ end
54
51
 
55
52
  desc "Creates database for examples"
56
53
  task :populate_db do
54
+ require 'fileutils'
57
55
  pwd = File.dirname __FILE__
58
56
  db = "#{pwd}/examples/database.db"
59
57
  sh %{sqlite3 #{db} < #{pwd}/examples/database.sql}
@@ -61,7 +59,7 @@ task :populate_db do
61
59
  FileUtils.cp db, "#{pwd}/examples/data_mapper_example/database.db"
62
60
  FileUtils.cp db, "#{pwd}/examples/sequel_example/database.db"
63
61
  end
64
- task :gem => :populate_db
62
+ task "pkg/#{NAME}-#{GEM_VERSION}" => [:populate_db]
65
63
 
66
64
  desc "Run all specs"
67
65
  Spec::Rake::SpecTask.new('specs') do |st|
data/TODO CHANGED
@@ -1,3 +1,4 @@
1
1
  = TODO
2
2
 
3
- This list will be added shortly. The list of things to do is long.
3
+ Please see http://trac.ikonoklastik.com/merb_global/ for the MerbGlobal issue
4
+ tracker.
@@ -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
+ Sun, 23 Nov 2008 22:30:17 GMT ~ info ~ Logfile created
2
+ ~
3
+ ~ FATAL: The gem merb_global (>= 0, runtime), [] was not found
4
+ ~
5
+ ~ Connecting to database...
6
+ ~ Parent pid: 17770
7
+ ~
8
+ ~ FATAL: The gem merb_global, [] was not found
9
+ ~
@@ -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
+ }
@@ -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 => 'data_mapper_example', :action =>'index')
8
+ end
9
+
10
+ use_orm :datamapper
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] = '5b587281e1b277c3e90f5de2e42e5125dc649837',
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: data_mapper
3
+ :locales: ['en', 'pl']
@@ -0,0 +1,3 @@
1
+ Fri, 30 May 2008 22:23:32 GMT ~ info ~ Logfile created
2
+ Fri, 30 May 2008 22:24:01 GMT ~ info ~ Logfile created
3
+ Fri, 30 May 2008 22:45:22 GMT ~ info ~ Logfile created
Binary file
@@ -0,0 +1,28 @@
1
+ DROP TABLE IF EXISTS merb_global_languages;
2
+ CREATE TABLE merb_global_languages (
3
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4
+ name VARCHAR(50),
5
+ nplural INTEGER,
6
+ plural TEXT
7
+ );
8
+
9
+ DROP TABLE IF EXISTS merb_global_translations;
10
+ CREATE TABLE merb_global_translations (
11
+ language_id INTEGER NOT NULL,
12
+ msgid TEXT NOT NULL,
13
+ msgid_plural TEXT,
14
+ msgstr TEXT NOT NULL,
15
+ msgstr_index INTEGER,
16
+ PRIMARY KEY(language_id, msgid, msgstr_index));
17
+
18
+
19
+ CREATE UNIQUE INDEX unique_index_merb_global_languages_name
20
+ ON merb_global_languages (name);
21
+
22
+ INSERT INTO merb_global_languages (name, nplural, plural)
23
+ VALUES ("pl", 3, "(n==1?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2)");
24
+
25
+ INSERT INTO merb_global_translations (language_id, msgid, msgstr)
26
+ SELECT id, "Hi! Hello world!", "Cześć. Witaj świecie!"
27
+ FROM merb_global_languages
28
+ WHERE name = "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,8 @@
1
+ class GettextExample < Merb::Controller
2
+ language do
3
+ 'pl' # It'll be always in Polish
4
+ end
5
+ def index
6
+ _('Hi! Hello world!')
7
+ end
8
+ end
@@ -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 => 'gettext_example', :action =>'index')
8
+ r.default_routes
9
+ end
10
+
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] = '489739417a2edcb2ae6ec7390fc467992e313ed8',
21
+ c[:exception_details] = true,
22
+ c[:reload_classes] = true,
23
+ c[:reload_time] = 0.5
24
+ }
@@ -0,0 +1,4 @@
1
+ :merb_global:
2
+ :message_provider: gettext
3
+ :flat: true
4
+ :locales: ['en', 'pl']
@@ -0,0 +1,21 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2008-05-22 13:59+0200\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=CHARSET\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+
19
+ #: gettext_example.rb:21
20
+ msgid "Hi! Hello world!"
21
+ msgstr ""
@@ -0,0 +1,23 @@
1
+ # Polish translations for PACKAGE package
2
+ # Polskie tłumaczenia dla pakietu PACKAGE.
3
+ # Copyright (C) 2008 THE PACKAGE'S COPYRIGHT HOLDER
4
+ # This file is distributed under the same license as the PACKAGE package.
5
+ # <uzytkownik2@gmail.com>, 2008.
6
+ #
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2008-05-22 13:59+0200\n"
12
+ "PO-Revision-Date: 2008-05-22 21:42+0100\n"
13
+ "Last-Translator: Maciej Piechotka <uzytkownik2@gmail.com>\n"
14
+ "Language-Team: Polish\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
19
+
20
+ #: gettext_example.rb:21
21
+ msgid "Hi! Hello world!"
22
+ msgstr "Cześć. Witaj świecie!"
23
+
@@ -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 MockExample < Merb::Controller
2
+ def index
3
+ _('Hi! Hello world!')
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Merb::Config[:framework] = {
2
+ :application => 'application.rb',
3
+ :view => 'views',
4
+ :config => 'config'
5
+ }
@@ -0,0 +1,23 @@
1
+ Gem.clear_paths
2
+ Gem.path.unshift((Pathname(__FILE__).dirname + '../../../pkg').expand_path)
3
+ $LOAD_PATH.unshift((Pathname(__FILE__).dirname + '../../../lib').expand_path)
4
+
5
+ Merb::Router.prepare do |r|
6
+ r.match('/').to(:controller => 'mock_example', :action =>'index')
7
+ r.default_routes
8
+ end
9
+
10
+ dependency 'merb_global'
11
+
12
+ Merb::Config.use { |c|
13
+ c[:environment] = 'production',
14
+ c[:framework] = {},
15
+ c[:log_level] = 'debug',
16
+ c[:use_mutex] = false,
17
+ c[:session_store] = 'cookie',
18
+ c[:session_id_key] = '_session_id',
19
+ c[:session_secret_key] = 'd729662a1de4755ac16f34d1bb012fe5c9e6a965',
20
+ c[:exception_details] = true,
21
+ c[:reload_classes] = true,
22
+ c[:reload_time] = 0.5
23
+ }
@@ -0,0 +1,3 @@
1
+ :merb_global:
2
+ :message_provider: mock
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 GettextExample < Merb::Controller
2
+ def index
3
+ _('Hi! Hello world!')
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ :development: &defaults
2
+ :adapter: sqlite
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 => 'gettext_example', :action =>'index')
8
+ end
9
+
10
+ use_orm :sequel
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] = 'dd578852e40789695203305439f3ee2cf77b0cfc',
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: sequel
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 YamlExample < Merb::Controller
2
+ def index
3
+ _('Hi! Hello world!')
4
+ end
5
+ end
@@ -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 => 'yaml_example', :action =>'index')
8
+ r.default_routes
9
+ end
10
+
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] = 'ceb534866f8bb368f8e935b31604e45b818c6dd4',
21
+ c[:exception_details] = true,
22
+ c[:reload_classes] = true,
23
+ c[:reload_time] = 0.5
24
+ }
@@ -0,0 +1,4 @@
1
+ :merb_global:
2
+ :message_provider: yaml
3
+ :flat: true
4
+ :locales: [en, pl]
@@ -0,0 +1,2 @@
1
+ :plural: "n==1 ? 0 : 1"
2
+ "Hi! Hello world!": "Hi! Hello world!"
@@ -0,0 +1,2 @@
1
+ :plural: "(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)"
2
+ "Hi! Hello world!": "Cześć. Witaj świecie!"
@@ -13,34 +13,8 @@ module Merb
13
13
  Merb::Global::Locale.new(params[:locale]) ||
14
14
  (self._mg_locale &&
15
15
  Merb::Global::Locale.new(self.instance_eval(&self._mg_locale))) ||
16
- begin
17
- unless accept_language.nil?
18
- accept_language = Merb::Global::Locale.parse(accept_language)
19
- accept_language.collect! do |lang|
20
- if lang.any?
21
- lang
22
- elsif Merb::Global::MessageProviders.provider.support? lang
23
- lang
24
- else
25
- lang = lang.base_locale
26
- if not lang.nil? and Merb::Global::MessageProviders.provider.support? lang
27
- lang
28
- else
29
- nil
30
- end
31
- end
32
- end
33
- accept_language.reject! {|lang| lang.nil?}
34
- unless accept_language.empty?
35
- unless accept_language.last.any?
36
- accept_language.last
37
- else
38
- accept_language.pop
39
- Merb::Global::MessageProviders.provider.choose accept_language
40
- end
41
- end
42
- end
43
- end || Merb::Global::Locale.new('en')
16
+ Merb::Global::Locale.from_accept_language(accept_language) ||
17
+ Merb::Global::Locale.new('en')
44
18
  end
45
19
 
46
20
  # Sets the language of block.
@@ -48,7 +22,7 @@ module Merb
48
22
  # The block should return language or nil if other method should be used
49
23
  # to determine the language
50
24
  #
51
- # Please note that this method is deprecated and the prefereed method is
25
+ # Please note that this method is deprecated and the preferred method is
52
26
  # locale.
53
27
  def self.language(&block)
54
28
  self._mg_locale = block
@@ -32,7 +32,7 @@ module Merb
32
32
  # Perform the registration
33
33
  #
34
34
  # ==== Parameters
35
- # name<~to_sym>:: Name under which it is registred
35
+ # name<~to_sym>:: Name under which it is registered
36
36
  def self.DateProvider(provider_name)
37
37
  Module.new do
38
38
  @@rb_date_provider_name = provider_name
@@ -10,14 +10,14 @@ module Merb
10
10
  module Global
11
11
  class Locale
12
12
  attr_reader :language, :country
13
-
13
+
14
14
  def initialize(name)
15
- # TODO: Understend RFC 1766 fully
15
+ # TODO: Understand RFC 1766 fully
16
16
  @language, @country = name.split('-')
17
17
  end
18
18
 
19
19
  def any?
20
- language == '*' && country.nil?\
20
+ language == '*' && country.nil?
21
21
  end
22
22
 
23
23
  def base_locale
@@ -35,6 +35,22 @@ module Merb
35
35
  "#{@language.downcase}_#{@country.upcase}"
36
36
  end
37
37
  end
38
+
39
+ if defined? RUBY_ENGINE and RUBY_ENGINE == "jruby"
40
+ def java_locale
41
+ require 'java'
42
+ @java_locale ||=
43
+ if @country.nil?
44
+ java.util.Locale.new(@language.downcase)
45
+ else
46
+ java.util.Locale.new(@language.downcase, @country.upcase)
47
+ end
48
+ end
49
+ else
50
+ def java_locale
51
+ nil
52
+ end
53
+ end
38
54
 
39
55
  def self.parse(header)
40
56
  header = header.split(',')
@@ -48,11 +64,26 @@ module Merb
48
64
  [lang[0], lang[1].to_f]
49
65
  end
50
66
  end
51
- header.sort! {|lang_a, lang_b| lang_a[1] <=> lang_b[1]}
52
- header.collect! {|lang| lang[0]}
53
- return header.collect! {|lang| Locale.new(lang)}
67
+ header.sort! {|lang_a, lang_b| lang_b[1] <=> lang_a[1]} # sorting by decreasing quality
68
+ header.collect! {|lang| Locale.new(lang[0])}
54
69
  end
55
-
70
+
71
+ def self.from_accept_language(accept_language)
72
+ unless accept_language.nil?
73
+ accept_language = Merb::Global::Locale.parse(accept_language)
74
+ accept_language.each_with_index do |lang, i|
75
+ if lang.any?
76
+ # In this case we need to choose a locale that is not in accept_language[i+1..-1]
77
+ return Merb::Global::Locale.choose(accept_language[i+1..-1])
78
+ elsif Merb::Global::Locale.support? lang
79
+ return lang
80
+ end
81
+ lang = lang.base_locale
82
+ return lang if lang && Merb::Global::Locale.support?(lang)
83
+ end
84
+ end
85
+ end
86
+
56
87
  def self.current
57
88
  Thread.current.mg_locale
58
89
  end
@@ -91,6 +122,18 @@ module Merb
91
122
  end
92
123
  end
93
124
  end
125
+
126
+ def self.support?(locale)
127
+ supported_locales.include? locale.to_s
128
+ end
129
+
130
+ def self.supported_locales
131
+ Merb::Global::config('locales', ['en'])
132
+ end
133
+
134
+ def self.choose(except)
135
+ new((supported_locales - except.map{|e| e.to_s}).first)
136
+ end
94
137
  end
95
138
  end
96
139
  end
@@ -7,7 +7,7 @@ module Merb
7
7
  # call-seq:
8
8
  # localedir => localdir
9
9
  #
10
- # Returns the directory where locales are stored for file-backended
10
+ # Returns the directory where locales are stored for file-backed
11
11
  # providers (such as gettext or yaml)
12
12
  #
13
13
  # ==== Returns
@@ -32,7 +32,7 @@ module Merb
32
32
  @@provider ||= self[Merb::Global.config(:message_provider, 'gettext')]
33
33
  end
34
34
  # Merb-global is able to store the translations in different types of
35
- # storage. An interface betwean merb-global and those storages are
35
+ # storage. An interface between merb_global and those storages are
36
36
  # providers.
37
37
  #
38
38
  # Please note that it is not required to include this module - despite it
@@ -43,7 +43,7 @@ module Merb
43
43
  # localize(singular, plural, opts) => translated
44
44
  #
45
45
  # Translate string using specific provider.
46
- # It should be overloaded by the implementator.
46
+ # It should be overloaded by the implementor.
47
47
  #
48
48
  # Do not use this method directly - use Merb::Global._ instead
49
49
  #
@@ -61,26 +61,6 @@ module Merb
61
61
  def localize(singular, plural, n, locale)
62
62
  raise NoMethodError.new 'method localize has not been implemented'
63
63
  end
64
- # call-seq:
65
- # support?(lang) => supported
66
- #
67
- # Checks if the language is supported (i.e. if the translation exists).
68
- #
69
- # In normal merb app the language is checked automatically in controller
70
- # so probably you don't have to use this method
71
- #
72
- # ==== Parameters
73
- # lang<String>:: A code of language
74
- #
75
- # ==== Returns
76
- # supported<Boolean>:: Is a program translated to this language
77
- #
78
- # ==== Raises
79
- # NoMethodError:: Raised by default implementation.
80
- # Should not be thrown.
81
- def support?(lang)
82
- raise NoMethodError.new('method support? has not been implemented')
83
- end
84
64
  # This method creates basic files and/or directory structures
85
65
  # (for example it adds migration) needed for provider to work.
86
66
  #
@@ -88,12 +68,6 @@ module Merb
88
68
  def create!
89
69
  raise NoMethodError.new('method create! has not been implemented')
90
70
  end
91
- # This method choos an supported language except those form the list
92
- # given. It may fallback to english if none language can be found
93
- # which agree with those criteria
94
- def choose(except)
95
- raise NoMethodError.new('method choose has not been implemented')
96
- end
97
71
  ##
98
72
  # Transfer data from importer into exporter
99
73
  #
@@ -1,8 +1,8 @@
1
1
  require 'activerecord'
2
- # As far as I understend we need it to have compostie keys
2
+ # As far as I understand, we need it to have composite keys.
3
3
  # However it may be better idea to drop them.
4
- # As far I implement it in this way - then we will see
5
- require 'composite_primary_keys' # As far as I understend we need
4
+ # So far I implement it in this way - then we will see
5
+ require 'composite_primary_keys' # As far as I understand we need
6
6
  require 'merb_global/plural'
7
7
 
8
8
  module Merb
@@ -34,10 +34,6 @@ module Merb
34
34
  return n > 1 ? plural : singular # Fallback if not in database
35
35
  end
36
36
 
37
- def support?(lang)
38
- Language.count(:conditions => {:name => lang.to_s}) != 0
39
- end
40
-
41
37
  def create!
42
38
  migration_exists = Dir[File.join(Merb.root, 'schema',
43
39
  'migrations', '*.rb')].detect do |f|
@@ -50,20 +46,6 @@ module Merb
50
46
  end
51
47
  end
52
48
 
53
- def choose(except)
54
- if except.empty?
55
- Language.find(:first).name
56
- else
57
- except = except.collect {|locale| locale.to_s}
58
- condition = 'name NOT IN (' + '?, ' * (except.length - 1) + '?)'
59
- Language.find(:first, :conditions => [condition, *except]).name
60
- end
61
- # On #rubyonrails the following method was given. However I do not
62
- # trust it. Please change if the validity is confirmed
63
- # Language.find(:first, :conditions => ['name NOT IN ?',
64
- # "(#{except.join(',')})"])
65
- end
66
-
67
49
  def import
68
50
  data = {}
69
51
  Language.transaction do
@@ -30,20 +30,11 @@ module Merb
30
30
  return n != 1 ? plural : singular
31
31
  end
32
32
 
33
- def support?(lang)
34
- not Language.first(:name => lang.to_s).nil?
35
- end
36
-
37
33
  def create!
38
34
  Language.auto_migrate!
39
35
  Translation.auto_migrate!
40
36
  end
41
37
 
42
- def choose(except)
43
- except = except.collect {|locale| except.to_s}
44
- Language.first(:name.not => except).name
45
- end
46
-
47
38
  def import
48
39
  data = {}
49
40
  ::DataMapper::Transaction.new(Language, Translation) do
@@ -26,25 +26,10 @@ module Merb
26
26
  end
27
27
  end
28
28
 
29
- def support?(lang)
30
- lang = lang.to_s
31
- lang == 'en' ||
32
- File.exist?(File.join(Merb::Global::MessageProviders.localedir, lang))
33
- end
34
-
35
29
  def create!
36
30
  File.mkdirs Merb::Global::MessageProviders.localedir
37
31
  end
38
32
 
39
- def choose(except)
40
- except = except.collect {|locale| locale.to_s}
41
- dir = Dir[Merb::Global::MessageProviders.localedir + '/*/']
42
- dir.collect! {|p| File.basename p}
43
- dir << 'en'
44
- dir.reject! {|lang| except.include? lang}
45
- dir.first
46
- end
47
-
48
33
  def import
49
34
  Treetop.load(Pathname(__FILE__).dirname.expand_path.to_s +
50
35
  '/gettext')
@@ -8,17 +8,9 @@ module Merb
8
8
  n > 1 ? plural : singular
9
9
  end
10
10
 
11
- def support?(lang)
12
- true
13
- end
14
-
15
11
  def create!
16
12
  nil # It's mock after all ;)
17
13
  end
18
-
19
- def choose(except)
20
- 'en'
21
- end
22
14
  end
23
15
  end
24
16
  end
@@ -24,10 +24,6 @@ module Merb
24
24
  return n > 1 ? plural : singular # Fallback if not in database
25
25
  end
26
26
 
27
- def support?(lang)
28
- Language.filter(:name => lang.to_s).count != 0
29
- end
30
-
31
27
  def create!
32
28
  migration_exists = Dir[File.join(Merb.root, 'schema',
33
29
  'migrations', "*.rb")].detect do |f|
@@ -40,15 +36,6 @@ module Merb
40
36
  end
41
37
  end
42
38
 
43
- def choose(except)
44
- if except.empty?
45
- Language.first[:name]
46
- else
47
- except = except.collect {|locale| locale.to_s}
48
- Language.filter(~{:name => except}).first[:name]
49
- end
50
- end
51
-
52
39
  def import
53
40
  data = {}
54
41
  DB.transaction do
@@ -48,27 +48,10 @@ module Merb
48
48
  return n > 1 ? plural : singular
49
49
  end
50
50
 
51
- def support?(lang)
52
- unless @lang.include? lang
53
- file = File.join Merb::Global::MessageProviders.localedir,
54
- lang.to_s + '.yaml'
55
- @lang[lang] = YAML.load_file file if File.exist? file
56
- end
57
- not @lang[lang].nil?
58
- end
59
-
60
51
  def create!
61
52
  FileUtils.mkdir_p Merb::Global::MessageProviders.localedir
62
53
  end
63
54
 
64
- def choose(except)
65
- except = except.collect {|locale| locale.to_s}
66
- dir = Dir[Merb::Global::MessageProviders.localedir + '/*.yaml']
67
- dir.collect! {|p| File.basename p, '.yaml'}
68
- dir.reject! {|lang| except.include? lang}
69
- dir.first
70
- end
71
-
72
55
  def import
73
56
  data = {}
74
57
  Dir[Merb::Global::MessageProviders.localedir +
@@ -0,0 +1,15 @@
1
+ require 'java'
2
+
3
+ module Merb
4
+ module Global
5
+ module NumericProviders
6
+ class Java
7
+ include Merb::Global::DateProviders::Base
8
+
9
+ def localize(locale, number)
10
+ java.text.NumberFormat.instance(locale).format(number)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -20,7 +20,7 @@ module Merb
20
20
  @@providers_classes[provider.to_sym].new
21
21
  else
22
22
  require "merb_global/#{self.name.split("::").last.snake_case}/#{provider.to_s}"
23
- @@providers[provider.to_sym] = eval "#{self.name}::#{provider.camel_case}.new"
23
+ @@providers[provider.to_sym] = self.const_get(provider.camel_case).new
24
24
  end
25
25
  end
26
26
  @@providers[provider.to_sym]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merb_global
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Coles
@@ -10,7 +10,7 @@ autorequire: merb_global
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-11-06 00:00:00 +01:00
13
+ date: 2009-02-15 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 1.2.3
35
35
  version:
36
36
  description: Localization (L10n) and Internationalization (i18n) support for the Merb MVC Framework
37
- email: alex@alexcolesportfolio.com
37
+ email: merb_global@googlegroups.com
38
38
  executables: []
39
39
 
40
40
  extensions: []
@@ -72,6 +72,7 @@ files:
72
72
  - lib/merb_global/base.rb
73
73
  - lib/merb_global/numeric_providers
74
74
  - lib/merb_global/numeric_providers/fork.rb
75
+ - lib/merb_global/numeric_providers/java.rb
75
76
  - lib/merb_global/merbrake.rb
76
77
  - lib/merb_global/date_providers.rb
77
78
  - lib/merb_global.rb
@@ -85,6 +86,71 @@ files:
85
86
  - activerecord_generators/translations_migration/translations_migration_generator.rb
86
87
  - activerecord_generators/translations_migration/templates
87
88
  - activerecord_generators/translations_migration/templates/translations_migration.erb
89
+ - examples/mock_example
90
+ - examples/mock_example/config
91
+ - examples/mock_example/config/plugins.yml
92
+ - examples/mock_example/config/framework.rb
93
+ - examples/mock_example/config/init.rb
94
+ - examples/mock_example/README.txt
95
+ - examples/mock_example/application.rb
96
+ - examples/data_mapper_example
97
+ - examples/data_mapper_example/log
98
+ - examples/data_mapper_example/log/dm.log
99
+ - examples/data_mapper_example/log/merb.4000.pid
100
+ - examples/data_mapper_example/database.db
101
+ - examples/data_mapper_example/config
102
+ - examples/data_mapper_example/config/plugins.yml
103
+ - examples/data_mapper_example/config/framework.rb
104
+ - examples/data_mapper_example/config/database.yml
105
+ - examples/data_mapper_example/config/init.rb
106
+ - examples/data_mapper_example/README.txt
107
+ - examples/data_mapper_example/application.rb
108
+ - examples/database.db
109
+ - examples/gettext_example
110
+ - examples/gettext_example/config
111
+ - examples/gettext_example/config/plugins.yml
112
+ - examples/gettext_example/config/framework.rb
113
+ - examples/gettext_example/config/init.rb
114
+ - examples/gettext_example/locale
115
+ - examples/gettext_example/locale/pl
116
+ - examples/gettext_example/locale/pl/LC_MESSAGES
117
+ - examples/gettext_example/locale/pl/LC_MESSAGES/merbapp.mo
118
+ - examples/gettext_example/locale/pl.po
119
+ - examples/gettext_example/locale/merbapp.pot
120
+ - examples/gettext_example/README.txt
121
+ - examples/gettext_example/application.rb
122
+ - examples/active_record_example
123
+ - examples/active_record_example/log
124
+ - examples/active_record_example/log/merb.main.log
125
+ - examples/active_record_example/log/merb.4000.pid
126
+ - examples/active_record_example/database.db
127
+ - examples/active_record_example/config
128
+ - examples/active_record_example/config/plugins.yml
129
+ - examples/active_record_example/config/framework.rb
130
+ - examples/active_record_example/config/database.yml
131
+ - examples/active_record_example/config/init.rb
132
+ - examples/active_record_example/README.txt
133
+ - examples/active_record_example/application.rb
134
+ - examples/database.sql
135
+ - examples/yaml_example
136
+ - examples/yaml_example/config
137
+ - examples/yaml_example/config/plugins.yml
138
+ - examples/yaml_example/config/framework.rb
139
+ - examples/yaml_example/config/init.rb
140
+ - examples/yaml_example/locale
141
+ - examples/yaml_example/locale/en.yaml
142
+ - examples/yaml_example/locale/pl.yaml
143
+ - examples/yaml_example/README.txt
144
+ - examples/yaml_example/application.rb
145
+ - examples/sequel_example
146
+ - examples/sequel_example/database.db
147
+ - examples/sequel_example/config
148
+ - examples/sequel_example/config/plugins.yml
149
+ - examples/sequel_example/config/framework.rb
150
+ - examples/sequel_example/config/database.yml
151
+ - examples/sequel_example/config/init.rb
152
+ - examples/sequel_example/README.txt
153
+ - examples/sequel_example/application.rb
88
154
  has_rdoc: true
89
155
  homepage: http://trac.ikonoklastik.com/merb_global/
90
156
  post_install_message:
@@ -107,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
173
  requirements: []
108
174
 
109
175
  rubyforge_project: merb-global
110
- rubygems_version: 1.2.0
176
+ rubygems_version: 1.3.1
111
177
  signing_key:
112
178
  specification_version: 2
113
179
  summary: Localization (L10n) and Internationalization (i18n) support for the Merb MVC Framework