scsmith / language_list Goto Github PK
View Code? Open in Web Editor NEWA list of languages based upon ISO-639-1 and ISO-639-3 with functions to retrieve only common languages.
A list of languages based upon ISO-639-1 and ISO-639-3 with functions to retrieve only common languages.
For example, LanguageList::LanguageInfo.find('greek') returns nil because "Greek" is the common name and isn't included in the BY_NAME hash.
I just noticed that the pretty cool TwitterCLDR gem has some similar functionality to language_list, possibly includes everything language_list does plus a lot more?
(Including a lot of unicode localization stuff unrelated to language lists, but also even more language code standards, and knowledge of language names in multiple languages, like "espanol" etc. )
Which context do you assume that these languages are common in? is it comparative on the global scale, or is it per country or per region per country?
In 1.1.0, you can do LanguageList::LanguageInfo.find(nil)
, and get nil
back. In 1.2.0, you get
NoMethodError: undefined method `downcase!' for nil:NilClass
from /Users/jrochkind/.gem/ruby/2.4.0/gems/language_list-1.2.0/lib/language_list.rb:65:in `find'
Probably related, it's also mutating the argument passed in.
str = "German"
LanguageList::LanguageInfo.find(str)
str # is now "german" not "German"
I don't want it mutating the arguments passed in, that's a bad practice.
Both of these things caused my build to fail upgrading from 1.1.0 to 1.2.0
Thanks very much for assembling the list of languages.
We needed a select tag of common languages, but with English and Spanish shown first. We also wanted to list both Mandarin and Cantonese, and remove the parentheticals. We used iso_639_3
to get a code for Cantonese. Others may find this useful:
# app/application_helper.rb
def our_languages
# Fix names, add Cantonese, and bring English and Spanish to the front
LanguageList::COMMON_LANGUAGES.map do |language|
[language.name.gsub('Modern Greek (1453-)', 'Greek')
.gsub('Tonga (Tonga Islands)', 'Tongan')
.gsub('Chinese', 'Chinese Mandarin'),
language.iso_639_3]
end.push(['Chinese Cantonese', 'yue']).sort.promote(%w(Spanish spa))
.promote(%w(English eng))
end
class ActionView::Helpers::FormBuilder
# http://stackoverflow.com/a/2625727/1935918
include ApplicationHelper
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
def language_select(name, options = { include_blank: true })
select_tag "#{@object_name}[#{name}]",
options_for_select(our_languages,
selected: @object.send(name)), options
end
class Array
def promote(promoted_element)
return self unless (found_index = find_index(promoted_element))
unshift(delete_at(found_index))
end
end
Is there any way to sort the list by name, rather than code?
The Moldovan language (MO) is not recognized:
LanguageList::LanguageInfo.find('mo')
=> nil
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.