/
List.pm6
2083 lines (1350 loc) · 29.7 KB
/
List.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use v6.c;
unit module I18N::LangTags::List;
use I18N::LangTags::Grammar;
use I18N::LangTags::Actions;
my $Debug = 0;
# Parsing
my $stop-skip = 0;
my $actions = I18N::LangTags::Actions.new;
# Storing
my Str $last-lang-name;
our %Name;
our %Is_Disrec;
my sub save-language(Str:D $tag, Str:D $name = $last-lang-name, Bool $is_disrec = True) {
$last-lang-name = $name;
%Name{ $tag } = $name;
%Is_Disrec{ $tag } = $name if $is_disrec;
}
for $=pod[0].contents() -> $node {
if $node ~~ Pod::Heading
and $node.contents.[0] ~~ Pod::Block::Para
and $node.contents.[0].contents.[0] eq 'LIST OF LANGUAGES'
{
$stop-skip = 1,
}
if $stop-skip {
if $node ~~ Pod::Item {
for $node.contents -> $subnode {
if $subnode ~~ (Pod::Block::Para|Pod::Block::Comment) {
for $subnode.contents -> $content {
if $content ~~ Str {
say $content if $Debug;
for I18N::LangTags::Grammar.parse(
$content,
:rule('scan_languages'),
:$actions).made -> $language {
say $language if $Debug;
with $language {
save-language($language<tag>, $language<name>, $language<is_disrec>);
}
}
if I18N::LangTags::Grammar.parse(
$content,
:rule('formerly'),
:$actions).made() -> $langtag {
save-language($langtag);
};
}
}
}
}
}
}
}
our sub name(Str:D $tag is copy --> Str:D) {
$tag .= trim();
return Nil unless I18N::LangTags::Grammar.parse($tag, :rule('langtag'));
say "Input: {$tag}" if $Debug;
my $subform = '';
my $name = '';
my $alt = '';
$alt = 'x-' ~ $/[0] if $tag ~~ / 'i-' (.*) /;
$alt = 'i-' ~ $/[0] if $tag ~~ / 'x-' (.*) /;
my regex shave { '-' <alnum>+ $ };
while $tag.chars {
last if $name = %Name{$tag};
last if $name = %Name{$alt};
if $tag ~~ s/ ( <shave> ) // {
say "Shaving off: $/[0] leaving $tag" if $Debug;
$subform = $/[0] ~ $subform;
$alt ~~ s/ ( <shave> )//;
say " alt -> $alt" if $Debug;
} else {
# we're trying to pull a subform off a primary tag. TILT!
say "Aborting on: {$name}{$subform}" if $Debug;
last;
}
}
return Nil unless $name;
return $name unless $subform;
$subform ~~ s/ ^ '-' //;
$subform ~~ s/ '-' $ //;
return "$name (Subform \"$subform\")";
}
our sub is_decent(Str:D $tag --> Bool) {
return False unless I18N::LangTags::Grammar.parse($tag, :rule('langtag'));
my @supers = ();
for $tag.split('-') -> $bit {
@supers.push( @supers.elems > 0 ?? @supers[*-1] ~ '-' ~ $bit !! $bit);
};
@supers.shift() if @supers[0].fc eq fc('i' | 'x' | 'sgn');
return False unless @supers;
for ($tag, |@supers) -> $f {
return False if %Is_Disrec{ $f }:exists;
return True if %Name{ $f }:exists;
}
return True;
}
=begin pod
=head1 NAME
I18N::LangTags::List -- tags and names for human languages
=head1 SYNOPSIS
use I18N::LangTags::List;
print "Parlez-vous... ", join(', ',
I18N::LangTags::List::name('elx') || 'unknown_language',
I18N::LangTags::List::name('ar-Kw') || 'unknown_language',
I18N::LangTags::List::name('en') || 'unknown_language',
I18N::LangTags::List::name('en-CA') || 'unknown_language',
), "?\n";
prints:
Parlez-vous... Elamite, Kuwait Arabic, English, Canadian English?
=head1 DESCRIPTION
This module provides a function
C<I18N::LangTags::List::name( I<langtag> ) > that takes
a language tag (see L<I18N::LangTags|I18N::LangTags>)
and returns the best attempt at an English name for it, or
undef if it can't make sense of the tag.
The function I18N::LangTags::List::name(...) is not exported.
This module also provides a function
C<I18N::LangTags::List::is_decent( I<langtag> )> that returns true iff
the language tag is syntactically valid and is for general use (like
"fr" or "fr-ca", below). That is, it returns false for tags that are
syntactically invalid and for tags, like "aus", that are listed in
brackets below. This function is not exported.
The map of tags-to-names that it uses is accessible as
%I18N::LangTags::List::Name, and it's the same as the list
that follows in this documentation, which should be useful
to you even if you don't use this module.
=head1 ABOUT LANGUAGE TAGS
Internet language tags, as defined in RFC 3066, are a formalism
for denoting human languages. The two-letter ISO 639-1 language
codes are well known (as "en" for English), as are their forms
when qualified by a country code ("en-US"). Less well-known are the
arbitrary-length non-ISO codes (like "i-mingo"), and the
recently (in 2001) introduced three-letter ISO-639-2 codes.
Remember these important facts:
=begin item
Language tags are not locale IDs. A locale ID is written with a "_"
instead of a "-", (almost?) always matches C<m/^\w\w_\w\w\b/>, and
I<means> something different than a language tag. A language tag
denotes a language. A locale ID denotes a language I<as used in>
a particular place, in combination with non-linguistic
location-specific information such as what currency is used
there. Locales I<also> often denote character set information,
as in "en_US.ISO8859-1".
=end item
=begin item
Language tags are not for computer languages.
=end item
=begin item
"Dialect" is not a useful term, since there is no objective
criterion for establishing when two language-forms are
dialects of eachother, or are separate languages.
=end item
=begin item
Language tags are not case-sensitive. en-US, en-us, En-Us, etc.,
are all the same tag, and denote the same language.
=end item
=begin item
Not every language tag really refers to a single language. Some
language tags refer to conditions: i-default (system-message text
in English plus maybe other languages), und (undetermined
language). Others (notably lots of the three-letter codes) are
bibliographic tags that classify whole groups of languages, as
with cus "Cushitic (Other)" (i.e., a
language that has been classed as Cushtic, but which has no more
specific code) or the even less linguistically coherent
sai for "South American Indian (Other)". Though useful in
bibliography, B<SUCH TAGS ARE NOT
FOR GENERAL USE>. For further guidance, email me.
=end item
=begin item
Language tags are not country codes. In fact, they are often
distinct codes, as with language tag ja for Japanese, and
ISO 3166 country code C<.jp> for Japan.
=end item
=head1 LIST OF LANGUAGES
The first part of each item is the language tag, between
{...}. It is followed by an English name for the language or language-group.
Language tags that I judge to be not for general use, are bracketed.
This list is in alphabetical order by English name of the language.
=begin item
{ab} : Abkhazian
eq Abkhaz
=end item
=item {ace} : Achinese
=item {ach} : Acoli
=item {ada} : Adangme
=begin item
{ady} : Adyghe
eq Adygei
=end item
=item {aa} : Afar
=begin item
{afh} : Afrihili
(Artificial)
=end item
=item {af} : Afrikaans
=item [{afa} : Afro-Asiatic (Other)]
=begin item
{ak} : Akan
(Formerly "aka".)
=end item
=begin item
{akk} : Akkadian
(Historical)
=end item
=item {sq} : Albanian
=item {ale} : Aleut
=begin item
[{alg} : Algonquian languages]
NOT Algonquin!
=end item
=item [{tut} : Altaic (Other)]
=begin item
{am} : Amharic
NOT Aramaic!
=end item
=begin item
{i-ami} : Ami
eq Amis. eq 'Amis. eq Pangca.
=end item
=item [{apa} : Apache languages]
=begin item
{ar} : Arabic
Many forms are mutually un-intelligible in spoken media.
Notable forms:
{ar-ae} UAE Arabic;
{ar-bh} Bahrain Arabic;
{ar-dz} Algerian Arabic;
{ar-eg} Egyptian Arabic;
{ar-iq} Iraqi Arabic;
{ar-jo} Jordanian Arabic;
{ar-kw} Kuwait Arabic;
{ar-lb} Lebanese Arabic;
{ar-ly} Libyan Arabic;
{ar-ma} Moroccan Arabic;
{ar-om} Omani Arabic;
{ar-qa} Qatari Arabic;
{ar-sa} Sauda Arabic;
{ar-sy} Syrian Arabic;
{ar-tn} Tunisian Arabic;
{ar-ye} Yemen Arabic.
=end item
=begin item
{arc} : Aramaic
NOT Amharic! NOT Samaritan Aramaic!
=end item
=item {arp} : Arapaho
=item {arn} : Araucanian
=item {arw} : Arawak
=item {hy} : Armenian
=item {an} : Aragonese
=item [{art} : Artificial (Other)]
=begin item
{ast} : Asturian
eq Bable.
=end item
=item {as} : Assamese
=begin item
[{ath} : Athapascan languages]
eq Athabaskan. eq Athapaskan. eq Athabascan.
=end item
=item [{aus} : Australian languages]
=item [{map} : Austronesian (Other)]
=begin item
{av} : Avaric
(Formerly "ava".)
=end item
=begin item
{ae} : Avestan
eq Zend
=end item
=item {awa} : Awadhi
=item {ay} : Aymara
=begin item
{az} : Azerbaijani
eq Azeri
Notable forms:
{az-Arab} Azerbaijani in Arabic script;
{az-Cyrl} Azerbaijani in Cyrillic script;
{az-Latn} Azerbaijani in Latin script.
=end item
=item {ban} : Balinese
=item [{bat} : Baltic (Other)]
=item {bal} : Baluchi
=begin item
{bm} : Bambara
(Formerly "bam".)
=end item
=item [{bai} : Bamileke languages]
=item {bad} : Banda
=item [{bnt} : Bantu (Other)]
=item {bas} : Basa
=item {ba} : Bashkir
=item {eu} : Basque
=item {btk} : Batak (Indonesia)
=item {bej} : Beja
=begin item
{be} : Belarusian
eq Belarussian. eq Byelarussian.
eq Belorussian. eq Byelorussian.
eq White Russian. eq White Ruthenian.
NOT Ruthenian!
=end item
=item {bem} : Bemba
=begin item
item {bn} : Bengali
eq Bangla.
=end item
=item [{ber} : Berber (Other)]
=item {bho} : Bhojpuri
=item {bh} : Bihari
=item {bik} : Bikol
=item {bin} : Bini
=begin item
{bi} : Bislama
eq Bichelamar.
=end item
=item {bs} : Bosnian
=item {bra} : Braj
=item {br} : Breton
=item {bug} : Buginese
=item {bg} : Bulgarian
=item {i-bnn} : Bunun
=item {bua} : Buriat
=item {my} : Burmese
=item {cad} : Caddo
=item {car} : Carib
=begin item
{ca} : Catalan
eq Catalán. eq Catalonian.
=end item
=item [{cau} : Caucasian (Other)]
=item {ceb} : Cebuano
=begin item
[{cel} : Celtic (Other)]
Notable forms:
{cel-gaulish} Gaulish (Historical)
=end item
=item [{cai} : Central American Indian (Other)]
=begin item
{chg} : Chagatai
(Historical?)
=end item
=item [{cmc} : Chamic languages]
=item {ch} : Chamorro
=item {ce} : Chechen
=begin item
{chr} : Cherokee
eq Tsalagi
=end item
=item {chy} : Cheyenne
=begin item
{chb} : Chibcha
(Historical) NOT Chibchan (which is a language family).
=end item
=begin item
{ny} : Chichewa
eq Nyanja. eq Chinyanja.
=end item
=begin item
{zh} : Chinese
Many forms are mutually un-intelligible in spoken media.
Notable forms:
{zh-Hans} Chinese, in simplified script;
{zh-Hant} Chinese, in traditional script;
{zh-tw} Taiwan Chinese;
{zh-cn} PRC Chinese;
{zh-sg} Singapore Chinese;
{zh-mo} Macau Chinese;
{zh-hk} Hong Kong Chinese;
{zh-guoyu} Mandarin [Putonghua/Guoyu];
{zh-hakka} Hakka [formerly "i-hakka"];
{zh-min} Hokkien;
{zh-min-nan} Southern Hokkien;
{zh-wuu} Shanghaiese;
{zh-xiang} Hunanese;
{zh-gan} Gan;
{zh-yue} Cantonese.
=comment {i-hakka} Hakka (old tag)
=end item
=begin item
{chn} : Chinook Jargon
eq Chinook Wawa.
=end item
=item {chp} : Chipewyan
=item {cho} : Choctaw
=begin item
{cu} : Church Slavic
eq Old Church Slavonic.
=end item
=begin item
{chk} : Chuukese
eq Trukese. eq Chuuk. eq Truk. eq Ruk.
=end item
=item {cv} : Chuvash
=item {cop} : Coptic
=item {kw} : Cornish
=begin item
{co} : Corsican
eq Corse.
=end item
=begin item
{cr} : Cree
NOT Creek! (Formerly "cre".)
=end item
=begin item
{mus} : Creek
NOT Cree!
=end item
=item [{cpe} : English-based Creoles and pidgins (Other)]
=item [{cpf} : French-based Creoles and pidgins (Other)]
=item [{cpp} : Portuguese-based Creoles and pidgins (Other)]
=item [{crp} : Creoles and pidgins (Other)]
=begin item
{hr} : Croatian
eq Croat.
=end item
=item [{cus} : Cushitic (Other)]
=item {cs} : Czech
=begin item
{dak} : Dakota
eq Nakota. eq Latoka.
=end item
=item {da} : Danish
=item {dar} : Dargwa
=item {day} : Dayak
=begin item
{i-default} : Default (Fallthru) Language
Defined in RFC 2277, this is for tagging text
(which must include English text, and might/should include text
in other appropriate languages) that is emitted in a context
where language-negotiation wasn't possible -- in SMTP mail failure
messages, for example.
=end item
=item {del} : Delaware
=item {din} : Dinka
=begin item
{dv} : Divehi
eq Maldivian. (Formerly "div".)
=end item
=begin item
{doi} : Dogri
NOT Dogrib!
=end item
=begin item
{dgr} : Dogrib
NOT Dogri!
=end item
=item [{dra} : Dravidian (Other)]
=item {dua} : Duala
=begin item
{nl} : Dutch
eq Netherlander. Notable forms:
{nl-nl} Netherlands Dutch;
{nl-be} Belgian Dutch.
=end item
=begin item
{dum} : Middle Dutch (ca.1050-1350)
(Historical)
=end item
=item {dyu} : Dyula
=item {dz} : Dzongkha
=item {efi} : Efik
=begin item
{egy} : Ancient Egyptian
(Historical)
=end item
=item {eka} : Ekajuk
=begin item
{elx} : Elamite
(Historical)
=end item
=begin item
{en} : English
Notable forms:
{en-au} Australian English;
{en-bz} Belize English;
{en-ca} Canadian English;
{en-gb} UK English;
{en-ie} Irish English;
{en-jm} Jamaican English;
{en-nz} New Zealand English;
{en-ph} Philippine English;
{en-tt} Trinidad English;
{en-us} US English;
{en-za} South African English;
{en-zw} Zimbabwe English.
=end item
=begin item
{enm} : Old English (1100-1500)
(Historical)
=end item
=begin item
{ang} : Old English (ca.450-1100)
eq Anglo-Saxon. (Historical)
=end item
=item {i-enochian} : Enochian (Artificial)
=item {myv} : Erzya
=begin item
{eo} : Esperanto
(Artificial)
=end item
=item {et} : Estonian
=begin item
{ee} : Ewe
(Formerly "ewe".)
=end item
=item {ewo} : Ewondo
=item {fan} : Fang
=item {fat} : Fanti
=item {fo} : Faroese
=item {fj} : Fijian
=item {fi} : Finnish
=begin item
[{fiu} : Finno-Ugrian (Other)]
eq Finno-Ugric. NOT Ugaritic!
=end item
=item {fon} : Fon
=begin item
{fr} : French
Notable forms:
{fr-fr} France French;
{fr-be} Belgian French;
{fr-ca} Canadian French;
{fr-ch} Swiss French;
{fr-lu} Luxembourg French;
{fr-mc} Monaco French.
=end item
=begin item
{frm} : Middle French (ca.1400-1600)
(Historical)
=end item
=begin item
{fro} : Old French (842-ca.1400)
(Historical)
=end item
=item {fy} : Frisian
=item {fur} : Friulian
=begin item
{ff} : Fulah
(Formerly "ful".)
=end item
=item {gaa} : Ga
=begin item
{gd} : Scots Gaelic
NOT Scots!
=end item
=begin item
{gl} : Gallegan
eq Galician
=end item
=begin item
{lg} : Ganda
(Formerly "lug".)
=end item
=item {gay} : Gayo
=item {gba} : Gbaya
=begin item
{gez} : Geez
eq Ge'ez
=end item
=item {ka} : Georgian
=begin item
{de} : German
Notable forms:
{de-at} Austrian German;
{de-be} Belgian German;
{de-ch} Swiss German;
{de-de} Germany German;
{de-li} Liechtenstein German;
{de-lu} Luxembourg German.
=end item
=begin item
{gmh} : Middle High German (ca.1050-1500)
(Historical)
=end item
=begin item
{goh} : Old High German (ca.750-1050)
(Historical)
=end item
=item [{gem} : Germanic (Other)]
=item {gil} : Gilbertese
=item {gon} : Gondi
=item {gor} : Gorontalo
=begin item
{got} : Gothic
(Historical)
=end item
=item {grb} : Grebo
=begin item
{grc} : Ancient Greek
(Historical) (Until 15th century or so.)
=end item
=begin item
{el} : Modern Greek
(Since 15th century or so.)
=end item
=begin item
{gn} : Guarani
Guaraní
=end item
=item {gu} : Gujarati
=begin item
{gwi} : Gwich'in
eq Gwichin
=end item
=item {hai} : Haida
=begin item
{ht} : Haitian
eq Haitian Creole
=end item
=item {ha} : Hausa
=begin item
{haw} : Hawaiian
Hawai'ian
=end item
=begin item
{he} : Hebrew
(Formerly "iw".)
=comment {iw} Hebrew (old tag)
=end item
=item {hz} : Herero
=item {hil} : Hiligaynon
=item {him} : Himachali
=item {hi} : Hindi
=item {ho} : Hiri Motu
=begin item
{hit} : Hittite
(Historical)
=end item
=item {hmn} : Hmong
=item {hu} : Hungarian
=item {hup} : Hupa
=item {iba} : Iban
=item {is} : Icelandic
=begin item
{io} : Ido
(Artificial)
=end item
=begin item
{ig} : Igbo
(Formerly "ibo".)
=end item
=item {ijo} : Ijo
=item {ilo} : Iloko
=item [{inc} : Indic (Other)]
=item [{ine} : Indo-European (Other)]
=begin item
{id} : Indonesian
(Formerly "in".)
=comment {in} Indonesian (old tag)
=end item
=item {inh} : Ingush
=begin item
{ia} : Interlingua (International Auxiliary Language Association)
(Artificial) NOT Interlingue!
=end item
=begin item
{ie} : Interlingue
(Artificial) NOT Interlingua!
=end item
=begin item
{iu} : Inuktitut
A subform of "Eskimo".
=end item
=begin item
{ik} : Inupiaq
A subform of "Eskimo".
=end item
=item [{ira} : Iranian (Other)]
=item {ga} : Irish
=begin item
{mga} : Middle Irish (900-1200)
(Historical)
=end item
=begin item
{sga} : Old Irish (to 900)
(Historical)
=end item