merb_global 0.0.5.2 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +5 -0
- data/Rakefile +1 -1
- data/lib/merb_global/base.rb +45 -21
- data/lib/merb_global/config.rb +8 -1
- data/lib/merb_global/controller.rb +27 -29
- data/lib/merb_global/date_providers/fork.rb +1 -1
- data/lib/merb_global/locale.rb +96 -0
- data/lib/merb_global/message_providers/active_record.rb +7 -6
- data/lib/merb_global/message_providers/data_mapper.rb +7 -6
- data/lib/merb_global/message_providers/gettext.rb +9 -9
- data/lib/merb_global/message_providers/mock.rb +3 -3
- data/lib/merb_global/message_providers/sequel.rb +8 -6
- data/lib/merb_global/message_providers/yaml.rb +12 -10
- data/lib/merb_global/message_providers.rb +3 -6
- data/lib/merb_global/numeric_providers/fork.rb +1 -1
- metadata +3 -2
data/HISTORY
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
|
7
7
|
PLUGIN = "merb_global"
|
8
8
|
NAME = "merb_global"
|
9
|
-
GEM_VERSION = "0.0.
|
9
|
+
GEM_VERSION = "0.0.6"
|
10
10
|
AUTHORS = ["Alex Coles", "Maciej Piechotka"]
|
11
11
|
EMAIL = "alex@alexcolesportfolio.com"
|
12
12
|
HOMEPAGE = "http://trac.ikonoklastik.com/merb_global/"
|
data/lib/merb_global/base.rb
CHANGED
@@ -1,29 +1,53 @@
|
|
1
1
|
require 'merb_global/config'
|
2
2
|
require 'merb_global/plural'
|
3
|
+
require 'merb_global/locale'
|
3
4
|
require 'merb_global/date_providers'
|
4
5
|
require 'merb_global/message_providers'
|
5
6
|
require 'merb_global/numeric_providers'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
class String
|
9
|
+
def localize(args = {})
|
10
|
+
opts = {:locale => Merb::Global::Locale.current, :n => 1, :plural => nil}
|
11
|
+
opts.merge!(args)
|
12
|
+
Merb::Global::MessageProviders.provider.localize self, opts[:plural],
|
13
|
+
opts[:n], opts[:locale]
|
14
|
+
end
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
class Numeric
|
18
|
+
def localize(args = {})
|
19
|
+
opts = {:locale => Merb::Global::Locale.current}
|
20
|
+
opts.merge!(args)
|
21
|
+
Merb::Global::NumericProviders.provider.localize opts[:locale], self
|
22
|
+
end
|
23
|
+
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
25
|
+
class Date
|
26
|
+
def localize(format, args = {})
|
27
|
+
opts = {:locale => Merb::Global::Locale.current}
|
28
|
+
opts.merge!(args)
|
29
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], self, format
|
30
|
+
end
|
31
|
+
end
|
18
32
|
|
19
|
-
|
20
|
-
|
21
|
-
|
33
|
+
class DateTime
|
34
|
+
def localize(format, args = {})
|
35
|
+
opts = {:locale => Merb::Global::Locale.current}
|
36
|
+
opts.merge!(args)
|
37
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], self, format
|
38
|
+
end
|
39
|
+
end
|
22
40
|
|
23
|
-
|
24
|
-
|
25
|
-
|
41
|
+
class Time
|
42
|
+
def localize(format, args = {})
|
43
|
+
opts = {:locale => Merb::Global::Locale.current}
|
44
|
+
opts.merge!(args)
|
45
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], self, format
|
46
|
+
end
|
47
|
+
end
|
26
48
|
|
49
|
+
module Merb
|
50
|
+
module Global
|
27
51
|
# call-seq:
|
28
52
|
# _(singular, opts) => translated message
|
29
53
|
# _(singlular, plural, opts) => translated message
|
@@ -40,7 +64,7 @@ module Merb
|
|
40
64
|
# number<Numeric>:: A numeber to localize
|
41
65
|
#
|
42
66
|
# ==== Options (opts)
|
43
|
-
# :
|
67
|
+
# :locale<Locale>:: A language to translate on
|
44
68
|
# :n<Fixnum>:: A number of objects (for messages)
|
45
69
|
#
|
46
70
|
# ==== Returns
|
@@ -49,25 +73,25 @@ module Merb
|
|
49
73
|
# ==== Example
|
50
74
|
# <tt>render _('%d file deleted', '%d files deleted', :n => del) % del</tt>
|
51
75
|
def _(*args)
|
52
|
-
opts = {:
|
76
|
+
opts = {:locale => Merb::Global::Locale.current, :n => 1}
|
53
77
|
opts.merge! args.pop if args.last.is_a? Hash
|
54
78
|
if args.first.respond_to? :strftime
|
55
79
|
if args.size == 2
|
56
|
-
|
80
|
+
Merb::Global::DateProviders.provider.localize opts[:locale], args[0], args[1]
|
57
81
|
else
|
58
82
|
raise ArgumentError, "wrong number of arguments (#{args.size} for 2)"
|
59
83
|
end
|
60
84
|
elsif args.first.is_a? Numeric
|
61
85
|
if args.size == 1
|
62
|
-
|
86
|
+
Merb::Global::NumericProviders.provider.localize opts[:locale], args.first
|
63
87
|
else
|
64
88
|
raise ArgumentError, "wrong number of arguments (#{args.size} for 1)"
|
65
89
|
end
|
66
90
|
elsif args.first.is_a? String
|
67
91
|
if args.size == 1
|
68
|
-
|
92
|
+
Merb::Global::MessageProviders.provider.localize args[0], nil, opts[:n], opts[:locale]
|
69
93
|
elsif args.size == 2
|
70
|
-
|
94
|
+
Merb::Global::MessageProviders.provider.localize args[0], args[1], opts[:n], opts[:locale]
|
71
95
|
else
|
72
96
|
raise ArgumentError,
|
73
97
|
"wrong number of arguments (#{args.size} for 1-2)"
|
data/lib/merb_global/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Merb
|
2
2
|
module Global
|
3
|
+
@@config = nil
|
3
4
|
# call-seq:
|
4
5
|
# config(key) => value
|
5
6
|
# config([key1, key2, ...]) => value
|
@@ -19,7 +20,13 @@ module Merb
|
|
19
20
|
# <tt>Merb::Global.config [:gettext, :domain], 'merbapp'</tt>
|
20
21
|
def self.config(keys, default = nil)
|
21
22
|
keys = [keys] unless keys.is_a? Array
|
22
|
-
|
23
|
+
#if @@config.nil?
|
24
|
+
@@config = Merb::Plugins.config[:merb_global].dup
|
25
|
+
unless Merb::Plugins.config[:merb_global][Merb.env].nil?
|
26
|
+
@@config.merge! Merb::Plugins.config[:merb_global][Merb.env]
|
27
|
+
end
|
28
|
+
#end
|
29
|
+
current = @@config
|
23
30
|
while current.respond_to?(:[]) and not keys.empty?
|
24
31
|
current = current[keys.shift]
|
25
32
|
end
|
@@ -3,64 +3,62 @@ require 'merb_global/base'
|
|
3
3
|
module Merb
|
4
4
|
class Controller
|
5
5
|
include Merb::Global
|
6
|
-
|
6
|
+
|
7
|
+
class_inheritable_accessor :_mg_locale
|
7
8
|
|
8
9
|
before do
|
9
10
|
# Set up the language
|
10
11
|
accept_language = self.request.env['HTTP_ACCEPT_LANGUAGE']
|
11
|
-
|
12
|
-
|
12
|
+
Merb::Global::Locale.current =
|
13
|
+
Merb::Global::Locale.new(params[:locale]) ||
|
14
|
+
(self._mg_locale &&
|
15
|
+
Merb::Global::Locale.new(self.instance_eval(&self._mg_locale))) ||
|
13
16
|
begin
|
14
17
|
unless accept_language.nil?
|
15
|
-
accept_language =
|
16
|
-
accept_language.collect! {|lang| lang.delete ' ' "\n" "\r" "\t"}
|
17
|
-
accept_language.reject! {|lang| lang.empty?}
|
18
|
-
accept_language.collect! {|lang| lang.split ';q='}
|
18
|
+
accept_language = Merb::Global::Locale.parse(accept_language)
|
19
19
|
accept_language.collect! do |lang|
|
20
|
-
if lang.
|
21
|
-
|
22
|
-
|
23
|
-
[lang[0], lang[1].to_f]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
accept_language.sort! {|lang_a, lang_b| lang_a[1] <=> lang_b[1]}
|
27
|
-
accept_language.collect! {|lang| lang[0]}
|
28
|
-
accept_language_orig = accept_language.dup
|
29
|
-
accept_language.collect! do |lang|
|
30
|
-
if lang == '*'
|
31
|
-
'*'
|
32
|
-
elsif self.message_provider.support? lang
|
20
|
+
if lang.any?
|
21
|
+
lang
|
22
|
+
elsif Merb::Global::MessageProviders.provider.support? lang
|
33
23
|
lang
|
34
|
-
|
35
|
-
lang = lang.
|
36
|
-
if
|
24
|
+
else
|
25
|
+
lang = lang.base_locale
|
26
|
+
if not lang.nil? and Merb::Global::MessageProviders.provider.support? lang
|
37
27
|
lang
|
38
28
|
else
|
39
29
|
nil
|
40
30
|
end
|
41
|
-
else
|
42
|
-
nil
|
43
31
|
end
|
44
32
|
end
|
45
33
|
accept_language.reject! {|lang| lang.nil?}
|
46
34
|
unless accept_language.empty?
|
47
|
-
unless accept_language.last
|
35
|
+
unless accept_language.last.any?
|
48
36
|
accept_language.last
|
49
37
|
else
|
50
38
|
accept_language.pop
|
51
|
-
|
39
|
+
Merb::Global::MessageProviders.provider.choose accept_language
|
52
40
|
end
|
53
41
|
end
|
54
42
|
end
|
55
|
-
end || 'en'
|
43
|
+
end || Merb::Global::Locale.new('en')
|
56
44
|
end
|
57
45
|
|
58
46
|
# Sets the language of block.
|
59
47
|
#
|
60
48
|
# The block should return language or nil if other method should be used
|
61
49
|
# to determine the language
|
50
|
+
#
|
51
|
+
# Please note that this method is deprecated and the prefereed method is
|
52
|
+
# locale.
|
62
53
|
def self.language(&block)
|
63
|
-
self.
|
54
|
+
self._mg_locale = block
|
55
|
+
end
|
56
|
+
# Sets the language of block.
|
57
|
+
#
|
58
|
+
# The block should return language or nil if other method should be used
|
59
|
+
# to determine the language
|
60
|
+
def self.locale(&block)
|
61
|
+
self._mg_locale = block
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'merb_global/base'
|
2
|
+
require 'thread'
|
3
|
+
require 'weakref'
|
4
|
+
|
5
|
+
class Thread
|
6
|
+
attr_accessor :mg_locale
|
7
|
+
end
|
8
|
+
|
9
|
+
module Merb
|
10
|
+
module Global
|
11
|
+
class Locale
|
12
|
+
attr_reader :language, :country
|
13
|
+
|
14
|
+
def initialize(name)
|
15
|
+
# TODO: Understend RFC 1766 fully
|
16
|
+
@language, @country = name.split('-')
|
17
|
+
end
|
18
|
+
|
19
|
+
def any?
|
20
|
+
language == '*' && country.nil?\
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_locale
|
24
|
+
if not @country.nil?
|
25
|
+
Locale.new(@language)
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
if country.nil?
|
33
|
+
"#{@language.downcase}"
|
34
|
+
else
|
35
|
+
"#{@language.downcase}_#{@country.upcase}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.parse(header)
|
40
|
+
header = header.split(',')
|
41
|
+
header.collect! {|lang| lang.delete ' ' "\n" "\r" "\t"}
|
42
|
+
header.reject! {|lang| lang.empty?}
|
43
|
+
header.collect! {|lang| lang.split ';q='}
|
44
|
+
header.collect! do |lang|
|
45
|
+
if lang.size == 1
|
46
|
+
[lang[0], 1.0]
|
47
|
+
else
|
48
|
+
[lang[0], lang[1].to_f]
|
49
|
+
end
|
50
|
+
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)}
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.current
|
57
|
+
Thread.current.mg_locale
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.current=(new_locale)
|
61
|
+
Thread.current.mg_locale = new_locale
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
alias_method :pure_new, :new
|
66
|
+
private :pure_new
|
67
|
+
end
|
68
|
+
|
69
|
+
@@current = {}
|
70
|
+
@@current_mutex = Mutex.new
|
71
|
+
# Create new locale object and returns it.
|
72
|
+
#
|
73
|
+
# Please note that this method is cached.
|
74
|
+
def self.new(name)
|
75
|
+
return nil if name.nil?
|
76
|
+
return name if name.is_a? Locale
|
77
|
+
@@current_mutex.synchronize do
|
78
|
+
begin
|
79
|
+
n = @@current[name]
|
80
|
+
if n.nil?
|
81
|
+
n = pure_new(name)
|
82
|
+
@@current[name] = WeakRef.new(n)
|
83
|
+
else
|
84
|
+
n = n.__getobj__
|
85
|
+
end
|
86
|
+
n
|
87
|
+
rescue WeakRef::RefError
|
88
|
+
n = pure_new(name)
|
89
|
+
@@current[name] = WeakRef.new(n)
|
90
|
+
n
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -13,13 +13,13 @@ module Merb
|
|
13
13
|
include Merb::Global::MessageProviders::Base::Importer
|
14
14
|
include Merb::Global::MessageProviders::Base::Exporter
|
15
15
|
|
16
|
-
def localize(singular, plural,
|
16
|
+
def localize(singular, plural, n, locale)
|
17
17
|
language = Language.find :first,
|
18
|
-
:conditions => {:name =>
|
18
|
+
:conditions => {:name => locale.to_s}
|
19
19
|
unless language.nil?
|
20
20
|
unless plural.nil?
|
21
|
-
|
22
|
-
translation = Translation.find [language.id, singular,
|
21
|
+
pn = Plural.which_form n, language.plural
|
22
|
+
translation = Translation.find [language.id, singular, pn]
|
23
23
|
else
|
24
24
|
# Bug of composite_primary_keys?
|
25
25
|
conditions = {
|
@@ -31,11 +31,11 @@ module Merb
|
|
31
31
|
end
|
32
32
|
return translation.msgstr
|
33
33
|
end rescue nil
|
34
|
-
return
|
34
|
+
return n > 1 ? plural : singular # Fallback if not in database
|
35
35
|
end
|
36
36
|
|
37
37
|
def support?(lang)
|
38
|
-
Language.count(:conditions => {:name => lang}) != 0
|
38
|
+
Language.count(:conditions => {:name => lang.to_s}) != 0
|
39
39
|
end
|
40
40
|
|
41
41
|
def create!
|
@@ -54,6 +54,7 @@ module Merb
|
|
54
54
|
if except.empty?
|
55
55
|
Language.find(:first).name
|
56
56
|
else
|
57
|
+
except = except.collect {|locale| locale.to_s}
|
57
58
|
condition = 'name NOT IN (' + '?, ' * (except.length - 1) + '?)'
|
58
59
|
Language.find(:first, :conditions => [condition, *except]).name
|
59
60
|
end
|
@@ -10,15 +10,15 @@ module Merb
|
|
10
10
|
include Merb::Global::MessageProviders::Base::Importer
|
11
11
|
include Merb::Global::MessageProviders::Base::Exporter
|
12
12
|
|
13
|
-
def localize(singular, plural,
|
13
|
+
def localize(singular, plural, n, locale)
|
14
14
|
# I hope it's from MemCache
|
15
|
-
language = Language.first :name =>
|
15
|
+
language = Language.first :name => locale.to_s
|
16
16
|
unless language.nil?
|
17
17
|
unless plural.nil?
|
18
|
-
|
18
|
+
pn = Plural.which_form n, language.plural
|
19
19
|
translation = Translation.first :language_id => language.id,
|
20
20
|
:msgid => singular,
|
21
|
-
:msgstr_index =>
|
21
|
+
:msgstr_index => pn
|
22
22
|
else
|
23
23
|
translation = Translation.first :language_id => language.id,
|
24
24
|
:msgid => singular,
|
@@ -27,11 +27,11 @@ module Merb
|
|
27
27
|
return translation.msgstr unless translation.nil?
|
28
28
|
end
|
29
29
|
# Fallback if not in database
|
30
|
-
return
|
30
|
+
return n != 1 ? plural : singular
|
31
31
|
end
|
32
32
|
|
33
33
|
def support?(lang)
|
34
|
-
not Language.first(:name => lang).nil?
|
34
|
+
not Language.first(:name => lang.to_s).nil?
|
35
35
|
end
|
36
36
|
|
37
37
|
def create!
|
@@ -40,6 +40,7 @@ module Merb
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def choose(except)
|
43
|
+
except = except.collect {|locale| except.to_s}
|
43
44
|
Language.first(:name.not => except).name
|
44
45
|
end
|
45
46
|
|
@@ -2,11 +2,9 @@ require 'gettext'
|
|
2
2
|
require 'treetop'
|
3
3
|
require 'pathname'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def gettext_context
|
9
|
-
@gettext_context ||= Merb::Global::MessageProviders::Gettext::GettextContext.new
|
5
|
+
class Merb::Global::Locale #:nodoc:
|
6
|
+
def _mg_gettext
|
7
|
+
@mg_gettext ||= Merb::Global::MessageProviders::Gettext::GettextContext.new
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -18,17 +16,18 @@ module Merb
|
|
18
16
|
include Merb::Global::MessageProviders::Base::Importer
|
19
17
|
include Merb::Global::MessageProviders::Base::Exporter
|
20
18
|
|
21
|
-
def localize(singular, plural,
|
22
|
-
context =
|
23
|
-
context.set_locale
|
19
|
+
def localize(singular, plural, n, locale)
|
20
|
+
context = locale._mg_gettext
|
21
|
+
context.set_locale locale.to_s, true
|
24
22
|
unless plural.nil?
|
25
|
-
context.ngettext singular, plural,
|
23
|
+
context.ngettext singular, plural, n
|
26
24
|
else
|
27
25
|
context.gettext singular
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
29
|
def support?(lang)
|
30
|
+
lang = lang.to_s
|
32
31
|
lang == 'en' ||
|
33
32
|
File.exist?(File.join(Merb::Global::MessageProviders.localedir, lang))
|
34
33
|
end
|
@@ -38,6 +37,7 @@ module Merb
|
|
38
37
|
end
|
39
38
|
|
40
39
|
def choose(except)
|
40
|
+
except = except.collect {|locale| locale.to_s}
|
41
41
|
dir = Dir[Merb::Global::MessageProviders.localedir + '/*/']
|
42
42
|
dir.collect! {|p| File.basename p}
|
43
43
|
dir << 'en'
|
@@ -4,8 +4,8 @@ module Merb
|
|
4
4
|
class Mock #:nodoc:
|
5
5
|
include Merb::Global::MessageProviders::Base
|
6
6
|
|
7
|
-
def localize(singular, plural,
|
8
|
-
|
7
|
+
def localize(singular, plural, n, locale)
|
8
|
+
n > 1 ? plural : singular
|
9
9
|
end
|
10
10
|
|
11
11
|
def support?(lang)
|
@@ -16,7 +16,7 @@ module Merb
|
|
16
16
|
nil # It's mock after all ;)
|
17
17
|
end
|
18
18
|
|
19
|
-
def choose
|
19
|
+
def choose(except)
|
20
20
|
'en'
|
21
21
|
end
|
22
22
|
end
|
@@ -9,22 +9,23 @@ module Merb
|
|
9
9
|
include Merb::Global::MessageProviders::Base::Importer
|
10
10
|
include Merb::Global::MessageProviders::Base::Exporter
|
11
11
|
|
12
|
-
def localize(singular, plural,
|
13
|
-
|
12
|
+
def localize(singular, plural, n, locale)
|
13
|
+
# I hope it's from MemCache
|
14
|
+
language = Language[:name => locale.to_s]
|
14
15
|
unless language.nil?
|
15
16
|
unless plural.nil?
|
16
|
-
|
17
|
-
translation = Translation[language.pk, singular,
|
17
|
+
pn = Plural.which_form n, language[:plural]
|
18
|
+
translation = Translation[language.pk, singular, pn]
|
18
19
|
else
|
19
20
|
translation = Translation[language.pk, singular, nil]
|
20
21
|
end
|
21
22
|
return translation[:msgstr] unless translation.nil?
|
22
23
|
end
|
23
|
-
return
|
24
|
+
return n > 1 ? plural : singular # Fallback if not in database
|
24
25
|
end
|
25
26
|
|
26
27
|
def support?(lang)
|
27
|
-
Language.filter(:name => lang).count != 0
|
28
|
+
Language.filter(:name => lang.to_s).count != 0
|
28
29
|
end
|
29
30
|
|
30
31
|
def create!
|
@@ -43,6 +44,7 @@ module Merb
|
|
43
44
|
if except.empty?
|
44
45
|
Language.first[:name]
|
45
46
|
else
|
47
|
+
except = except.collect {|locale| locale.to_s}
|
46
48
|
Language.filter(~{:name => except}).first[:name]
|
47
49
|
end
|
48
50
|
end
|
@@ -16,41 +16,42 @@ module Merb
|
|
16
16
|
@lang = Hash.new
|
17
17
|
end
|
18
18
|
|
19
|
-
def localize(singular, plural,
|
19
|
+
def localize(singular, plural, n, locale)
|
20
20
|
unless Merb.environment == "development"
|
21
21
|
lang = @lang
|
22
22
|
else
|
23
23
|
lang = {}
|
24
24
|
end
|
25
25
|
|
26
|
-
unless lang.include?
|
26
|
+
unless lang.include? locale
|
27
27
|
file = File.join Merb::Global::MessageProviders.localedir,
|
28
|
-
|
28
|
+
locale.to_s + '.yaml'
|
29
29
|
if File.exist? file
|
30
|
-
lang[
|
30
|
+
lang[locale] = YAML.load_file file
|
31
31
|
else
|
32
|
-
|
32
|
+
# TODO: Check if it not opens security risk
|
33
|
+
lang[locale] = nil
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
36
|
-
unless lang[
|
37
|
-
lang = lang[
|
37
|
+
unless lang[locale].nil?
|
38
|
+
lang = lang[locale]
|
38
39
|
unless lang[singular].nil?
|
39
40
|
unless plural.nil?
|
40
|
-
n = Merb::Global::Plural.which_form
|
41
|
+
n = Merb::Global::Plural.which_form n, lang[:plural]
|
41
42
|
return lang[singular][n] unless lang[singular][n].nil?
|
42
43
|
else
|
43
44
|
return lang[singular] unless lang[singular].nil?
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
|
-
return
|
48
|
+
return n > 1 ? plural : singular
|
48
49
|
end
|
49
50
|
|
50
51
|
def support?(lang)
|
51
52
|
unless @lang.include? lang
|
52
53
|
file = File.join Merb::Global::MessageProviders.localedir,
|
53
|
-
lang + '.yaml'
|
54
|
+
lang.to_s + '.yaml'
|
54
55
|
@lang[lang] = YAML.load_file file if File.exist? file
|
55
56
|
end
|
56
57
|
not @lang[lang].nil?
|
@@ -61,6 +62,7 @@ module Merb
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def choose(except)
|
65
|
+
except = except.collect {|locale| locale.to_s}
|
64
66
|
dir = Dir[Merb::Global::MessageProviders.localedir + '/*.yaml']
|
65
67
|
dir.collect! {|p| File.basename p, '.yaml'}
|
66
68
|
dir.reject! {|lang| except.include? lang}
|
@@ -50,18 +50,15 @@ module Merb
|
|
50
50
|
# ==== Parameters
|
51
51
|
# singular<String>:: A string to translate
|
52
52
|
# plural<String>:: A plural form of string (nil if only singular)
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# ==== Options (opts)
|
56
|
-
# :lang<String>:: A language to translate on
|
57
|
-
# :n<Fixnum>:: A number of objects
|
53
|
+
# n<Fixnum>:: A number of objects
|
54
|
+
# locale<Locale>:: A locale to which translate
|
58
55
|
#
|
59
56
|
# ==== Returns
|
60
57
|
# translated<String>:: A translated string
|
61
58
|
#
|
62
59
|
# ==== Raises
|
63
60
|
# NoMethodError:: Raised by default implementation. Should not be thrown.
|
64
|
-
def localize(singular, plural,
|
61
|
+
def localize(singular, plural, n, locale)
|
65
62
|
raise NoMethodError.new 'method localize has not been implemented'
|
66
63
|
end
|
67
64
|
# call-seq:
|
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.
|
4
|
+
version: 0.0.6
|
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-
|
13
|
+
date: 2008-11-06 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/merb_global/date_providers
|
69
69
|
- lib/merb_global/date_providers/fork.rb
|
70
70
|
- lib/merb_global/controller.rb
|
71
|
+
- lib/merb_global/locale.rb
|
71
72
|
- lib/merb_global/base.rb
|
72
73
|
- lib/merb_global/numeric_providers
|
73
74
|
- lib/merb_global/numeric_providers/fork.rb
|