flag_icon 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +18 -12
- data/lib/flag_icon/helpers.rb +21 -13
- data/lib/flag_icon/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eb44a2a8ed7fb1441698dcea487554797d9a325e94dc85fd56b7652c01d23c6
|
4
|
+
data.tar.gz: 95f2d1a9f896e7aa0678dd41bbff73f7cb2f26a2eb747fa9b82b15c40bf2c30e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8acf0dc35b8fe1fe8afdec533f17062b7dc283431d6b0a96a711d999f2c72f9c81a967c318f7df7a1f8e84567adbec0b4cb36bc4b4d9ac33a5915c91147656b4
|
7
|
+
data.tar.gz: 7d949f724295bffd37af1347e7b7ef42a8d705d4fbf6ab199caa420bd2cebd13684e5ff6662c3016b954f758cae5eb064b765686d6bb29b4b07117d7b730121c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,16 +2,15 @@
|
|
2
2
|
[](https://badge.fury.io/rb/flag_icon)
|
3
3
|
|
4
4
|
### Purpose
|
5
|
-
An attempt to map languages to flags!
|
5
|
+
An attempt to map languages to country flags!
|
6
6
|
|
7
7
|
### Approach
|
8
8
|
Matching flags to languages can be really tricky and even problematic sometimes because there is no direct association
|
9
|
-
between languages and countries since the same language is spoken in many countries and many languages are spoken in a single.
|
10
|
-
So a effort was made to identify the official language of each country and then assign the flag to the language not the country.
|
9
|
+
between languages and countries since the same language is spoken in many countries and many languages are spoken in a single country.
|
11
10
|
|
12
11
|
So for a title from Mexico which has spanish as the official language the spanish flag will appear.
|
13
12
|
|
14
|
-
|
13
|
+
If you notice any flags being mismatched please raise an [issue](https://github.com/alexwebgr/flag_icon/issues)
|
15
14
|
or even better open a [pull request](https://github.com/alexwebgr/flag_icon/pulls)
|
16
15
|
|
17
16
|
|
@@ -43,12 +42,12 @@ There is a number of helpers available that will render country names, language
|
|
43
42
|
language_icon
|
44
43
|
```
|
45
44
|
```ruby
|
46
|
-
# It returns HTML element with country icon
|
45
|
+
# It returns HTML element with country icon and title
|
47
46
|
#
|
48
47
|
# @param code -> country iso code
|
49
|
-
# @example
|
48
|
+
# @example country_icon('gr')
|
50
49
|
# @return String
|
51
|
-
|
50
|
+
country_icon
|
52
51
|
```
|
53
52
|
```ruby
|
54
53
|
# It returns the language name
|
@@ -62,7 +61,7 @@ language_name
|
|
62
61
|
# It returns the country name
|
63
62
|
#
|
64
63
|
# @param code -> country iso code
|
65
|
-
# @example
|
64
|
+
# @example country_name('gr') # => Greece
|
66
65
|
# @return String
|
67
66
|
country_name
|
68
67
|
```
|
@@ -70,18 +69,25 @@ country_name
|
|
70
69
|
# It returns the country iso code
|
71
70
|
#
|
72
71
|
# @param code -> language locale
|
73
|
-
# @example
|
72
|
+
# @example language_flag('el') # => gr
|
74
73
|
# @return String
|
75
74
|
language_flag
|
76
75
|
```
|
77
76
|
```ruby
|
78
|
-
# It returns the
|
77
|
+
# It returns an array that can be used in the select tag
|
78
|
+
#
|
79
|
+
# @example select_language
|
80
|
+
# @return Array
|
81
|
+
select_language
|
82
|
+
```
|
83
|
+
```ruby
|
84
|
+
# It returns an hash of arrays that can be used in the select tag
|
79
85
|
#
|
80
86
|
# @param popular -> title of the popular group
|
81
87
|
# @param available -> title of the available group
|
82
|
-
# @example
|
88
|
+
# @example grouped_select_language(popular: 'Popular', available: 'Available')
|
83
89
|
# @return Hash
|
84
|
-
|
90
|
+
grouped_select_language
|
85
91
|
```
|
86
92
|
```ruby
|
87
93
|
# Define in your application_helper to override the popular languages
|
data/lib/flag_icon/helpers.rb
CHANGED
@@ -11,7 +11,7 @@ module FlagIcon
|
|
11
11
|
# It returns the country name
|
12
12
|
#
|
13
13
|
# @param code -> country iso code
|
14
|
-
# @example
|
14
|
+
# @example country_name('gr') # => Greece
|
15
15
|
# @return String
|
16
16
|
def country_name(code)
|
17
17
|
FlagIcon::Countries::NAMES[code.to_sym]
|
@@ -20,42 +20,49 @@ module FlagIcon
|
|
20
20
|
# It returns the country iso code
|
21
21
|
#
|
22
22
|
# @param code -> language locale
|
23
|
-
# @example
|
23
|
+
# @example language_flag('el') # => gr
|
24
24
|
# @return String
|
25
25
|
def language_flag(code)
|
26
26
|
FlagIcon::Countries::LANGUAGE_FLAGS[code.to_sym] || 'xx'
|
27
27
|
end
|
28
28
|
|
29
|
-
# It returns the
|
29
|
+
# It returns an array that can be used in the select tag
|
30
|
+
#
|
31
|
+
# @example select_language
|
32
|
+
# @return Array
|
33
|
+
def select_language
|
34
|
+
available_languages.map { |lang| [language_name(lang), lang] }
|
35
|
+
end
|
36
|
+
|
37
|
+
# It returns an hash of arrays that can be used in the select tag
|
30
38
|
#
|
31
39
|
# @param popular -> title of the popular group
|
32
40
|
# @param available -> title of the available group
|
33
|
-
# @example
|
41
|
+
# @example grouped_select_language(popular: 'Popular', available: 'Available')
|
34
42
|
# @return Hash
|
35
|
-
def
|
43
|
+
def grouped_select_language(popular: 'Popular', available: 'Available')
|
36
44
|
{
|
37
45
|
popular => popular_languages,
|
38
46
|
available => available_languages.map { |lang| [language_name(lang), lang] }
|
39
47
|
}
|
40
48
|
end
|
41
49
|
|
42
|
-
|
43
50
|
# It returns HTML element with country icon and title
|
44
51
|
#
|
45
52
|
# @param code -> language locale
|
46
53
|
# @example language_icon('el')
|
47
54
|
# @return String
|
48
|
-
def language_icon(code)
|
49
|
-
"<span class='flag-icon flag-icon-#{language_flag(code)}' title='
|
55
|
+
def language_icon(code, title: "Audio language - #{language_name(code)}")
|
56
|
+
"<span class='flag-icon flag-icon-#{language_flag(code)}' title='#{title}'></span>"
|
50
57
|
end
|
51
58
|
|
52
|
-
# It returns HTML element with country icon
|
59
|
+
# It returns HTML element with country icon and title
|
53
60
|
#
|
54
61
|
# @param code -> country iso code
|
55
|
-
# @example
|
62
|
+
# @example country_icon('gr')
|
56
63
|
# @return String
|
57
|
-
def
|
58
|
-
"<span class='flag-icon flag-icon-#{code}' title='
|
64
|
+
def country_icon(code, title: "Available in #{country_name(code)}")
|
65
|
+
"<span class='flag-icon flag-icon-#{code}' title='#{title}'></span>"
|
59
66
|
end
|
60
67
|
|
61
68
|
# Define in your application_helper to override the popular languages
|
@@ -86,8 +93,9 @@ module FlagIcon
|
|
86
93
|
module_function :country_name
|
87
94
|
module_function :language_flag
|
88
95
|
module_function :select_language
|
96
|
+
module_function :grouped_select_language
|
89
97
|
module_function :language_icon
|
90
|
-
module_function :
|
98
|
+
module_function :country_icon
|
91
99
|
module_function :popular_languages
|
92
100
|
module_function :available_languages
|
93
101
|
end
|