gaigo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/CHANGELOG +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/README.rdoc +1 -0
- data/Rakefile +1 -0
- data/gaigo.gemspec +24 -0
- data/lib/gaigo/countries.rb +38 -0
- data/lib/gaigo/engine.rb +4 -0
- data/lib/gaigo/has_locale.rb +19 -0
- data/lib/gaigo/helpers/action_view_extension.rb +27 -0
- data/lib/gaigo/helpers/form_helper_v3/form_builder.rb +11 -0
- data/lib/gaigo/helpers/form_helper_v3/instance_tag.rb +62 -0
- data/lib/gaigo/helpers/form_helper_v3.rb +26 -0
- data/lib/gaigo/helpers/form_helper_v4/form_builder.rb +11 -0
- data/lib/gaigo/helpers/form_helper_v4/tags.rb +63 -0
- data/lib/gaigo/helpers/form_helper_v4.rb +15 -0
- data/lib/gaigo/i18n_extend/try_translate.rb +24 -0
- data/lib/gaigo/i18n_extend.rb +9 -0
- data/lib/gaigo/langs.rb +61 -0
- data/lib/gaigo/library/countries.rb +78 -0
- data/lib/gaigo/library/langs.rb +86 -0
- data/lib/gaigo/models/active_record_extension.rb +21 -0
- data/lib/gaigo/models/localized.rb +24 -0
- data/lib/gaigo/models/naming/human_attribute_name.rb +49 -0
- data/lib/gaigo/models/naming/human_model_name.rb +36 -0
- data/lib/gaigo/models/naming.rb +10 -0
- data/lib/gaigo/railtie.rb +17 -0
- data/lib/gaigo/utilities.rb +23 -0
- data/lib/gaigo/version.rb +3 -0
- data/lib/gaigo.rb +27 -0
- metadata +94 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Valery Kvon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Gaigo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gaigo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gaigo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/README.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Under development
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/gaigo.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gaigo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "gaigo"
|
8
|
+
gem.version = Gaigo::VERSION
|
9
|
+
gem.authors = ["Valery Kvon"]
|
10
|
+
gem.email = ["addagger@gmail.com"]
|
11
|
+
gem.homepage = %q{http://vkvon.ru/projects/gaigo}
|
12
|
+
gem.description = %q{76 world's languages and codes}
|
13
|
+
gem.summary = %q{World's languages/countries, locale attribute for Rails' models}
|
14
|
+
|
15
|
+
gem.rubyforge_project = "gaigo"
|
16
|
+
|
17
|
+
gem.add_development_dependency "i18n"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
gem.licenses = ['MIT']
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'gaigo/library/countries'
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
|
5
|
+
class Countries < Array
|
6
|
+
|
7
|
+
class Country
|
8
|
+
attr_reader :en, :code, :native
|
9
|
+
def initialize(en, code, native)
|
10
|
+
@en = en
|
11
|
+
@code = code
|
12
|
+
@native = native
|
13
|
+
freeze
|
14
|
+
end
|
15
|
+
def to_s
|
16
|
+
"#{en} (#{native})"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_country(attributes)
|
21
|
+
self << Country.new(*attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(code)
|
25
|
+
self.find {|i| i.code == code.to_s}
|
26
|
+
end
|
27
|
+
|
28
|
+
def codes
|
29
|
+
self.map {|i| i.code}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
COUNTRIES = Countries.new
|
35
|
+
Library.countries.each {|attributes| COUNTRIES.add_country(attributes)}
|
36
|
+
COUNTRIES.freeze
|
37
|
+
|
38
|
+
end
|
data/lib/gaigo/engine.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'gaigo/models/localized'
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
module HasLocale
|
5
|
+
|
6
|
+
def has_locale!(*args)
|
7
|
+
options = args.extract_options!
|
8
|
+
class_attribute :_locales unless defined?(_locales)
|
9
|
+
self._locales = LANGS.copy(*args)
|
10
|
+
unless respond_to?(:has_locale?)
|
11
|
+
unless options[:accessible] == false
|
12
|
+
attr_accessible :locale
|
13
|
+
end
|
14
|
+
end
|
15
|
+
include Localized
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'gaigo/utilities'
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
|
5
|
+
module ActionViewExtension
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
include Utilities
|
9
|
+
|
10
|
+
included do
|
11
|
+
if Rails.version <= "3.2.8"
|
12
|
+
require 'gaigo/helpers/form_helper_v3'
|
13
|
+
else
|
14
|
+
require 'gaigo/helpers/form_helper_v4'
|
15
|
+
end
|
16
|
+
include FormHelper
|
17
|
+
end
|
18
|
+
|
19
|
+
def render_with_locale(locale, *args, &block)
|
20
|
+
I18n.with_locale locale do
|
21
|
+
render(*args, &block)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Gaigo
|
2
|
+
|
3
|
+
module FormHelperV3
|
4
|
+
module InstanceTag
|
5
|
+
def to_ilabel_tag(text = nil, options = {}, &block)
|
6
|
+
options = options.stringify_keys
|
7
|
+
tag_value = options.delete("value")
|
8
|
+
name_and_id = options.dup
|
9
|
+
|
10
|
+
if name_and_id["for"]
|
11
|
+
name_and_id["id"] = name_and_id["for"]
|
12
|
+
else
|
13
|
+
name_and_id.delete("id")
|
14
|
+
end
|
15
|
+
|
16
|
+
current_locale =
|
17
|
+
if options[:locale].present?
|
18
|
+
check_locale_code(options[:locale])
|
19
|
+
elsif object && object.class.respond_to?(:has_locale?)
|
20
|
+
object.locale
|
21
|
+
else
|
22
|
+
I18n.locale
|
23
|
+
end
|
24
|
+
|
25
|
+
add_default_name_and_id_for_value(tag_value, name_and_id)
|
26
|
+
options.delete("index")
|
27
|
+
options.delete("namespace")
|
28
|
+
options["for"] ||= name_and_id["id"]
|
29
|
+
|
30
|
+
if block_given?
|
31
|
+
@template_object.label_tag(name_and_id["id"], options, &block)
|
32
|
+
else
|
33
|
+
content = if text.blank?
|
34
|
+
object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
|
35
|
+
method_and_value = tag_value.present? ? "#{method_name}.#{tag_value}" : method_name
|
36
|
+
|
37
|
+
if object.respond_to?(:to_model)
|
38
|
+
key = object.class.model_name.i18n_key
|
39
|
+
i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
|
40
|
+
end
|
41
|
+
|
42
|
+
i18n_default ||= ""
|
43
|
+
I18n.try_translate("#{object_name}.#{method_and_value}", :locale => (object ? object.try(:locale) : nil), :default => i18n_default, :scope => "helpers.label").presence
|
44
|
+
else
|
45
|
+
text.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
content ||= if object && object.class.respond_to?(:try_human_attribute_name)
|
49
|
+
object.class.try_human_attribute_name(@method_name, :locale => current_locale)
|
50
|
+
elsif object && object.class.respond_to?(:human_attribute_name)
|
51
|
+
object.class.human_attribute_name(method_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
content ||= method_name.humanize
|
55
|
+
|
56
|
+
label_tag(name_and_id["id"], content, options)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'gaigo/helpers/form_helper_v3/form_builder'
|
2
|
+
require 'gaigo/helpers/form_helper_v3/instance_tag'
|
3
|
+
|
4
|
+
module Gaigo
|
5
|
+
|
6
|
+
module FormHelper
|
7
|
+
# module_eval <<-EOV
|
8
|
+
def ilabel(object_name, method, content_or_options = nil, options = nil, &block)
|
9
|
+
options ||= {}
|
10
|
+
|
11
|
+
content_is_options = content_or_options.is_a?(Hash)
|
12
|
+
if content_is_options || block_given?
|
13
|
+
options.merge!(content_or_options) if content_is_options
|
14
|
+
text = nil
|
15
|
+
else
|
16
|
+
text = content_or_options
|
17
|
+
end
|
18
|
+
|
19
|
+
ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_ilabel_tag(text, options, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
ActionView::Helpers::InstanceTag.send(:include, Gaigo::FormHelperV3::InstanceTag)
|
26
|
+
ActionView::Helpers::FormBuilder.send(:include, Gaigo::FormHelperV3::FormBuilder)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Gaigo
|
2
|
+
|
3
|
+
module FormHelperV4
|
4
|
+
class ILabel < ActionView::Helpers::Tags::Label
|
5
|
+
def render(&block)
|
6
|
+
options = @options.stringify_keys
|
7
|
+
tag_value = options.delete("value")
|
8
|
+
name_and_id = options.dup
|
9
|
+
|
10
|
+
if name_and_id["for"]
|
11
|
+
name_and_id["id"] = name_and_id["for"]
|
12
|
+
else
|
13
|
+
name_and_id.delete("id")
|
14
|
+
end
|
15
|
+
|
16
|
+
current_locale =
|
17
|
+
if options[:locale].present?
|
18
|
+
check_locale_code(options[:locale])
|
19
|
+
elsif object && object.class.respond_to?(:has_locale?)
|
20
|
+
object.locale
|
21
|
+
else
|
22
|
+
I18n.locale
|
23
|
+
end
|
24
|
+
|
25
|
+
add_default_name_and_id_for_value(tag_value, name_and_id)
|
26
|
+
options.delete("index")
|
27
|
+
options.delete("namespace")
|
28
|
+
options["for"] = name_and_id["id"] unless options.key?("for")
|
29
|
+
|
30
|
+
if block_given?
|
31
|
+
content = @template_object.capture(&block)
|
32
|
+
else
|
33
|
+
content = if @content.blank?
|
34
|
+
@object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
|
35
|
+
method_and_value = tag_value.present? ? "#{@method_name}.#{tag_value}" : @method_name
|
36
|
+
|
37
|
+
if object.respond_to?(:to_model)
|
38
|
+
key = object.class.model_name.i18n_key
|
39
|
+
i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
|
40
|
+
end
|
41
|
+
|
42
|
+
i18n_default ||= ""
|
43
|
+
I18n.try_translate("#{@object_name}.#{method_and_value}", :locale => current_locale, :default => i18n_default, :scope => "helpers.label").presence
|
44
|
+
else
|
45
|
+
@content.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
content ||= if object && object.class.respond_to?(:try_human_attribute_name)
|
49
|
+
object.class.try_human_attribute_name(@method_name, :locale => current_locale)
|
50
|
+
elsif object && object.class.respond_to?(:human_attribute_name)
|
51
|
+
object.class.human_attribute_name(@method_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
content ||= @method_name.humanize
|
55
|
+
end
|
56
|
+
|
57
|
+
label_tag(name_and_id["id"], content, options)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'gaigo/helpers/form_helper_v4/form_builder'
|
2
|
+
require 'gaigo/helpers/form_helper_v4/tags'
|
3
|
+
|
4
|
+
module Gaigo
|
5
|
+
|
6
|
+
module FormHelper
|
7
|
+
def ilabel(object_name, method, content_or_options = nil, options = nil, &block)
|
8
|
+
Tags::ILabel.new(object_name, method, self, content_or_options, options).render(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionView::Helpers::Tags.send(:include, Gaigo::FormHelperV4::Tags)
|
15
|
+
ActionView::Helpers::FormBuilder.send(:include, Gaigo::FormHelperV4::FormBuilder)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Gaigo
|
2
|
+
|
3
|
+
module I18nExtend
|
4
|
+
module TryTranslate
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def try_translate(*args, &block)
|
9
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
10
|
+
locale = options.delete(:locale) || config.locale
|
11
|
+
begin
|
12
|
+
translate!(*args, options.merge(:locale => locale))
|
13
|
+
rescue Exception
|
14
|
+
if block_given?
|
15
|
+
yield args, options
|
16
|
+
end
|
17
|
+
translate(*args, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/gaigo/langs.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'gaigo/library/langs'
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
|
5
|
+
class Langs < Array
|
6
|
+
|
7
|
+
class Lang
|
8
|
+
attr_reader :en, :code, :native
|
9
|
+
def initialize(en, code, native)
|
10
|
+
@en = en
|
11
|
+
@code = code
|
12
|
+
@native = native
|
13
|
+
freeze
|
14
|
+
end
|
15
|
+
def to_s
|
16
|
+
"#{en} (#{native})"
|
17
|
+
end
|
18
|
+
def to_method
|
19
|
+
en.downcase.gsub(/\W|\d/,"_")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_lang(attributes)
|
24
|
+
self << Lang.new(*attributes)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(code)
|
28
|
+
self.find {|i| i.code == code.to_s}
|
29
|
+
end
|
30
|
+
|
31
|
+
def codes
|
32
|
+
self.map {|i| i.code}
|
33
|
+
end
|
34
|
+
|
35
|
+
def en
|
36
|
+
self.map {|i| i.en}
|
37
|
+
end
|
38
|
+
|
39
|
+
def native
|
40
|
+
self.map {|i| i.native}
|
41
|
+
end
|
42
|
+
|
43
|
+
def copy(*locale_codes)
|
44
|
+
if locale_codes.any?
|
45
|
+
Langs.new.tap do |new_langs|
|
46
|
+
locale_codes.each do |code|
|
47
|
+
new_langs << get(code.to_s)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
else
|
51
|
+
self.dup
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
LANGS = Langs.new
|
58
|
+
Library.langs.each {|attributes| LANGS.add_lang(attributes)}
|
59
|
+
LANGS.freeze
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
module Library
|
5
|
+
def self.countries
|
6
|
+
[["Albania", "AL", "Shqipëria"],
|
7
|
+
["Anguilla", "AI", "Anguila"],
|
8
|
+
["Argentina", "AR", "Argentina"],
|
9
|
+
["Austria", "AT", "Österreich"],
|
10
|
+
["Belgium", "BE", "Belgique"],
|
11
|
+
["Bolivia", "BO", "Bolivia"],
|
12
|
+
["Bosnia & Herzegovina", "BA", "Bosna I Hercegovina"],
|
13
|
+
["Brazil", "BR", "Brasil"],
|
14
|
+
["Bulgaria", "BG", "България"],
|
15
|
+
["Canada", "CA", "Canada"],
|
16
|
+
["Chile", "CL", "Chile"],
|
17
|
+
["Colombia", "CO", "Colombia"],
|
18
|
+
["Costa Rica", "CR", "Costa Rica"],
|
19
|
+
["Croatia", "HR", "Hrvatska"],
|
20
|
+
["Cyprus", "CY", "Κύπρος"],
|
21
|
+
["Czech Republic", "CZ", "Česká republika"],
|
22
|
+
["Denmark", "DK", "Danmark"],
|
23
|
+
["Dominican Republic", "DO", "República Dominicana"],
|
24
|
+
["Ecuador", "EC", "Ecuador"],
|
25
|
+
["El Salvador", "SV", "El Salvador"],
|
26
|
+
["Estonia", "EE", "Eesti"],
|
27
|
+
["Finland", "FI", "Suomi"],
|
28
|
+
["France", "FR", "France"],
|
29
|
+
["Germany", "DE", "Deutschland"],
|
30
|
+
["Greece", "GR", "Ελλάδα"],
|
31
|
+
["Guatemala", "GT", "Guatemala"],
|
32
|
+
["Honduras", "HN", "Honduras"],
|
33
|
+
["Hungary", "HU", "Magyarország"],
|
34
|
+
["Iceland", "IS", "Island"],
|
35
|
+
["Ireland", "IE", "Éire"],
|
36
|
+
["Israel", "IL", "ישראל"],
|
37
|
+
["Italy", "IT", "Italia"],
|
38
|
+
["Indonesia", "ID", "Republik Indonesia"],
|
39
|
+
["Jamaica", "JM", "Jamaica"],
|
40
|
+
["Japan", "JP", "日本"],
|
41
|
+
["Korea (South)", "KR", "한국"],
|
42
|
+
["Latvia", "LV", "Latvija"],
|
43
|
+
["Lithuania", "LT", "Lietuva"],
|
44
|
+
["Luxembourg", "LU", "Luxembourg"],
|
45
|
+
["Macedonia", "MK", "Македонија"],
|
46
|
+
["Malaysia", "MY", "Malaysia"],
|
47
|
+
["Malta", "MT", "Malta"],
|
48
|
+
["Mexico", "MX", "México"],
|
49
|
+
["New Zealand", "NZ", "New Zealand"],
|
50
|
+
["Nicaragua", "NI", "Nicaragua"],
|
51
|
+
["Norway", "NO", "Norge"],
|
52
|
+
["Panama", "PA", "Panamá"],
|
53
|
+
["Paraguay", "PY", "Paraguay"],
|
54
|
+
["Peru", "PE", "Perú"],
|
55
|
+
["Philippines", "PH", "Pilipinas"],
|
56
|
+
["Poland", "PL", "Polska"],
|
57
|
+
["Portugal", "PT", "Portugal"],
|
58
|
+
["Romania", "RO", "Romănia"],
|
59
|
+
["Russian Federation", "RU", "Россия"],
|
60
|
+
["Serbia/Montenegro", "CS", "Србија и Црна Гора"],
|
61
|
+
["Singapore", "SG", "Singapore"],
|
62
|
+
["Slovakia", "SK", "Slovensko"],
|
63
|
+
["Slovenia", "SI", "Slovenija"],
|
64
|
+
["Spain", "ES", "España"],
|
65
|
+
["Sweden", "SE", "Sverige"],
|
66
|
+
["Switzerland", "CH", "Suisse"],
|
67
|
+
["Taiwan", "TW", "中華民國"],
|
68
|
+
["Thailand", "TH", "ประเทศไทย"],
|
69
|
+
["The Netherlands", "NL", "Nederland"],
|
70
|
+
["Turkey", "TR", "Türkiye"],
|
71
|
+
["Ukraine", "UA", "Україна"],
|
72
|
+
["United Kingdom", "GB", "United Kingdom"],
|
73
|
+
["Uruguay", "UY", "Uruguay"],
|
74
|
+
["United States", "US", "United States"],
|
75
|
+
["Venezuela", "VE", "Venezuel"]]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
module Library
|
5
|
+
def self.langs
|
6
|
+
[["Abkhaz", "ab", "аҧсуа бызшәа"],
|
7
|
+
["Afrikaans", "af", "Afrikaans"],
|
8
|
+
["Albanian", "sq", "shqip"],
|
9
|
+
["Amharic", "am", "አማርኛ"],
|
10
|
+
["Arabic", "ar", "العربية"],
|
11
|
+
["Armenian", "hy", "Հայերեն"],
|
12
|
+
["Azerbaijani", "az", "azərbaycan"],
|
13
|
+
["Bambara", "bm", "Bamanankan"],
|
14
|
+
["Basque", "eu", "euskera"],
|
15
|
+
["Belorussian", "be", "Беларуская"],
|
16
|
+
["Bulgarian", "bg", "Български"],
|
17
|
+
["Catalan", "ca", "Català"],
|
18
|
+
["Chinese", "zh", "中文"],
|
19
|
+
["Chinese (Simplified script)", "zh-Hans", "简体中文"],
|
20
|
+
["Chinese (Traditional script)", "zh-Hant", "繁體中文"],
|
21
|
+
["Croatian", "hr", "Hrvatski"],
|
22
|
+
["Czech", "cs", "čeština"],
|
23
|
+
["Danish", "da", "Dansk"],
|
24
|
+
["Dutch", "nl", "Nederlands"],
|
25
|
+
["English", "en", "English"],
|
26
|
+
["Estonian", "et", "Eesti"],
|
27
|
+
["Ewe", "ee", "Ɛʋɛ"],
|
28
|
+
["Finnish", "fi", "suomi"],
|
29
|
+
["French", "fr", "français"],
|
30
|
+
["French (Canadian)", "fr-CA", "français canadien"],
|
31
|
+
["Fula/Fulah/Fulani", "ff", "Fulfulde, Pulaar, Pular"],
|
32
|
+
["Galician", "gl", "Galego"],
|
33
|
+
["Georgian", "ka", "ქართული ენა"],
|
34
|
+
["German", "de", "Deutsch"],
|
35
|
+
["Greek", "el", "Ελληνικά"],
|
36
|
+
["Hausa", "ha", "Hausa"],
|
37
|
+
["Hebrew", "he", "עברית"],
|
38
|
+
["Hindi", "hi", "हिंदी"],
|
39
|
+
["Hungarian", "hu", "Magyar"],
|
40
|
+
["Icelandic", "is", "Íslenska"],
|
41
|
+
["Indonesian", "id", "Bahasa indonesia"],
|
42
|
+
["Irish", "ga", "Gaeilge"],
|
43
|
+
["Italian", "it", "italiano"],
|
44
|
+
["Japanese", "ja", "日本語"],
|
45
|
+
["Kannada", "kn", "ಕನ್ನಡ"],
|
46
|
+
["Kazakh", "kk", "Қазақ"],
|
47
|
+
["Kinyarwanda", "rw", "Kinyarwanda"],
|
48
|
+
["Kirghiz", "ky", "Кыргыз"],
|
49
|
+
["Kirundi", "rn", "Kirundi"],
|
50
|
+
["Korean", "ko", "한국어"],
|
51
|
+
["Latvian", "lv", "Latviešu"],
|
52
|
+
["Lithuanian", "lt", "Lietuviškai"],
|
53
|
+
["Luo", "luo", "Dholuo"],
|
54
|
+
["Macedonian", "mk", "Македонски"],
|
55
|
+
["Malaysian", "ms", "Bahasa melayu"],
|
56
|
+
["Maltese", "mt", "Malti"],
|
57
|
+
["Norwegian", "no", "Norsk"],
|
58
|
+
["Pashto", "ps", "پښتو"],
|
59
|
+
["Persian", "fa", "فارسی"],
|
60
|
+
["Polish", "pl", "polski"],
|
61
|
+
["Portuguese", "pt", "português"],
|
62
|
+
["Portuguese (Brazilian)", "pt-BR", "português brasileiro"],
|
63
|
+
["Romanian", "ro", "Română"],
|
64
|
+
["Russian", "ru", "Pyccĸий"],
|
65
|
+
["Serbian", "sr", "Srpski"],
|
66
|
+
["Somali", "so", "Somali"],
|
67
|
+
["Spanish", "es", "Español"],
|
68
|
+
["Slovak", "sk", "Slovenčina"],
|
69
|
+
["Slovenian", "sl", "Slovenščina"],
|
70
|
+
["Swahili", "sw", "Kiswahili"],
|
71
|
+
["Swedish", "sv", "svenska"],
|
72
|
+
["Telugu", "te", "తెలుగు"],
|
73
|
+
["Thai", "th", "ภาษาไทย"],
|
74
|
+
["Turkish", "tr", "Tϋrkçe"],
|
75
|
+
["Ukrainian", "uk", "Українська"],
|
76
|
+
["Urdu", "ur", "اردو"],
|
77
|
+
["Uzbek", "uz", "o'zbek"],
|
78
|
+
["Vietnamese", "vi", "Tiếng Việt"],
|
79
|
+
["Welsh", "cy", "Cymraeg"],
|
80
|
+
["Wolof", "wo", "Wolof"],
|
81
|
+
["Xhosa", "xs", "isiXhosa"],
|
82
|
+
["Yoruba", "yo", "Yorùbá"],
|
83
|
+
["Zulu", "zu", "isiZulu"]]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'gaigo/utilities'
|
2
|
+
require 'gaigo/has_locale'
|
3
|
+
require 'gaigo/models/naming'
|
4
|
+
|
5
|
+
module Gaigo
|
6
|
+
|
7
|
+
module ActiveRecordExtension
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
class_eval do
|
12
|
+
include Gaigo::Utilities
|
13
|
+
include Gaigo::HasLocale
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
include Gaigo::Utilities
|
18
|
+
include Gaigo::Naming::HumanAttributeName
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Gaigo
|
2
|
+
module Localized
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def has_locale?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def try_native_attribute_name(attribute, options = {})
|
12
|
+
try_human_attribute_name(attribute, options.merge(:locale => locale))
|
13
|
+
end
|
14
|
+
|
15
|
+
def locale=(value)
|
16
|
+
super(check_locale_code(value))
|
17
|
+
end
|
18
|
+
|
19
|
+
def lang
|
20
|
+
LANGS.get(locale)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Gaigo
|
2
|
+
module Naming
|
3
|
+
module HumanAttributeName
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
delegate :try_human_attribute_name, :to => "self.class"
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def try_human_attribute_name(attribute, options = {}, &block)
|
13
|
+
options = { :count => 1 }.merge!(options)
|
14
|
+
parts = attribute.to_s.split(".")
|
15
|
+
attribute = parts.pop
|
16
|
+
namespace = parts.join("/") unless parts.empty?
|
17
|
+
attributes_scope = "#{self.i18n_scope}.attributes"
|
18
|
+
|
19
|
+
if namespace
|
20
|
+
defaults = lookup_ancestors.map do |klass|
|
21
|
+
:"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}"
|
22
|
+
end
|
23
|
+
defaults << :"#{attributes_scope}.#{namespace}.#{attribute}"
|
24
|
+
else
|
25
|
+
defaults = lookup_ancestors.map do |klass|
|
26
|
+
:"#{attributes_scope}.#{klass.model_name.i18n_key}.#{attribute}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
if block_given? #
|
31
|
+
yield defaults #
|
32
|
+
end #
|
33
|
+
|
34
|
+
defaults << :"attributes.#{attribute}"
|
35
|
+
defaults << options.delete(:default) if options[:default]
|
36
|
+
|
37
|
+
options[:default] = defaults
|
38
|
+
|
39
|
+
I18n.try_translate(defaults.shift, options) do |args, options|
|
40
|
+
options[:default] << attribute.humanize
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Gaigo
|
2
|
+
module Naming
|
3
|
+
module HumanModelName
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
def try_human(options={}, &block)
|
13
|
+
options = { :count => 1 }.merge!(options)
|
14
|
+
return @human unless @klass.respond_to?(:lookup_ancestors) &&
|
15
|
+
@klass.respond_to?(:i18n_scope)
|
16
|
+
|
17
|
+
defaults = @klass.lookup_ancestors.map do |klass|
|
18
|
+
:"#{klass.i18n_scope}.models.#{klass.model_name.i18n_key}" ## changed
|
19
|
+
end
|
20
|
+
|
21
|
+
if block_given? #
|
22
|
+
yield defaults #
|
23
|
+
end #
|
24
|
+
|
25
|
+
defaults << options.delete(:default) if options[:default]
|
26
|
+
|
27
|
+
options[:default] = defaults
|
28
|
+
|
29
|
+
I18n.try_translate(defaults.shift, options) do
|
30
|
+
options[:default] << @human
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
config.before_initialize do
|
6
|
+
ActiveSupport.on_load :active_record do
|
7
|
+
require 'gaigo/models/active_record_extension'
|
8
|
+
include ActiveRecordExtension
|
9
|
+
end
|
10
|
+
ActiveSupport.on_load :action_view do
|
11
|
+
require 'gaigo/helpers/action_view_extension'
|
12
|
+
include ActionViewExtension
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Gaigo
|
2
|
+
|
3
|
+
module Utilities
|
4
|
+
|
5
|
+
def check_locale_code(code)
|
6
|
+
if lang = LANGS.get(code)
|
7
|
+
lang.code
|
8
|
+
else
|
9
|
+
raise(Exception, "Unacceptable locale code: #{code}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_country_code(code)
|
14
|
+
if country = COUNTRIES.get(code)
|
15
|
+
country.code
|
16
|
+
else
|
17
|
+
raise(Exception, "Unacceptable country code: #{code}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/gaigo.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "gaigo/version"
|
2
|
+
|
3
|
+
module Gaigo
|
4
|
+
def self.load!
|
5
|
+
load_langs!
|
6
|
+
load_countries!
|
7
|
+
i18n_extend!
|
8
|
+
require 'gaigo/engine'
|
9
|
+
require 'gaigo/railtie'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.load_langs!
|
13
|
+
require 'gaigo/langs'
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_countries!
|
17
|
+
require 'gaigo/countries'
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.i18n_extend!
|
21
|
+
require 'gaigo/i18n_extend'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
Gaigo.load!
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gaigo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Valery Kvon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: i18n
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: 76 world's languages and codes
|
31
|
+
email:
|
32
|
+
- addagger@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- CHANGELOG
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- README.rdoc
|
43
|
+
- Rakefile
|
44
|
+
- gaigo.gemspec
|
45
|
+
- lib/gaigo.rb
|
46
|
+
- lib/gaigo/countries.rb
|
47
|
+
- lib/gaigo/engine.rb
|
48
|
+
- lib/gaigo/has_locale.rb
|
49
|
+
- lib/gaigo/helpers/action_view_extension.rb
|
50
|
+
- lib/gaigo/helpers/form_helper_v3.rb
|
51
|
+
- lib/gaigo/helpers/form_helper_v3/form_builder.rb
|
52
|
+
- lib/gaigo/helpers/form_helper_v3/instance_tag.rb
|
53
|
+
- lib/gaigo/helpers/form_helper_v4.rb
|
54
|
+
- lib/gaigo/helpers/form_helper_v4/form_builder.rb
|
55
|
+
- lib/gaigo/helpers/form_helper_v4/tags.rb
|
56
|
+
- lib/gaigo/i18n_extend.rb
|
57
|
+
- lib/gaigo/i18n_extend/try_translate.rb
|
58
|
+
- lib/gaigo/langs.rb
|
59
|
+
- lib/gaigo/library/countries.rb
|
60
|
+
- lib/gaigo/library/langs.rb
|
61
|
+
- lib/gaigo/models/active_record_extension.rb
|
62
|
+
- lib/gaigo/models/localized.rb
|
63
|
+
- lib/gaigo/models/naming.rb
|
64
|
+
- lib/gaigo/models/naming/human_attribute_name.rb
|
65
|
+
- lib/gaigo/models/naming/human_model_name.rb
|
66
|
+
- lib/gaigo/railtie.rb
|
67
|
+
- lib/gaigo/utilities.rb
|
68
|
+
- lib/gaigo/version.rb
|
69
|
+
homepage: http://vkvon.ru/projects/gaigo
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project: gaigo
|
90
|
+
rubygems_version: 1.8.24
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: World's languages/countries, locale attribute for Rails' models
|
94
|
+
test_files: []
|