world-flags 0.3.2.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,64 +1,60 @@
1
1
  module WorldFlags
2
- module Countries
3
- class << self
4
- attr_writer :en
5
-
6
- def en
7
- {
8
- :ar => 'Argentina',
9
- :br => 'Brazil',
10
- :gb => 'Great Britain',
11
- :us => 'United States',
12
- :es => 'Spain',
13
- :gr => 'Greece',
14
- :it => 'Italy',
15
- :nl => 'Netherlands',
16
- :de => 'Germany',
17
- :dk => 'Denmark',
18
- :sv => 'Sweden',
19
- :no => 'Norway',
20
- :fi => 'Finland'
21
- }
22
- end
2
+ class Countries < Hashie::Mash
3
+ def en
4
+ @en ||= {
5
+ :ar => 'Argentina',
6
+ :br => 'Brazil',
7
+ :gb => 'Great Britain',
8
+ :us => 'United States',
9
+ :es => 'Spain',
10
+ :gr => 'Greece',
11
+ :it => 'Italy',
12
+ :nl => 'Netherlands',
13
+ :de => 'Germany',
14
+ :dk => 'Denmark',
15
+ :sv => 'Sweden',
16
+ :no => 'Norway',
17
+ :fi => 'Finland'
18
+ }
19
+ end
23
20
 
24
- def da
25
- {
26
- :gb => 'England',
27
- :us => 'USA',
28
- :es => 'Spanien',
29
- :de => 'Tyskland',
30
- :dk => 'Danmark',
31
- :sv => 'Sverige',
32
- :no => 'Norge',
33
- }
34
- end
35
- alias_method :dk, :da
21
+ def da
22
+ @da ||= {
23
+ :gb => 'England',
24
+ :us => 'USA',
25
+ :es => 'Spanien',
26
+ :de => 'Tyskland',
27
+ :dk => 'Danmark',
28
+ :sv => 'Sverige',
29
+ :no => 'Norge',
30
+ }
31
+ end
32
+ alias_method :dk, :da
36
33
 
37
- def se
38
- {
39
- :gb => 'England',
40
- :us => 'USA',
41
- :es => 'Spanien',
42
- :de => 'Tyskland',
43
- :dk => 'Danmark',
44
- :sv => 'Sverige',
45
- :no => 'Norge',
46
- }
47
- end
48
- alias_method :sv, :se
34
+ def se
35
+ {
36
+ :gb => 'England',
37
+ :us => 'USA',
38
+ :es => 'Spanien',
39
+ :de => 'Tyskland',
40
+ :dk => 'Danmark',
41
+ :sv => 'Sverige',
42
+ :no => 'Norge',
43
+ }
44
+ end
45
+ alias_method :sv, :se
49
46
 
50
- def no
51
- {
52
- :gb => 'England',
53
- :us => 'USA',
54
- :es => 'Spanien',
55
- :de => 'Tyskland',
56
- :dk => 'Danmark',
57
- :se => 'Sverige',
58
- :no => 'Norge'
59
- }
60
- end
61
- alias_method :nb, :no
47
+ def no
48
+ {
49
+ :gb => 'England',
50
+ :us => 'USA',
51
+ :es => 'Spanien',
52
+ :de => 'Tyskland',
53
+ :dk => 'Danmark',
54
+ :se => 'Sverige',
55
+ :no => 'Norge'
56
+ }
62
57
  end
58
+ alias_method :nb, :no
63
59
  end
64
60
  end
@@ -0,0 +1,46 @@
1
+ module WorldFlags
2
+ module CountryUtil
3
+ def country_label code, locale
4
+ WorldFlags.country code, locale
5
+ end
6
+
7
+ def countries
8
+ @countries ||= Countries.new
9
+ end
10
+
11
+ def country code = :us, locale = :en
12
+ locale ||= default_locale_used
13
+
14
+ locale_countries_map = countries_map[locale] || countries_map[default_locale_used]
15
+ locale_countries_map = countries_map[:en] if locale_countries_map.blank?
16
+
17
+ raise "No country-locale map defined for locale: #{locale} or :en in #{countries.inspect}" if locale_countries_map.blank?
18
+
19
+ # raise("No country map defined for country code: #{code} in #{locale_countries_map[code]}")
20
+ locale_countries_map[code] ? locale_countries_map[code] : locale_countries_map[default_code_used]
21
+ rescue Exception => e
22
+ raise e if WorldFlags.raise_error?
23
+ "Undefined"
24
+ end
25
+
26
+ def countries= countries
27
+ raise ArgumentError, "Must be a hash, was: #{countries}" unless countries.kind_of?(Hash)
28
+ @countries = countries
29
+ end
30
+
31
+ def countries_map
32
+ @countries_map ||= begin
33
+ active_locales.inject({}) do |res, loc|
34
+ res[loc] = find_country_map(loc)
35
+ res
36
+ end
37
+ end
38
+ end
39
+
40
+ def find_country_map loc
41
+ countries.respond_to?(loc) ? countries.send(loc) : languages.send(locale(loc))
42
+ rescue
43
+ countries.send(default_locale_used)
44
+ end
45
+ end
46
+ end
@@ -29,8 +29,8 @@ module WorldFlags
29
29
  extra_options = title ? {:title => title } : {}
30
30
  selected = flag_selected?(code, options) ? ' selected' : ''
31
31
 
32
- language_name = WorldFlags.language(:en, code)
33
- country_name = WorldFlags.country(:en, code)
32
+ language_name = WorldFlags.language(locale, code)
33
+ country_name = WorldFlags.country(locale, code)
34
34
 
35
35
  # add semi class if not selected
36
36
  semi = (selected.blank? ? ' semi' : '') if options[:with_semi]
@@ -0,0 +1,46 @@
1
+ module WorldFlags
2
+ module LangUtil
3
+ def language_label code, locale
4
+ WorldFlags.language code, locale
5
+ end
6
+
7
+ def language code = :us, locale = :en
8
+ locale ||= default_locale_used
9
+
10
+ locale_languages_map = languages_map[locale] || languages_map[default_locale_used]
11
+ locale_languages_map = languages_map[:en] if locale_languages_map.blank?
12
+
13
+ raise "No language-locale map defined for locale: #{locale} or :en in #{languages.inspect}" if locale_languages_map.blank?
14
+
15
+ # raise("No language map defined for language code: #{code} in #{locale_languages_map[code]}")
16
+ locale_languages_map[code] ? locale_languages_map[code] : locale_languages_map[default_code_used]
17
+ rescue Exception => e
18
+ raise e if WorldFlags.raise_error?
19
+ "Undefined"
20
+ end
21
+
22
+ def languages
23
+ @languages ||= Languages.new
24
+ end
25
+
26
+ def languages= languages
27
+ raise ArgumentError, "Must be a hash, was: #{languages}" unless languages.kind_of?(Hash)
28
+ @languages = languages
29
+ end
30
+
31
+ def languages_map
32
+ @languages_map ||= begin
33
+ active_locales.inject({}) do |res, loc|
34
+ res[loc] = find_language_map(loc)
35
+ res
36
+ end
37
+ end
38
+ end
39
+
40
+ def find_language_map loc
41
+ languages.respond_to?(loc) ? languages.send(loc) : languages.send(locale(loc))
42
+ rescue
43
+ languages.send(default_locale_used)
44
+ end
45
+ end
46
+ end
@@ -1,70 +1,66 @@
1
1
  module WorldFlags
2
- module Languages
3
- class << self
4
- attr_writer :en
5
-
6
- def en
7
- @en ||= {
8
- :ar => 'Argentinian Spanish',
9
- :br => 'Brazilian Portuguese',
10
- :po => 'Portuguese',
11
- :gr => 'Greek',
12
- :gb => 'British English',
13
- :us => 'US English',
14
- :es => 'Spanish',
15
- :it => 'Italian',
16
- :nl => 'Dutch',
17
- :de => 'German',
18
- :dk => 'Danish',
19
- :se => 'Swedish',
20
- :sv => 'Swedish',
21
- :no => 'Norwegian',
22
- :nb => 'Norwegian',
23
- :fi => 'Finnish'
24
- }
25
- end
2
+ class Languages < Hashie::Mash
3
+ def en
4
+ @en ||= {
5
+ :ar => 'Argentinian Spanish',
6
+ :br => 'Brazilian Portuguese',
7
+ :po => 'Portuguese',
8
+ :gr => 'Greek',
9
+ :gb => 'British English',
10
+ :us => 'US English',
11
+ :es => 'Spanish',
12
+ :it => 'Italian',
13
+ :nl => 'Dutch',
14
+ :de => 'German',
15
+ :dk => 'Danish',
16
+ :se => 'Swedish',
17
+ :sv => 'Swedish',
18
+ :no => 'Norwegian',
19
+ :nb => 'Norwegian',
20
+ :fi => 'Finnish'
21
+ }
22
+ end
26
23
 
27
- def da
28
- {
29
- :gb => 'Engelsk',
30
- :us => 'Engelsk',
31
- :es => 'Spansk',
32
- :de => 'Tysk',
33
- :dk => 'Dansk',
34
- :se => 'Svensk',
35
- :sv => 'Svensk',
36
- :no => 'Norsk'
37
- }
38
- end
39
- alias_method :dk, :da
24
+ def da
25
+ @da ||= {
26
+ :gb => 'Engelsk',
27
+ :us => 'Engelsk',
28
+ :es => 'Spansk',
29
+ :de => 'Tysk',
30
+ :dk => 'Dansk',
31
+ :se => 'Svensk',
32
+ :sv => 'Svensk',
33
+ :no => 'Norsk'
34
+ }
35
+ end
36
+ alias_method :dk, :da
40
37
 
41
- def se
42
- {
43
- :gb => 'Engelska',
44
- :us => 'Engelska',
45
- :es => 'Spansk',
46
- :de => 'Tysk',
47
- :dk => 'Dansk',
48
- :se => 'Svenska',
49
- :sv => 'Svenska',
50
- :no => 'Norsk'
51
- }
52
- end
53
- alias_method :sv, :se
38
+ def se
39
+ @se ||= {
40
+ :gb => 'Engelska',
41
+ :us => 'Engelska',
42
+ :es => 'Spansk',
43
+ :de => 'Tysk',
44
+ :dk => 'Dansk',
45
+ :se => 'Svenska',
46
+ :sv => 'Svenska',
47
+ :no => 'Norsk'
48
+ }
49
+ end
50
+ alias_method :sv, :se
54
51
 
55
- def no
56
- {
57
- :gb => 'Engelsk',
58
- :us => 'Engelsk',
59
- :es => 'Spansk',
60
- :de => 'Tysk',
61
- :dk => 'Dansk',
62
- :se => 'Svensk',
63
- :sb => 'Svensk',
64
- :no => 'Norsk'
65
- }
66
- end
67
- alias_method :nb, :no
52
+ def no
53
+ @no ||= {
54
+ :gb => 'Engelsk',
55
+ :us => 'Engelsk',
56
+ :es => 'Spansk',
57
+ :de => 'Tysk',
58
+ :dk => 'Dansk',
59
+ :se => 'Svensk',
60
+ :sb => 'Svensk',
61
+ :no => 'Norsk'
62
+ }
68
63
  end
64
+ alias_method :nb, :no
69
65
  end
70
66
  end
@@ -2,12 +2,8 @@ module WorldFlags
2
2
  module Rails
3
3
  class Engine < ::Rails::Engine
4
4
  initializer "setup for rails" do
5
- WorldFlags::Rails::Engine.add_view_ext
6
- end
7
-
8
- def self.add_view_ext
9
5
  ActionView::Base.send :include, WorldFlags::Helper::View
10
- end
6
+ end
11
7
  end
12
8
  end
13
9
  end
@@ -0,0 +1,15 @@
1
+ # In order to decode language_table.txt
2
+
3
+ reg_exps = [
4
+ /(\w+)\s+-?((\w|\s|')+)?\s+(\w+)\s+((\w+|-)+)/,
5
+ /(\w+)\s+((\w|\s|')+)\s+(\w+)/,
6
+ /(\w+)\s+((\w|\s|')+)/
7
+ /(\w+)/,
8
+
9
+ /(\w+)\s+-?((\w|\s|')+)?\s+(\w+)\s+((\w+|-)+)\s+:?\s+((\w|\s|')+)/,
10
+ /(\w+)\s+((\w|\s|')+)\s+(\w+)\s+:?\s+((\w|\s|')+)/,
11
+ /(\w+)\s+((\w|\s|')+)\s+:?\s+((\w|\s|')+)/
12
+ /(\w+)\s+:?\s+((\w|\s|')+)/
13
+ ]
14
+
15
+ # Find regexp the best matches line. Discard any matching of a single char.
@@ -0,0 +1,185 @@
1
+ Afrikaans af af : South africa
2
+ Albanian sq sq : Albania
3
+ Amharic am am : Ethiopia
4
+ Arabic - Algeria ar ar-dz
5
+ Arabic - Bahrain ar ar-bh
6
+ Arabic - Egypt ar ar-eg
7
+ Arabic - Iraq ar ar-iq
8
+ Arabic - Jordan ar ar-jo
9
+ Arabic - Kuwait ar ar-kw
10
+ Arabic - Lebanon ar ar-lb
11
+ Arabic - Libya ar ar-ly
12
+ Arabic - Morocco ar ar-ma
13
+ Arabic - Oman ar ar-om
14
+ Arabic - Qatar ar ar-qa
15
+ Arabic - Saudi Arabia ar ar-sa
16
+ Arabic - Syria ar ar-sy
17
+ Arabic - Tunisia ar ar-tn
18
+ Arabic - United Arab Emirates ar ar-ae
19
+ Arabic - Yemen ar ar-ye
20
+ Armenian hy hy : Armenia
21
+ Assamese as as
22
+ Azeri - Cyrillic az az-az : Azerbaijan
23
+ Azeri - Latin az az-az : Azerbaijan
24
+ Basque eu eu : Basque Country
25
+ Belarusian be be : Belarus
26
+ Bengali - Bangladesh bn bn
27
+ Bengali - India bn bn-in
28
+ Bosnian bs bs : Bosnia
29
+ Bulgarian bg bg : Bulgaria
30
+ Burmese my my : Burma
31
+ Catalan ca ca : Catalania
32
+ Chinese - China zh zh-cn
33
+ Chinese - Hong Kong SAR zh zh-hk
34
+ Chinese - Macau SAR zh zh-mo
35
+ Chinese - Singapore zh zh-sg
36
+ Chinese - Taiwan zh zh-tw
37
+ Croatian hr hr
38
+ Czech cs cs - Czech Republic
39
+ Danish da da - Denmark
40
+ Divehi; Dhivehi; Maldivian dv dv : Maldives
41
+ Dutch - Belgium nl nl-be
42
+ Dutch - Netherlands nl nl-nl
43
+ Edo jp jp : Japan
44
+ English - Australia en en-au
45
+ English - Belize en en-bz
46
+ English - Canada en en-ca
47
+ English - Caribbean en en-cb
48
+ English - Great Britain en en-gb
49
+ English - India en en-in
50
+ English - Ireland en en-ie
51
+ English - Jamaica en en-jm
52
+ English - New Zealand en en-nz
53
+ English - Phillippines en en-ph
54
+ English - Southern Africa en en-za
55
+ English - Trinidad en en-tt
56
+ English - United States en en-us
57
+ English - Zimbabwe en
58
+ Estonian et et : Estonia
59
+ Faroese fo fo : Faroe Islands
60
+ Farsi - Persian fa fa : Farsi
61
+ Filipino : Philippines
62
+ Finnish fi fi : Finland
63
+ French - Belgium fr fr-be
64
+ French - Cameroon fr
65
+ French - Canada fr fr-ca
66
+ French - Congo fr
67
+ French - Cote d'Ivoire fr
68
+ French - France fr fr-fr
69
+ French - Luxembourg fr fr-lu
70
+ French - Mali fr
71
+ French - Monaco fr
72
+ French - Morocco fr
73
+ French - Senegal fr
74
+ French - Switzerland fr fr-ch
75
+ French - West Indies fr
76
+ Frisian - Netherlands
77
+ Macedonian mk mk : Macedonia
78
+ Gaelic - Ireland gd gd-ie
79
+ Gaelic - Scotland gd gd
80
+ Galician gl : Galicia
81
+ Georgian ka : Georgia
82
+ German - Austria de de-at
83
+ German - Germany de de-de
84
+ German - Liechtenstein de de-li
85
+ German - Luxembourg de de-lu
86
+ German - Switzerland de de-ch
87
+ Greek el el : Greece
88
+ Guarani - Paraguay gn gn
89
+ Gujarati gu gu : Gujarat
90
+ Hebrew he he : Israel
91
+ Hindi hi hi 1081 439 : India
92
+ Hungarian hu hu : Hungary
93
+ Icelandic is is : Iceland
94
+ Igbo - Nigeria
95
+ Indonesian id id : Indonesia
96
+ Italian - Italy it it-it
97
+ Italian - Switzerland it it-ch
98
+ Japanese ja ja : Japan
99
+ Kannada kn kn : Karnataka
100
+ Kashmiri ks ks : Kashmir
101
+ Kazakh kk kk : Kazakhstan
102
+ Khmer km km : Cambodia
103
+ Konkani : Goa
104
+ Korean ko ko : Korea
105
+ Kyrgyz - Cyrillic
106
+ Lao lo lo : Laos
107
+ Latvian lv lv : Latvia
108
+ Lithuanian lt lt : Lithuania
109
+ Malay - Brunei ms ms-bn
110
+ Malay - Malaysia ms ms-my
111
+ Malayalam ml ml : Kerala
112
+ Maltese mt mt : Malta
113
+ Manipuri : Manipur
114
+ Maori mi mi : New Zealand
115
+ Marathi mr mr : Maharashtra
116
+ Mongolian mn mn : Mongolia
117
+ Nepali ne ne : Nepal
118
+ Norwegian - Bokml nb no-no : Norway
119
+ Norwegian - Nynorsk nn : Norway
120
+ Oriya or or : Oriya
121
+ Polish pl pl : Poland
122
+ Portuguese - Brazil pt pt-br
123
+ Portuguese - Portugal pt pt-pt
124
+ Punjabi pa pa : Punjab
125
+ Raeto-Romance rm rm : Rhaetia
126
+ Romanian - Moldova ro ro-mo
127
+ Romanian - Romania ro ro
128
+ Russian ru ru : Russia
129
+ Russian - Moldova ru ru-mo
130
+ Sami Lappish : Lapland
131
+ Sanskrit sa sa : Uttarakhand
132
+ Serbian - Cyrillic sr sr-sp : Serbia
133
+ Serbian - Latin sr sr-sp : Serbia
134
+ Sesotho : South Africa
135
+ Setswana tn tn : South Africa
136
+ Sindhi sd sd : Sindh
137
+ Sinhalese si si : Sri Lanka
138
+ Slovak sk sk : Slovakia
139
+ Slovenian sl sl : Slovenia
140
+ Somali so so : Somalia
141
+ Sorbian sb sb : Germany
142
+ Spanish - Argentina es es-ar
143
+ Spanish - Bolivia es es-bo
144
+ Spanish - Chile es es-cl
145
+ Spanish - Colombia es es-co
146
+ Spanish - Costa Rica es es-cr
147
+ Spanish - Dominican Republic es es-do
148
+ Spanish - Ecuador es es-ec
149
+ Spanish - El Salvador es es-sv
150
+ Spanish - Guatemala es es-gt
151
+ Spanish - Honduras es es-hn
152
+ Spanish - Mexico es es-mx
153
+ Spanish - Nicaragua es es-ni
154
+ Spanish - Panama es es-pa
155
+ Spanish - Paraguay es es-py
156
+ Spanish - Peru es es-pe
157
+ Spanish - Puerto Rico es es-pr
158
+ Spanish - Spain es es-es
159
+ Spanish - Uruguay es es-uy
160
+ Spanish - Venezuela es es-ve
161
+ Swahili - Kenya sw sw-ke :
162
+ Swahili - Tanzania sw sw-ta
163
+ Swahili - Mozambique sw sw-mz
164
+ Swedish - Finland sv sv-fi
165
+ Swedish - Sweden sv sv-se
166
+ Syriac : Syria
167
+ Tajik tg tg : Tajikistan
168
+ Tamil ta ta : Sri Lanka
169
+ Tatar tt tt : Tatarstan
170
+ Telugu te te : Andhra Pradesh
171
+ Thai th th : Thailand
172
+ Tibetan bo bo : Tibet
173
+ Tsonga ts ts : South Africa
174
+ Turkish tr tr : Turkey
175
+ Turkmen tk tk : Turkmenistan
176
+ Ukrainian uk uk : Ukraine
177
+ Urdu ur ur : Pakistan
178
+ Uzbek - Cyrillic : Uzbekistan
179
+ Uzbek - Latin uz uz-uz : Uzbekistan
180
+ Venda : South Africa
181
+ Vietnamese vi vi : Vietnam
182
+ Welsh cy cy : Wales
183
+ Xhosa xh xh : South Africa
184
+ Yiddish yi yi : Israel
185
+ Zulu zu zu : South Africa