summaryrefslogtreecommitdiff
path: root/vendor
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-06-15 17:14:26 -0700
committerelijah <elijah@riseup.net>2015-06-15 17:14:26 -0700
commit83a9cadbb13bd2292c7d064d40721fa5f64119fb (patch)
tree294c13678a0514634a6817428d2c656738c14e52 /vendor
parent12ab515ecd448f98ff006e30a93e43626183b6d0 (diff)
added CommonLanguages gem
Diffstat (limited to 'vendor')
-rw-r--r--vendor/gems/common_languages/LICENSE.txt22
-rw-r--r--vendor/gems/common_languages/README.md36
-rw-r--r--vendor/gems/common_languages/Rakefile5
-rw-r--r--vendor/gems/common_languages/common_languages.gemspec23
-rw-r--r--vendor/gems/common_languages/lib/common_languages.rb46
-rw-r--r--vendor/gems/common_languages/lib/common_languages/data.rb116
-rw-r--r--vendor/gems/common_languages/lib/common_languages/language.rb19
-rw-r--r--vendor/gems/common_languages/lib/common_languages/version.rb3
-rw-r--r--vendor/gems/common_languages/test/test_helper.rb3
-rw-r--r--vendor/gems/common_languages/test/usage_test.rb33
10 files changed, 306 insertions, 0 deletions
diff --git a/vendor/gems/common_languages/LICENSE.txt b/vendor/gems/common_languages/LICENSE.txt
new file mode 100644
index 0000000..f1423ff
--- /dev/null
+++ b/vendor/gems/common_languages/LICENSE.txt
@@ -0,0 +1,22 @@
+Copyright (c) 2015 LEAP Encryption Access Project
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/gems/common_languages/README.md b/vendor/gems/common_languages/README.md
new file mode 100644
index 0000000..264fe0a
--- /dev/null
+++ b/vendor/gems/common_languages/README.md
@@ -0,0 +1,36 @@
+# CommonLanguages
+
+A simple gem that provides the ability to display the list of
+I18n.available_locales in a localized and friendly way.
+
+There are many similar or related gems. For example:
+
+* https://github.com/davec/localized_language_select
+* https://github.com/teonimesic/language_switcher
+* https://github.com/grosser/i18n_data
+* https://github.com/scsmith/language_list
+
+I wanted something different than what these others provide:
+
+* Language names should be displayed in the native name for each language, not
+ a localized or anglicized version.
+* There should not be any gem dependencies.
+* Since there is no universal collation across all languages, they should be
+ sorted in order of popularity.
+* There should not be any need to parse large data files, 99% of which will
+ never be used.
+
+# Usage
+
+This code:
+
+ I18n.available_locales = [:de, :en, :pt]
+ CommonLanguages.available.each do |language|
+ p [language.code, language.name, language.english_name, language.rtl?]
+ end
+
+Produces:
+
+ [:en, "English", "English", false]
+ [:pt, "Português", "Portugues", false]
+ [:de, "Deutsch", "German", false] \ No newline at end of file
diff --git a/vendor/gems/common_languages/Rakefile b/vendor/gems/common_languages/Rakefile
new file mode 100644
index 0000000..b7af52d
--- /dev/null
+++ b/vendor/gems/common_languages/Rakefile
@@ -0,0 +1,5 @@
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.test_files = FileList['test/*_test.rb']
+end
+task :default => :test \ No newline at end of file
diff --git a/vendor/gems/common_languages/common_languages.gemspec b/vendor/gems/common_languages/common_languages.gemspec
new file mode 100644
index 0000000..cc67b5a
--- /dev/null
+++ b/vendor/gems/common_languages/common_languages.gemspec
@@ -0,0 +1,23 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'common_languages/version'
+
+Gem::Specification.new do |spec|
+ spec.name = "common_languages"
+ spec.version = CommonLanguages::VERSION
+ spec.authors = ["elijah"]
+ spec.email = ["elijah@leap.se"]
+ spec.summary = %q{Information on the most common languages.}
+ spec.description = %q{Information on the most common languages, including native name and script direction.}
+ spec.homepage = ""
+ spec.license = "MIT"
+
+ spec.files = Dir['lib/*.rb', 'lib/*/*.rb'] + ['README.md', 'LICENSE.txt']
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
+ spec.require_paths = ["lib"]
+
+ spec.add_dependency "i18n"
+ spec.add_development_dependency "minitest"
+end
diff --git a/vendor/gems/common_languages/lib/common_languages.rb b/vendor/gems/common_languages/lib/common_languages.rb
new file mode 100644
index 0000000..0b2d9c2
--- /dev/null
+++ b/vendor/gems/common_languages/lib/common_languages.rb
@@ -0,0 +1,46 @@
+# encoding: utf-8
+
+require_relative "common_languages/version"
+require_relative "common_languages/data"
+require_relative "common_languages/language"
+
+module CommonLanguages
+ def self.available_codes
+ @available_codes ||= self.codes & I18n.available_locales.map(&:to_s)
+ end
+
+ def self.available
+ @available ||= self.available_codes.map {|lc| self.get(lc) }
+ end
+
+ def self.available_code?(code)
+ if !code.nil?
+ self.available_codes.include?(code.to_s)
+ else
+ false
+ end
+ end
+
+ def self.get(code)
+ if !code.nil?
+ self.languages[code.to_s]
+ else
+ false
+ end
+ end
+
+ # a regexp that will match the available codes
+ def self.match_available
+ @match_available ||= /(#{self.available_codes.join('|')})/
+ end
+
+ # clears caches, useful only when testing
+ def self.reset
+ @codes = nil
+ @available_codes = nil
+ @available = nil
+ @languages = nil
+ @match = nil
+ @match_available = nil
+ end
+end
diff --git a/vendor/gems/common_languages/lib/common_languages/data.rb b/vendor/gems/common_languages/lib/common_languages/data.rb
new file mode 100644
index 0000000..965e18b
--- /dev/null
+++ b/vendor/gems/common_languages/lib/common_languages/data.rb
@@ -0,0 +1,116 @@
+# encoding: utf-8
+
+module CommonLanguages
+
+ #
+ # Language data, sorted by number of native speakers
+ # https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers
+ #
+ # fields: code, name, english name, right to left?
+ #
+ DATA = [
+ ['zh', '中文', 'Chinese'],
+ ['es', 'Español', 'Spanish'],
+ ['en', 'English'],
+ ['hi', 'हिन्दी', 'Hindi'],
+ ['ar', 'العربية', 'Arabic', true],
+ ['pt', 'Português', 'Portugues'],
+ ['bn', 'বাংলা', 'Bengali'],
+ ['ru', 'Pyccĸий', 'Russian'],
+ ['ja', '日本語', 'Japanese'],
+ ['pa', 'ਪੰਜਾਬੀ', 'Punjabi'],
+ ['de', 'Deutsch', 'German'],
+ ['ms', 'بهاس ملايو', 'Malay'],
+ ['te', 'తెలుగు', 'Telugu'],
+ ['vi', 'Tiếng Việt', 'Vietnamese'],
+ ['ko', '한국어', 'Korean'],
+ ['fr', 'Français', 'French'],
+ ['mr', 'मराठी', 'Marathi'],
+ ['ta', 'தமிழ்', 'Tamil'],
+ ['ur', 'اُردُو', 'Urdu'],
+ ['fa', 'فارسی', 'Farsi'],
+ ['tr', 'Türkçe', 'Turkish'],
+ ['it', 'Italiano', 'Italian'],
+ ['th', 'ภาษาไทย', 'Thai'],
+ ['gu', 'Gujarati'],
+ ['pl', 'Polski', 'Polish'],
+ ['ml', 'Malayalam'],
+ ['uk', 'Ukrainian'],
+ ['sw', 'Swahili'],
+ ['uz', 'Uzbek'],
+ ['ro', 'Romanian'],
+ ['nl', 'Nederlands', 'Dutch'],
+ ['sr', 'Serbian'],
+ ['el', 'Ελληνικά', 'Greek'],
+ ['ca', 'Català', 'Catalan'],
+ ['he', 'עברית', 'Hebrew', true]
+ ]
+
+ # just the codes, in sorted order
+ def self.codes
+ @codes ||= DATA.map {|d| d[0]}
+ end
+
+ # a regexp that will match the possible codes
+ def self.match
+ @match ||= /(#{@codes.join('|')})/
+ end
+
+ # map of codes to Language objects
+ # e.g. languages['en'] => <Language>
+ def self.languages
+ @languages ||= Hash[
+ DATA.map {|data|
+ [data[0], Language.new(data)]
+ }
+ ]
+ end
+
+end
+
+#
+# TO BE ADDED
+#
+# [:bn, 'Bengali']
+# [:bo, 'Tibetan']
+# [:bg, 'Bulgarian']
+# [:ca, 'Catalan']
+# [:cs, 'Czech']
+# [:cy, 'Welsh']
+# [:da, 'Danish']
+# [:et, 'Estonian']
+# [:eu, 'Basque']
+# [:fj, 'Fijian']
+# [:fi, 'Finnish']
+# [:ga, 'Irish']
+# [:hr, 'Croatian']
+# [:hu, 'Hungarian']
+# [:hy, 'Armenian']
+# [:id, 'Indonesian']
+# [:is, 'Icelandic']
+# [:ka, 'Georgian']
+# [:km, 'Central Khmer']
+# [:lv, 'Latvian']
+# [:lt, 'Lithuanian']
+# [:mr, 'Marathi']
+# [:mk, 'Macedonian']
+# [:mt, 'Maltese']
+# [:mn, 'Mongolian']
+# [:mi, 'Maori']
+# [:ms, 'Malay']
+# [:ne, 'Nepali']
+# [:no, 'Norwegian']
+# [:pa, 'Panjabi']
+# [:qu, 'Quechua']
+# [:sk, 'Slovak']
+# [:sl, 'Slovenian']
+# [:sm, 'Samoan']
+# [:sq, 'Albanian']
+# [:sv, 'Swedish']
+# [:ta, 'Tamil']
+# [:tt, 'Tatar']
+# [:te, 'Telugu']
+# [:to, 'Tonga']
+# [:tr, 'Turkish']
+# [:ur, 'Urdu']
+# [:xh, 'Xhosa']
diff --git a/vendor/gems/common_languages/lib/common_languages/language.rb b/vendor/gems/common_languages/lib/common_languages/language.rb
new file mode 100644
index 0000000..a6a3521
--- /dev/null
+++ b/vendor/gems/common_languages/lib/common_languages/language.rb
@@ -0,0 +1,19 @@
+# encoding: utf-8
+
+module CommonLanguages
+ class Language
+ attr_accessor :code, :name, :english_name, :rtl
+ def initialize(data)
+ @code = data[0].to_sym
+ @name = data[1]
+ @english_name = data[2] || data[1]
+ @rtl = data[3] === true
+ end
+ def rtl?
+ @rtl
+ end
+ def ==(l)
+ @code == l.code && @name = l.name
+ end
+ end
+end
diff --git a/vendor/gems/common_languages/lib/common_languages/version.rb b/vendor/gems/common_languages/lib/common_languages/version.rb
new file mode 100644
index 0000000..bb42aff
--- /dev/null
+++ b/vendor/gems/common_languages/lib/common_languages/version.rb
@@ -0,0 +1,3 @@
+module CommonLanguages
+ VERSION = "0.0.1"
+end
diff --git a/vendor/gems/common_languages/test/test_helper.rb b/vendor/gems/common_languages/test/test_helper.rb
new file mode 100644
index 0000000..339e22d
--- /dev/null
+++ b/vendor/gems/common_languages/test/test_helper.rb
@@ -0,0 +1,3 @@
+gem 'minitest'
+require 'minitest/autorun'
+require_relative '../lib/common_languages'
diff --git a/vendor/gems/common_languages/test/usage_test.rb b/vendor/gems/common_languages/test/usage_test.rb
new file mode 100644
index 0000000..dc545f4
--- /dev/null
+++ b/vendor/gems/common_languages/test/usage_test.rb
@@ -0,0 +1,33 @@
+require_relative 'test_helper'
+require 'i18n'
+
+class UsageTest < MiniTest::Test
+
+ def setup
+ CommonLanguages.reset
+ end
+
+ def test_available_codes_are_sorted
+ I18n.available_locales = ['pt', 'en', :de, :es]
+ assert_equal ['es', 'en', 'pt', 'de'], CommonLanguages.available_codes
+ end
+
+ def test_available
+ I18n.available_locales = [:en]
+ english = CommonLanguages::Language.new(CommonLanguages::DATA[2])
+ assert_equal english, CommonLanguages.get(:en)
+ assert_equal [english], CommonLanguages.available
+ end
+
+ def test_unique_codes
+ assert_equal CommonLanguages::DATA.size, CommonLanguages::languages.size
+ end
+
+ #def test_data
+ # I18n.available_locales = [:en, :de, :pt]
+ # CommonLanguages.available.each do |language|
+ # p [language.code, language.name, language.english_name, language.rtl?]
+ # end
+ #end
+
+end