i18n_plus 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -0
- data/LICENSE +21 -0
- data/README.md +16 -0
- data/lib/i18n_plus.rb +5 -0
- data/lib/i18n_plus/country.rb +55 -0
- data/lib/i18n_plus/currency.rb +55 -0
- data/lib/i18n_plus/language.rb +55 -0
- data/lib/i18n_plus/locale.rb +55 -0
- data/lib/i18n_plus/state.rb +47 -0
- metadata +91 -0
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010-2011 Oliver Eilhard
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# I18nPlus
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Yet another library for internationalization. Contains helpers for
|
6
|
+
countries, states, locales, and currencies.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
$ gem install i18n_plus
|
11
|
+
|
12
|
+
## License
|
13
|
+
|
14
|
+
Released under the MIT License. See the LICENSE file for further
|
15
|
+
details.
|
16
|
+
|
data/lib/i18n_plus.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module I18nPlus
|
4
|
+
data_path = ::Pathname.new(File.dirname(__FILE__) + '/../../data')
|
5
|
+
COUNTRIES = ::YAML.load_file(data_path.join("countries.yml"))
|
6
|
+
|
7
|
+
def self.countries(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
locale = (options[:locale] || I18n.locale || I18n.default_locale).to_s.downcase
|
10
|
+
COUNTRIES[locale]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.country_name(code, *args)
|
14
|
+
countries(*args)[code.to_s.upcase]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActionView
|
19
|
+
module Helpers
|
20
|
+
module FormOptionsHelper
|
21
|
+
def country_select(object, method, priority_country_codes = nil, options = {}, html_options = {})
|
22
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_country_codes, options, html_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def country_options_for_select(selected = nil, *priority_country_codes)
|
26
|
+
html = ""
|
27
|
+
unless priority_country_codes.empty?
|
28
|
+
priority_countries = priority_country_codes.map { |code| [I18nPlus.country_name(code), code] }
|
29
|
+
unless priority_countries.empty?
|
30
|
+
html += options_for_select(priority_countries, selected)
|
31
|
+
html += "<option value=\"\" disabled=\"disabled\">----------</option>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
all_countries = I18nPlus.countries.map { |code,name| [name, code] }.sort
|
35
|
+
return html + options_for_select(all_countries, priority_country_codes.include?(selected) ? nil : selected)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class InstanceTag
|
40
|
+
def to_country_select_tag(priority_country_codes, options, html_options)
|
41
|
+
html_options = html_options.stringify_keys
|
42
|
+
add_default_name_and_id(html_options)
|
43
|
+
value = value(object)
|
44
|
+
opts = add_options(country_options_for_select(value, *priority_country_codes), options, value)
|
45
|
+
content_tag(:select, opts, html_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class FormBuilder
|
50
|
+
def country_select(method, priority_country_codes = nil, options = {}, html_options = {})
|
51
|
+
@template.country_select(@object_name, method, priority_country_codes, options.merge(:object => @object), html_options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module I18nPlus
|
4
|
+
data_path = ::Pathname.new(File.dirname(__FILE__) + '/../../data')
|
5
|
+
CURRENCIES = ::YAML.load_file(data_path.join("currencies.yml"))
|
6
|
+
|
7
|
+
def self.currencies(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
locale = (options[:locale] || I18n.locale || I18n.default_locale).to_s.downcase
|
10
|
+
CURRENCIES[locale]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.currency_name(code, *args)
|
14
|
+
currencies(*args)[code.to_s.upcase]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActionView
|
19
|
+
module Helpers
|
20
|
+
module FormOptionsHelper
|
21
|
+
def currency_select(object, method, priority_country_codes = nil, options = {}, html_options = {})
|
22
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_currency_select_tag(priority_country_codes, options, html_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def currency_options_for_select(selected = nil, *priority_currency_codes)
|
26
|
+
html = ""
|
27
|
+
unless priority_currency_codes.empty?
|
28
|
+
priority_currencies = priority_currency_codes.map { |code| [I18nPlus.currency_name(code), code] }
|
29
|
+
unless priority_currencies.empty?
|
30
|
+
html += options_for_select(priority_currencies, selected)
|
31
|
+
html += "<option value=\"\" disabled=\"disabled\">----------</option>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
all_currencies = I18nPlus.currencies.map { |code,name| [name, code] }.sort
|
35
|
+
return html + options_for_select(all_currencies, priority_currency_codes.include?(selected) ? nil : selected)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class InstanceTag
|
40
|
+
def to_currency_select_tag(priority_currency_codes, options, html_options)
|
41
|
+
html_options = html_options.stringify_keys
|
42
|
+
add_default_name_and_id(html_options)
|
43
|
+
value = value(object)
|
44
|
+
opts = add_options(currency_options_for_select(value, *priority_currency_codes), options, value)
|
45
|
+
content_tag(:select, opts, html_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class FormBuilder
|
50
|
+
def currency_select(method, priority_currency_codes = nil, options = {}, html_options = {})
|
51
|
+
@template.currency_select(@object_name, method, priority_currency_codes, options.merge(:object => @object), html_options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module I18nPlus
|
4
|
+
data_path = Pathname.new(File.dirname(__FILE__) + '/../../data')
|
5
|
+
LANGUAGES = YAML.load_file(data_path.join("languages.yml"))
|
6
|
+
|
7
|
+
def self.languages(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
locale = (options[:locale] || I18n.locale || I18n.default_locale).to_s.downcase
|
10
|
+
LANGUAGES[locale]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.language_name(code, *args)
|
14
|
+
languages(*args)[code.to_s.upcase]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActionView
|
19
|
+
module Helpers
|
20
|
+
module FormOptionsHelper
|
21
|
+
def language_select(object, method, priority_language_codes = nil, options = {}, html_options = {})
|
22
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_language_select_tag(priority_language_codes, options, html_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def language_options_for_select(selected = nil, *priority_language_codes)
|
26
|
+
html = ""
|
27
|
+
unless priority_language_codes.empty?
|
28
|
+
priority_languages = priority_language_codes.map { |code| [I18nPlus.language_name(code), code] }
|
29
|
+
unless priority_languages.empty?
|
30
|
+
html += options_for_select(priority_languages, selected)
|
31
|
+
html += "<option value=\"\" disabled=\"disabled\">----------</option>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
all_languages = I18nPlus.languages.map { |code,name| [name, code] }.sort
|
35
|
+
return html + options_for_select(all_languages, priority_language_codes.include?(selected) ? nil : selected)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class InstanceTag
|
40
|
+
def to_language_select_tag(priority_language_codes, options, html_options)
|
41
|
+
html_options = html_options.stringify_keys
|
42
|
+
add_default_name_and_id(html_options)
|
43
|
+
value = value(object)
|
44
|
+
opts = add_options(language_options_for_select(value, *priority_language_codes), options, value)
|
45
|
+
content_tag(:select, opts, html_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class FormBuilder
|
50
|
+
def language_select(method, priority_language_codes = nil, options = {}, html_options = {})
|
51
|
+
@template.language_select(@object_name, method, priority_language_codes, options.merge(:object => @object), html_options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module I18nPlus
|
4
|
+
data_path = Pathname.new(File.dirname(__FILE__) + '/../../data')
|
5
|
+
LOCALES = YAML.load_file(data_path.join("locales.yml"))
|
6
|
+
|
7
|
+
def self.locales(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
locale = (options[:locale] || I18n.locale || I18n.default_locale).to_s.downcase
|
10
|
+
LOCALES[locale]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.locale_name(code, *args)
|
14
|
+
locales(*args)[code.to_s]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActionView
|
19
|
+
module Helpers
|
20
|
+
module FormOptionsHelper
|
21
|
+
def locale_select(object, method, priority_locale_codes = nil, options = {}, html_options = {})
|
22
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_locale_select_tag(priority_locale_codes, options, html_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def locale_options_for_select(selected = nil, *priority_locale_codes)
|
26
|
+
html = ""
|
27
|
+
unless priority_locale_codes.empty?
|
28
|
+
priority_locales = priority_locale_codes.map { |code| [I18nPlus.locale_name(code), code] }
|
29
|
+
unless priority_locales.empty?
|
30
|
+
html += options_for_select(priority_locales, selected)
|
31
|
+
html += "<option value=\"\" disabled=\"disabled\">----------</option>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
all_locales = I18nPlus.locales.map { |code,name| [name, code] }.sort
|
35
|
+
return html + options_for_select(all_locales, priority_locale_codes.include?(selected) ? nil : selected)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class InstanceTag
|
40
|
+
def to_locale_select_tag(priority_locale_codes, options, html_options)
|
41
|
+
html_options = html_options.stringify_keys
|
42
|
+
add_default_name_and_id(html_options)
|
43
|
+
value = value(object)
|
44
|
+
opts = add_options(locale_options_for_select(value, *priority_locale_codes), options, value)
|
45
|
+
content_tag(:select, opts, html_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class FormBuilder
|
50
|
+
def locale_select(method, priority_locale_codes = nil, options = {}, html_options = {})
|
51
|
+
@template.locale_select(@object_name, method, priority_locale_codes, options.merge(:object => @object), html_options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module I18nPlus
|
4
|
+
data_path = ::Pathname.new(File.dirname(__FILE__) + '/../../data')
|
5
|
+
STATES = ::YAML.load_file(data_path.join("states.yml"))
|
6
|
+
|
7
|
+
def self.states(country_code, *args)
|
8
|
+
options = args.extract_options!
|
9
|
+
locale = (options[:locale] || I18n.locale || I18n.default_locale).to_s.downcase
|
10
|
+
STATES[locale][country_code.to_s.upcase]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.state_name(country_code, state_code, *args)
|
14
|
+
states(country_code, *args)[code.to_s.upcase]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ActionView
|
19
|
+
module Helpers
|
20
|
+
module FormOptionsHelper
|
21
|
+
def state_select(object, method, country_code, options = {}, html_options = {})
|
22
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_state_select_tag(country_code, options, html_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_options_for_select(country_code, selected = nil)
|
26
|
+
all_states = I18nPlus.states(country_code).map { |code,name| [name, code] }.sort
|
27
|
+
options_for_select(all_states, selected)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class InstanceTag
|
32
|
+
def to_state_select_tag(country_code, options, html_options)
|
33
|
+
html_options = html_options.stringify_keys
|
34
|
+
add_default_name_and_id(html_options)
|
35
|
+
value = value(object)
|
36
|
+
opts = add_options(state_options_for_select(country_code, value), options, value)
|
37
|
+
content_tag(:select, opts, html_options)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class FormBuilder
|
42
|
+
def state_select(method, country_code, options = {}, html_options = {})
|
43
|
+
@template.country_select(@object_name, method, country_code, options.merge(:object => @object), html_options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Oliver Eilhard
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: &70272401363680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70272401363680
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rdoc
|
27
|
+
requirement: &70272401363220 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.5'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70272401363220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70272401362760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.8'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70272401362760
|
47
|
+
description: A library for i18n of countries, states, currencies, and locales.
|
48
|
+
email:
|
49
|
+
- oliver.eilhard@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files:
|
53
|
+
- CHANGELOG.md
|
54
|
+
- LICENSE
|
55
|
+
- README.md
|
56
|
+
files:
|
57
|
+
- lib/i18n_plus.rb
|
58
|
+
- lib/i18n_plus/country.rb
|
59
|
+
- lib/i18n_plus/currency.rb
|
60
|
+
- lib/i18n_plus/language.rb
|
61
|
+
- lib/i18n_plus/locale.rb
|
62
|
+
- lib/i18n_plus/state.rb
|
63
|
+
- CHANGELOG.md
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
homepage: http://github.com/olivere/i18n_plus
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.3.6
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.10
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: A library for i18n of countries, states, currencies, and locales.
|
91
|
+
test_files: []
|