Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flag_icon

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flag_icon

  • 1.5.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

FlagIcon

Gem Version

Purpose

An attempt to map languages to country flags!

Approach

Matching flags to languages can be really tricky and even problematic sometimes because there is no direct association between languages and countries since the same language is spoken in many countries and many languages are spoken in a single country.

So for a title from Mexico which has spanish as the official language the spanish flag will appear.

If you notice any flags being mismatched please raise an issue or even better open a pull request

Installation

Add this line to your application's Gemfile:

gem 'flag_icon'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install flag_icon

Usage

There is a number of helpers available that will render country names, language names and flags given a country code or locale.

# It returns HTML element with country icon and title
#
# @param code -> language locale
# @example language_icon('el')
# @return String
language_icon
# It returns HTML element with country icon and title
#
# @param code -> country iso code
# @example country_icon('gr')
# @return String
country_icon
# It returns the language name
#
# @param code -> language locale
# @example language_name('el') # => Greek
# @return String
language_name
# It returns the country name
#
# @param code -> country iso code
# @example country_name('gr') # => Greece
# @return String
country_name
# It returns the country iso code
#
# @param code -> language locale
# @example language_flag('el') # => gr
# @return String
language_flag
# It returns an array that can be used in the select tag
#
# @example select_language
# @return Array
select_language
  # It returns an hash of arrays that can be used in the select tag
#
# @param popular -> title of the popular group
# @param available -> title of the available group
# @example grouped_select_language(popular: 'Popular', available: 'Available')
# @return Hash
grouped_select_language
# Define in your application_helper to override the popular languages
# Default: [['English', :en], ['Spanish', :es]]
#
# @example
#   def popular_languages
#     [['English', :en], ['Spanish', :es]]
#   end
# @return Array
popular_languages
# Define in your application_helper to override the available languages
# @example [['English', :en], ['Spanish', :es]] #default
# @example
#   def available_languages
#     Language.all.order(:language_locale).pluck(:language_locale)
#   end
# @return Array
available_languages

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the FlagIcon project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Credits

FAQs

Package last updated on 09 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc