iso639 1.3.3 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e488ef76243b248bc5c4899adafd8569e4dcd4fa315262cfb1341aa63e19b031
4
- data.tar.gz: ebba0a06b0a0bd4ecc288a09d85a9c10a46c91aff3fa8fff3a3ce632de119ca7
3
+ metadata.gz: b62781aae3b7d40d8ee8cc71491566cc8f9f20884430cef754a7c35947ac2116
4
+ data.tar.gz: 5003ec17cf125a113986d112489e0b4e266bff9daf53cfac73ef4edc160d6702
5
5
  SHA512:
6
- metadata.gz: 93100582c3cec24a578237af39966f2de599e0ef05a1caf4e9b3227789d174a396cd3fd60d2444356078fb1c2079aae32064e164a621c4701413768b7aa3e61e
7
- data.tar.gz: 181ad31c6eb663aec563966d57ce9cef94f39f05aa18666420c5fa6fc4e31e9d363e676490cf377c7c268c4397793bea2a336b431bbd312a2de03b004bc097f0
6
+ metadata.gz: 44824e2797eb5e6dde70eb8ebf3ebade9cc6e25253894b07188303a368702c234a708547038e6577525afa18838a574307af080043368e705a4c8422a539fead
7
+ data.tar.gz: f24aa87607d243d766c7eb3ecf14415d329e618b451c026fa54471e6b84afb9c31c6a6c23bb317f6516be995a713c4fce87bdc1c22f4775093bee472b983e83e
@@ -1,16 +1,20 @@
1
1
  name: CI
2
- on: [push, pull_request]
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ pull_request:
6
+ branches: [master]
3
7
 
4
8
  jobs:
5
9
  test:
6
10
  runs-on: ubuntu-latest
7
11
  strategy:
8
12
  matrix:
9
- ruby: ["2.4", "2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "3.3"]
13
+ ruby: ["2.4", "2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "3.3", "3.4", "4.0"]
10
14
 
11
15
  steps:
12
16
  # https://github.com/marketplace/actions/checkout
13
- - uses: actions/checkout@v4
17
+ - uses: actions/checkout@v6
14
18
  # https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
15
19
  - name: Set up Ruby
16
20
  uses: ruby/setup-ruby@v1
data/CONTRIBUTING.md CHANGED
@@ -41,3 +41,8 @@ Syntax:
41
41
  * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
42
42
  * `a = b` not `a=b`.
43
43
  * Follow the conventions you see used in the source already.
44
+
45
+ ## Updating language data
46
+
47
+ Run `bundle exec rake data:update` to refresh the Library of Congress snapshot.
48
+ Review the diff and run `bundle exec rake` before committing.
data/README.md CHANGED
@@ -9,7 +9,10 @@ The iso639 gem provides convenience methods for looking up ISO-639-1 or
9
9
  ISO-639-2 language codes by their english name, 2-char, or 3-char counterpart
10
10
 
11
11
  All data was generated from the Library of Congress's list of UTF-8
12
- [**Codes for the Representation of Names of Languages**](http://www.loc.gov/standards/iso639-2/ascii_8bits.html).
12
+ [**Codes for the Representation of Names of Languages**](https://www.loc.gov/standards/iso639-2/ascii_8bits.html).
13
+ The bundled [data snapshot](https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt)
14
+ was retrieved on 2026-09-19 and normalized to UTF-8 without a byte order mark,
15
+ with LF line endings and a final newline.
13
16
 
14
17
  ## Installation
15
18
 
@@ -95,6 +98,16 @@ Iso639["deu"].name # => "German"
95
98
  Iso639["ger"].name # => "German"
96
99
  Iso639["german"].name # => "German"
97
100
  Iso639["GeRmAn"].name # => "German"
101
+
102
+ # Lookup codes with locale suffixes
103
+ Iso639["en_US"].name # => "English"
104
+ Iso639["fr-CA"].name # => "French"
105
+ Iso639["zh-Hant-TW"].name # => "Chinese"
106
+
107
+ # Hyphenated names are matched in full before locale suffixes are ignored
108
+ Iso639["Judeo-Persian"].alpha3 # => "jpr"
109
+ Iso639["Luba-Lulua"].alpha3 # => "lua"
110
+ Iso639["bas-sorabe"].alpha3 # => "dsb"
98
111
  ```
99
112
 
100
113
  ## Versioning
data/Rakefile CHANGED
@@ -8,3 +8,20 @@ Rake::TestTask.new do |t|
8
8
  t.libs << "lib" << "test"
9
9
  t.pattern = "test/**/*_test.rb"
10
10
  end
11
+
12
+ namespace :data do
13
+ desc "Refresh the ISO 639 snapshot from the Library of Congress"
14
+ task :update do
15
+ require "net/http"
16
+
17
+ url = URI("https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt")
18
+ response = Net::HTTP.get_response(url)
19
+ abort "Download failed: HTTP #{response.code}" unless response.is_a?(Net::HTTPOK)
20
+
21
+ data = response.body.force_encoding("UTF-8")
22
+ data = data.sub(/\A\uFEFF/, "").gsub(/\r\n?/, "\n").chomp + "\n"
23
+ path = File.expand_path("lib/iso639/ISO-639-2_utf-8.txt", __dir__)
24
+ File.binwrite(path, data)
25
+ puts "Updated #{path}"
26
+ end
27
+ end
@@ -1,4 +1,4 @@
1
- aar||aa|Afar|afar
1
+ aar||aa|Afar|afar
2
2
  abk||ab|Abkhazian|abkhaze
3
3
  ace|||Achinese|aceh
4
4
  ach|||Acoli|acoli
@@ -50,12 +50,12 @@ bem|||Bemba|bemba
50
50
  ben||bn|Bengali|bengali
51
51
  ber|||Berber languages|berbères, langues
52
52
  bho|||Bhojpuri|bhojpuri
53
- bih||bh|Bihari languages|langues biharis
53
+ bih|||Bihari languages|langues biharis
54
54
  bik|||Bikol|bikol
55
55
  bin|||Bini; Edo|bini; edo
56
56
  bis||bi|Bislama|bichlamar
57
57
  bla|||Siksika|blackfoot
58
- bnt|||Bantu (Other)|bantoues, autres langues
58
+ bnt|||Bantu languages|bantou, langues
59
59
  bos||bs|Bosnian|bosniaque
60
60
  bra|||Braj|braj
61
61
  bre||br|Breton|breton
@@ -87,15 +87,16 @@ chu||cu|Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church
87
87
  chv||cv|Chuvash|tchouvache
88
88
  chy|||Cheyenne|cheyenne
89
89
  cmc|||Chamic languages|chames, langues
90
+ cnr|||Montenegrin|monténégrin
90
91
  cop|||Coptic|copte
91
92
  cor||kw|Cornish|cornique
92
93
  cos||co|Corsican|corse
93
94
  cpe|||Creoles and pidgins, English based|créoles et pidgins basés sur l'anglais
94
- cpf|||Creoles and pidgins, French-based |créoles et pidgins basés sur le français
95
- cpp|||Creoles and pidgins, Portuguese-based |créoles et pidgins basés sur le portugais
95
+ cpf|||Creoles and pidgins, French-based|créoles et pidgins basés sur le français
96
+ cpp|||Creoles and pidgins, Portuguese-based|créoles et pidgins basés sur le portugais
96
97
  cre||cr|Cree|cree
97
98
  crh|||Crimean Tatar; Crimean Turkish|tatar de Crimé
98
- crp|||Creoles and pidgins |créoles et pidgins
99
+ crp|||Creoles and pidgins|créoles et pidgins
99
100
  csb|||Kashubian|kachoube
100
101
  cus|||Cushitic languages|couchitiques, langues
101
102
  cze|ces|cs|Czech|tchèque
@@ -105,7 +106,7 @@ dar|||Dargwa|dargwa
105
106
  day|||Land Dayak languages|dayak, langues
106
107
  del|||Delaware|delaware
107
108
  den|||Slave (Athapascan)|esclave (athapascan)
108
- dgr|||Dogrib|dogrib
109
+ dgr|||Tlicho; Dogrib|tlicho; dogrib
109
110
  din|||Dinka|dinka
110
111
  div||dv|Divehi; Dhivehi; Maldivian|maldivien
111
112
  doi|||Dogri|dogri
@@ -161,7 +162,7 @@ gor|||Gorontalo|gorontalo
161
162
  got|||Gothic|gothique
162
163
  grb|||Grebo|grebo
163
164
  grc|||Greek, Ancient (to 1453)|grec ancien (jusqu'à 1453)
164
- gre|ell|el|Greek, Modern (1453-)|grec moderne (après 1453)
165
+ gre|ell|el|Modern Greek (1453-)|grec moderne (1453-)
165
166
  grn||gn|Guarani|guarani
166
167
  gsw|||Swiss German; Alemannic; Alsatian|suisse alémanique; alémanique; alsacien
167
168
  guj||gu|Gujarati|goudjrati
@@ -300,17 +301,17 @@ nai|||North American Indian languages|nord-amérindiennes, langues
300
301
  nap|||Neapolitan|napolitain
301
302
  nau||na|Nauru|nauruan
302
303
  nav||nv|Navajo; Navaho|navaho
303
- nbl||nr|Ndebele, South; South Ndebele|ndébélé du Sud
304
- nde||nd|Ndebele, North; North Ndebele|ndébélé du Nord
304
+ nbl||nr|South Ndebele|ndébélé du Sud
305
+ nde||nd|North Ndebele|ndébélé du Nord
305
306
  ndo||ng|Ndonga|ndonga
306
307
  nds|||Low German; Low Saxon; German, Low; Saxon, Low|bas allemand; bas saxon; allemand, bas; saxon, bas
307
308
  nep||ne|Nepali|népalais
308
- new|||Nepal Bhasa; Newari|nepal bhasa; newari
309
+ new|||Nepal Bhasa; Newar; Newari|nepal bhasa; néwar; newari
309
310
  nia|||Nias|nias
310
311
  nic|||Niger-Kordofanian languages|nigéro-kordofaniennes, langues
311
312
  niu|||Niuean|niué
312
- nno||nn|Norwegian Nynorsk; Nynorsk, Norwegian|norvégien nynorsk; nynorsk, norvégien
313
- nob||nb|Bokmål, Norwegian; Norwegian Bokmål|norvégien bokmål
313
+ nno||nn|Norwegian Nynorsk|norvégien nynorsk
314
+ nob||nb|Norwegian Bokmål|norvégien bokmål
314
315
  nog|||Nogai|nogaï; nogay
315
316
  non|||Norse, Old|norrois, vieux
316
317
  nor||no|Norwegian|norvégien
@@ -323,7 +324,7 @@ nym|||Nyamwezi|nyamwezi
323
324
  nyn|||Nyankole|nyankolé
324
325
  nyo|||Nyoro|nyoro
325
326
  nzi|||Nzima|nzema
326
- oci||oc|Occitan (post 1500); Provençal|occitan (après 1500); provençal
327
+ oci||oc|Occitan (post 1500)|occitan (après 1500)
327
328
  oji||oj|Ojibwa|ojibwa
328
329
  ori||or|Oriya|oriya
329
330
  orm||om|Oromo|galla
@@ -347,7 +348,7 @@ pol||pl|Polish|polonais
347
348
  pon|||Pohnpeian|pohnpei
348
349
  por||pt|Portuguese|portugais
349
350
  pra|||Prakrit languages|prâkrit, langues
350
- pro|||Provençal, Old (to 1500)|provençal ancien (jusqu'à 1500)
351
+ pro|||Provençal, Old (to 1500); Occitan, Old (to 1500)|provençal ancien (jusqu'à 1500); occitan ancien (jusqu'à 1500)
351
352
  pus||ps|Pushto; Pashto|pachto
352
353
  qaa-qtz|||Reserved for local use|réservée à l'usage local
353
354
  que||qu|Quechua|quechua
@@ -364,7 +365,7 @@ rus||ru|Russian|russe
364
365
  sad|||Sandawe|sandawe
365
366
  sag||sg|Sango|sango
366
367
  sah|||Yakut|iakoute
367
- sai|||South American Indian (Other)|indiennes d'Amérique du Sud, autres langues
368
+ sai|||South American Indian languages|sud-amérindiennes, langues
368
369
  sal|||Salishan languages|salishennes, langues
369
370
  sam|||Samaritan Aramaic|samaritain
370
371
  san||sa|Sanskrit|sanskrit
@@ -460,7 +461,7 @@ vie||vi|Vietnamese|vietnamien
460
461
  vol||vo|Volapük|volapük
461
462
  vot|||Votic|vote
462
463
  wak|||Wakashan languages|wakashanes, langues
463
- wal|||Walamo|walamo
464
+ wal|||Wolaitta; Wolaytta|wolaitta; wolaytta
464
465
  war|||Waray|waray
465
466
  was|||Washo|washo
466
467
  wel|cym|cy|Welsh|gallois
@@ -483,4 +484,4 @@ znd|||Zande languages|zandé, langues
483
484
  zul||zu|Zulu|zoulou
484
485
  zun|||Zuni|zuni
485
486
  zxx|||No linguistic content; Not applicable|pas de contenu linguistique; non applicable
486
- zza|||Zaza; Dimili; Dimli; Kirdki; Kirmanjki; Zazaki|zaza; dimili; dimli; kirdki; kirmanjki; zazaki
487
+ zza|||Zaza; Dimili; Dimli; Kirdki; Kirmanjki; Zazaki|zaza; dimili; dimli; kirdki; kirmanjki; zazaki
@@ -0,0 +1,11 @@
1
+ require "iso639/insensitive_hash"
2
+
3
+ module Iso639
4
+ class CodeHash < InsensitiveHash # :nodoc:
5
+ private
6
+
7
+ def normalize(key)
8
+ super.split(/[-_]/).first
9
+ end
10
+ end
11
+ end
@@ -11,7 +11,7 @@ module Iso639
11
11
  private
12
12
 
13
13
  def normalize(key)
14
- key.to_s.downcase.strip.split(/[-_]/).first
14
+ key.to_s.downcase.strip
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Iso639
2
- VERSION = "1.3.3"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/iso639.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  require "iso639/version"
2
2
  require "iso639/language"
3
3
  require "iso639/insensitive_hash"
4
+ require "iso639/code_hash"
4
5
 
5
6
  # Public: Various methods useful for performing ISO-639 language code lookup
6
7
  # either given their ISO-639-1 or ISO-639-2 character code value or from human
7
8
  # input.
8
9
  #
9
10
  # Language code mappings came from
10
- # http://loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
11
+ # https://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt
11
12
  #
12
13
  # Examples
13
14
  #
@@ -29,9 +30,9 @@ require "iso639/insensitive_hash"
29
30
  # Iso639["German"].english_name # => "German"
30
31
  # Iso639["German"].french_name # => "allemand"
31
32
  module Iso639
32
- LanguagesByAlpha2 = InsensitiveHash.new
33
- LanguagesByAlpha3Bibliographic = LanguagesByAlpha3 = InsensitiveHash.new
34
- LanguagesByAlpha3Terminology = InsensitiveHash.new
33
+ LanguagesByAlpha2 = CodeHash.new
34
+ LanguagesByAlpha3Bibliographic = LanguagesByAlpha3 = CodeHash.new
35
+ LanguagesByAlpha3Terminology = CodeHash.new
35
36
  LanguagesByEnglishName = LanguagesByName = InsensitiveHash.new
36
37
  LanguagesByFrenchName = InsensitiveHash.new
37
38
 
@@ -59,10 +60,16 @@ module Iso639
59
60
  #
60
61
  # Returns an Iso639::Language object
61
62
  def self.[](lookup)
62
- LanguagesByAlpha2[lookup] ||
63
- LanguagesByAlpha3Bibliographic[lookup] ||
64
- LanguagesByAlpha3Terminology[lookup] ||
63
+ lookup = lookup.to_s.downcase.strip
64
+
65
+ # Prefer exact codes and complete names before ignoring locale suffixes.
66
+ LanguagesByAlpha2.fetch(lookup, nil) ||
67
+ LanguagesByAlpha3Bibliographic.fetch(lookup, nil) ||
68
+ LanguagesByAlpha3Terminology.fetch(lookup, nil) ||
65
69
  LanguagesByEnglishName[lookup] ||
66
- LanguagesByFrenchName[lookup]
70
+ LanguagesByFrenchName[lookup] ||
71
+ LanguagesByAlpha2[lookup] ||
72
+ LanguagesByAlpha3Bibliographic[lookup] ||
73
+ LanguagesByAlpha3Terminology[lookup]
67
74
  end
68
75
  end
@@ -0,0 +1,15 @@
1
+ require "test_helper"
2
+
3
+ describe Iso639::CodeHash do
4
+ it "should return results ignoring regional designators" do
5
+ hash = Iso639::CodeHash.new
6
+ hash["en_GB"] = "english"
7
+ hash["fr_CA"] = "french"
8
+
9
+ assert_equal "english", hash["en_US"]
10
+ assert_equal "french", hash["fr_FR"]
11
+ assert_equal "english", hash["en-US"]
12
+ assert_equal "french", hash["fr-FR"]
13
+ assert_equal "english", hash[" EN_us\t"]
14
+ end
15
+ end
@@ -23,14 +23,16 @@ describe Iso639::InsensitiveHash do
23
23
  assert_equal "last thing", hash["baz"]
24
24
  end
25
25
 
26
- it "should return results ignoring regional designators" do
26
+ it "should preserve hyphens and underscores in keys" do
27
27
  hash = Iso639::InsensitiveHash.new
28
- hash["en_GB"] = "english"
29
- hash["fr_CA"] = "french"
28
+ hash["Judeo-Persian"] = "jpr"
29
+ hash["Judeo-Arabic"] = "jrb"
30
+ hash["Judeo_Persian"] = "underscore"
30
31
 
31
- assert_equal "english", hash["en_US"]
32
- assert_equal "french", hash["fr_FR"]
33
- assert_equal "english", hash["en-US"]
34
- assert_equal "french", hash["fr-FR"]
32
+ assert_equal "jpr", hash[" JUDEO-PERSIAN "]
33
+ assert_equal "jrb", hash["judeo-arabic"]
34
+ assert_equal "underscore", hash["judeo_persian"]
35
+ assert_nil hash["Judeo"]
36
+ assert_nil hash["Judeo-Unknown"]
35
37
  end
36
38
  end
data/test/iso639_test.rb CHANGED
@@ -8,6 +8,10 @@ describe Iso639::LanguagesByAlpha2 do
8
8
  assert_equal "German", Iso639::LanguagesByAlpha2["de"].name
9
9
  end
10
10
 
11
+ it "should ignore regional designations" do
12
+ assert_equal "en", Iso639::LanguagesByAlpha2["en_US"].alpha2
13
+ end
14
+
11
15
  it "should return nil for unknown codes" do
12
16
  assert_nil Iso639::LanguagesByAlpha2["xx"]
13
17
  assert_nil Iso639::LanguagesByAlpha2["eng"]
@@ -23,6 +27,10 @@ describe Iso639::LanguagesByAlpha3Bibliographic do
23
27
  assert_equal "German", Iso639::LanguagesByAlpha3["ger"].name
24
28
  end
25
29
 
30
+ it "should ignore regional designations" do
31
+ assert_equal "fre", Iso639::LanguagesByAlpha3Bibliographic["fre-CA"].alpha3
32
+ end
33
+
26
34
  it "should return nil for unknown codes" do
27
35
  assert_nil Iso639::LanguagesByAlpha3["xxx"]
28
36
  assert_nil Iso639::LanguagesByAlpha3["en"]
@@ -36,6 +44,10 @@ describe Iso639::LanguagesByAlpha3Terminology do
36
44
  assert_equal "German", Iso639::LanguagesByAlpha3Terminology["DEU"].name
37
45
  end
38
46
 
47
+ it "should ignore regional designations" do
48
+ assert_equal "fre", Iso639::LanguagesByAlpha3Terminology["fra_CA"].alpha3
49
+ end
50
+
39
51
  it "should return valid languages by alpha-3 terminology code when it matches the bibliographic" do
40
52
  assert_equal "English", Iso639::LanguagesByAlpha3Terminology["eng"].name
41
53
  end
@@ -58,6 +70,15 @@ describe Iso639::LanguagesByEnglishName do
58
70
  assert_equal "Klingon", Iso639::LanguagesByName["tlhIngan-Hol"].name
59
71
  end
60
72
 
73
+ it "should resolve every English name to its language" do
74
+ Iso639::LanguagesByAlpha3.each_value do |lang|
75
+ lang.english_names.each do |name|
76
+ assert_same lang, Iso639::LanguagesByEnglishName[name],
77
+ "Expected #{name.inspect} to resolve to #{lang.alpha3}"
78
+ end
79
+ end
80
+ end
81
+
61
82
  it "should return nil for unknown codes" do
62
83
  assert_nil Iso639::LanguagesByName["xxxxxx"]
63
84
  assert_nil Iso639::LanguagesByName["en"]
@@ -71,6 +92,15 @@ describe Iso639::LanguagesByFrenchName do
71
92
  assert_equal "German", Iso639::LanguagesByFrenchName["allemand"].name
72
93
  end
73
94
 
95
+ it "should resolve every French name to its language" do
96
+ Iso639::LanguagesByAlpha3.each_value do |lang|
97
+ lang.french_names.each do |name|
98
+ assert_same lang, Iso639::LanguagesByFrenchName[name],
99
+ "Expected #{name.inspect} to resolve to #{lang.alpha3}"
100
+ end
101
+ end
102
+ end
103
+
74
104
  it "should return nil for unknown codes" do
75
105
  assert_nil Iso639::LanguagesByFrenchName["xxxxxx"]
76
106
  assert_nil Iso639::LanguagesByFrenchName["an"]
@@ -89,6 +119,80 @@ describe Iso639 do
89
119
  assert_equal "krc", Iso639["Karachay-Balkar"].alpha3
90
120
  end
91
121
 
122
+ it "should resolve Afar by its alpha-3 code without a byte order mark" do
123
+ assert_equal "aar", Iso639["aa"].alpha3
124
+ assert_same Iso639["aa"], Iso639["aar"]
125
+ assert_same Iso639["aa"], Iso639::LanguagesByAlpha3Terminology["aar"]
126
+ end
127
+
128
+ it "should resolve Montenegrin by code and name" do
129
+ lang = Iso639["cnr"]
130
+ refute_nil lang
131
+ assert_equal "Montenegrin", lang.name
132
+ assert_equal "monténégrin", lang.french_name
133
+ assert_nil lang.alpha2
134
+ assert_same lang, Iso639["Montenegrin"]
135
+ assert_same lang, Iso639["monténégrin"]
136
+ end
137
+
138
+ it "should resolve updated language names and aliases" do
139
+ assert_equal "Tlicho", Iso639["dgr"].name
140
+ assert_equal "dgr", Iso639["Tlicho"].alpha3
141
+ assert_equal "dgr", Iso639["Dogrib"].alpha3
142
+ assert_equal "Modern Greek (1453-)", Iso639["ell"].name
143
+ assert_equal "gre", Iso639["Modern Greek (1453-)"].alpha3
144
+ assert_equal "Wolaitta", Iso639["wal"].name
145
+ assert_equal "wal", Iso639["Wolaitta"].alpha3
146
+ assert_equal "wal", Iso639["Wolaytta"].alpha3
147
+ assert_equal "new", Iso639["Newar"].alpha3
148
+ assert_equal "new", Iso639["néwar"].alpha3
149
+ assert_equal "pro", Iso639["Occitan, Old (to 1500)"].alpha3
150
+ end
151
+
152
+ it "should retain Bihari languages without the removed alpha-2 code" do
153
+ assert_equal "Bihari languages", Iso639["bih"].name
154
+ assert_nil Iso639["bih"].alpha2
155
+ assert_nil Iso639["bh"]
156
+ assert_nil Iso639::LanguagesByAlpha2["bh"]
157
+ end
158
+
159
+ it "should return nil for names removed from the snapshot" do
160
+ assert_nil Iso639["Walamo"]
161
+ assert_nil Iso639["Provençal"]
162
+ end
163
+
164
+ it "should distinguish hyphenated language names" do
165
+ assert_equal "jpr", Iso639["Judeo-Persian"].alpha3
166
+ assert_equal "jrb", Iso639["Judeo-Arabic"].alpha3
167
+ assert_equal "lua", Iso639["Luba-Lulua"].alpha3
168
+ assert_equal "lub", Iso639["Luba-Katanga"].alpha3
169
+ assert_equal "jpr", Iso639[" JUDÉO-PERSAN\t"].alpha3
170
+ assert_equal "jrb", Iso639["judéo-arabe"].alpha3
171
+ assert_equal "lad", Iso639["judéo-espagnol"].alpha3
172
+ assert_equal "lua", Iso639["luba-lulua"].alpha3
173
+ assert_equal "inc", Iso639["indo-aryennes, langues"].alpha3
174
+ assert_equal "ine", Iso639["indo-européennes, langues"].alpha3
175
+ end
176
+
177
+ it "should prefer complete language names to locale prefixes" do
178
+ assert_equal "mkh", Iso639["Mon-Khmer languages"].alpha3
179
+ assert_equal "dsb", Iso639["bas-sorabe"].alpha3
180
+ end
181
+
182
+ it "should prefer exact codes to matching language names" do
183
+ assert_equal "gle", Iso639["Ga"].alpha3
184
+ assert_equal "gaa", Iso639::LanguagesByName["Ga"].alpha3
185
+ end
186
+
187
+ it "should return nil for incomplete or unknown hyphenated names" do
188
+ assert_nil Iso639["Judeo"]
189
+ assert_nil Iso639["Judeo-Unknown"]
190
+ assert_nil Iso639["Karachay"]
191
+ assert_nil Iso639["Karachay-Unknown"]
192
+ assert_nil Iso639["English-Unknown"]
193
+ assert_nil Iso639["English_Unknown"]
194
+ end
195
+
92
196
  it "should ignore case sensitivity" do
93
197
  assert_equal "en", Iso639["EN"].alpha2
94
198
  assert_equal "fr", Iso639["Fre"].alpha2
@@ -108,5 +212,9 @@ describe Iso639 do
108
212
  assert_equal "en", Iso639["en_GB"].alpha2
109
213
  assert_equal "fr", Iso639["fr-CA"].alpha2
110
214
  assert_equal "fr", Iso639["fr-FR"].alpha2
215
+ assert_equal "en", Iso639[" ENG_us\t"].alpha2
216
+ assert_equal "fr", Iso639["fre-CA"].alpha2
217
+ assert_equal "fr", Iso639["fra_CA"].alpha2
218
+ assert_equal "zh", Iso639["zh-Hant-TW"].alpha2
111
219
  end
112
220
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso639
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan McGeary
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: minitest
@@ -58,9 +57,11 @@ files:
58
57
  - iso639.gemspec
59
58
  - lib/iso639.rb
60
59
  - lib/iso639/ISO-639-2_utf-8.txt
60
+ - lib/iso639/code_hash.rb
61
61
  - lib/iso639/insensitive_hash.rb
62
62
  - lib/iso639/language.rb
63
63
  - lib/iso639/version.rb
64
+ - test/code_hash_test.rb
64
65
  - test/insensitive_hash_test.rb
65
66
  - test/iso639_test.rb
66
67
  - test/language_test.rb
@@ -73,7 +74,6 @@ metadata:
73
74
  changelog_uri: https://github.com/rmm5t/iso639/releases
74
75
  source_code_uri: https://github.com/rmm5t/iso639
75
76
  funding_uri: https://github.com/sponsors/rmm5t
76
- post_install_message:
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib
@@ -88,11 +88,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.5.23
92
- signing_key:
91
+ rubygems_version: 4.0.21
93
92
  specification_version: 4
94
93
  summary: ISO 639-1 and ISO 639-2 lookups by name, alpha-2 code, or alpha-3 code
95
94
  test_files:
95
+ - test/code_hash_test.rb
96
96
  - test/insensitive_hash_test.rb
97
97
  - test/iso639_test.rb
98
98
  - test/language_test.rb