1 module nxt.iso_639_1;
2 
3 @safe:
4 
5 private alias LanguageT = ubyte;
6 
7 /** ISO 639-1 language code.
8  *
9  * See_Also: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
10  * See_Also: https://github.com/LBeaudoux/iso639
11  * See_Also: http://www.lingoes.net/en/translator/langcode.htm
12  * See_Also: http://www.mathguide.de/info/tools/languagecode.html
13  * See_Also: http://msdn.microsoft.com/en-us/library/ms533052(v=vs.85).aspx
14  */
15 enum Language : LanguageT {
16 	unknown, nullValue = unknown, // `HybridHashMap` null support
17 
18 	ab, abkhaz = ab,/// Abkhaz	Caucasus	needed!
19 	am, amharic = am,/// Amharic	Ethopia, Egypt	ሰላም (salām)
20 	aa, afar = aa,/// Afar	(Ethiopia, Eritrea, Djibouti Salaamata)
21 	ae, avestan = ae,					   /// Avestan Iran (extinct)
22 	af, afrikaans = af, afr = afrikaans, /// Afrikaans
23 	ak, akan = ak,					   /// Akan
24 	an, aragonese = an,	 /// Aragonese
25 	ar, arabic = ar,					   /// Arabic
26 	as, assamese = as,			/// Assamese
27 	az, azerbaijani = az, azeri = azerbaijani,					   /// Azerbaijani (Azeri)
28 	ba, baskhir = ba,					   /// Baskhir: Volga, Urals, Central Asia
29 	be, belarusian = be,					   /// Belarusian
30 	bg, bulgarian = bg, bul = bulgarian,					  /// Bulgarian
31 	bn, bengali = bn,					  /// Bengali (Bangla): Bangladesh, India
32 	bo, tibetan = bo,					  /// Tibetan
33 	br, breton = br,					  /// Breton: France
34 	bs, bosnian = bs,					  /// Bosnian
35 	ca, catalan = ca, valencian = catalan, cat = valencian,					 /// Catalan/Valencian (Spain)
36 	cs, czech = cs, ces = czech,					  /// Czech: Czech Republic
37 	cy, welch = cy, welsh = welch, cym = welsh,					 /// Welch: Wales, Heddwch, Tangnefedd
38 	da, danish = da, dan = danish,					  /// Danish: Denmark, Greenland
39 	de, german = de, deu = german,					  /// German: Germany, Austria, Switzerland, Liechtenstein, Italy, Belgium
40 	dz, dzongkha = dz,/// Dzongkha	Bhutan	གཞི་བདེ (gzhi-bde)
41 	el, greek = el, ell = greek,	 /// Greek: Greece, Cyprus
42 	en, english = en,			/// English
43 	eo, esperanto = eo,					  /// Esperanto
44 	es, spanish = es, spa = spanish,					  /// Spanish
45 	et, estonian = et,					  /// Estonian
46 	eu, basque = eu,					   /// Basque: Spain, France
47 	fa, persian = fa, farsi = persian,					 /// Persian (Farsi): Iran, Iraq, Afghanistan, Pakistan, Azerbaijan
48 	fi, finnish = fi, fin = finnish,					  /// Finnish: Finland, Sweden, Russia
49 	fj, fijian = fj,					  /// Fijian: Fiji
50 	fo, faroese = fo,					  /// Faroese (Faeroese): Faroe Islands
51 	fr, french = fr, fra = french,					  /// French: France, Belgium, Canada, Caribbean, West Africa, Polynesia
52 	ga, irish = ga,					  /// Irish: Ireland
53 	gd, scottish_gaelic = gd,					  /// Scottish Gaelic: Scotland
54 	gl, galician = gl, gallegan = galician,					  /// Galician (Gallegan): Spain, Portugal
55 	gv, manx = gv,					  /// Manx: Isle of Man
56 	ha, hausa = ha,					  /// Hausa: Nigeria
57 	he, hebrew = he,					  /// Hebrew: Israel
58 	hi, hindi = hi,					  /// Hindi: India, Nepal, Uganda, Suriname
59 	hr, croatian = hr,					  /// Croatian: Croatia
60 	hu, hungarian = hu,					  /// Hungarian: Hungary, Romania, Slovakia
61 	hy, armenian = hy,					   /// Armenian: Armenia
62 	in_, indonesian = in_,
63 	io, ido = io,					  /// Ido: Nigeria
64 	is_, icelandic = is_,					 /// Icelandic
65 	it, italian = it, ita = italian,					  /// Italian: Italy, Switzerland
66 	ja, japanese = ja,					  /// Japanese, 日本語: Japan
67 	ka, georgian = ka,					  /// Georgian: Georgia
68 	kk, kazakh = kk,					  /// Kazakh: Kazakhstan
69 	km, khmer = km,					  /// Khmer: Cambodia
70 	kn, kannada = kn,					  /// Kannada: India
71 	ko, korean = ko,					  /// Korean: Korea
72 	ku, kurdish = ku,					  /// Kurdish: Kurdistan (Turkey, Syria, Iran, Iraq)
73 	ky, kirghiz = ky, kyrgyz = kirghiz,					  /// Kirghiz (Kyrgyz): Kirghizstan, China
74 	la, latin = la, lat = latin,					  /// Latin: Rome (extinct)
75 	lo, lao = lo,					  /// Lao: Laos
76 	lt, lithuanian = lt,					  /// Lithuanian: Lithuania
77 	lv, latvian = lv,					  /// Latvian: Latvia
78 	mg, malagasy = mg, malgache = malagasy,					/// Malagasy (Malgache): Madagascar
79 	mk, macedonian = mk,					  /// Macedonian: Macedonia
80 	mn, mongolian = mn,					  /// Mongolian: Mongolia
81 	ms, malay = ms, zsm = malay,			 /// Malay: Malaysia
82 	mt, maltese = mt,					  /// Maltese: Malta
83 	my, burmese = my,					  /// Burmese: Myanmar
84 	ne, nepali = ne,					  /// Nepali: Nepal
85 	nl, dutch = nl, flemish = dutch,					  /// Dutch (Flemish): Netherlands, Belgium
86 	no, norwegian = no, nob = norwegian,  /// Norwegian: Norway
87 	oc, occitan = oc,					  /// Occitan (Provençal, Languedocian): France
88 	pl, polish = pl,					  /// Polish
89 	ps, pashto = ps,					  /// Pashto: Afghanistan, Iran, Pakistan
90 	pt, portuguese = pt, por = portuguese,					 /// Portuguese: Portugal, Brazil, Angola, Mozambique, Cape Verde, Guinea-Bissau
91 	ro, romanian = ro,					  /// Romanian: Romania, Hungary
92 	ru, russian = ru, rus = russian,					  /// Russian
93 	sa, sanskrit = sa,					  /// Sanskrit: India (extinct, liturgical)
94 	si, sinhalese = si,					  /// Sinhalese: Sri Lanka
95 	sk, slovak = sk, slk = slovak,		 /// Slovak: Slovak Republic
96 	sl, slovene = sl, slovenian = slovene, slv = slovenian, /// Slovene, Slovenian: Slovenia, Austria, Italy
97 	sm, samoan = sm,					  /// Samoan: Samoa
98 	sq, albanian = sq,					  /// Albanian: Albania, Kosovo
99 	sr, serbian = sr,					  /// Serbian: Serbia, Montenegro, Bosnia
100 	sv, swedish = sv, swe = swedish,					   /// Swedish
101 	sw, swahili = sw, swa = swahili, /// Swahili: East Africa
102 	ta, tamil = ta, tam = tamil,		 /// Tamil: India
103 	te, telugu = te,					  /// Telugu: India
104 	tg, tajik = tg,					  /// Tajik: Tajikistan, Afghanistan
105 	th, thai = th, tha = thai,					  /// Thai: Thailand
106 	tk, turkmen = tk,					  /// Turkmen: Turkmenistan, Afghanistan
107 	tl, tagalog = tl, pilipino = tagalog,					  /// Tagalog (Pilipino): Philippines
108 	tr, turkish = tr, tur = turkish,				/// Turkish: Turkey, Cyprus
109 	uk, ukrainian = uk, ukr = ukrainian,   /// Ukrainian
110 	ur, urdu = ur,					  /// Urdu: Pakistan, India, Central Asia
111 	uz, uzbek = uz,					  /// Uzbek: Uzbekistan, Central Asia, China
112 	vi, vietnamese = vi, vie = vietnamese, /// Vietnamese: Viet Nam
113 	vo, volapuk = vo,					  /// Volapük
114 	wa, waloon = wa, wln = waloon,		 /// Waloon: Belgium
115 	yi, yiddish = yi, yid = yiddish, /// Yiddish: Israel, USA, Russia
116 	zh, chinese = zh,					  /// Chinese (Mandarin, Putonghua): China, Singapore
117 
118 	holeValue = LanguageT.max,				  // `HybridHashMap` hole support,
119 }
120 // pragma(msg, cast(uint)Language.regularExpression);
121 
122 /** TODO: Remove when `__traits(documentation)` is merged
123  */
124 string toSpoken(in Language lang, in Language spokenLang = Language.init) pure nothrow @safe @nogc {
125 	with (Language) {
126 		final switch (lang) {
127 		case unknown: return `nullValue`;
128 		case holeValue: return `holeValue`;
129 		case aa: return `Afar`;
130 		case ab: return `Abkhaz`;
131 		case ae: return `Avestan`;
132 		case af: return `Afrikaans`;
133 		case ak: return `Akan`;
134 		case am: return `Amharic`;
135 		case an: return `Aragonese`;
136 		case ar: return `Arabic`;
137 		case as: return `Assamese`;
138 		case az: return `Azerbaijani`;
139 		case ba: return `Baskhir`;
140 		case be: return `Belarusian`;
141 		case bg: return `Bulgarian`;
142 		case bn: return `Bengali`;
143 		case bo: return `Tibetan`;
144 		case br: return `Breton`;
145 		case bs: return `Bosnian`;
146 		case ca: return `Catalan`;
147 		case cs: return `Czech`;
148 		case cy: return `Welch`;
149 		case da: return `Danish`;
150 		case de: return `German`;
151 		case dz: return `Dzongkha`;
152 		case el: return `Greek`;
153 		case en: return `English`;
154 		case eo: return `Esperanto`;
155 		case es: return `Spanish`;
156 		case et: return `Estonian`;
157 		case eu: return `Basque`;
158 		case fa: return `Persian`;
159 		case fi: return `Finnish`;
160 		case fj: return `Fiji`;
161 		case fo: return `Faroese`;
162 		case fr: return `French`;
163 		case ga: return `Irish`;
164 		case gd: return `Gaelic`; // Scottish Gaelic
165 		case gl: return `Galician`;
166 		case gv: return `Manx`;
167 		case ha: return `Hausa`;
168 		case he: return `Hebrew`;
169 		case hi: return `Hindi`;
170 		case hr: return `Croatian`;
171 		case hu: return `Hungarian`;
172 		case hy: return `Armenian`;
173 		case in_: return `Indonesian`;
174 		case io: return `Ido`;
175 		case is_: return `Icelandic`;
176 		case it: return `Italian`;
177 		case ja: return `Japanese`;
178 		case ka: return `Georgian`;
179 		case kk: return `Kazakh`;
180 		case km: return `Khmer`;
181 		case kn: return `Kannada`;
182 		case ko: return `Korean`;
183 		case ku: return `Kurdish`;
184 		case ky: return `Kyrgyz`;
185 		case la: return `Latin`;
186 		case lo: return `Lao`;
187 		case lt: return `Lithuanian`;
188 		case lv: return `Latvian`;
189 		case mg: return `Malagasy`;
190 		case mk: return `Macedonian`;
191 		case mn: return `Mongolian`;
192 		case ms: return `Malay`;
193 		case mt: return `Maltese`;
194 		case my: return `Burmese`;
195 		case ne: return `Nepali`;
196 		case nl: return `Dutch`;
197 		case no: return `Norwegian`;
198 		case oc: return `Occitan`;
199 		case pl: return `Polish`;
200 		case ps: return `Pashto`;
201 		case pt: return `Portuguese`;
202 		case ro: return `Romanian`;
203 		case ru: return `Russian`;
204 		case sa: return `Sanskrit`;
205 		case si: return `Sinhalese`;
206 		case sk: return `Slovak`;
207 		case sl: return `Slovene`;
208 		case sm: return `Samoan`;
209 		case sq: return `Albanian`;
210 		case sr: return `Serbian`;
211 		case sv: return `Swedish`;
212 		case sw: return `Swahili`;
213 		case ta: return `Tamil`;
214 		case te: return `Tegulu`;
215 		case tg: return `Tajik`;
216 		case th: return `Thai`;
217 		case tk: return `Turkmen`;
218 		case tl: return `Tagalog`;
219 		case tr: return `Turkish`;
220 		case uk: return `Ukrainian`;
221 		case ur: return `Urdu`;
222 		case uz: return `Uzbek`;
223 		case vi: return `Vietnamese`;
224 		case vo: return `Volapük`;
225 		case wa: return `Waloon`;
226 		case yi: return `Yiddish`;
227 		case zh: return `Chinese`;
228 		}
229 	}
230 }
231 
232 /// Parse Language `lang`.
233 Language parseLanguage(scope const(char)[] lang, in Language defaultLang) pure nothrow @safe @nogc {
234 	switch (lang) {
235 		case `is`:
236 			return Language.is_;
237 		case `in`:
238 			return Language.in_;
239 		default:
240 			import nxt.conv_ex : toDefaulted;
241 			return typeof(return)(lang.toDefaulted!Language(defaultLang));
242 	}
243 }
244 
245 ///
246 pure nothrow @safe unittest {
247 	assert(`_`.parseLanguage(Language.unknown) == Language.unknown);
248 	assert(`_`.parseLanguage(Language.en) == Language.en);
249 	assert(`sv`.parseLanguage(Language.unknown) == Language.sv);
250 	assert(`en`.parseLanguage(Language.unknown) == Language.en);
251 }
252 
253 /** Check if `lang` capitalize all its nouns include common nouns.
254  */
255 bool capitalizesCommonNoun(in Language lang) pure nothrow @safe @nogc => lang == Language.de;
256 
257 ///
258 pure nothrow @safe @nogc unittest {
259 	assert(Language.de.capitalizesCommonNoun);
260 	assert(!Language.en.capitalizesCommonNoun);
261 }