lazier 2.0.0 → 2.1.0
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.
- data/doc/Lazier.html +315 -60
- data/doc/Lazier/Boolean.html +1 -1
- data/doc/Lazier/DateTime.html +1 -1
- data/doc/Lazier/DateTime/ClassMethods.html +1 -1
- data/doc/Lazier/Exceptions.html +1 -1
- data/doc/Lazier/Exceptions/Dump.html +1 -1
- data/doc/Lazier/Hash.html +1 -1
- data/doc/Lazier/Math.html +1 -1
- data/doc/Lazier/Math/ClassMethods.html +1 -1
- data/doc/Lazier/Object.html +1 -1
- data/doc/Lazier/Pathname.html +1 -1
- data/doc/Lazier/Settings.html +7 -7
- data/doc/Lazier/String.html +1 -1
- data/doc/Lazier/TimeZone.html +1 -1
- data/doc/Lazier/TimeZone/ClassMethods.html +1 -1
- data/doc/Lazier/Version.html +2 -2
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +96 -72
- data/doc/top-level-namespace.html +1 -1
- data/lazier.gemspec +1 -0
- data/lib/lazier.rb +30 -2
- data/lib/lazier/settings.rb +6 -6
- data/lib/lazier/version.rb +1 -1
- data/locales/en.yml +53 -0
- data/locales/it.yml +52 -0
- data/spec/lazier_spec.rb +40 -0
- metadata +19 -1
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Tue Jan 29 08:05:14 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.3 (ruby-1.9.3).
|
109
109
|
</div>
|
data/lazier.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.add_dependency("json", "~> 1.7.6")
|
26
26
|
gem.add_dependency("actionpack", ">= 3.2.11") # We don't use ~> to enable use with 4.0
|
27
27
|
gem.add_dependency("tzinfo", "~> 0.3.35")
|
28
|
+
gem.add_dependency("r18n-desktop", "~> 1.1.3")
|
28
29
|
|
29
30
|
gem.add_development_dependency("rspec", "~> 2.12.0")
|
30
31
|
gem.add_development_dependency("rake", "~> 10.0.3")
|
data/lib/lazier.rb
CHANGED
@@ -8,6 +8,7 @@ require "json"
|
|
8
8
|
require "tzinfo"
|
9
9
|
require "active_support/all"
|
10
10
|
require "action_view"
|
11
|
+
require "r18n-desktop"
|
11
12
|
|
12
13
|
require "lazier/version" if !defined?(Lazier::Version)
|
13
14
|
require "lazier/exceptions"
|
@@ -22,16 +23,18 @@ require "lazier/pathname"
|
|
22
23
|
|
23
24
|
# Several Ruby object enhancements.
|
24
25
|
module Lazier
|
25
|
-
# Returns the settings for the extensions
|
26
|
+
# Returns the settings for the extensions.
|
26
27
|
#
|
27
28
|
# @return [Settings] The settings for the extensions.
|
28
29
|
def self.settings
|
30
|
+
::Lazier.localize if !Lazier.localized?
|
29
31
|
::Lazier::Settings.instance
|
30
32
|
end
|
31
33
|
|
32
34
|
# Loads the extensions.
|
33
35
|
#
|
34
36
|
# @param what [Array] The modules to load. Valid values are:
|
37
|
+
#
|
35
38
|
# @option object Extensions for all objects.
|
36
39
|
# @option boolean Extensions for boolean values.
|
37
40
|
# @option string Extensions for strings.
|
@@ -41,8 +44,10 @@ module Lazier
|
|
41
44
|
# @option pathname Extensions for path objects.
|
42
45
|
# @return [Settings] The settings for the extensions.
|
43
46
|
def self.load!(*what)
|
47
|
+
::Lazier.localize if !Lazier.localized?
|
48
|
+
|
44
49
|
what = ["object", "boolean", "string", "hash", "datetime", "math", "pathname"] if what.count == 0
|
45
|
-
what.collect! { |w| Lazier.send("load_#{w}") }
|
50
|
+
what.collect! { |w| ::Lazier.send("load_#{w}") }
|
46
51
|
|
47
52
|
yield if block_given?
|
48
53
|
::Lazier::Settings.instance
|
@@ -120,4 +125,27 @@ module Lazier
|
|
120
125
|
include ::Lazier::Pathname
|
121
126
|
end
|
122
127
|
end
|
128
|
+
|
129
|
+
# Get the list of available translation for the current locale.
|
130
|
+
#
|
131
|
+
# @return The translation
|
132
|
+
def self.i18n
|
133
|
+
Lazier.localize if !Lazier.localized?
|
134
|
+
::R18n.get.try(:t)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Set the current locale for messages.
|
138
|
+
#
|
139
|
+
# @param locale [String] The new locale. Default is the current system locale.
|
140
|
+
def self.localize(locale = nil)
|
141
|
+
@i18n_locales_path ||= ::File.absolute_path(::Pathname.new(::File.dirname(__FILE__)).to_s + "/../locales/")
|
142
|
+
locale ? ::R18n.set(locale, @i18n_locales_path) : ::R18n.set(:en, @i18n_locales_path)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Check whether the i18n support have been enabled.
|
146
|
+
#
|
147
|
+
# @return [Boolean] Whether the i18n support have been enabled or not.
|
148
|
+
def self.localized?
|
149
|
+
@i18n_locales_path.present?
|
150
|
+
end
|
123
151
|
end
|
data/lib/lazier/settings.rb
CHANGED
@@ -51,8 +51,8 @@ module Lazier
|
|
51
51
|
# @param false_name [String] The string representation of `false`. Defaults to `No`.
|
52
52
|
# @return [Hash] The new representations.
|
53
53
|
def setup_boolean_names(true_name = nil, false_name = nil)
|
54
|
-
true_name ||=
|
55
|
-
false_name ||=
|
54
|
+
true_name ||= Lazier.i18n.boolean[0]
|
55
|
+
false_name ||= Lazier.i18n.boolean[1]
|
56
56
|
@boolean_names = {true => true_name, false => false_name}
|
57
57
|
end
|
58
58
|
|
@@ -90,10 +90,10 @@ module Lazier
|
|
90
90
|
# @param short_days [Array] The abbreviated string representation of days.
|
91
91
|
# @return [Hash] The new representations.
|
92
92
|
def setup_date_names(long_months = nil, short_months = nil, long_days = nil, short_days = nil)
|
93
|
-
long_months =
|
94
|
-
short_months =
|
95
|
-
long_days =
|
96
|
-
short_days =
|
93
|
+
long_months = Lazier.i18n.date.long_months if long_months.blank?
|
94
|
+
short_months = Lazier.i18n.date.short_months if short_months.blank?
|
95
|
+
long_days = Lazier.i18n.date.long_days if long_days.blank?
|
96
|
+
short_days = Lazier.i18n.date.short_days if short_days.blank?
|
97
97
|
|
98
98
|
@date_names = { long_months: long_months, short_months: short_months, long_days: long_days, short_days: short_days }
|
99
99
|
end
|
data/lib/lazier/version.rb
CHANGED
data/locales/en.yml
ADDED
@@ -0,0 +1,53 @@
|
|
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
|
+
---
|
8
|
+
boolean:
|
9
|
+
- "Yes"
|
10
|
+
- "No"
|
11
|
+
date:
|
12
|
+
long_months:
|
13
|
+
- "January"
|
14
|
+
- "February"
|
15
|
+
- "March"
|
16
|
+
- "April"
|
17
|
+
- "May"
|
18
|
+
- "June"
|
19
|
+
- "July"
|
20
|
+
- "August"
|
21
|
+
- "September"
|
22
|
+
- "October"
|
23
|
+
- "November"
|
24
|
+
- "December"
|
25
|
+
short_months:
|
26
|
+
- "Jan"
|
27
|
+
- "Feb"
|
28
|
+
- "Mar"
|
29
|
+
- "Apr"
|
30
|
+
- "May"
|
31
|
+
- "Jun"
|
32
|
+
- "Jul"
|
33
|
+
- "Aug"
|
34
|
+
- "Sep"
|
35
|
+
- "Oct"
|
36
|
+
- "Nov"
|
37
|
+
- "Dec"
|
38
|
+
long_days:
|
39
|
+
- "Sunday"
|
40
|
+
- "Monday"
|
41
|
+
- "Tuesday"
|
42
|
+
- "Wednesday"
|
43
|
+
- "Thursday"
|
44
|
+
- "Friday"
|
45
|
+
- "Saturday"
|
46
|
+
short_days:
|
47
|
+
- "Sun"
|
48
|
+
- "Mon"
|
49
|
+
- "Tue"
|
50
|
+
- "Wed"
|
51
|
+
- "Thu"
|
52
|
+
- "Fri"
|
53
|
+
- "Sat"
|
data/locales/it.yml
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
+
---
|
8
|
+
boolean:
|
9
|
+
- "Yes"
|
10
|
+
- "No"
|
11
|
+
date:
|
12
|
+
long_months:
|
13
|
+
- "Gennaio"
|
14
|
+
- "Febbraio"
|
15
|
+
- "Marzo"
|
16
|
+
- "Aprile"
|
17
|
+
- "Maggio"
|
18
|
+
- "Giugno"
|
19
|
+
- "Luglio"
|
20
|
+
- "Agosto"
|
21
|
+
- "Settembre"
|
22
|
+
- "Ottobre"
|
23
|
+
- "Novembre"
|
24
|
+
- "Dicembre"
|
25
|
+
short_monts:
|
26
|
+
- "Gen"
|
27
|
+
- "Feb"
|
28
|
+
- "Mar"
|
29
|
+
- "Apr"
|
30
|
+
- "Mag"
|
31
|
+
- "Giu"
|
32
|
+
- "Lug"
|
33
|
+
- "Ago"
|
34
|
+
- "SetOtt"
|
35
|
+
- "Nov"
|
36
|
+
- "Dic"
|
37
|
+
long_days:
|
38
|
+
- "Domenica"
|
39
|
+
- "Lunedì"
|
40
|
+
- "Martedì"
|
41
|
+
- "Mercoledì"
|
42
|
+
- "Giovedì"
|
43
|
+
- "Venerdì"
|
44
|
+
- "Sabato"
|
45
|
+
short_days:
|
46
|
+
- "Dom"
|
47
|
+
- "Lun"
|
48
|
+
- "Mar"
|
49
|
+
- "Mer"
|
50
|
+
- "Gio"
|
51
|
+
- "Ven"
|
52
|
+
- "Sab"
|
data/spec/lazier_spec.rb
CHANGED
@@ -42,4 +42,44 @@ describe Lazier do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
describe ".i18n" do
|
47
|
+
it "should run localize if needed" do
|
48
|
+
Lazier.instance_variable_set(:@i18n_locales_path, nil)
|
49
|
+
Lazier.should_receive(:localize)
|
50
|
+
Lazier.i18n
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return a localizer object" do
|
54
|
+
R18n.stub(:get).and_return(Object.new)
|
55
|
+
R18n.get.should_receive(:try).with(:t)
|
56
|
+
Lazier.i18n
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".localize" do
|
61
|
+
it "should set the right locale path" do
|
62
|
+
Lazier.localize
|
63
|
+
expect(Lazier.instance_variable_get(:@i18n_locales_path)).to eq(File.absolute_path(::Pathname.new(File.dirname(__FILE__)).to_s + "/../locales/"))
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should set using English if called without arguments" do
|
67
|
+
R18n.should_receive(:set).with(:en, File.absolute_path(::Pathname.new(File.dirname(__FILE__)).to_s + "/../locales/"))
|
68
|
+
Lazier.localize
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should set the requested locale" do
|
72
|
+
R18n.should_receive(:set).with(:it, File.absolute_path(::Pathname.new(File.dirname(__FILE__)).to_s + "/../locales/"))
|
73
|
+
Lazier.localize(:it)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe ".localize?" do
|
78
|
+
it "should respect the value of the internal variable" do
|
79
|
+
Lazier.instance_variable_set(:@i18n_locales_path, nil)
|
80
|
+
expect(Lazier.localized?).to be_false
|
81
|
+
Lazier.localize(:en)
|
82
|
+
expect(Lazier.localized?).to be_true
|
83
|
+
end
|
84
|
+
end
|
45
85
|
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.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.3.35
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: r18n-desktop
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.3
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: rspec
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,6 +243,8 @@ files:
|
|
227
243
|
- lib/lazier/settings.rb
|
228
244
|
- lib/lazier/string.rb
|
229
245
|
- lib/lazier/version.rb
|
246
|
+
- locales/en.yml
|
247
|
+
- locales/it.yml
|
230
248
|
- spec/coverage_helper.rb
|
231
249
|
- spec/lazier/boolean_spec.rb
|
232
250
|
- spec/lazier/datetime_spec.rb
|