lazier 2.6.4 → 2.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Thu Feb 7 23:34:10 2013 by
106
+ Generated on Sat Feb 9 10:45:50 2013 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.4 (ruby-1.9.3).
109
109
  </div>
data/lib/lazier.rb CHANGED
@@ -13,6 +13,7 @@ require "r18n-desktop"
13
13
  require "lazier/version" if !defined?(Lazier::Version)
14
14
  require "lazier/exceptions"
15
15
  require "lazier/i18n"
16
+ require "lazier/localizer"
16
17
  require "lazier/settings"
17
18
  require "lazier/object"
18
19
  require "lazier/boolean"
data/lib/lazier/i18n.rb CHANGED
@@ -6,11 +6,22 @@
6
6
 
7
7
  module Lazier
8
8
  # Provides an easy way to localized messages in a class.
9
+ #
10
+ # @attribute [r] i18n_locale
11
+ # @return [String|Symbol|nil] The current locale.
12
+ # @attribute [r] i18n_root
13
+ # @return [Symbol] The root level of the translation.
14
+ # @attribute [r] i18n_locales_path
15
+ # @return [String] The path where the translations are stored.
9
16
  module I18n
17
+ attr_reader :i18n_locale
18
+ attr_reader :i18_root
19
+ attr_reader :i18n_locales_path
20
+
10
21
  # Setup all I18n translations.
11
22
  #
12
- # @param root [Symbol] The root level of translation.
13
- # @param path [String] The path where the translation are stored.
23
+ # @param root [Symbol] The root level of the translation.
24
+ # @param path [String] The path where the translations are stored.
14
25
  def i18n_setup(root, path)
15
26
  @i18n_root = root.to_sym
16
27
  @i18n_locales_path = path
@@ -25,9 +36,10 @@ module Lazier
25
36
 
26
37
  # Set the current locale for messages.
27
38
  #
28
- # @param locale [String] The new locale. Default is the current system locale.
39
+ # @param locale [String|Symbol|nil] The new locale. Default is the current system locale.
29
40
  # @return [R18n::Translation] The new translation object.
30
41
  def i18n=(locale)
42
+ @i18n_locale = locale
31
43
  @i18n = i18n_load_locale(locale)
32
44
  end
33
45
 
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ module Lazier
8
+ # A utility class to localize messages
9
+ class Localizer
10
+ include Lazier::I18n
11
+
12
+ # Initialize a new localizer.
13
+ #
14
+ # @param root [Symbol] The root level of the translation.
15
+ # @param path [String] The path where the translations are stored.
16
+ # @param locale [String|Symbol] The locale to use for localization.
17
+ def initialize(root = nil, path = nil, locale = nil)
18
+ root ||= :lazier
19
+ path ||= ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/")
20
+ self.i18n_setup(root, path)
21
+ self.i18n = locale
22
+ end
23
+
24
+ # Localize a message.
25
+ #
26
+ # @param message [String|Symbol] The message to localize.
27
+ # @param args [Array] Optional arguments to localize the message.
28
+ # @return [String|R18n::Untranslated] The localized message.
29
+ def self.localize(message, *args)
30
+ self.new.i18n.send(message, *args)
31
+ end
32
+
33
+ # Localize a message in a specified locale.
34
+ #
35
+ # @param locale [String|Symbol] The locale to use for localization.
36
+ # @param message [String|Symbol] The message to localize.
37
+ # @param args [Array] Optional arguments to localize the message.
38
+ # @return [String|R18n::Untranslated] The localized message.
39
+ def self.localize_on_locale(locale, message, *args)
40
+ self.new(nil, nil, locale).i18n.send(message, *args)
41
+ end
42
+ end
43
+ end
@@ -16,7 +16,7 @@ module Lazier
16
16
  MINOR = 6
17
17
 
18
18
  # The patch version.
19
- PATCH = 4
19
+ PATCH = 5
20
20
 
21
21
  # The current version of lazier.
22
22
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
4
+ # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
5
+ #
6
+
7
+ require "spec_helper"
8
+
9
+ describe Lazier::Localizer do
10
+ describe "#initialize" do
11
+ it "should call i18n_setup and then i18n=" do
12
+ ::Lazier::Localizer.any_instance.should_receive(:i18n_setup).with("ROOT", "PATH")
13
+ ::Lazier::Localizer.any_instance.should_receive(:i18n=).with(:it)
14
+ Lazier::Localizer.new("ROOT", "PATH", :it)
15
+ end
16
+
17
+ it "should setup default arguments" do
18
+ ::Lazier::Localizer.any_instance.should_receive(:i18n_setup).with(:lazier, ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../../locales/"))
19
+ ::Lazier::Localizer.any_instance.should_receive(:i18n=).with(nil)
20
+ Lazier::Localizer.new
21
+ end
22
+ end
23
+
24
+ describe ".localize" do
25
+ it "should create a new localizer and forward the message" do
26
+ obj = Object.new
27
+ obj.should_receive(:string).with("ARGUMENT")
28
+ ::Lazier::Localizer.should_receive(:new).and_call_original
29
+ ::Lazier::Localizer.any_instance.should_receive(:i18n).and_return(obj)
30
+ ::Lazier::Localizer.localize(:string, "ARGUMENT")
31
+ end
32
+ end
33
+
34
+ describe ".localize" do
35
+ it "should create a new localizer and forward the message" do
36
+ obj = Object.new
37
+ obj.should_receive(:string).with("ARGUMENT")
38
+ ::Lazier::Localizer.should_receive(:new).with(nil, nil, :it).and_call_original
39
+ ::Lazier::Localizer.any_instance.should_receive(:i18n).and_return(obj)
40
+ ::Lazier::Localizer.localize_on_locale(:it, :string, "ARGUMENT")
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -128,6 +128,7 @@ files:
128
128
  - lib/lazier/exceptions.rb
129
129
  - lib/lazier/hash.rb
130
130
  - lib/lazier/i18n.rb
131
+ - lib/lazier/localizer.rb
131
132
  - lib/lazier/math.rb
132
133
  - lib/lazier/object.rb
133
134
  - lib/lazier/pathname.rb
@@ -141,6 +142,7 @@ files:
141
142
  - spec/lazier/datetime_spec.rb
142
143
  - spec/lazier/hash_spec.rb
143
144
  - spec/lazier/i18n_spec.rb
145
+ - spec/lazier/localizer_spec.rb
144
146
  - spec/lazier/math_spec.rb
145
147
  - spec/lazier/object_spec.rb
146
148
  - spec/lazier/pathname_spec.rb
@@ -168,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  version: '0'
169
171
  segments:
170
172
  - 0
171
- hash: 1673408804754958952
173
+ hash: 4371094391757405950
172
174
  requirements: []
173
175
  rubyforge_project: lazier
174
176
  rubygems_version: 1.8.25
@@ -181,6 +183,7 @@ test_files:
181
183
  - spec/lazier/datetime_spec.rb
182
184
  - spec/lazier/hash_spec.rb
183
185
  - spec/lazier/i18n_spec.rb
186
+ - spec/lazier/localizer_spec.rb
184
187
  - spec/lazier/math_spec.rb
185
188
  - spec/lazier/object_spec.rb
186
189
  - spec/lazier/pathname_spec.rb