language-select 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWE1YWI1NTg3ZmI1ODlkMmI5NmUxN2RjZmY1NzBjZDhmNWUxZTA5ZQ==
5
+ data.tar.gz: !binary |-
6
+ N2UxNDllOTcyOTg3Y2ZjMThmYzVkYTE1ZmQ0ZTRmNWU3YWU5YWJiNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDU0NGY0YWU4NjdhZWViZjNmODkzMDAyMDU4ZGFiNDE1ODk2Yjc0OWZhMTlj
10
+ YzBkYTY4MWI0YzVkZDhkZjc5NGJmZjJhMTY4MDJkNWNlY2RiNDc3MzY0NjVm
11
+ NjZiOTA3NmQwNTQwNTkwZWRiMDU3Y2JjZGJmNGE4M2FiOTE2ZDU=
12
+ data.tar.gz: !binary |-
13
+ NTc3Mzc3NDQ5OWQ4Njc1MGNkN2UwMGI1NGMzYjNmYWJlYjZjODM2ODQwNTNk
14
+ MzdkMzU0MjU3NGFiMGQwYjhkNzgzZDczNGExZTY1MWQzYTk1MjVkZjljNTNj
15
+ NWQwMWU4ZjNkODRjZjUzMDM2OWQyMjNiYTgxNjBmODJhOTQ2MDk=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in language-select.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Viduranga Wijesooriya
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,39 @@
1
+ # Language Select
2
+
3
+ Ruby gem to populate language select dropdown list
4
+
5
+ Provides a simple helper to get an HTML select list of languages. The list of countries comes from the ISO ISO 639-1 standard (http://www.w3schools.com/tags/ref_language_codes.asp).
6
+
7
+
8
+ ## Installation
9
+
10
+ Install as a gem using
11
+
12
+ gem install language-select
13
+
14
+ Or put the following in your Gemfile
15
+
16
+ gem 'language-select'
17
+
18
+ ## Example
19
+
20
+ Simple use supplying model and attribute as parameters:
21
+
22
+ form.language_select("language", nil, nil)
23
+
24
+ Supplying specific countries to be listed instead of all the languages:
25
+
26
+ country_select("language", [ "English", "Spanish", "French" ], nil, nil)
27
+
28
+ Supplying additional languages to be listed, additinally to the default list of languages:
29
+
30
+ country_select("language", nil, [ "English", "Spanish", "French" ], nil)
31
+
32
+ Supplying priority languages to be listed at the top of the list:
33
+
34
+ country_select("language", nil, nil [ "English", "Spanish", "French" ])
35
+
36
+
37
+
38
+
39
+ Copyright (c) 2014 Viduranga Wijesooriya, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "language-select"
8
+ spec.version = "1.1.1"
9
+ spec.date = "2014-07-28"
10
+ spec.authors = ["Viduranga Wijesooriya"]
11
+ spec.email = ["vpowerrc@gmail.com"]
12
+ spec.summary = ""
13
+ spec.description = "Ruby gem to populate language select dropdown list"
14
+ spec.homepage = "https://github.com/vpowerrc/language-select"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,70 @@
1
+ # CountrySelect
2
+ module ActionView
3
+ module Helpers
4
+ module FormOptionsHelper
5
+ mattr_accessor :language_list
6
+
7
+ #Read language json file
8
+ language_file_path = File.expand_path("../languages.json", __FILE__)
9
+ language_file = File.read(language_file_path)
10
+ #Adds all the languages in the languages.json file
11
+ self.language_list = JSON.parse(language_file)
12
+
13
+ # Return select and option tags for the given object and method, using language_options_for_select to generate the list of option tags.
14
+ def language_select(object, method, specific_languages = nil, additional_languages = nil, priority_languages = nil, options = {}, html_options = {})
15
+ InstanceTag.new(object, method, self, options.delete(:object)).to_language_select_tag(specific_languages, additional_languages, priority_languages, options, html_options)
16
+ end
17
+
18
+ # Returns a string of option tags for standered languages in the world.
19
+ # You can also supply an array of languages as 'specific_languages', so that only they will be listed intead of the long list of languages.
20
+ # You can also supply an array of languages as 'additional_languages', so that they will be listed additinally to the default list.
21
+ # You can also supply an array of languages as 'priority_languages', so that they will be listed above the rest of the (long) list.
22
+
23
+ def language_options_for_select(specific = nil,specific_languages = nil, additional_languages = nil, priority_languages = nil)
24
+ languages_list = FormOptionsHelper.language_list
25
+ language_options = ""
26
+
27
+
28
+ # Adds the languages specified in the tag
29
+ if specific_languages
30
+ languages_list = Hash[ languages_list.select{|k, _| specific_languages.include?(k)} ]
31
+ end
32
+ # Adds additional languages
33
+ if additional_languages
34
+ languages_list = languages_list.merge(additional_languages).sort
35
+ end
36
+ # Adds the priority languages
37
+ if priority_languages
38
+ priority_languages_hash = Hash[ languages_list.select{|k, _| priority_languages.include?(k)} ]
39
+ language_options += options_for_select(priority_languages_hash, specific)
40
+ language_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
41
+ specific=nil if priority_languages.include?(specific)
42
+ end
43
+
44
+ language_options += options_for_select(languages_list, specific)
45
+ language_options = language_options.html_safe if language_options.respond_to?(:html_safe)
46
+ return language_options
47
+ end
48
+ end
49
+
50
+ class InstanceTag
51
+ def to_language_select_tag(specific_languages, additional_languages, priority_languages, options, html_options)
52
+ html_options = html_options.stringify_keys
53
+ add_default_name_and_id(html_options)
54
+ value = value(object)
55
+ content_tag("select",
56
+ add_options(
57
+ language_options_for_select(value, specific_languages, additional_languages, priority_languages),
58
+ options, value
59
+ ), html_options
60
+ )
61
+ end
62
+ end
63
+
64
+ class FormBuilder
65
+ def language_select(method, specific_languages = nil, additional_languages = nil, priority_languages = nil, options = {}, html_options = {})
66
+ @template.language_select(@object_name, method, specific_languages, additional_languages, priority_languages, options.merge(:object => @object), html_options)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,162 @@
1
+ {
2
+ "Abkhazian": "ab",
3
+ "Afar": "aa",
4
+ "Afrikaans": "af",
5
+ "Albanian": "sq",
6
+ "Amharic": "am",
7
+ "Arabic": "ar",
8
+ "Aragonese": "an",
9
+ "Armenian": "hy",
10
+ "Assamese": "as",
11
+ "Aymara": "ay",
12
+ "Azerbaijani": "az",
13
+ "Bashkir": "ba",
14
+ "Basque": "eu",
15
+ "Bengali (Bangla)": "bn",
16
+ "Bhutani": "dz",
17
+ "Bihari": "bh",
18
+ "Bislama": "bi",
19
+ "Breton": "br",
20
+ "Bulgarian": "bg",
21
+ "Burmese": "my",
22
+ "Byelorussian (Belarusian)": "be",
23
+ "Cambodian": "km",
24
+ "Catalan": "ca",
25
+ "Cherokee": "chr",
26
+ "Chewa": "nya",
27
+ "Chinese": "zh",
28
+ "Chinese (Simplified)": "zh-Hans",
29
+ "Chinese (Traditional)": "zh-Hant",
30
+ "Corsican": "co",
31
+ "Croatian": "hr",
32
+ "Czech": "cs",
33
+ "Danish": "da",
34
+ "Divehi": "div",
35
+ "Dutch": "nl",
36
+ "Edo": "bin",
37
+ "English": "en",
38
+ "Esperanto": "eo",
39
+ "Estonian": "et",
40
+ "Faeroese": "fo",
41
+ "Farsi": "fa",
42
+ "Fiji": "fj",
43
+ "Finnish": "fi",
44
+ "French": "fr",
45
+ "Frisian": "fy",
46
+ "Fulfulde": "ful",
47
+ "Galician": "gl",
48
+ "Gaelic (Scottish)": "gd",
49
+ "Gaelic (Manx)": "gv",
50
+ "Georgian": "ka",
51
+ "German": "de",
52
+ "Greek": "el",
53
+ "Greenlandic": "kl",
54
+ "Guarani": "gn",
55
+ "Gujarati": "gu",
56
+ "Haitian Creole": "ht",
57
+ "Hausa": "ha",
58
+ "Hawaiian": "haw",
59
+ "Hebrew he": "iw",
60
+ "Hindi": "hi",
61
+ "Hungarian": "hu",
62
+ "Icelandic": "is",
63
+ "Ido": "io",
64
+ "Igbo": "ibo",
65
+ "Indonesian": "in",
66
+ "Interlingua": "ia",
67
+ "Interlingue": "ie",
68
+ "Inuktitut": "iu",
69
+ "Inupiak": "ik",
70
+ "Irish": "ga",
71
+ "Italian": "it",
72
+ "Japanese": "ja",
73
+ "Javanese": "jv",
74
+ "Kannada": "kn",
75
+ "Kanuri": "kau",
76
+ "Kashmiri": "ks",
77
+ "Kazakh": "kk",
78
+ "Kinyarwanda (Ruanda)": "rw",
79
+ "Kirghiz": "ky",
80
+ "Kirundi (Rundi)": "rn",
81
+ "Konkani": "kok",
82
+ "Korean": "ko",
83
+ "Kurdish": "ku",
84
+ "Laothian": "lo",
85
+ "Latin": "la",
86
+ "Latvian (Lettish)": "lv",
87
+ "Limburgish ( Limburger)": "li",
88
+ "Lingala": "ln",
89
+ "Lithuanian": "lt",
90
+ "Macedonian": "mk",
91
+ "Malagasy": "mg",
92
+ "Malay": "ms",
93
+ "Malayalam": "ml",
94
+ "Maltese": "mt",
95
+ "Maori": "mi",
96
+ "Marathi": "mr",
97
+ "Moldavian": "mo",
98
+ "Mongolian": "mn",
99
+ "Nauru": "na",
100
+ "Nepali": "ne",
101
+ "Norwegian": "no",
102
+ "Occitan": "oc",
103
+ "Oriya": "or",
104
+ "Oromo (Afaan Oromo)": "om",
105
+ "Papiamentu": "pap",
106
+ "Pashto (Pushto)": "ps",
107
+ "Polish": "pl",
108
+ "Portuguese": "pt",
109
+ "Punjabi": "pa",
110
+ "Quechua": "qu",
111
+ "Rhaeto-Romance": "rm",
112
+ "Romanian": "ro",
113
+ "Russian": "ru",
114
+ "Samoan": "sm",
115
+ "Sangro": "sg",
116
+ "Sanskrit": "sa",
117
+ "Serbian": "sr",
118
+ "Serbo-Croatian": "sh",
119
+ "Sesotho": "st",
120
+ "Setswana": "tn",
121
+ "Shona": "sn",
122
+ "Sichuan Yi": "ii",
123
+ "Sindhi": "sd",
124
+ "Sinhalese": "si",
125
+ "Siswati": "ss",
126
+ "Slovak": "sk",
127
+ "Slovenian": "sl",
128
+ "Somali": "so",
129
+ "Spanish": "es",
130
+ "Sundanese": "su",
131
+ "Swahili (Kiswahili)": "sw",
132
+ "Swedish": "sv",
133
+ "Syriac": "syr",
134
+ "Tagalog": "tl",
135
+ "Tajik": "tg",
136
+ "Tamazight": "zgh",
137
+ "Tamil": "ta",
138
+ "Tatar": "tt",
139
+ "Telugu": "te",
140
+ "Thai": "th",
141
+ "Tibetan": "bo",
142
+ "Tigrinya": "ti",
143
+ "Tonga": "to",
144
+ "Tsonga": "ts",
145
+ "Turkish": "tr",
146
+ "Turkmen": "tk",
147
+ "Twi": "tw",
148
+ "Uighur": "ug",
149
+ "Ukrainian": "uk",
150
+ "Urdu": "ur",
151
+ "Uzbek": "uz",
152
+ "Venda": "ven",
153
+ "Vietnamese": "vi",
154
+ "Volapük": "vo",
155
+ "Wallon": "wa",
156
+ "Welsh": "cy",
157
+ "Wolof": "wo",
158
+ "Xhosa": "xh",
159
+ "Yiddish yi,": "yi",
160
+ "Yoruba": "yo",
161
+ "Zulu": "zu"
162
+ }
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: language-select
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Viduranga Wijesooriya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Ruby gem to populate language select dropdown list
42
+ email:
43
+ - vpowerrc@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - language-select.gemspec
54
+ - lib/language-select.rb
55
+ - lib/languages.json
56
+ homepage: https://github.com/vpowerrc/language-select
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: ''
80
+ test_files: []