summaryrefslogtreecommitdiff
path: root/macros/generic/tracklang/tracklang-manual.tex
blob: cd04b1e3ec439e364ef62fbe5deef3f5d0159857 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
% arara: lualatex
% arara: bib2gls: { group: on, options: [ "--replace-quotes" ] }
% arara: lualatex
% arara: bib2gls: { group: on, options: [ "--replace-quotes" ] } if found ("log", "Glossary entry `sym.")
% arara: lualatex
% arara: lualatex if found ("log", "Rerun to")

% This document requires glossaries v4.51, glossaries-extra v1.50
% and nlctuserguide.sty v1.09. If they haven't already 
% been uploaded to CTAN, they will be in a few days.

\documentclass[titlepage=false,oneside,
 fontsize=12pt,captions=tableheading]{scrbook}

\usepackage
 [
  floats,
  %debug=showwrgloss
 ]
 {nlctuserguide}

\usepackage{glossary-table}

\glsxtrnewgls{opt.envvar.}{\envvar}
\defsemanticcmd[style2]{\envvarfmt}{\texttt}{}
\defsemanticcmd[style1]{\langtagfmt}{\texttt}{}

\glsaddstoragekey{dialect}{}{\dialect}
\glsaddstoragekey{isotag}{}{\isotag}
\glsaddstoragekey{langtag}{}{\langtag}
\glsxtrprovidestoragekey{tags}{}{}
\glsxtrprovidestoragekey{region}{}{}
\glsaddstoragekey{numeric}{}{\numerictag}
\glsxtrprovidestoragekey{alpha3}{}{}

\newcommand{\optisotag}[1]{\isotag{opt.#1}}
\newcommand{\iso}[1]{\glslink{opt.#1}{\optfmt{\optisotag{#1}}}}
\newcommand{\numericcode}[1]{\glslink{opt.#1}{\glsxtrusefield{opt.#1}{numeric}}}

\newcommand{\tklscript}[1]{\glslink{TrackLangScriptCode}{\csfmt{TrackLangScript#1}}}
\newcommand{\tklcaptions}[1]{\glslink{captionsdialect}{\csfmt{captions#1}}}
\newcommand{\tkldate}[1]{\glslink{datedialect}{\csfmt{date#1}}}

\newcommand{\ldf}[2]{%
 \glslink{file.prefix-localeid.ldf}{\filefmt{#1\dhyphen #2.ldf}}}
\newcommand{\localefile}[1]{%
 \glslink{file.prefix-localeid.ldf}{\metafilefmt{#1\dhyphen}{localeid}{.ldf}}}
\newcommand{\localemetafile}[1]{%
 \glslink{file.prefix-localeid.ldf}{\metametafilefmt{}{#1}{\dhyphen}{localeid}{.ldf}}}
\newcommand{\localemetametafile}[2]{%
 \glslink{file.prefix-localeid.ldf}{\metametafilefmt{}{#1}{\dhyphen}{#2}{.ldf}}}

\newcommand{\fnregion}{\fnsym*{2}}

\renewcommand{\filetag}[1]{}

\renewcommand{\nlctuserguidecustomentryaliases}{%
  isolangregion=index,
  rootlang=index,
  noniso=index,
  isocode=index,
  region=index,
  script=index
}

\nlctuserguidegls[selection=all]
{
  \def\genvvar#1#2{%
   \glsbibwriteentry{option}{opt.envvar.#1}{%
    \field{name}{\envvarfmt{#1}}\parent{idx.envvar}#2}}%
  \gidxpl{envvar}{\field{text}{environment variable}}
  % predefined ISO language-region tags
  % \gisolangtag{xx}{XX}{dialect}{options}
  \def\gisolangtag#1#2#3#4{%  
   \glsbibwriteentry{isolangregion}{opt.#1-#2}{%
    \name{\optfmt{#1-#2}}%
    \field{langtag}{#1}\field{region}{#2}%
    \field{isotag}{#1-#2}%
    \field{dialect}{#3}#4}%
  }%
  % \gisolangtagwithvar{xx}{XX}{variant}{dialect}{options}
  \def\gisolangtagwithvar#1#2#3#4#5{%  
   \glsbibwriteentry{isolangregion}{opt.#1-#2-#3}{%
    \name{\optfmt{#1-#2-#3}}%
    \field{langtag}{#1}\field{region}{#2}%
    \field{isotag}{#1-#2-#3}%
    \field{dialect}{#4}#5}%
  }%
  % predefined root language labels
  % \grootlangtag{language}{iso tag}{options}
  \def\grootlangtag#1#2#3{%  
   \glsbibwriteentry{rootlang}{opt.#1}{%
    \name{\optfmt{#1}}%
    \field{dialect}{#1}%
    \field{langtag}{#2}%
    \field{isotag}{#2}#3}%
   \glsbibwriteentry{isocode}{opt.#2}{\name{\optfmt{#2}}\field{alias}{opt.#1}}%
  }%
  % \grootlangsametag{language}{options}
  \def\grootlangsametag#1#2{%  
   \glsbibwriteentry{rootlang}{opt.#1}{%
    \name{\optfmt{#1}}%
    \field{dialect}{#1}%
    \field{langtag}{#1}%
    \field{isotag}{#1}#2}%
  }%
  % \grootlangtagwithreg{language}{lang}{region}{options}
  \def\grootlangtagwithreg#1#2#3#4{%  
   \glsbibwriteentry{rootlang}{opt.#1}{%
    \field{name}{\optfmt{#1}\fnregion}
    \field{text}{\optfmt{#1}}
    \field{region}{#3}
    \field{dialect}{#1}%
    \field{langtag}{#2}
    \field{isotag}{#2-#3}#4}%
   \glsbibwriteentry{isocode}{opt.#2}{\name{\optfmt{#2}}\field{alias}{opt.#1}}%
  }
  % predefined non-iso dialects
  % \gdialecttag{dialect}{tag}{options}
  \def\gdialecttag#1#2#3{%  
   \glsbibwriteentry{noniso}{opt.#1}{%
    \name{\optfmt{#1}}%
    \field{dialect}{#1}%
    \field{isotag}{\optisotag{#2}}%
    \field{tags}{\optfmt{\optisotag{#2}}}#3}%
  }%
  % \gdialecttagsuppl{dialect}{tag}{suppl}{options}
  \def\gdialecttagsuppl#1#2#3#4{%  
   \glsbibwriteentry{noniso}{opt.#1}{%
    \name{\optfmt{#1}}%
    \field{dialect}{#1}%
    \field{isotag}{\optisotag{#2}-#3}%
    \field{tags}{\optfmt{\optisotag{#2}-#3}}#4}%
  }%
  % \gdialecttagwithmap{dialect}{tag}{mapped}{options}
  \def\gdialecttagwithmap#1#2#3#4{%  
   \glsbibwriteentry{noniso}{opt.#1}{%
    \field{dialect}{#1}%
    \field{isotag}{\optisotag{#2}}%
    \field{tags}{\optfmt{\optisotag{#2}} / \optfmt{#3}}#4}%
  }%
  % \gdialecttagsupplwithmap{dialect}{tag}{suppl}{mapped}{options}
  \def\gdialecttagsupplwithmap#1#2#3#4#5{%  
   \glsbibwriteentry{noniso}{opt.#1}{%
    \name{\optfmt{#1}}%
    \field{dialect}{#1}%
    \field{isotag}{\optisotag{#2}-#3}%
    \field{tags}{\optfmt{\optisotag{#2}-#3} / \opt{#4}}#5}%
  }%
  % \gdialecttagwithreg{dialect}{lang}{region}{options}
  \def\gdialecttagwithreg#1#2#3#4{%  
   \glsbibwriteentry{noniso}{opt.#1}{%
    \field{name}{\optfmt{#1}\fnregion }
    \field{text}{\optfmt{#1}}
    \field{region}{#3}
    \field{dialect}{#1}%
    \field{isotag}{\langtag{opt.#2}-#3}%
    \field{tags}{\optfmt{\langtag{opt.#2}-#3}}#4
   }%
  }%
  % \gdialecttagwithmapandreg{dialect}{tag}{region}{mapped}{options}
  \def\gdialecttagwithmapandreg#1#2#3#4#5{%  
   \glsbibwriteentry{noniso}{opt.#1}{%
    \field{name}{\optfmt{#1}\fnregion }
    \field{text}{\optfmt{#1}}
    \field{region}{#3}
    \field{dialect}{#1}%
    \field{isotag}{\optisotag{#2}-#3}%
    \field{tags}{\optfmt{\langtag{opt.#2}-#3} / \opt{#4}}#5}%
  }%
  % \gregion{numeric}{2-alpha}{3-alpha}{options}
  \def\gregion#1#2#3#4{%
   \glsbibwriteentry{region}{opt.#2}{%
     \field{name}{\optfmt{#2}}
     \field{numeric}{#1}\field{alpha3}{#3}
     #4}%
  }%
  % \gscript{alpha}{numeric}{name}{direction}{parent}{options}
  \def\gscript#1#2#3#4#5#6{%
   \glsbibwriteentry{script}{opt.#1}{%
     \field{name}{\optfmt{#1}}
     \field{numeric}{#2}\field{user2}{#4}\field{description}{#3}
     #6}%
  }%
  % COMMANDS
  % \AnyTrackedLanguages
  \gcmd{Any\-Track\-ed\-Lan\-guages}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there are any tracked languages,
    otherwise expands to \meta{false}}
  }
  % \IfTrackedLanguage
  \gcmd{If\-Track\-ed\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{language-label}\margm{true}\margm{false}}
    \desc{does \meta{true} if the language identified by
    \meta{language-label} has been tracked,
     otherwise does \meta{false}}
  }
  % \IfTrackedDialect
  \gcmd{If\-Track\-ed\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{dialect-label}\margm{true}\margm{false}}
    \desc{does \meta{true} if the dialect identified by
    \meta{dialect-label} has been tracked,
     otherwise does \meta{false}}
  }
  % \IfTrackedLanguageFileExists
  \gcmd{If\-Track\-ed\-Lan\-guage\-File\-Exists}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{dialect}\margm{prefix}\margm{suffix}\margm{true
code}\margm{false code}}
    \desc{does \code{\gls{SetCurrentTrackedDialect}\margm{dialect}} 
    and if the dialect is recognised, then determines if the file
    \filefmt{\meta{prefix}\meta{tag}\meta{suffix}} exists. If it does,
    \gls{CurrentTrackedTag} is set to \meta{tag} and \meta{true} is
    done, otherwise \meta{false} is done}
  }
  % \CurrentTrackedTag
  \gcmd{Current\-Track\-ed\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \desc{expands to the current tracked tag}
  }
  % \ifTrackLangShowWarnings
  \gcond{if\-Track\-Lang\-Show\-Warnings}
  {
    \initval{\cmd{iftrue}}
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{conditional that indicates whether or not to show warnings}
  }
  % \TrackLangShowWarningsfalse
  \gcmd{Track\-Lang\-Show\-Warnings\-false}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{sets \gls{ifTrackLangShowWarnings} to false}
  }
  % \TrackLangShowWarningstrue
  \gcmd{Track\-Lang\-Show\-Warnings\-true}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{sets \gls{ifTrackLangShowWarnings} to true}
  }
  % \ifTrackLangShowInfo
  \gcond{if\-Track\-Lang\-Show\-Info}
  {
    \initval{\cmd{iftrue}}
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{conditional that indicates whether or not to show
information messages}
  }
  % \ifTrackLangShowVerbose
  \gcond{if\-Track\-Lang\-Show\-Verbose}
  {
    \initval{\cmd{iffalse}}
    \providedby{\file{tracklang.tex} v1.4+}
    \desc{conditional that indicates whether or not to show
verbose messages}
  }
  % \TrackLangQueryEnv
  \gcmd{Track\-Lang\-Query\-Env}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{attempts to obtain locale information from the
    \envvar{LCALL} environment variable via the \idx{shellescape}
    or, with \LuaTeX, \gls{directlua}}
  }
  % \TrackLangQueryOtherEnv
  \gcmd{Track\-Lang\-Query\-Other\-Env}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{env-name}}
    \desc{attempts to obtain locale information from the
    \envvar{LCALL} environment variable and then by the
    \meta{env-name} environment variable via the \idx{shellescape}
    or, with \LuaTeX, \gls{directlua}}
  }
  % \TrackLangParseFromEnv
  \gcmd{Track\-Lang\-Parse\-From\-Env}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{attempts to obtain locale information from the
    expansion of \gls{TrackLangEnv}}
  }
  % \TrackLangEnv
  \gcmd{Track\-Lang\-Env}
  {
    \note{user defined}
    \desc{may be defined using the same format as \envvar{LCALL}
    before using \gls{TrackLangParseFromEnv} to skip the environment
    variable query}
  }
  % \TrackLangEnvLang
  \gcmd{Track\-Lang\-Env\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{set by \gls{TrackLangParseFromEnv} to the language code}
  }
  % \TrackLangEnvTerritory
  \gcmd{Track\-Lang\-Env\-Territory}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{set by \gls{TrackLangParseFromEnv} to the \idx{territory}}
  }
  % \TrackLangEnvCodeSet
  \gcmd{Track\-Lang\-Env\-Code\-Set}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{set by \gls{TrackLangParseFromEnv} to the \idx{code-set}}
  }
  % \TrackLangEnvModifier
  \gcmd{Track\-Lang\-Env\-Modifier}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{set by \gls{TrackLangParseFromEnv} to the \idx{modifier}}
  }
  % \ForEachTrackedLanguage
  \gcmd{For\-Each\-Track\-ed\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{cs}\margm{body}}
    \desc{iterates through the list of tracked languages. On each
    iteration \meta{cs} is set to the language tag and \meta{body} is
    performed}
  }
  % \ForEachTrackedDialect
  \gcmd{For\-Each\-Track\-ed\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{cs}\margm{body}}
    \desc{iterates through the list of tracked dialects. On each
    iteration \meta{cs} is set to the dialect tag and \meta{body} is
    performed}
  }
  % \TrackLangNewLanguage
  \gcmd{Track\-Lang\-New\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language label}\margm{639-1 code}\margm{639-2 (T)}%
    \margm{639-2 (B)}\margm{639-3}\margm{3166-1}\margm{default script}}
    \desc{identifies a new language that may be tracked. Apart from
    \meta{language label}, the other arguments may be empty if
    the information is unavailable}
  }
  % \TrackLangIfKnownLang
  \gcmd{Track\-Lang\-If\-Known\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}\margm{true}\margm{false}}
    \desc{does \meta{true} if \meta{language} is known 
    (but not necessarily tracked), otherwise does \meta{false}}
  }
  % \TrackLangIfKnownIsoTwoLetterLang
  \gcmd{Track\-Lang\-If\-Known\-Iso\-Two\-Letter\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}\margm{true}\margm{false}}
    \desc{does \meta{true} if \meta{language} has an \idxn{639-1} code 
    (but is not necessarily tracked), otherwise does \meta{false}}
  }
  % \TrackLangGetKnownIsoTwoLetterLang
  \gcmd{Track\-Lang\-Get\-Known\-Iso\-Two\-Letter\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}}
    \desc{expands to the \idxn{639-1} language code associated with
    \meta{language}}
  }
  % \TrackLangIfKnownIsoThreeLetterLang
  \gcmd{Track\-Lang\-If\-Known\-Iso\-Three\-Letter\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}\margm{true}\margm{false}}
    \desc{does \meta{true} if \meta{language} has an \idxn{639-2} code 
    (but is not necessarily tracked), otherwise does \meta{false}}
  }
  % \TrackLangGetKnownIsoThreeLetterLang
  \gcmd{Track\-Lang\-Get\-Known\-Iso\-Three\-Letter\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}}
    \desc{expands to the \idxn{639-2} language code associated with
    \meta{language}}
  }
  % \TrackLangIfKnownIsoThreeLetterLangB
  \gcmd{Track\-Lang\-If\-Known\-Iso\-Three\-Letter\-LangB}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}\margm{true}\margm{false}}
    \desc{does \meta{true} if \meta{language} has an \idxn{639-2B} code 
    (but is not necessarily tracked), otherwise does \meta{false}}
  }
  % \TrackLangGetKnownIsoThreeLetterLangB
  \gcmd{Track\-Lang\-Get\-Known\-Iso\-Three\-Letter\-LangB}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}}
    \desc{expands to the \idxn{639-2B} language code associated with
    \meta{language}}
  }
  % \IfTrackedLanguageHasIsoCode
  \gcmd{If\-Track\-ed\-Lan\-guage\-Has\-Iso\-Code}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{code type}\margm{label}\margm{true}\margm{false}}
    \desc{does \meta{true} if the given language or dialect has a
    corresponding \idx{ISO} code of the given type, otherwise does
    \meta{false}}
  }
  % \IfTrackedIsoCode
  \gcmd{If\-Track\-ed\-Iso\-Code}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{code type}\margm{code}\margm{true}\margm{false}}
    \desc{does \meta{true} if the given \idx{ISO} code has been defined
    otherwise does \meta{false}}
  }
  % \TrackLangIfKnownLangFromIso
  \gcmd{Track\-Lang\-If\-Known\-Lang\-From\-Iso}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{ISO code}\margm{true}\margm{false}}
    \desc{does \meta{true} if the given language code (\idx{639-1} or 
    \idx{639-2} or \idx{639-3}) is
    recognised (but not necessarily tracked), otherwise does \meta{false}}
  }
  % \TrackLangGetKnownLangFromIso
  \gcmd{Track\-Lang\-Get\-Known\-Lang\-From\-Iso}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{ISO code}}
    \desc{expands to the root language label from the 
    given \idx{ISO} code (\idx{639-1} or \idx{639-2} or \idx{639-3})}
  }
  % \TrackLangIfHasKnownCountry
  \gcmd{Track\-Lang\-If\-Has\-Known\-Coun\-try}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}\margm{true}\margm{false}}
    \desc{does \meta{true} if the given language has an \idxn{3166-1}
    country code (but is not necessarily tracked), otherwise does \meta{false}}
  }
  % \TrackLangGetKnownCountry
  \gcmd{Track\-Lang\-Get\-Known\-Coun\-try}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}}
    \desc{expands to the \idxn{3166-1} country code for the given language}
  }
  % \TrackLangGetDefaultScript
  \gcmd{Track\-Lang\-Get\-Default\-Script}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}}
    \desc{expands to the default script for the given language}
  }
  % \TrackLangIfHasDefaultScript
  \gcmd{Track\-Lang\-If\-Has\-Default\-Script}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}\margm{true}\margm{false}}
    \desc{does \meta{true} if the given language has a default
    script (but is not necessarily tracked), otherwise does \meta{false}}
  }
  % \AddTrackedDialect
  \gcmd{Add\-Track\-ed\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{dialect label}\margm{root language label}}
    \desc{tracks a dialect. This command defines
\gls{TrackLangLastTrackedDialect} to provide a convenient way to
reference the last dialect to be tracked}
  }
  % \AddTrackedLanguage
  \gcmd{Add\-Track\-ed\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{root language label}}
    \desc{shortcut for \code{\gls{AddTrackedDialect}\margm{root language
label}\margm{root language label}}}
  }
  % \AddTrackedIsoLanguage
  \gcmd{Add\-Track\-ed\-Iso\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{code type}\margm{code}\margm{language}}
    \desc{adds a mapping between the given \idx{ISO} code and language name}
  }
  % \TrackedLanguageFromIsoCode
  \gcmd{Tracked\-Lan\-guage\-From\-Iso\-Code}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{code type}\margm{code}}
    \desc{expands to a comma-separated list of language or 
    dialect labels associated with the given code}
  }
  % \TrackedIsoCodeFromLanguage
  \gcmd{Track\-ed\-Iso\-Code\-From\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{code type}\margm{label}}
    \desc{expands to the code associated with the given language or
dialect identified by \meta{label}}
  }
  % \TrackedLanguageFromDialect
  \gcmd{Track\-ed\-Lan\-guage\-From\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{dialect}}
    \desc{expands to the language from the given dialect}
  }
  % \TrackedDialectsFromLanguage
  \gcmd{Tracked\-Di\-alects\-From\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{root language label}}
    \desc{expands to a comma-separated list of the tracked dialects with the given language}
  }
  % \TwoLetterIsoCountryCode
  \gcmd{Two\-Letter\-Iso\-Coun\-try\-Code}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \desc{expands to \idx{3166-1} (should not be redefined)}
  }
  % \TwoLetterIsoLanguageCode
  \gcmd{Two\-Letter\-Iso\-Lan\-guage\-Code}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \desc{expands to \idx{639-1} (should not be redefined)}
  }
  % \ThreeLetterIsoLanguageCode
  \gcmd{Three\-Letter\-Iso\-Lan\-guage\-Code}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \desc{expands to \idx{639-2} (should not be redefined)}
  }
  % \ThreeLetterExtIsoLanguageCode
  \gcmd{Three\-Letter\-Ext\-Iso\-Lan\-guage\-Code}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{expands to \idx{639-3} (should not be redefined)}
  }
  % \SetTrackedDialectModifier
  \gcmd{Set\-Track\-ed\-Di\-alect\-Mod\-i\-fier}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{value}}
    \desc{sets the modifier for the given \meta{dialect} to
\meta{value}}
  }
  % \GetTrackedDialectModifier
  \gcmd{Get\-Track\-ed\-Di\-alect\-Mod\-i\-fier}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{expands to the modifier for the given dialect}
  }
  % \IfHasTrackedDialectModifier
  \gcmd{If\-Has\-Track\-ed\-Di\-alect\-Mod\-i\-fier}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a modifier for the given
dialect, otherwise expands to \meta{false}}
  }
  % \SetTrackedDialectScript
  \gcmd{Set\-Track\-ed\-Di\-alect\-Script}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{value}}
    \desc{sets the script for \meta{dialect} to \meta{value}}
  }
  % \GetTrackedDialectScript
  \gcmd{Get\-Track\-ed\-Di\-alect\-Script}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{expands to the script for \meta{dialect}}
  }
  % \IfHasTrackedDialectScript
  \gcmd{If\-Has\-Track\-ed\-Di\-alect\-Script}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a script for
    \meta{dialect},  otherwise expands to \meta{false}}
  }
  % \IfTrackedDialectIsScriptCs
  \gcmd{If\-Track\-ed\-Di\-alect\-Is\-Script\-Cs}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{cs}\margm{true}\margm{false}}
    \desc{if the given tracked dialect has an associated script and that
     script code matches the replacement text for the control sequence
     \meta{cs} then do \meta{true} otherwise to \meta{false}. If the
     tracked dialect doesn't have an associated script then the default
     script for the root language is tested}
  }
  % \SetTrackedDialectVariant
  \gcmd{Set\-Track\-ed\-Di\-alect\-Vari\-ant}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{value}}
    \desc{sets the modifier for \meta{dialect} to \meta{value}}
  }
  % \GetTrackedDialectVariant
  \gcmd{Get\-Track\-ed\-Di\-alect\-Vari\-ant}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{expands to the modifier for \meta{dialect}}
  }
  % \IfHasTrackedDialectVariant
  \gcmd{If\-Has\-Track\-ed\-Di\-alect\-Vari\-ant}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a modifier for
    \meta{dialect},  otherwise expands to \meta{false}}
  }
  % \SetTrackedDialectSubLang
  \gcmd{Set\-Track\-ed\-Di\-alect\-Sub\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{value}}
    \desc{sets the sub-language for \meta{dialect} to \meta{value}}
  }
  % \GetTrackedDialectSubLang
  \gcmd{Get\-Track\-ed\-Di\-alect\-Sub\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{expands to the sub-language for \meta{dialect}}
  }
  % \IfHasTrackedDialectSubLang
  \gcmd{If\-Has\-Track\-ed\-Di\-alect\-Sub\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a sub-language for
    \meta{dialect},  otherwise expands to \meta{false}}
  }
  % \SetTrackedDialectAdditional
  \gcmd{Set\-Track\-ed\-Di\-alect\-Ad\-di\-tional}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{value}}
    \desc{sets the extra information for \meta{dialect} to \meta{value}}
  }
  % \GetTrackedDialectAdditional
  \gcmd{Get\-Track\-ed\-Di\-alect\-Ad\-di\-tional}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{expands to the extra information for \meta{dialect}}
  }
  % \IfHasTrackedDialectAdditional
  \gcmd{If\-Has\-Track\-ed\-Di\-alect\-Ad\-di\-tional}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's extra information for
    \meta{dialect},  otherwise expands to \meta{false}}
  }
  % \GetTrackedLanguageTag
  \gcmd{Get\-Track\-ed\-Lan\-guage\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{gets the language tag for \meta{dialect}}
  }
  % \SetCurrentTrackedDialect
  \gcmd{Set\-Current\-Track\-ed\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}}
    \desc{sets the current tracked dialect}
  }
  % \CurrentTrackedDialect
  \gcmd{Current\-Track\-ed\-Dialect}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
      dialect label, which may be the supplied \meta{dialect} label
      or the mapped label or, if \meta{dialect} is a root language label, 
      the last tracked dialect for the given root language}
  }
  % \CurrentTrackedLanguage
  \gcmd{Current\-Track\-ed\-Language}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
     associated root language label}
  }
  % \CurrentTrackedDialectModifier
  \gcmd{Current\-Track\-ed\-Di\-alect\-Modifier}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
     associated modifier (may be empty)}
  }
  % \CurrentTrackedDialectVariant
  \gcmd{Current\-Track\-ed\-Di\-alect\-Variant}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
    associated variant (may be empty)}
  }
  % \CurrentTrackedDialectScript
  \gcmd{Current\-Track\-ed\-Di\-alect\-Script}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
     script associated with the dialect, or to the default script for the language}
  }
  % \CurrentTrackedDialectSubLang
  \gcmd{Current\-Track\-ed\-Di\-alect\-Sub\-Lang}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the sub
     language associated with the dialect (may be empty)}
  }
  % \CurrentTrackedDialectAdditional
  \gcmd{Current\-Track\-ed\-Di\-alect\-Ad\-di\-tional}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
     additional part associated with the dialect (may be empty)}
  }
  % \CurrentTrackedLanguageTag
  \gcmd{Current\-Track\-ed\-Lan\-guage\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the language
     tag that identifies the dialect or \iso{undetermined} if no match}
  }
  % \CurrentTrackedRegion
  \gcmd{Current\-Track\-ed\-Region}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the 
    \idxn{3166-1} region code associated with the dialect (may be empty)}
  }
  % \CurrentTrackedIsoCode
  \gcmd{Current\-Track\-ed\-Iso\-Code}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{SetCurrentTrackedDialect} to the
     \idxn{639-1} or \idx{639-2} or \idx{639-3} language code (may be empty)}
  }
  % \AddTrackedLanguageIsoCodes
  \gcmd{Add\-Track\-ed\-Lan\-guage\-Iso\-Codes}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{root language label}}
    \desc{adds the \idxn{639-1}, \idx{639-2} and \idx{639-3} codes, which must have
    previously been declared using \gls{TrackLangNewLanguage}}
  }
  % \AddTrackedCountryIsoCode
  \gcmd{Add\-Track\-ed\-Coun\-try\-Iso\-Code}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language}}
    \desc{adds the \idxn{3166-1} code}
  }
  % \GetTrackedDialectFromLanguageTag
  \gcmd{Get\-Track\-ed\-Di\-alect\-From\-Lan\-guage\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{cs}}
    \desc{finds the tracked dialect that matches the given language
    tag and stores the dialect label in \meta{cs}. If no match found,
    \meta{cs} will be empty}
  }
  % \TrackedDialectClosestSubMatch
  \gcmd{Track\-ed\-Dialect\-Closest\-Sub\-Match}
  {
    \providedby{\file{tracklang.tex} v1.3.6+}
    \desc{defined by \gls{GetTrackedDialectFromLanguageTag} to the
    closest match}
  }
  % \TrackPredefinedDialect
  \gcmd{Track\-Pre\-de\-fined\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\margm{dialect label}}
    \desc{tracks a predefined language or dialect}
  }
  % \TrackLangIfAlphaNumericChar
  \gcmd{Track\-Lang\-If\-Alpha\-Numeric\-Char}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{true}\margm{false}}
    \desc{does \meta{true} if the argument is a single alphanumeric character
     otherwise does \meta{false}}
  }
  % \TrackLangIfLanguageTag
  \gcmd{Track\-Lang\-If\-Lan\-guage\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{true}\margm{false}}
    \desc{does \meta{true} if the argument is a language tag
     otherwise does \meta{false}}
  }
  % \TrackLangIfRegionTag
  \gcmd{Track\-Lang\-If\-Region\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{true}\margm{false}}
    \desc{does \meta{true} if the argument is a region tag
     otherwise does \meta{false}}
  }
  % \TrackLangIfScriptTag
  \gcmd{Track\-Lang\-If\-Script\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{true}\margm{false}}
    \desc{does \meta{true} if the argument is a script tag
     otherwise does \meta{false}}
  }
  % \TrackLangIfVariantTag
  \gcmd{Track\-Lang\-If\-Vari\-ant\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{true}\margm{false}}
    \desc{does \meta{true} if the argument is a variant tag
     otherwise does \meta{false}}
  }
  % \TrackLanguageTag
  \gcmd{Track\-Lan\-guage\-Tag}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}}
    \desc{parse \meta{tag}, which should be a regular, well-formed
     RFC 5646 language tag (not an irregular grandfather tag) and track the dialect}
  }
  % \TrackIfKnownLanguage
  \gcmd{Track\-If\-Known\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.3.9+}
    \syntax{\margm{tag}\margm{success code}\margm{fail code}}
    \desc{as \gls{TrackLanguageTag} but does \meta{fail code}
    if the tag doesn't contain a valid language code. If successful, does
    \meta{success code} after tracking the language}
  }
  % \TrackLangAddExtraRegionFile
  \gcmd{Track\-Lang\-Add\-Extra\-Region\-File}
  {
    \providedby{\file{tracklang.tex} v1.4+}
    \syntax{\margm{file}}
    \desc{adds \meta{file} to the list of extra region code files that should
    be input by \file{tracklang-region-codes.tex}}
  }
  % \TrackLangAddExtraScriptFile
  \gcmd{Track\-Lang\-Add\-Extra\-Script\-File}
  {
    \providedby{\file{tracklang.tex} v1.4+}
    \syntax{\margm{file}}
    \desc{adds \meta{file} to the list of files that should
    be input by \file{tracklang-scripts.tex}}
  }
  % \TrackLangFromEnv
  \gcmd{Track\-Lang\-From\-Env}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{queries environment variable if \gls{TrackLangEnv} not
    already set, parses \gls{TrackLangEnv} if it has been set, and
    adds the dialect if it's recognised}
  }
  % \TrackLocale
  \gcmd{Track\-Locale}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{locale}}
    \desc{tracks the dialect identified by the given \meta{locale}, which
    may either be a predefined language\slash dialect or in the same format as
    \gls{TrackLangEnv}}
  }
  % \TrackLangProvidePredefinedLanguage
  \gcmd{Track\-Lang\-Provide\-Pre\-de\-fined\-Lan\-guage}
  {
    \providedby{\file{tracklang.tex} v1.4+}
    \syntax{\margm{language label}}
    \desc{sets up a language label for use with \gls{TrackPredefinedDialect}}
  }
  % \TrackLangDeclareLanguageOption
  \gcmd{Track\-Lang\-Declare\-Lan\-guage\-Op\-tion}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{language name}\margm{639-1 code}\margm{639-2 (T)}\margm{639-2
(B)}\margm{639-3}\margm{3166-1}\margm{default script}}
    \desc{defines a new root language that's declared as an option}
  }
  % \TrackLangProvidePredefinedDialect
  \gcmd{Track\-Lang\-Provide\-Pre\-de\-fined\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.4+}
    \syntax{\margm{dialect label}\margm{root
language label}\margm{3166-1 code}\margm{modifier}\margm{variant}\margm{map}\margm{script}}
    \desc{defines a predefined dialect label that can be used
by \gls{TrackPredefinedDialect}}
  }
  % \TrackLangDeclareDialectOption
  \gcmd{Track\-Lang\-Declare\-Di\-alect\-Op\-tion}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{dialect}\margm{root
language}\margm{3166-1
code}\margm{modifier}\margm{variant}\margm{map}\margm{script}}
    \desc{defines a predefined dialect label that can be used
by \gls{TrackPredefinedDialect}}
  }
  % \TrackLangProvidesResource
  \gcmd{Track\-Lang\-Provides\-Resource}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\oargm{version info}}
    \desc{analogous to \gls{ProvidesFile}}
  }
  % \TrackLangEncodingName
  \gcmd{Track\-Lang\-Encoding\-Name}
  {
    \providedby{\file{tracklang.tex} v1.6.1+}
    \desc{expands to \gls{inputencodingname} if it has been defined
    or \code{utf8} otherwise}
  }
  % \TrackLangAddToHook
  \gcmd{Track\-Lang\-Add\-To\-Hook}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{code}\margm{type}}
    \desc{for use within resource files, this can be used to add
\meta{code} to the appropriate hook}
  }
  % \TrackLangAddToCaptions
  \gcmd{Track\-Lang\-Add\-To\-Captions}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{code}}
    \desc{a shortcut that just does
    \code{\gls{TrackLangAddToHook}\margm{code}\marg{captions}}}
  }
  % \TrackLangRedefHook
  \gcmd{Track\-Lang\-Re\-def\-Hook}
  {
    \providedby{\file{tracklang.tex} v1.4+}
    \syntax{\margm{code}\margm{type}}
    \desc{similar to \gls{TrackLangAddToHook} but redefines the hook
   rather than appending to it}
  }
  % \TrackLangRequireResource
  \gcmd{Track\-Lang\-Require\-Resource}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}}
    \desc{loads the appropriate \ext{ldf} file if it hasn't already
been loaded}
  }
  % \TrackLangRequireResourceOrDo
  \gcmd{Track\-Lang\-Require\-Resource\-Or\-Do}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{code1}\margm{code2}}
    \desc{as \gls{TrackLangRequireResource} but does \meta{code1} 
    if the file is now loaded or \meta{code2}
    if the file has already been loaded}
  }
  % \TrackLangRequestResource
  \gcmd{Track\-Lang\-Request\-Resource}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tag}\margm{not found code}}
    \desc{as \gls{TrackLangRequireResource} but does \meta{not found code}
if the file doesn't exist}
  }
  % \TrackLangRequireDialect
  \gcmd{Track\-Lang\-Require\-Di\-alect}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\oargm{load code}\margm{pkgname}\margm{dialect}}
    \desc{loads the dialect for the given package}
  }
  % \TrackLangRequireDialectPrefix
  \gcmd{Track\-Lang\-Require\-Di\-alect\-Prefix}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{defined by \gls{TrackLangRequireDialect}}
  }
  % \SetTrackedDialectLabelMap
  \gcmd{Set\-Track\-ed\-Di\-alect\-Label\-Map}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \syntax{\margm{tracklang-label}\margm{hook-label}}
    \desc{defines a mapping between a \sty{tracklang} dialect label
     and the corresponding dialect label used by a language hook, such as
     \gls{captionsdialect}}
  }
  % \TrackLangLastTrackedDialect
  \gcmd{Track\-Lang\-Last\-Track\-ed\-Dialect}
  {
    \providedby{\file{tracklang.tex} v1.3+}
    \desc{expands to the label of the last tracked dialect}
  }
  % COMMANDS: INTERNAL
  % \@tracklang@declareoption
  \gcmd{@track\-lang\-@\-declare\-option}
  {
    \providedby{\sty{tracklang} v1.1+}
    \syntax{\margm{dialect}}
    \desc{provided by \file{tracklang.sty} to declare \meta{dialect} 
     as a package option that tracks \meta{dialect}. Provided by
     \file{tracklang.tex}, if not already defined, to ignore its argument}
  }
  % \@tracklang@for
  \gcmd{@track\-lang\-@\-for}
  {
    \providedby{\file{tracklang.tex} v1.0+}
    \syntax{\meta{cs}:=\meta{list}\cmd{do}\margm{body}}
    \desc{as \LaTeX's \gls{@for}}
  }
  % \@tracklang@prelangpkgcheck@hook
  \gcmd{@track\-lang\-@\-pre\-lang\-pkg\-check\-@\-hook}
  {
    \desc{if defined before \file{tracklang.sty} v1.3.8+ is loaded, this
    command will be done after package options have been processed but
    before the check for language packages, such as \sty{babel} and
    \sty{polyglossia}}
  }
  % COMMANDS: tracklang-region-codes.tex
  % \TrackLangAlphaIIToNumericRegion
  \gcmd{Track\-Lang\-Alpha\-II\-To\-Numeric\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{alpha-2 code}}
    \desc{expands to the numeric code corresponding to the given
alpha-2 code}
  }
  % \TrackLangNumericToAlphaIIRegion
  \gcmd{Track\-Lang\-Numeric\-To\-Alpha\-II\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{numeric code}}
    \desc{expands to the alpha-2 code corresponding to the given
numeric code}
  }
  % \TrackLangIfKnownAlphaIIRegion
  \gcmd{Track\-Lang\-If\-Known\-Alpha\-II\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{alpha-2 code}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a known mapping for the
given alpha-2 \idx{region} code, otherwise expands to \meta{false}}
  }
  % \TrackLangIfKnownNumericRegion
  \gcmd{Track\-Lang\-If\-Known\-Numeric\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{numeric code}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a known mapping for the
given numeric \idx{region} code, otherwise expands to \meta{false}}
  }
  % \TrackLangAlphaIIIToNumericRegion
  \gcmd{Track\-Lang\-Alpha\-III\-To\-Numeric\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{alpha-3 code}}
    \desc{expands to the numeric code corresponding to the given
alpha-3 code}
  }
  % \TrackLangNumericToAlphaIIIRegion
  \gcmd{Track\-Lang\-Numeric\-To\-Alpha\-III\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{numeric code}}
    \desc{expands to the alpha-3 code corresponding to the given
numeric code}
  }
  % \TrackLangIfKnownAlphaIIIRegion
  \gcmd{Track\-Lang\-If\-Known\-Alpha\-III\-Region}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{alpha-3 code}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a known mapping for the
given \meta{alpha-3 code}, otherwise expands to \meta{false}}
  }
  % \TrackLangRegionMap
  \gcmd{Track\-Lang\-Region\-Map}
  {
    \providedby{\file{tracklang-region-codes.tex} v1.3+}
    \syntax{\margm{numeric}\margm{alpha-2}\margm{alpha-3}}
    \desc{establishes a mapping between a numeric \idx{region} code
    and alpha-2 and alpha-3 codes}
  }
  % COMMANDS: tracklang-scripts.tex
  % \TrackLangScriptMap
  \gcmd{Track\-Lang\-Script\-Map}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{letter code}\margm{numeric code}\margm{script name}\margm{direction}\margm{parent script}}
    \desc{defines a mapping between an alpha code and a numeric code}
  }
  % \TrackLangScriptAlphaToNumeric
  \gcmd{Track\-Lang\-Script\-Alpha\-To\-Numeric}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}}
    \desc{expands to the numeric script code corresponding to the given alpha code}
  }
  % \TrackLangScriptIfKnownAlpha
  \gcmd{Track\-Lang\-Script\-If\-Known\-Alpha}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a known mapping for the
    given alpha script code otherwise expands to \meta{false}}
  }
  % \TrackLangScriptNumericToAlpha
  \gcmd{Track\-Lang\-Script\-Numeric\-To\-Alpha}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{numeric code}}
    \desc{expands to the alpha script code corresponding to the
     given numeric code}
  }
  % \TrackLangScriptIfKnownNumeric
  \gcmd{Track\-Lang\-Script\-If\-Known\-Numeric}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{numeric code}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if there's a known mapping for the
     given numeric script code otherwise expands to \meta{false}}
  }
  % \TrackLangScriptAlphaToName
  \gcmd{Track\-Lang\-Script\-Alpha\-To\-Name}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}}
    \desc{expands to the name associated with the given alpha script
    code}
  }
  % \TrackLangScriptAlphaToDir
  \gcmd{Track\-Lang\-Script\-Alpha\-To\-Dir}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}}
    \desc{expands to the direction associated with the given alpha script
    code}
  }
  % \TrackLangScriptSetParent
  \gcmd{Track\-Lang\-Script\-Set\-Parent}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}\margm{parent alpha code}}
    \desc{sets the parent for the given alpha script code}
  }
  % \TrackLangScriptGetParent
  \gcmd{Track\-Lang\-Script\-Get\-Parent}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}}
    \desc{expands to the parent of the given alpha script code}
  }
  % \TrackLangScriptIfHasParent
  \gcmd{Track\-Lang\-Script\-If\-Has\-Parent}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \syntax{\margm{alpha code}\margm{true}\margm{false}}
    \desc{expands to \meta{true} if the given alpha script code has
     a parent otherwise expands to \meta{false}}
  }
  % \TrackLangScript<Code>
  \gcmdmeta{Track\-Lang\-Script}{Code}{}
  {
    \providedby{\file{tracklang-scripts.tex} v1.3+}
    \desc{set by \gls{TrackLangScriptMap} to the associated alpha code \meta{Code}}
  }
  % FILES
  \gfile{track\-lang.tex}{}% tracklang.tex
  \gfile{track\-lang.sty}% tracklang.sty
  {\field{alias}{pkg.tracklang}}%
  \gfile{track\-lang\dhyphen scripts.sty}% tracklang-scripts.sty
  {\field{alias}{pkg.tracklang-scripts}}%
  \gfile{tracklang\dhyphen region\dhyphen codes.tex}{}% tracklang-region-codes.tex
  \gfile{tracklang\dhyphen scripts.tex}{}% tracklang-scripts.tex
  \gfile{tex\-os\-query.tex}{}% texosquery.tex
  \gfile{tex\-os\-query.cfg}{}% texosquery.cfg
  \gfilemetameta{}{prefix}{\dhyphen}{localeid}{.ldf}{} % <prefix>-<localeid>.ldf
  % FILE EXTENSIONS
  \gext{tex}{}% .tex
  \gext{ldf}{}% .ldf
  \gext{log}{}% .log
  % PACKAGES
  \gpkg{track\-lang}{\common}% tracklang
  \gpkg{track\-lang\dhyphen scripts}{}% tracklang-scripts
  \gpkg{tex\-os\-query}{}% texosquery
  \gpkg{poly\-glossia}{}% polyglossia.sty
  \gpkg{babel}{}% babel.sty
  \gpkg{translator}{}% translator.sty
  \gpkg{shell\-esc}{}% shellesc.sty
  \gpkg{ngerman}{}% ngerman.sty
  \gpkg{german}{}% german.sty
  \gpkg{glossaries}{}% glossaries.sty
  \gpkg{etool\-box}{}% etoolbox.sty
  \gpkg{date\-time2}{}% datetime2.sty
  \gpkg{input\-enc}{}% inputenc.sty
  % Example packages
  \gfile{animals.sty}{}% animals.sty
  \gfile{regions.sty}{}% regions.sty
  \gfile{alien.sty}{}% alien.sty
  \gpkg{alien}{\field{alias}{file.alien.sty}}
  % environment variables
  \genvvar{LC\dsb ALL}{}% LC_ALL
  \genvvar{LANG}{}% LANG
  \genvvar{LC\dsb MONETARY}{}% LC_MONETARY
  % TERMS
  \gterm{shellescape}
  {
     \name{shell escape}
     \desc{\TeX\ has the ability to run \idx{cli} applications while
      it's typesetting a document. Whilst this is a convenient way
      of using tools to help build the document, it's a security
      risk. To help protect users from arbitrary\dash and
      potentially dangerous\dash code from begin executed, \TeX\ has
      a restricted mode, where only trusted applications are allowed to
      run. This is usually the default mode, but your \TeX\
      installation may be set up so that the shell escape is disabled by
      default. The unrestricted mode allows you to run any
      application from the shell escape. Take care about
      enabling this option. If you receive a document or package
      from an untrusted source, first run \TeX\ with the shell escape
      disabled or in restricted mode and search the \ext+{log} file for
      \qt{runsystem} before using the unrestricted mode. Note that
      \LuaLaTeX\ additionally requires the \sty{shellesc} package}
  }
  \gtermacr{cli}{CLI}{command-line interface}%
  {%  
    \desc{an application that doesn't have a graphical user
     interface. That is, an application that doesn't have any windows,
     buttons or menus and can be run in
     \dickimawhref{latex/novices/html/terminal.html}{a command
     prompt or terminal}}% 
  }%
  % INDEX ONLY
  % COMMANDS - GENERAL
  \gcmd{input\-encoding\-name}{}% \inputencodingname
  \gcmd{Input\-If\-File\-Exists}{}% \InputIfFileExists
  \gcmd{direct\-lua}{}% \directlua
  \gcmd{babel\-provide}{}% \babelprovide
  \gcmd{bbl\-@\-loaded}{}% \bbl@loaded
  \gcmd{select\-language}{}% \selectlanguage
  \gcmd{input}{}% \input
  \gcmd{Require\-Package}{}% \RequirePackage
  \gcmd{Declare\-Option}{}% \DeclareOption
  \gcmdmeta{captions}{dialect}{}{}% \captions<dialect>
  \gcmdmeta{date}{dialect}{}{}% \date<dialect>
  \gcmd{Provides\-File}{}% \ProvidesFile
  \gcmd{xpg\-@\-bcp\-@\-loaded}{}% \xpg@bcp@loaded
  \gcmd{xpg\-@\-loaded}{}% \xpg@loaded
  \gcmd{trans\-@\-languages}{}% \trans@languages
  \gcmd{lan\-guage\-name}{}% \languagename
  \gcmd{TeX\-OS\-Query\-Lang\-Tag}{}% \TeXOSQueryLangTag
  \gcmd{TeX\-OS\-Query\-Locale}{}% \TeXOSQueryLocale
  \gcmd{@for}{}
  \gcmd{@nil}{}
  \gcmd{At\-Begin\-Doc\-u\-ment}{}% \AtBeginDocument
  % APPLICATIONS
  \gapp{tex\-os\-query}{}% texosquery
  \gapp{kpse\-which}{}% kpsewhich
  \gapp{etex}{}% etex
  \gapp{tex}{}% tex
  \gapp{pdflatex}{}% pdflatex
  % PUNCTUATION
  \gpunc{atletter}% @ as a letter
  {\name{\code{@} (catcode 11)}\field{text}{\code{@}}}%
  \gpunc{atmod}% @ separates modifier
  {\name{\code{@} (modifier)}\field{text}{\code{@}}}%
  \gpunc{hyphensep}% - in tag
  {\name{\code{-} (separator)}\field{text}{\code{-}}}%
  \gpunc{underscoresep}% _ in tag
  {\name{\code{\_} (separator)}\field{text}{\code{\_}}}%
  \gpunc{dotsep}% . separates code-set
  {\name{\code{.}\ (code-set)}\field{text}{\code{.}}}%
  \gpunc{dollarenv}% ${ENV VAR}
  {\name{\code{\$} (environment variable)}\field{text}{\code{\$}}}
  \gpunc{escbsl}% \\
  {\name{\code{\glsbackslash\glsbackslash} (escaped backslash)}
   \field{text}{\code{\glsbackslash\glsbackslash}}
  }
  % INDEX ONLY TERMS
  \gidx{code-set}{}
  \gidx{modifier}{}
  \gidx{variant}{}
  \gidx{territory}{}
  \gidx{region}{\field{alias}{idx.territory}}
  \gidx{script}{}
  \gidx{BCP47}{\name{BCP~47}}
  % ISO CODES
  \gidx{639-1}{\name{ISO \mbox{639-1}}\field{text}{\mbox{639-1}}}
  \gidx{639-2}{\name{ISO \mbox{639-2}}\field{text}{\mbox{639-2}}}
  \gidx{639-2B}{\parent{idx.639-2}%
    \name{ISO \mbox{639-2} (B)}%
    \field{text}{\mbox{639-2} (B)}}
  \gidx{639-2T}{\parent{idx.639-2}%
    \name{ISO \mbox{639-2} (T)}%
    \field{text}{\mbox{639-2} (T)}}
  \gidx{639-3}{\name{ISO \mbox{639-3}}\field{text}{\mbox{639-3}}}
  \gidx{3166-1}{\name{ISO \mbox{3166-1}}\field{text}{\mbox{3166-1}}}
  \gidx{15924}{\name{ISO 15924}\field{text}{15924}}
  % ABBREVIATIONS
  \gacr{ISO}{ISO}{International Organization for Standardization}{\common}
  \gacr{POSIX}{POSIX}{Portable Operating System Interface}{}
  % SWITCHES
  \glongswitchpunc{shell\dhyphen escape}{}
  % PREDEFINED ISO LANGUAGE-REGION TAGS
  \gisolangtag{en}{US}{american}{}
  \gisolangtag{en}{GB}{british}{}
  \gisolangtag{en}{AU}{australian}{}
  \gisolangtag{en}{NZ}{newzealand}{}
  \gisolangtag{en}{CA}{canadian}{}
  \gisolangtag{fr}{CA}{canadien}{}
  \gisolangtag{fr}{BE}{belgique}{}
  \gisolangtag{pt}{BR}{brazilian}{}
  \gisolangtag{it}{HR}{istriacountyitalian}{}
  \gisolangtag{nl}{BE}{flemish}{}
  \gisolangtag{fr}{FR}{france}{}
  \gisolangtag{de}{DE}{germanDE}{}
  \gisolangtag{de}{BE}{belgiangerman}{}
  \gisolangtag{en}{GG}{guernseyenglish}{}
  \gisolangtag{fr}{GG}{guernseyfrench}{}
  \gisolangtag{it}{IT}{italy}{}
  \gisolangtag{mt}{MT}{maltamaltese}{}
  \gisolangtag{en}{MT}{maltaenglish}{}
  \gisolangtag{en}{IM}{isleofmanenglish}{}
  \gisolangtag{en}{JE}{jerseyenglish}{}
  \gisolangtag{fr}{JE}{jerseyfrench}{}
  \gisolangtag{nl}{NL}{netherlands}{}
  \gisolangtag{pt}{PT}{portugal}{}
  \gisolangtag{it}{SM}{sanmarino}{}
  \gisolangtag{sl}{SI}{slovenia}{}
  \gisolangtag{it}{SI}{sloveneistriaitalian}{}
  \gisolangtag{es}{ES}{spainspanish}{}
  \gisolangtag{es}{AR}{argentinespanish}{}
  \gisolangtag{es}{BO}{bolivianspanish}{}
  \gisolangtag{es}{CL}{chilianspanish}{}
  \gisolangtag{es}{CO}{columbianspanish}{}
  \gisolangtag{es}{CR}{costaricanspanish}{}
  \gisolangtag{es}{CU}{cubanspanish}{}
  \gisolangtag{es}{DO}{dominicanspanish}{}
  \gisolangtag{es}{EC}{ecudorianspanish}{}
  \gisolangtag{es}{SV}{elsalvadorspanish}{}
  \gisolangtag{es}{GT}{guatemalanspanish}{}
  \gisolangtag{es}{HN}{honduranspanish}{}
  \gisolangtag{es}{MX}{mexicanspanish}{}
  \gisolangtag{es}{NI}{nicaraguanspanish}{}
  \gisolangtag{es}{PA}{panamaspanish}{}
  \gisolangtag{es}{PY}{paraguayspanish}{}
  \gisolangtag{es}{PE}{peruvianspanish}{}
  \gisolangtag{es}{PR}{puertoricospanish}{}
  \gisolangtag{es}{UY}{uruguayspanish}{}
  \gisolangtag{es}{VE}{venezuelanspanish}{}
  \gisolangtag{de}{CH}{swissgerman}{}
  \gisolangtag{fr}{CH}{swissfrench}{}
  \gisolangtag{it}{CH}{swissitalian}{}
  \gisolangtag{rm}{CH}{swissromansh}{}
  \gisolangtag{it}{VA}{vatican}{}
  \gisolangtag{ga}{IE}{IEirish}{}
  \gisolangtag{ga}{GB}{GBirish}{}
  \gisolangtag{en}{IE}{IEenglish}{}
  \gisolangtagwithvar{de}{AT}{1996}{naustrian}{}
  \gisolangtag{de}{AT}{austrian}{}
  \gisolangtag{id}{IN}{bahasa}{}
  \gisolangtag{ms}{MY}{malay}{}
  \gisolangtag{hr}{HR}{croatia}{}
  \gisolangtagwithvar{de}{DE}{1996}{ngermanDE}{}
  \gisolangtagwithvar{de}{CH}{1996}{nswissgerman}{}
  \gisolangtag{hu}{HU}{hungarian}{}
  \gisolangtag{gd}{GB}{GBscottish}{}
  \gisolangtag{cy}{GB}{GBwelsh}{}
  % PREDEFINED ROOT LANGUAGE TAGS
  \grootlangtag{abkhaz}{ab}{}
  \grootlangtag{afar}{aa}{}
  \grootlangtag{afrikaans}{af}{}
  \grootlangtag{akan}{ak}{}
  \grootlangtag{albanian}{sq}{}
  \grootlangtagwithreg{amharic}{am}{ET}{}
  \grootlangtag{anglosaxon}{ang}{}
  \grootlangtag{apache}{apa}{}
  \grootlangtag{arabic}{ar}{}
  \grootlangtagwithreg{aragonese}{an}{ES}{}
  \grootlangtag{armenian}{hy}{}
  \grootlangtag{assamese}{as}{}
  \grootlangtag{asturian}{ast}{}
  \grootlangtag{avaric}{av}{}
  \grootlangtag{avestan}{ae}{}
  \grootlangtag{aymara}{ay}{}
  \grootlangtag{azerbaijani}{az}{}
  \grootlangtagwithreg{bahasai}{id}{IN}{}
  \grootlangtagwithreg{bahasam}{ms}{MY}{}
  \grootlangtagwithreg{bambara}{bm}{ML}{}
  \grootlangtag{bashkir}{ba}{}
  \grootlangtag{basque}{eu}{}
  \grootlangtag{belarusian}{be}{}
  \grootlangtag{bengali}{bn}{}
  \grootlangtag{berber}{ber}{}
  \grootlangtag{bihari}{bh}{}
  \grootlangtagwithreg{bislama}{bi}{VU}{}
  \grootlangtagwithreg{bokmal}{nb}{NO}{}
  \grootlangtag{bosnian}{bs}{}
  \grootlangtagwithreg{breton}{br}{FR}{}
  \grootlangtag{bulgarian}{bg}{}
  \grootlangtag{burmese}{my}{}
  \grootlangtag{catalan}{ca}{}
  \grootlangtag{chamorro}{ch}{}
  \grootlangtag{chechen}{ce}{}
  \grootlangtag{chichewa}{ny}{}
  \grootlangtag{chinese}{zh}{}
  \grootlangtag{churchslavonic}{cu}{}
  \grootlangtagwithreg{chuvash}{cv}{RU}{}
  \grootlangtag{coptic}{cop}{}
  \grootlangtagwithreg{cornish}{kw}{GB}{}
  \grootlangtag{corsican}{co}{}
  \grootlangtag{cree}{cr}{}
  \grootlangtag{croatian}{hr}{}
  \grootlangtag{czech}{cs}{}
  \grootlangtag{danish}{da}{}
  \grootlangtagwithreg{divehi}{dv}{MV}{}
  \grootlangtag{dutch}{nl}{}
  \grootlangtagwithreg{dzongkha}{dz}{BT}{}
  \grootlangtagwithreg{easternpunjabi}{pa}{IN}{}
  \grootlangtag{english}{en}{}
  \grootlangtag{esperanto}{eo}{}
  \grootlangtag{estonian}{et}{}
  \grootlangtag{ewe}{ee}{}
  \grootlangtag{faroese}{fo}{}
  \grootlangtag{farsi}{fa}{}
  \grootlangtagwithreg{fijian}{fj}{FJ}{}
  \grootlangtag{finnish}{fi}{}
  \grootlangtag{french}{fr}{}
  \grootlangtagwithreg{friulan}{fur}{IT}{}
  \grootlangtag{fula}{ff}{}
  \grootlangtag{galician}{gl}{}
  \grootlangtagwithreg{ganda}{lg}{UG}{}
  \grootlangtag{georgian}{ka}{}
  \grootlangtag{german}{de}{}
  \grootlangtag{greek}{el}{}
  \grootlangtag{guarani}{gn}{}
  \grootlangtag{gujarati}{gu}{}
  \grootlangtagwithreg{haitian}{ht}{HT}{}
  \grootlangtag{hausa}{ha}{}
  \grootlangtag{hebrew}{he}{}
  \grootlangtag{herero}{hz}{}
  \grootlangtag{hindi}{hi}{}
  \grootlangtagwithreg{hirimotu}{ho}{PG}{}
  \grootlangtagwithreg{icelandic}{is}{IS}{}
  \grootlangtag{ido}{io}{}
  \grootlangtag{igbo}{ig}{}
  \grootlangtag{interlingua}{ia}{}
  \grootlangtag{interlingue}{ie}{}
  \grootlangtag{inuktitut}{iu}{}
  \grootlangtag{inupiaq}{ik}{}
  \grootlangtag{irish}{ga}{}
  \grootlangtag{italian}{it}{}
  \grootlangtag{japanese}{ja}{}
  \grootlangtag{javanese}{jv}{}
  \grootlangtag{kalaallisut}{kl}{}
  \grootlangtagwithreg{kannada}{kn}{IN}{}
  \grootlangtag{kanuri}{kr}{}
  \grootlangtagwithreg{kashmiri}{ks}{IN}{}
  \grootlangtag{kazakh}{kk}{}
  \grootlangtag{khmer}{km}{}
  \grootlangtag{kikuyu}{ki}{}
  \grootlangtag{kinyarwanda}{rw}{}
  \grootlangtag{kirundi}{rn}{}
  \grootlangtagwithreg{komi}{kv}{RU}{}
  \grootlangtag{kongo}{kg}{}
  \grootlangtag{korean}{ko}{}
  \grootlangtag{kurdish}{ku}{}
  \grootlangtag{kwanyama}{kj}{}
  \grootlangtag{kyrgyz}{ky}{}
  \grootlangtag{lao}{lo}{}
  \grootlangtag{latin}{la}{}
  \grootlangtag{latvian}{lv}{}
  \grootlangtag{limburgish}{li}{}
  \grootlangtag{lingala}{ln}{}
  \grootlangtag{lithuanian}{lt}{}
  \grootlangtagwithreg{lsorbian}{dsb}{DE}{}
  \grootlangtagwithreg{lubakatanga}{lu}{CD}{}
  \grootlangtag{luxembourgish}{lb}{}
  \grootlangtag{macedonian}{mk}{}
  \grootlangtag{magyar}{hu}{}
  \grootlangtag{malagasy}{mg}{}
  \grootlangtagwithreg{malayalam}{ml}{IN}{}
  \grootlangtag{maltese}{mt}{}
  \grootlangtagwithreg{manx}{gv}{IM}{}
  \grootlangtagwithreg{maori}{mi}{NZ}{}
  \grootlangtagwithreg{marathi}{mr}{IN}{}
  \grootlangtagwithreg{marshallese}{mh}{MH}{}
  \grootlangtag{mongolian}{mn}{}
  \grootlangtagwithreg{nauruan}{na}{NR}{}
  \grootlangtagwithreg{navajo}{nv}{US}{}
  \grootlangtag{ndonga}{ng}{}
  \grootlangtag{nepali}{ne}{}
  \grootlangtag{nko}{nqo}{}
  \grootlangtag{northernndebele}{nd}{}
  \grootlangtagwithreg{nynorsk}{nn}{NO}{}
  \grootlangtag{norsk}{no}{}
  \grootlangtag{northernsotho}{nso}{}
  \grootlangtagwithreg{nuosu}{ii}{CN}{}
  \grootlangtag{occitan}{oc}{}
  \grootlangtag{ojibwe}{oj}{}
  \grootlangtag{oromo}{om}{}
  \grootlangtag{oriya}{or}{}
  \grootlangtag{ossetian}{os}{}
  \grootlangtag{pali}{pi}{}
  \grootlangtag{pashto}{ps}{}
  \grootlangtagwithreg{piedmontese}{pms}{IT}{}
  \grootlangtag{polish}{pl}{}
  \grootlangtag{portuges}{pt}{}
  \grootlangtag{quechua}{qu}{}
  \grootlangtag{romanian}{ro}{}
  \grootlangtagwithreg{romansh}{rm}{CH}{}
  \grootlangtag{russian}{ru}{}
  \grootlangtag{samin}{se}{}
  \grootlangtag{sanskrit}{sa}{}
  \grootlangtag{samoan}{sm}{}
  \grootlangtag{sango}{sg}{}
  \grootlangtagwithreg{sardinian}{sc}{IT}{}
  \grootlangtag{scottish}{gd}{}
  \grootlangtag{serbian}{sr}{}
  \grootlangtag{shona}{sn}{}
  \grootlangtag{sindhi}{sd}{}
  \grootlangtagwithreg{sinhalese}{si}{LK}{}
  \grootlangtag{slovak}{sk}{}
  \grootlangtag{slovene}{sl}{}
  \grootlangtag{somali}{so}{}
  \grootlangtagwithreg{southernndebele}{nr}{ZA}{}
  \grootlangtag{southernsotho}{st}{}
  \grootlangtag{spanish}{es}{}
  \grootlangtag{sudanese}{su}{}
  \grootlangtag{swahili}{sw}{}
  \grootlangtag{swati}{ss}{}
  \grootlangtag{swedish}{sv}{}
  \grootlangtag{syriac}{syr}{}
  \grootlangtagwithreg{tagalog}{tl}{PH}{}
  \grootlangtagwithreg{tahitian}{ty}{PF}{}
  \grootlangsametag{tai}{}
  \grootlangtag{tajik}{tg}{}
  \grootlangtag{tamil}{ta}{}
  \grootlangtag{tatar}{tt}{}
  \grootlangtagwithreg{telugu}{te}{IN}{}
  \grootlangtagwithreg{thai}{th}{TH}{}
  \grootlangtag{tibetan}{bo}{}
  \grootlangtag{tigrinya}{ti}{}
  \grootlangtagwithreg{tonga}{to}{TO}{}
  \grootlangtag{tsonga}{ts}{}
  \grootlangtag{tswana}{tn}{}
  \grootlangtag{turkish}{tr}{}
  \grootlangtag{turkmen}{tk}{}
  \grootlangtagwithreg{twi}{tw}{GH}{}
  \grootlangtagwithreg{ukrainian}{uk}{UA}{}
  \grootlangtag{undetermined}{und}{}
  \grootlangtag{urdu}{ur}{}
  \grootlangtagwithreg{usorbian}{hsb}{DE}{}
  \grootlangtagwithreg{uyghur}{ug}{CN}{}
  \grootlangtag{uzbek}{uz}{}
  \grootlangtagwithreg{venda}{ve}{ZA}{}
  \grootlangtag{vietnamese}{vi}{}
  \grootlangtag{volapuk}{vo}{}
  \grootlangtag{walloon}{wa}{}
  \grootlangtag{welsh}{cy}{}
  \grootlangtagwithreg{westernfrisian}{fy}{NL}{}
  \grootlangtag{wolof}{wo}{}
  \grootlangtag{xhosa}{xh}{}
  \grootlangtag{yiddish}{yi}{}
  \grootlangtag{yoruba}{yo}{}
  \grootlangtagwithreg{zhuang}{za}{CN}{}
  \grootlangtag{zulu}{zu}{}
  % PREDEFINED NON-ISO DIALECTS
  \gdialecttag{acadian}{french}{}
  \gdialecttagwithreg{american}{english}{US}{}
  \gdialecttagwithreg{australian}{english}{AU}{}
  \gdialecttagwithreg{austrian}{german}{AT}{}
  \gdialecttagwithreg{naustrian}{german}{AT-1996}{}
  \gdialecttagwithreg{bahasa}{bahasai}{IN}{}
  \gdialecttagwithreg{brazil}{portuges}{BR}{}
  \gdialecttagwithreg{brazilian}{portuges}{BR}{}
  \gdialecttagwithreg{british}{english}{GB}{}
  \gdialecttagwithreg{canadian}{english}{CA}{}
  \gdialecttagwithreg{canadien}{french}{CA}{}
  \gdialecttagwithreg{croatia}{croatian}{HR}{}
  \gdialecttagwithreg{istriacountycroatian}{croatian}{HR}{}
  \gdialecttagwithreg{istriacountyitalian}{italian}{HR}{}
  \gdialecttagwithreg{netherlands}{dutch}{NL}{}
  \gdialecttag{persian}{farsi}{}
  \gdialecttagwithreg{flemish}{dutch}{BE}{}
  \gdialecttag{francais}{french}{}
  \gdialecttag{frenchb}{french}{}
  \gdialecttagwithreg{france}{french}{FR}{}
  \gdialecttagwithreg{belgique}{french}{BE}{}
  \gdialecttagwithreg{belgiangerman}{german}{BE}{}
  \gdialecttagwithmapandreg{nbelgiangerman}{german}{BE-1996}{ngerman}{}
  \gdialecttagwithreg{friulian}{friulan}{IT}{}
  \gdialecttagwithreg{friulano}{friulan}{IT}{}
  \gdialecttagwithreg{furlan}{friulan}{IT}{}
  \gdialecttag{kurmanji}{kurdish}{}
  \gdialecttag{galicien}{galician}{}
  \gdialecttag{deutsch}{german}{}
  \gdialecttagsuppl{ngerman}{german}{1996}{}
  \gdialecttagsupplwithmap{ngermanb}{german}{1996}{ngerman}{}
  \gdialecttag{germanb}{german}{}
  \gdialecttagwithmapandreg{ngermanDE}{german}{DE-1996}{ngerman}{}
  \gdialecttagwithreg{germanDE}{german}{DE}{}
  \gdialecttagwithreg{hungarian}{magyar}{HU}{}
  \gdialecttagwithreg{indon}{bahasai}{IN}{}
  \gdialecttagwithreg{indonesian}{bahasai}{IN}{}
  \gdialecttag{gaeilge}{irish}{}
  \gdialecttagwithreg{IEirish}{irish}{IE}{}
  \gdialecttagwithreg{GBirish}{irish}{GB}{}
  \gdialecttagwithmapandreg{IEenglish}{english}{IE}{british}{}
  \gdialecttagwithreg{italy}{italian}{IT}{}
  \gdialecttagwithreg{vatican}{italian}{VA}{}
  \gdialecttagwithreg{sanmarino}{italian}{SM}{}
  \gdialecttagwithreg{sloveneistriaitalian}{italian}{SI}{}
  \gdialecttagwithmapandreg{jerseyenglish}{english}{JE}{british}{}
  \gdialecttagwithreg{jerseyfrench}{french}{JE}{}
  \gdialecttagwithmapandreg{guernseyenglish}{english}{GG}{british}{}
  \gdialecttagwithreg{guernseyfrench}{french}{GG}{}
  \gdialecttag{latein}{latin}{}
  \gdialecttagwithreg{lowersorbian}{lsorbian}{DE}{}
  \gdialecttagwithreg{malay}{bahasam}{MY}{}
  \gdialecttagwithreg{meyalu}{bahasam}{MY}{}
  \gdialecttagwithreg{maltamaltese}{maltese}{MT}{}
  \gdialecttagwithmapandreg{maltaenglish}{english}{MT}{british}{}
  \gdialecttagwithreg{newzealand}{english}{NZ}{}
  \gdialecttagwithmapandreg{isleofmanenglish}{english}{IM}{british}{}
  \gdialecttagwithreg{norwegian}{norsk}{NO}{}
  \gdialecttagwithreg{piemonteis}{piedmontese}{IT}{}
  \gdialecttag{polutonikogreek}{greek}{}
  \gdialecttag{polutoniko}{greek}{}
  \gdialecttag{portuguese}{portuges}{}
  \gdialecttagwithreg{portugal}{portuges}{PT}{}
  \gdialecttag{romansch}{romansh}{}
  \gdialecttag{rumantsch}{romansh}{}
  \gdialecttag{romanche}{romansh}{}
  \gdialecttag{russianb}{russian}{}
  \gdialecttag{gaelic}{scottish}{}
  \gdialecttagwithreg{GBscottish}{scottish}{GB}{}
  \gdialecttagsuppl{serbianc}{serbian}{Cyrl}{}
  \gdialecttagsuppl{serbianl}{serbian}{Latn}{}
  \gdialecttag{slovenian}{slovene}{}
  \gdialecttagwithmapandreg{slovenia}{slovene}{SI}{slovenian}{}
  \gdialecttagwithmapandreg{sloveneistriaslovenian}{slovene}{SI}{slovenian}{}
  \gdialecttagwithreg{spainspanish}{spanish}{ES}{}
  \gdialecttagwithreg{argentinespanish}{spanish}{AR}{}
  \gdialecttagwithreg{bolivianspanish}{spanish}{BO}{}
  \gdialecttagwithreg{chilianspanish}{spanish}{CL}{}
  \gdialecttagwithreg{columbianspanish}{spanish}{CO}{}
  \gdialecttagwithreg{costaricanspanish}{spanish}{CR}{}
  \gdialecttagwithreg{cubanspanish}{spanish}{CU}{}
  \gdialecttagwithreg{dominicanspanish}{spanish}{DO}{}
  \gdialecttagwithreg{ecudorianspanish}{spanish}{EC}{}
  \gdialecttagwithreg{elsalvadorspanish}{spanish}{SV}{}
  \gdialecttagwithreg{guatemalanspanish}{spanish}{GT}{}
  \gdialecttagwithreg{honduranspanish}{spanish}{HN}{}
  \gdialecttagwithreg{mexicanspanish}{spanish}{MX}{}
  \gdialecttagwithreg{nicaraguanspanish}{spanish}{NI}{}
  \gdialecttagwithreg{panamaspanish}{spanish}{PA}{}
  \gdialecttagwithreg{paraguayspanish}{spanish}{PY}{}
  \gdialecttagwithreg{peruvianspanish}{spanish}{PE}{}
  \gdialecttagwithreg{puertoricospanish}{spanish}{PR}{}
  \gdialecttagwithreg{uruguayspanish}{spanish}{UY}{}
  \gdialecttagwithreg{venezuelanspanish}{spanish}{VE}{}
  \gdialecttagwithreg{swissgerman}{german}{CH}{}
  \gdialecttagwithmapandreg{nswissgerman}{german}{CH-1996}{ngerman}{}
  \gdialecttagwithreg{swissfrench}{french}{CH}{}
  \gdialecttagwithreg{swissitalian}{italian}{CH}{}
  \gdialecttagwithreg{swissromansh}{romansh}{CH}{}
  \gdialecttagwithreg{UKenglish}{english}{GB}{}
  \gdialecttagwithreg{ukraineb}{ukrainian}{UA}{}
  \gdialecttagwithreg{ukraine}{ukrainian}{UA}{}
  \gdialecttagwithreg{uppersorbian}{usorbian}{DE}{}
  \gdialecttagwithreg{USenglish}{english}{US}{}
  \gdialecttag{valencian}{catalan}{}
  \gdialecttag{valencien}{catalan}{}
  \gdialecttag{cymraeg}{welsh}{}
  \gdialecttagwithreg{GBwelsh}{welsh}{GB}{}
  \gdialecttag{nil}{undetermined}{}
  % PREDEFINED REGIONS
  \gregion{004}{AF}{AFG}{}%
  \gregion{248}{AX}{ALA}{}%
  \gregion{008}{AL}{ALB}{}%
  \gregion{012}{DZ}{DZA}{}%
  \gregion{016}{AS}{ASM}{}%
  \gregion{020}{AD}{AND}{}%
  \gregion{024}{AO}{AGO}{}%
  \gregion{660}{AI}{AIA}{}%
  \gregion{010}{AQ}{ATA}{}%
  \gregion{028}{AG}{ATG}{}%
  \gregion{032}{AR}{ARG}{}%
  \gregion{051}{AM}{ARM}{}%
  \gregion{533}{AW}{ABW}{}%
  \gregion{036}{AU}{AUS}{}%
  \gregion{040}{AT}{AUT}{}%
  \gregion{031}{AZ}{AZE}{}%
  \gregion{044}{BS}{BHS}{}%
  \gregion{048}{BH}{BHR}{}%
  \gregion{050}{BD}{BGD}{}%
  \gregion{052}{BB}{BRB}{}%
  \gregion{112}{BY}{BLR}{}%
  \gregion{056}{BE}{BEL}{}%
  \gregion{084}{BZ}{BLZ}{}%
  \gregion{204}{BJ}{BEN}{}%
  \gregion{060}{BM}{BMU}{}%
  \gregion{064}{BT}{BTN}{}%
  \gregion{068}{BO}{BOL}{}%
  \gregion{535}{BQ}{BES}{}%
  \gregion{070}{BA}{BIH}{}%
  \gregion{072}{BW}{BWA}{}%
  \gregion{074}{BV}{BVT}{}%
  \gregion{076}{BR}{BRA}{}%
  \gregion{086}{IO}{IOT}{}%
  \gregion{096}{BN}{BRN}{}%
  \gregion{100}{BG}{BGR}{}%
  \gregion{854}{BF}{BFA}{}%
  \gregion{108}{BI}{BDI}{}%
  \gregion{132}{CV}{CPV}{}%
  \gregion{116}{KH}{KHM}{}%
  \gregion{120}{CM}{CMR}{}%
  \gregion{124}{CA}{CAN}{}%
  \gregion{136}{KY}{CYM}{}%
  \gregion{140}{CF}{CAF}{}%
  \gregion{148}{TD}{TCD}{}%
  \gregion{152}{CL}{CHL}{}%
  \gregion{156}{CN}{CHN}{}%
  \gregion{162}{CX}{CXR}{}%
  \gregion{166}{CC}{CCK}{}%
  \gregion{170}{CO}{COL}{}%
  \gregion{174}{KM}{COM}{}%
  \gregion{180}{CD}{COD}{}%
  \gregion{178}{CG}{COG}{}%
  \gregion{184}{CK}{COK}{}%
  \gregion{188}{CR}{CRI}{}%
  \gregion{384}{CI}{CIV}{}%
  \gregion{191}{HR}{HRV}{}%
  \gregion{192}{CU}{CUB}{}%
  \gregion{531}{CW}{CUW}{}%
  \gregion{196}{CY}{CYP}{}%
  \gregion{203}{CZ}{CZE}{}%
  \gregion{208}{DK}{DNK}{}%
  \gregion{262}{DJ}{DJI}{}%
  \gregion{212}{DM}{DMA}{}%
  \gregion{214}{DO}{DOM}{}%
  \gregion{218}{EC}{ECU}{}%
  \gregion{818}{EG}{EGY}{}%
  \gregion{222}{SV}{SLV}{}%
  \gregion{226}{GQ}{GNQ}{}%
  \gregion{232}{ER}{ERI}{}%
  \gregion{233}{EE}{EST}{}%
  \gregion{231}{ET}{ETH}{}%
  \gregion{238}{FK}{FLK}{}%
  \gregion{234}{FO}{FRO}{}%
  \gregion{242}{FJ}{FJI}{}%
  \gregion{246}{FI}{FIN}{}%
  \gregion{250}{FR}{FRA}{}%
  \gregion{254}{GF}{GUF}{}%
  \gregion{258}{PF}{PYF}{}%
  \gregion{260}{TF}{ATF}{}%
  \gregion{266}{GA}{GAB}{}%
  \gregion{270}{GM}{GMB}{}%
  \gregion{268}{GE}{GEO}{}%
  \gregion{276}{DE}{DEU}{}%
  \gregion{288}{GH}{GHA}{}%
  \gregion{292}{GI}{GIB}{}%
  \gregion{300}{GR}{GRC}{}%
  \gregion{304}{GL}{GRL}{}%
  \gregion{308}{GD}{GRD}{}%
  \gregion{312}{GP}{GLP}{}%
  \gregion{316}{GU}{GUM}{}%
  \gregion{320}{GT}{GTM}{}%
  \gregion{831}{GG}{GGY}{}%
  \gregion{324}{GN}{GIN}{}%
  \gregion{624}{GW}{GNB}{}%
  \gregion{328}{GY}{GUY}{}%
  \gregion{332}{HT}{HTI}{}%
  \gregion{334}{HM}{HMD}{}%
  \gregion{336}{VA}{VAT}{}%
  \gregion{340}{HN}{HND}{}%
  \gregion{344}{HK}{HKG}{}%
  \gregion{348}{HU}{HUN}{}%
  \gregion{352}{IS}{ISL}{}%
  \gregion{356}{IN}{IND}{}%
  \gregion{360}{ID}{IDN}{}%
  \gregion{364}{IR}{IRN}{}%
  \gregion{368}{IQ}{IRQ}{}%
  \gregion{372}{IE}{IRL}{}%
  \gregion{833}{IM}{IMN}{}%
  \gregion{376}{IL}{ISR}{}%
  \gregion{380}{IT}{ITA}{}%
  \gregion{388}{JM}{JAM}{}%
  \gregion{392}{JP}{JPN}{}%
  \gregion{832}{JE}{JEY}{}%
  \gregion{400}{JO}{JOR}{}%
  \gregion{398}{KZ}{KAZ}{}%
  \gregion{404}{KE}{KEN}{}%
  \gregion{296}{KI}{KIR}{}%
  \gregion{408}{KP}{PRK}{}%
  \gregion{410}{KR}{KOR}{}%
  \gregion{414}{KW}{KWT}{}%
  \gregion{417}{KG}{KGZ}{}%
  \gregion{418}{LA}{LAO}{}%
  \gregion{428}{LV}{LVA}{}%
  \gregion{422}{LB}{LBN}{}%
  \gregion{426}{LS}{LSO}{}%
  \gregion{430}{LR}{LBR}{}%
  \gregion{434}{LY}{LBY}{}%
  \gregion{438}{LI}{LIE}{}%
  \gregion{440}{LT}{LTU}{}%
  \gregion{442}{LU}{LUX}{}%
  \gregion{446}{MO}{MAC}{}%
  \gregion{807}{MK}{MKD}{}%
  \gregion{450}{MG}{MDG}{}%
  \gregion{454}{MW}{MWI}{}%
  \gregion{458}{MY}{MYS}{}%
  \gregion{462}{MV}{MDV}{}%
  \gregion{466}{ML}{MLI}{}%
  \gregion{470}{MT}{MLT}{}%
  \gregion{584}{MH}{MHL}{}%
  \gregion{474}{MQ}{MTQ}{}%
  \gregion{478}{MR}{MRT}{}%
  \gregion{480}{MU}{MUS}{}%
  \gregion{175}{YT}{MYT}{}%
  \gregion{484}{MX}{MEX}{}%
  \gregion{583}{FM}{FSM}{}%
  \gregion{498}{MD}{MDA}{}%
  \gregion{492}{MC}{MCO}{}%
  \gregion{496}{MN}{MNG}{}%
  \gregion{499}{ME}{MNE}{}%
  \gregion{500}{MS}{MSR}{}%
  \gregion{504}{MA}{MAR}{}%
  \gregion{508}{MZ}{MOZ}{}%
  \gregion{104}{MM}{MMR}{}%
  \gregion{516}{NA}{NAM}{}%
  \gregion{520}{NR}{NRU}{}%
  \gregion{524}{NP}{NPL}{}%
  \gregion{528}{NL}{NLD}{}%
  \gregion{540}{NC}{NCL}{}%
  \gregion{554}{NZ}{NZL}{}%
  \gregion{558}{NI}{NIC}{}%
  \gregion{562}{NE}{NER}{}%
  \gregion{566}{NG}{NGA}{}%
  \gregion{570}{NU}{NIU}{}%
  \gregion{574}{NF}{NFK}{}%
  \gregion{580}{MP}{MNP}{}%
  \gregion{578}{NO}{NOR}{}%
  \gregion{512}{OM}{OMN}{}%
  \gregion{586}{PK}{PAK}{}%
  \gregion{585}{PW}{PLW}{}%
  \gregion{275}{PS}{PSE}{}%
  \gregion{591}{PA}{PAN}{}%
  \gregion{598}{PG}{PNG}{}%
  \gregion{600}{PY}{PRY}{}%
  \gregion{604}{PE}{PER}{}%
  \gregion{608}{PH}{PHL}{}%
  \gregion{612}{PN}{PCN}{}%
  \gregion{616}{PL}{POL}{}%
  \gregion{620}{PT}{PRT}{}%
  \gregion{630}{PR}{PRI}{}%
  \gregion{634}{QA}{QAT}{}%
  \gregion{638}{RE}{REU}{}%
  \gregion{642}{RO}{ROU}{}%
  \gregion{643}{RU}{RUS}{}%
  \gregion{646}{RW}{RWA}{}%
  \gregion{652}{BL}{BLM}{}%
  \gregion{654}{SH}{SHN}{}%
  \gregion{659}{KN}{KNA}{}%
  \gregion{662}{LC}{LCA}{}%
  \gregion{663}{MF}{MAF}{}%
  \gregion{666}{PM}{SPM}{}%
  \gregion{670}{VC}{VCT}{}%
  \gregion{882}{WS}{WSM}{}%
  \gregion{674}{SM}{SMR}{}%
  \gregion{678}{ST}{STP}{}%
  \gregion{682}{SA}{SAU}{}%
  \gregion{686}{SN}{SEN}{}%
  \gregion{688}{RS}{SRB}{}%
  \gregion{690}{SC}{SYC}{}%
  \gregion{694}{SL}{SLE}{}%
  \gregion{702}{SG}{SGP}{}%
  \gregion{534}{SX}{SXM}{}%
  \gregion{703}{SK}{SVK}{}%
  \gregion{705}{SI}{SVN}{}%
  \gregion{090}{SB}{SLB}{}%
  \gregion{706}{SO}{SOM}{}%
  \gregion{710}{ZA}{ZAF}{}%
  \gregion{239}{GS}{SGS}{}%
  \gregion{728}{SS}{SSD}{}%
  \gregion{724}{ES}{ESP}{}%
  \gregion{144}{LK}{LKA}{}%
  \gregion{729}{SD}{SDN}{}%
  \gregion{740}{SR}{SUR}{}%
  \gregion{744}{SJ}{SJM}{}%
  \gregion{748}{SZ}{SWZ}{}%
  \gregion{752}{SE}{SWE}{}%
  \gregion{756}{CH}{CHE}{}%
  \gregion{760}{SY}{SYR}{}%
  \gregion{158}{TW}{TWN}{}%
  \gregion{762}{TJ}{TJK}{}%
  \gregion{834}{TZ}{TZA}{}%
  \gregion{764}{TH}{THA}{}%
  \gregion{626}{TL}{TLS}{}%
  \gregion{768}{TG}{TGO}{}%
  \gregion{772}{TK}{TKL}{}%
  \gregion{776}{TO}{TON}{}%
  \gregion{780}{TT}{TTO}{}%
  \gregion{788}{TN}{TUN}{}%
  \gregion{792}{TR}{TUR}{}%
  \gregion{795}{TM}{TKM}{}%
  \gregion{796}{TC}{TCA}{}%
  \gregion{798}{TV}{TUV}{}%
  \gregion{800}{UG}{UGA}{}%
  \gregion{804}{UA}{UKR}{}%
  \gregion{784}{AE}{ARE}{}%
  \gregion{826}{GB}{GBR}{}%
  \gregion{581}{UM}{UMI}{}%
  \gregion{840}{US}{USA}{}%
  \gregion{858}{UY}{URY}{}%
  \gregion{860}{UZ}{UZB}{}%
  \gregion{548}{VU}{VUT}{}%
  \gregion{862}{VE}{VEN}{}%
  \gregion{704}{VN}{VNM}{}%
  \gregion{092}{VG}{VGB}{}%
  \gregion{850}{VI}{VIR}{}%
  \gregion{876}{WF}{WLF}{}%
  \gregion{732}{EH}{ESH}{}%
  \gregion{887}{YE}{YEM}{}%
  \gregion{894}{ZM}{ZMB}{}%
  \gregion{716}{ZW}{ZWE}{}%
  % PREDEFINED SCRIPTS
  \gscript{Adlm}{166}{Adlam}{RL}{}{}
  \gscript{Afak}{439}{Afaka}{varies}{}{}
  \gscript{Aghb}{239}{Caucasian Albanian}{LR}{}{}
  \gscript{Ahom}{338}{Ahom, Tai Ahom}{LR}{}{}
  \gscript{Arab}{160}{Arabic}{RL}{}{}
  \gscript{Aran}{161}{Arabic (Nastaliq variant)}{RL}{}{}
  \gscript{Armi}{124}{Imperial Aramaic}{RL}{}{}
  \gscript{Armn}{230}{Armenian}{LR}{}{}
  \gscript{Avst}{134}{Avestan}{RL}{}{}
  \gscript{Bali}{360}{Balinese}{LR}{}{}
  \gscript{Bamu}{435}{Bamum}{LR}{}{}
  \gscript{Bass}{259}{Bassa Vah}{LR}{}{}
  \gscript{Batk}{365}{Batak}{LR}{}{}
  \gscript{Beng}{334}{Bhaiksuki}{LR}{}{}
  \gscript{Blis}{550}{Blissymbols}{varies}{}{}
  \gscript{Bopo}{285}{Bopomofo}{LR}{}{}
  \gscript{Brah}{300}{Brahmi}{LR}{}{}
  \gscript{Brai}{570}{Braille}{LR}{}{}
  \gscript{Bugi}{367}{Buginese}{LR}{}{}
  \gscript{Buhd}{372}{Buhid}{LR}{}{}
  \gscript{Cakm}{349}{Chakma}{LR}{}{}
  \gscript{Cans}{440}{Unified Canadian Aboriginal Syllabics}{LR}{}{}
  \gscript{Cari}{201}{Carian}{LR}{}{}
  \gscript{Cham}{358}{Cham}{LR}{}{}
  \gscript{Cher}{445}{Cherokee}{LR}{}{}
  \gscript{Cirt}{291}{Cirth}{varies}{}{}
  \gscript{Copt}{204}{Coptic}{LR}{}{}
  \gscript{Cprt}{403}{Cypriot}{RL}{}{}
  \gscript{Cyrl}{220}{Cyrillic}{LR}{}{}
  \gscript{Cyrs}{221}{Cyrillic (Old Church Slavonic variant)}{varies}{}{}
  \gscript{Deva}{315}{Devanagari (Nagari)}{LR}{}{}
  \gscript{Dsrt}{250}{Deseret (Mormon)}{LR}{}{}
  \gscript{Dupl}{755}{Duployan shorthand, Duployan stenography}{LR}{}{}
  \gscript{Egyd}{070}{Egyptian demotic}{RL}{}{}
  \gscript{Egyh}{060}{Egyptian hieratic}{RL}{}{}
  \gscript{Egyp}{050}{Egyptian hieroglyphs}{LR}{}{}
  \gscript{Elba}{226}{Elbasan}{LR}{}{}
  \gscript{Ethi}{430}{Ethiopic (Ge'ez)}{LR}{}{}
  \gscript{Geok}{241}{Khutsuri (Asomtavruli and Nuskhuri)}{LR}{}{}
  \gscript{Geor}{240}{Georgian (Mkhedruli)}{LR}{}{}
  \gscript{Glag}{225}{Glagolitic}{LR}{}{}
  \gscript{Goth}{206}{Gothic}{LR}{}{}
  \gscript{Gran}{343}{Grantha}{LR}{}{}
  \gscript{Grek}{200}{Greek}{LR}{}{}
  \gscript{Gujr}{320}{Gujarati}{LR}{}{}
  \gscript{Guru}{310}{Gurmukhi}{LR}{}{}
  \gscript{Hanb}{503}{Han with Bopomofo (alias for Han + Bopomofo)}{LR}{}{}
  \gscript{Hang}{286}{Hangul}{LR}{}{}
  \gscript{Hani}{500}{Han (Hanzi, Kanji, Hanja)}{LR}{}{}
  \gscript{Hano}{371}{Hanunoo}{LR}{}{}
  \gscript{Hans}{501}{Han (Simplified variant)}{varies}{}{}
  \gscript{Hant}{502}{Han (Traditional variant)}{varies}{}{}
  \gscript{Hatr}{127}{Hatran}{RL}{}{}
  \gscript{Hebr}{125}{Hebrew}{RL}{}{}
  \gscript{Hira}{410}{Hiragana}{LR}{}{}
  \gscript{Hluw}{080}{Anatolian Hieroglyphs (Luwian Hieroglyphs, Hittite Hieroglyphs)}{LR}{}{}
  \gscript{Hmng}{450}{Pahawh Hmong}{LR}{}{}
  \gscript{Hrkt}{412}{Japanese syllabaries (alias for Hiragana + Katakana)}{varies}{}{}
  \gscript{Hung}{176}{Old Hungarian (Hungarian Runic)}{RL}{}{}
  \gscript{Inds}{610}{Indus (Harappan)}{RL}{}{}
  \gscript{Ital}{210}{Old Italic (Etruscan, Oscan, etc.)}{LR}{}{}
  \gscript{Jamo}{284}{Jamo (alias for Jamo subset of Hangul)}{LR}{}{}
  \gscript{Java}{361}{Javanese}{LR}{}{}
  \gscript{Jpan}{413}{Japanese (alias for Han + Hiragana + Katakana)}{varies}{}{}
  \gscript{Jurc}{510}{Jurchen}{LR}{}{}
  \gscript{Kali}{357}{Kayah Li}{LR}{}{}
  \gscript{Kana}{411}{Katakana}{LR}{}{}
  \gscript{Khar}{305}{Kharoshthi}{RL}{}{}
  \gscript{Khmr}{355}{Khmer}{LR}{}{}
  \gscript{Khoj}{322}{Khojki}{LR}{}{}
  \gscript{Kitl}{505}{Khitan large script}{LR}{}{}
  \gscript{Kits}{288}{Khitan small script}{TB}{}{}
  \gscript{Knda}{345}{Kannada}{LR}{}{}
  \gscript{Kore}{287}{Korean (alias for Hangul + Han)}{LR}{}{}
  \gscript{Kpel}{436}{Kpelle}{LR}{}{}
  \gscript{Kthi}{317}{Kaithi}{LR}{}{}
  \gscript{Lana}{351}{Tai Tham (Lanna)}{LR}{}{}
  \gscript{Laoo}{356}{Lao}{LR}{}{}
  \gscript{Latf}{217}{Latin (Fraktur variant)}{varies}{}{}
  \gscript{Latg}{216}{Latin (Gaelic variant)}{LR}{}{}
  \gscript{Latn}{215}{Latin}{LR}{}{}
  \gscript{Leke}{364}{Leke}{LR}{}{}
  \gscript{Lepc}{335}{Lepcha}{LR}{}{}
  \gscript{Limb}{336}{Limbu}{LR}{}{}
  \gscript{Lina}{400}{Linear A}{LR}{}{}
  \gscript{Linb}{401}{Linear B}{LR}{}{}
  \gscript{Lisu}{399}{Lisu (Fraser)}{LR}{}{}
  \gscript{Loma}{437}{Loma}{LR}{}{}
  \gscript{Lyci}{202}{Lycian}{LR}{}{}
  \gscript{Lydi}{116}{Lydian}{RL}{}{}
  \gscript{Mahj}{314}{Mahajani}{LR}{}{}
  \gscript{Mand}{140}{Mandaic, Mandaean}{RL}{}{}
  \gscript{Mani}{139}{Manichaean}{RL}{}{}
  \gscript{Marc}{332}{Marchen}{LR}{}{}
  \gscript{Maya}{090}{Mayan hieroglyphs}{varies}{}{}
  \gscript{Mend}{438}{Mende Kikakui}{RL}{}{}
  \gscript{Merc}{101}{Meroitic Cursive}{RL}{}{}
  \gscript{Mero}{100}{Meroitic Hieroglyphs}{RL}{}{}
  \gscript{Mlym}{347}{Malayalam}{LR}{}{}
  \gscript{Modi}{324}{Modi}{LR}{}{}
  \gscript{Mong}{145}{Mongolian}{TB}{}{}
  \gscript{Moon}{218}{Moon (Moon code, Moon script, Moon type)}{varies}{}{}
  \gscript{Mroo}{199}{Mro, Mru}{LR}{}{}
  \gscript{Mtei}{337}{Meitei Mayek (Meithei, Meetei)}{LR}{}{}
  \gscript{Mult}{323}{Multani}{LR}{}{}
  \gscript{Mymr}{350}{Myanmar (Burmese)}{LR}{}{}
  \gscript{Narb}{106}{Old North Arabian (Ancient North Arabian)}{RL}{}{}
  \gscript{Nbat}{159}{Nabataean}{RL}{}{}
  \gscript{Newa}{333}{Newa, Newar, Newari}{LR}{}{}
  \gscript{Nkgb}{420}{Nakhi Geba}{LR}{}{}
  \gscript{Nkoo}{165}{N'Ko}{RL}{}{}
  \gscript{Nshu}{499}{Nushu}{LR}{}{}
  \gscript{Ogam}{212}{Ogham}{varies}{}{}
  \gscript{Olck}{261}{Ol Chiki}{LR}{}{}
  \gscript{Orkh}{175}{Old Turkic, Orkhon Runic}{RL}{}{}
  \gscript{Orya}{327}{Oriya}{LR}{}{}
  \gscript{Osge}{219}{Osage}{LR}{}{}
  \gscript{Osma}{260}{Osmanya}{LR}{}{}
  \gscript{Palm}{126}{Palmyrene}{RL}{}{}
  \gscript{Pauc}{263}{Pau Cin Hau}{LR}{}{}
  \gscript{Perm}{227}{Old Permic}{LR}{}{}
  \gscript{Phag}{331}{Phags-pa}{TB}{}{}
  \gscript{Phli}{131}{Inscriptional Pahlavi}{RL}{}{}
  \gscript{Phlp}{132}{Psalter Pahlavi}{RL}{}{}
  \gscript{Phlv}{133}{Book Pahlavi}{RL}{}{}
  \gscript{Phnx}{115}{Phoenician}{RL}{}{}
  \gscript{Piqd}{293}{Klingon (KLI plqaD)}{LR}{}{}
  \gscript{Plrd}{282}{Miao (Pollard)}{LR}{}{}
  \gscript{Prti}{130}{Inscriptional Parthian}{RL}{}{}
  \gscript{Qaaa}{900}{Reserved for private use (start)}{varies}{}{}
  \gscript{Qaai}{908}{Private use}{varies}{}{}
  \gscript{Qabx}{949}{Reserved for private use (end)}{varies}{}{}
  \gscript{Rjng}{363}{Rejang (Redjang, Kaganga)}{LR}{}{}
  \gscript{Roro}{620}{Rongorongo}{varies}{}{}
  \gscript{Runr}{211}{Runic}{LR}{}{}
  \gscript{Samr}{123}{Samaritan}{RL}{}{}
  \gscript{Sara}{292}{Sarati}{varies}{}{}
  \gscript{Sarb}{105}{Old South Arabian}{RL}{}{}
  \gscript{Saur}{344}{Saurashtra}{LR}{}{}
  \gscript{Sgnw}{095}{SignWriting}{TB}{}{}
  \gscript{Shaw}{281}{Shavian (Shaw)}{LR}{}{}
  \gscript{Shrd}{319}{Sharada}{LR}{}{}
  \gscript{Sidd}{302}{Siddham}{LR}{}{}
  \gscript{Sind}{318}{Khudawadi, Sindhi}{LR}{}{}
  \gscript{Sinh}{348}{Sinhala}{LR}{}{}
  \gscript{Sora}{398}{Sora Sompeng}{LR}{}{}
  \gscript{Sund}{362}{Sundanese}{LR}{}{}
  \gscript{Sylo}{316}{Syloti Nagri}{LR}{}{}
  \gscript{Syrc}{135}{Syriac}{RL}{}{}
  \gscript{Syre}{138}{Syriac (Estrangelo variant)}{RL}{}{}
  \gscript{Syrj}{137}{Syriac (Western variant)}{RL}{}{}
  \gscript{Syrn}{136}{Syriac (Eastern variant)}{RL}{}{}
  \gscript{Tagb}{373}{Tagbanwa}{LR}{}{}
  \gscript{Takr}{321}{Takri}{LR}{}{}
  \gscript{Tale}{353}{Tai Le}{LR}{}{}
  \gscript{Talu}{354}{New Tai Lue}{LR}{}{}
  \gscript{Taml}{346}{Tamil}{LR}{}{}
  \gscript{Tang}{520}{Tangut}{LR}{}{}
  \gscript{Tavt}{359}{Tai Viet}{LR}{}{}
  \gscript{Telu}{340}{Telugu}{LR}{}{}
  \gscript{Teng}{290}{Tengwar}{LR}{}{}
  \gscript{Tfng}{120}{Tifinagh (Berber)}{LR}{}{}
  \gscript{Tglg}{370}{Tagalog (Baybayin, Alibata)}{LR}{}{}
  \gscript{Thaa}{170}{Thaana}{RL}{}{}
  \gscript{Thai}{352}{Thai}{LR}{}{}
  \gscript{Tibt}{330}{Tibetan}{LR}{}{}
  \gscript{Tirh}{326}{Tirhuta}{LR}{}{}
  \gscript{Ugar}{040}{Ugaritic}{LR}{}{}
  \gscript{Vaii}{470}{Vai}{LR}{}{}
  \gscript{Visp}{280}{Visible Speech}{LR}{}{}
  \gscript{Wara}{262}{Warang Citi (Varang Kshiti)}{LR}{}{}
  \gscript{Wole}{480}{Woleai}{RL}{}{}
  \gscript{Xpeo}{030}{Old Persian}{LR}{}{}
  \gscript{Xsux}{020}{Cuneiform, Sumero-Akkadian}{LR}{}{}
  \gscript{Yiii}{460}{Yi}{LR}{}{}
  \gscript{Zinh}{994}{Inherited script}{inherited}{}{}
  \gscript{Zmth}{995}{Mathematical notation}{LR}{}{}
  \gscript{Zsym}{996}{Symbols}{varies}{}{}
  \gscript{Zsye}{993}{Symbols (emoji variant)}{varies}{}{}
  \gscript{Zxxx}{997}{Unwritten documents}{varies}{}{}
  \gscript{Zyyy}{998}{Undetermined script}{varies}{}{}
  \gscript{Zzzz}{999}{Uncoded script}{varies}{}{}
}

\title{tracklang.sty v1.6.1: 
tracking language options}
\author{Nicola L.C. Talbot\\[10pt]
Dickimaw Books\\
\href{https://www.dickimaw-books.com/}{\nolinkurl{dickimaw-books.com}}}
\date{2022-12-13
} 

\newcommand{\refoptstables}{\tablesref{tab:isoopts,tab:rootlangopts,tab:nonisoopts}}

\begin{document}
\maketitle

\htmlavailable

\begin{abstract}
The \sty+{tracklang} package is provided for package developers
who want a simple interface to find out which languages the user has
requested through packages such as \sty{babel} and
\sty{polyglossia}. \emph{This package doesn't provide any
translations.}
Its purpose is simply to track which languages have been requested by the
user. Generic \TeX\ code is in \file{tracklang.tex} for
non-\LaTeX\ users.

If the \idx{shellescape} is enabled or \gls{directlua} is available,
this package may also be used to query the \envvar{LCALL}
or \envvar{LANG} environment variable (see
\sectionref{sec:langsty}). Windows users, who don't have the locale
stored in environment variables, can use \app{texosquery}
in combination with \sty{tracklang}. (Similarly if \envvar{LCALL}
or \envvar{LANG} don't contain sufficient information.) In order to
use \app{texosquery} through the restricted \idx{shellescape}, you must
have at least Java~8 and set up \file{texosquery.cfg}
appropriately. (See the \app{texosquery} manual for further details.)
\end{abstract}

The fundamental aim of this generic package is to be able to
effectively say:
\begin{quote}
The user (that is, the \emph{document} author) wants to use
dialects \langtagfmt{xx-XX}, \langtagfmt{yy-YY-Scrp}, etc in their
document. Any packages used by their document that provide 
multilingual or region-dependent support should do whatever is
required to activate the settings for those languages and regions
(or warn the user that there's no support).
\end{quote}
Naturally, this is only of use if the locale-sensitive packages use
\sty{tracklang} to pick up this information, which is entirely up
to the package authors, but at the moment there's no standard method
for packages to detect the required language and region. The aim of
\sty{tracklang} is to provide that method. In particular, the
emphasis is on using \idx+{ISO} language and region codes rather than
hard-coding the various language labels used by different language
packages.

Related articles: 
\tugboat{Localisation of \TeX\ documents: \styfmt{tracklang}.}
{2016}{37}{3}{http://www.tug.org/TUGboat/tb37-3/tb117talbot.pdf},
\dickimawhref{latex/tracklang}{Localisation with \filefmt{tracklang.tex}},
and \faqspkg{tracklang}.

\frontmatter
\tableofcontents
\listoftables

\mainmatter
\part{User Guide}

\chapter{Introduction}
\label{sec:intro}

When I'm developing a package that provides multilingual support
(for example, \sty{glossaries}) it's cumbersome trying to work out
if the user has requested translations for fixed text.  This usually
involves checking if \sty{babel} or \sty{translator} or
\sty{polyglossia} has been loaded and, if so, what language settings
have been used. The result can be a tangled mass of conditional
code. The alternative is to tell users to add the language as
a~document class option, which they may or may not want to do, or to
tell them to supply the language settings to every package they load
that provides multilingual support, which users are even less likely
to want to do.

The \sty{tracklang} package tries to neaten this up by working out
as much of this information as possible for you and providing a
command that iterates through the loaded languages. This way, you
can just iterate through the list of tracked languages and, for each
language, either define the translations or warn the user that
there's no translation for that language.

This package works best with \sty{ngerman} and \sty{german} (since
it's a simple test to determine if they have been loaded) and recent versions
of \sty{polyglossia} (which conveniently provides \gls{xpg@bcp@loaded}) or 
when the language options are specified
in the document class option list. It works fairly well with
\sty{translator} but will additionally assume the root language was
also requested when a dialect is specified. So, for example,
\begin{codebox}
\cmd{usepackage}[\opt{british}]\marg{translator}
\cmd{usepackage}\marg{tracklang}
\end{codebox}
is equivalent to
\begin{compactcodebox}
\cmd{usepackage}[\opt{british}]\marg{translator}
\cmd{usepackage}[\opt{english},\opt{british}]\marg{tracklang}
\end{compactcodebox}
This means that \gls{ForEachTrackedDialect} will iterate
through the list \qt{\opt{english},\opt{british}} instead of just
\qt{\opt{british}}, which can result in some redundancy.

Unfortunately I can't find any way of detecting a list of languages loaded
through \sty{babel}['s] new \gls{babelprovide} command. As far as I
can tell, the only stored list is in \gls{bbl@loaded} which only
contains the languages loaded through package options.

If the \sty{ngerman} package has been loaded, \sty{tracklang}
effectively does:
\begin{compactcodebox}
\gls{TrackPredefinedDialect}\marg{\opt{ngerman}}
\end{compactcodebox}
Similarly, if the \sty{german} package has been loaded, 
\sty{tracklang} effectively does
\begin{compactcodebox}
\gls{TrackPredefinedDialect}\marg{\opt{german}}
\end{compactcodebox}

If any document class or package options are passed to
\sty{tracklang}, then \sty{tracklang} won't bother checking
for \sty{babel}, \sty{translator}, \sty{ngerman}, \sty{german} or
\sty{polyglossia}. So, if the above example is changed to:
\begin{codebox}
\cmd{documentclass}[\opt{british}]\marg{article}
\cmd{usepackage}\marg{translator}
\cmd{usepackage}\marg{tracklang}
\end{codebox}
then the dialect list will just consist of \qt{\opt{british}} rather than
\qt{\opt{english},\opt{british}}. This does, however, mean that if the user mixes
class and package options, only the class options will be detected.
For example:
\begin{codebox}
\cmd{documentclass}[\opt{british}]\marg{article}
\cmd{usepackage}[\opt{french}]\marg{babel}
\cmd{usepackage}\marg{tracklang}
\end{codebox}
In this case, only the \opt{british} option will be detected. The user
can therefore use the document class option (or \sty{tracklang}
package option) to override the dialect and set the country code
(where provided). For example:
\begin{codebox}
\cmd{documentclass}[\opt{es-MX}]\marg{article}
\cmd{usepackage}[\opt{spanish}]\marg{babel}
\cmd{usepackage}\marg{tracklang}
\end{codebox}
This sets the dialect to \opt{mexicanspanish} and the root language to
\opt{spanish}. 

Predefined dialects are listed in \refoptstables. These may be 
passed in the document class options or
used in \gls{TrackPredefinedDialect}, as illustrated above. 

\Sectionref{sec:summary} provides brief examples of use for those
who want a general overview before reading the more detailed
sections.
\Sectionref{sec:generic} describes generic commands for
identifying the document languages.
\Sectionref{sec:user} is for package writers who want to
add multilingual support to their package and need to know which
settings the user has requested through language packages like
\sty{babel}. \Sectionref{sec:langsty} is for
developers of language definition packages who want to help other
package writers to detect what languages have been requested.

\printunsrttable
[
  type=index,
  block-style=name-other,
  other=dialect,
  toctitle={Predefined ISO Language-Region Dialects},
  title={Predefined \idx+{ISO} Language-Region Dialects. (\idx{ISO} tag or
  dialect label may be used as a
   package option or with \gls{TrackPredefinedDialect})},
  label={tab:isoopts},
  postamble={Other combinations need to be set with \gls{TrackLocale}
  or \gls{TrackLanguageTag}},
  init={%
   \renewcommand{\glstableNameTarget}[1]{\inlineglsdef[optdef]{##1}}%
   \let\glstableOtherFmt\optfmt
   \renewcommand{\glstablenameheader}{ISO Tag}%
   \renewcommand{\glstableotherheader}{Dialect Label}%
   \renewcommand{\glstableiffilter}[3]{\glsifcategory{##1}{isolangregion}{##3}{##2}}%
  }
]

\printunsrttable
[
  type=index,
  header=false,rules=false,blocksep={},clearpage,
  block-style=name,blocks=3,
  other=isotag,
  toctitle={Predefined Root Languages},
  title={Predefined Root Languages. (\fnregion Has an associated
   territory.) The corresponding tag obtained with
  \code{\gls{GetTrackedLanguageTag}\margm{dialect}} is shown in 
  parentheses},
  label={tab:rootlangopts},
  init={\let\glstableOtherFmt\optfmt
   \renewcommand{\glstableNameTarget}[1]{\inlineglsdef[optdef]{##1}}%
   \renewcommand{\glstableiffilter}[3]{\glsifcategory{##1}{rootlang}{##3}{##2}}%
  }
]

\printunsrttable
[
  type=index,
  block-style=name,rules=false,header=false,blocksep={},clearpage,
  other=tags,par=ragged,
  toctitle={Predefined Non-ISO Dialects},
  title={Predefined Non-ISO Dialects. (\fnregion Has an 
  associated territory.) The corresponding
language tag obtained with
\code{\gls{GetTrackedLanguageTag}\margm{dialect}}
is shown in parentheses. If the dialect has a corresponding mapping
for the closest matching non-root language \gls{captionsdialect} or
\gls{datedialect}, this is also included after the tag following a
slash.},
  label={tab:nonisoopts},
  init={%
   \renewcommand{\glstableiffilter}[3]{\glsifcategory{##1}{noniso}{##3}{##2}}%
   \renewcommand{\glstableNameTarget}[1]{\inlineglsdef[optdef]{##1}}%
  }
]

\chapter{Summary of Use}
\label{sec:summary}

There are three levels of use:
\begin{enumerate}
\item document level (code used by document authors);

\item locale-sensitive package level 
(code for package authors who need to 
know what languages or locale the document is
using, such as \sty{glossaries} to translate commands like
\cmd{descriptionname} or \sty{datetime2} to provide localised 
formats or time zone information);

\item language set-up level (code for packages that set up
the document languages, such as \sty{babel} or \sty{polyglossia}).
\end{enumerate}

\section{Document Level}
\label{sec:summary-doc}

Document level use can be divided into generic \TeX\ use 
(\sectionref{sec:tex}) and \LaTeX-specific use (\sectionref{sec:latex}).

\subsection{Generic \texorpdfstring{\TeX}{TeX}}
\label{sec:tex}

This section is for generic \TeX\ use. The \sty+{tracklang} files are
loaded with \gls{input}. See \sectionref{sec:latex} for \LaTeX\ use.

A Unix-like user wants the locale information picked up from the 
locale environment variable (the \ext+{tex} extension may be omitted):
\begin{codebox*}
\gls{input} \file{tracklang.tex} \comment{v1.3}
\gls{TrackLangFromEnv}
\comment{load packages that use tracklang for localisation}
\end{codebox*}

A Windows user wants the locale information picked up from the 
operating system (again the \ext{tex} extension may be omitted):
\begin{codebox*}
\gls{input} \file{texosquery.tex}
\gls{input} \file{tracklang.tex} \comment{v1.3}
\gls{TrackLangFromEnv}
\comment{load packages that use tracklang for localisation}
\end{codebox*}
Or (\sty{texosquery} v1.2)
\begin{codebox*}
\gls{input} \file{texosquery.tex} \comment{v1.2}
\gls{input} \file{tracklang.tex} \comment{v1.3}
\codepar
\gls{TeXOSQueryLangTag}\marg{\cmd{langtag}}
\gls{TrackLanguageTag}\marg{\cmd{langtag}}
\comment{load packages that use tracklang for localisation}
\end{codebox*}
A Unix-like user who may or may not have \app{texosquery} setup to run in the
\idx{shellescape}:
\begin{codebox*}
\gls{input} \file{texosquery.tex}
\gls{input} \file{tracklang.tex} \comment{v1.3}
\codepar
\cmd{ifx}\gls{TeXOSQueryLangTag}\cmd{undefined}
 \gls{TrackLangFromEnv}
\cmd{else}
 \gls{TeXOSQueryLangTag}\marg{\cmd{langtag}}
 \gls{TrackLanguageTag}\marg{\cmd{langtag}}
\cmd{fi}
\comment{load packages that use tracklang for localisation}
\end{codebox*}

A user is writing in Italy in Armenian with a Latin
\idx{script} (\opt{Latn}) and the arevela \idx{variant}:
\begin{codebox*}
\gls{input} \file{tracklang.tex} \comment{v1.3}
\gls{TrackLanguageTag}\marg{hy-Latn-IT-arevela}
\comment{load packages that use tracklang for localisation}
\end{codebox*}

A user is writing in English in the UK:
\begin{codebox*}
\gls{input} \file{tracklang.tex}
\gls{TrackPredefinedDialect}\marg{british}
\comment{load packages that use tracklang for localisation}
\end{codebox*}

Find out information about the current language (supplied
in \gls{languagename}):
\begin{codebox*}
\gls{SetCurrentTrackedDialect}\marg{\gls{languagename}}
Dialect: \gls{CurrentTrackedDialect}.
Language: \gls{CurrentTrackedLanguage}.
ISO Code: \gls{CurrentTrackedIsoCode}.
Region: \gls{CurrentTrackedRegion}.
Modifier: \gls{CurrentTrackedDialectModifier}.
Variant: \gls{CurrentTrackedDialectVariant}.
Script: \gls{CurrentTrackedDialectScript}.
Sub-Lang: \gls{CurrentTrackedDialectSubLang}.
Additional: \gls{CurrentTrackedDialectAdditional}.
Language Tag: \gls{CurrentTrackedLanguageTag}.
\end{codebox*}
Additional information about the \idx{script} can be obtained by
also loading \sty{tracklang-scripts}:
\begin{codebox*}
\gls{input} \file{tracklang-scripts.tex}
\end{codebox*}
The name, numeric code and direction can now be obtained:
\begin{codebox*}
Name: \gls{TrackLangScriptAlphaToName}\marg{\gls{CurrentTrackedDialectScript}}.
Numeric: 
\gls{TrackLangScriptAlphaToNumeric}\marg{\gls{CurrentTrackedDialectScript}}.
Direction: 
\gls{TrackLangScriptAlphaToDir}\marg{\gls{CurrentTrackedDialectScript}}.
\end{codebox*}
Test for a specific \idx{script} (in this case \opt{Latn}):
\begin{codebox*}
Latin?
\cmd{ifx}\gls{CurrentTrackedDialectScript}\tklscript{Latn}
 Yes
\cmd{else}
 No
\cmd{fi}
\end{codebox*}

\subsection{\texorpdfstring{\LaTeX}{LaTeX}}
\label{sec:latex}

This section is for \LaTeX\ use. See \sectionref{sec:tex} for generic \TeX\ use.

With newer versions of \sty{polyglossia}, where \gls{xpg@bcp@loaded}
is defined, you just need to make sure the languages are set before
\sty{tracklang} is loaded:
\begin{codebox*}
\cmd{documentclass}\marg{article}
\cmd{usepackage}\marg{polyglossia}
\cmd{setmainlanguage}[variant=uk]\marg{english}
\comment{load packages that use tracklang for localisation}
\end{codebox*}
For older versions of \sty{polyglossia} where the regional
information is required, use recognised class options:
\begin{codebox*}
\cmd{documentclass}[\opt{en-GB}]\marg{article}
\cmd{usepackage}\marg{polyglossia}
\cmd{setmainlanguage}[variant=uk]\marg{english}
\comment{load packages that use tracklang for localisation}
\end{codebox*}

For \sty{babel} users where the supplied \sty{babel} dialect
label is sufficient, and is passed either through the document class
or package options, there's no need to do anything special:
\begin{codebox*}
\cmd{documentclass}[\opt{british},\opt{canadien}]\marg{article}
\cmd{usepackage}[T1]\marg{fontenc}
\cmd{usepackage}\marg{babel}
\comment{load packages that use tracklang for localisation}
\end{codebox*}
If the region is important but there's no \sty{babel} dialect that
represents it, there are several options.
The first method is to use the class options recognised by \sty{tracklang}
and the root language labels when loading \sty{babel}:
\begin{codebox*}
\cmd{documentclass}[\opt{en-IE},\opt{ga-IE}]\marg{article}
\cmd{usepackage}[english,irish]\marg{babel}
\comment{load packages that use tracklang for localisation}
\end{codebox*}

Another method with \sty{babel} is to use \gls{TrackLanguageTag} and map the new
dialect label to the nearest matching \gls{captionsdialect}:
\begin{codebox*}
\cmd{documentclass}\marg{article}
\codepar
\cmd{usepackage}\marg{tracklang}\comment{v1.3}
\gls{TrackLanguageTag}\marg{\opt{en-MT}}
\gls{SetTrackedDialectLabelMap}\marg{\gls{TrackLangLastTrackedDialect}}\marg{\opt{UKenglish}}
\codepar
\cmd{usepackage}[UKenglish]\marg{babel}
\comment{load packages that use tracklang for localisation}
\end{codebox*}
This ensures that the \tklcaptions{UKenglish} hook is detected
by the localisation packages. This mapping isn't needed
for \sty{polyglossia} as the caption hooks use the root language
label. This mapping also isn't needed if \opt{british} is used
instead of \opt{UKenglish} since the \opt{en-MT}
(\opt{maltaenglish})
predefined dialect automatically sets up a mapping to
\opt{british}. (The default mappings are shown in
\tableref{tab:nonisoopts}.)

There's no support for \gls{babelprovide}. If you are using
\gls{babelprovide}, you will need to use the class option or
\gls{TrackLanguageTag} as above.

\section{Locale-Sensitive Packages}
\label{sec:summary-localepkg}

Let's suppose you are developing a package called 
\filefmt{mypackage.sty} or \filefmt{mypackage.tex} and you want
to find out what languages the document author has requested. (See also:
\dickimawhref{latex/tracklang/otherpkg.shtml}{Using
\filefmt{tracklang.tex} in Packages with Localisation Features}.)

Generic \TeX\ use (the \ext{tex} extension may be omitted):
\begin{codebox*}
\gls{input} \file{tracklang.tex}
\end{codebox*}
(Most of the commands used in this section require at least
\sty{tracklang} version 1.3 but 1.4 is better if you want to
include the \idx{script} tag in the \ext+{ldf} files.)
Note that \file{tracklang.tex} has a check to determine if
it's already been loaded, so you don't need to worry about that.

\LaTeX\ use:
\begin{codebox*}
\gls{RequirePackage}\marg{tracklang}[2019/11/30]\comment{at least v1.4}
\end{codebox*}
This will picked up any language options supplied in the document
class options and will also detect if \sty{babel} or
\sty{polyglossia} have been loaded.

(\LaTeX) If you want to allow the user to set the locale in the 
package options:
\begin{codebox*}
\gls{DeclareOption}*\marg{\gls{TrackLanguageTag}\marg{\cmd{CurrentOption}}}
\end{codebox*}
This means the user can do, say,
\begin{codebox}
\cmd{usepackage}[hy-Latn-IT-arevela]\marg{mypackage}
\end{codebox}
With at least version 1.4, it's better to use \gls{TrackIfKnownLanguage}:
\begin{codebox}
\gls{DeclareOption}*\marg{\comment{}
 \gls{TrackIfKnownLanguage}\marg{\cmd{CurrentOption}}\comment{}
 \marg{\comment{successful}
  \cmd{PackageInfo}\marg{mypackage}\marg{Tracking language `\cmd{CurrentOption}'}\comment{}
 }\comment{}
 \marg{\comment{failed}
  \cmd{PackageError}\marg{mypackage}\comment{}
  \marg{Unknown language specification `\cmd{CurrentOption}'}\comment{}
  \marg{You need to supply either a known dialect label 
   or a valid language tag}\comment{}
 }\comment{}
}
\end{codebox}

\begin{information}
The rest of the example package in this section uses generic code.
If you are using \LaTeX, it's better to replace \cmd{def} and
\cmd{ifx} with more appropriate \LaTeX\ commands.
\end{information}

If you want to fetch the locale information from the operating
system when the user hasn't requested a language:
\begin{codebox*}
\gls{AnyTrackedLanguages}
\marg{}
\marg{\comment{fetch locale information from the operating system}
  \cmd{ifx}\gls{TeXOSQueryLangTag}\cmd{undefined}
    \comment{texosquery v1.2 not available}
    \gls{TrackLangFromEnv}
  \cmd{else}
    \comment{texosquery v1.2 available}
    \gls{TeXOSQueryLangTag}\marg{\cmd{langtag}}
    \gls{TrackLanguageTag}\marg{\cmd{langtag}}
  \cmd{fi}
}
\end{codebox*}

Set up the defaults if necessary:
\begin{codebox}
\cmd{def}\cmd{fooname}\marg{Foo}
\cmd{def}\cmd{barname}\marg{Bar}
\end{codebox}

Now load the resource files:
\begin{codebox*}
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedDialect}\marg{\cmd{thisdialect}}\marg{\comment{}
    \gls{TrackLangRequireDialect}\marg{mypackage}\marg{\cmd{thisdialect}}\comment{}
  }\comment{}
}
\marg{}\comment{no tracked languages, default already set up}
\end{codebox*}

Each resource file has the naming scheme \file{prefix-localeid.ldf}\glsadd{ext.ldf}.
In this example, the \meta{prefix} is \filefmt{mypackage}. The
\meta{localeid} part may be the language or dialect label (for
example, \opt{english} or \opt{british}) or a combination of the
\idx{ISO} language and region codes (for example, \opt{en-GB} or
\iso{english} or \optfmt{GB}). As from version 1.4, \meta{localeid}
may also include the \idx{script} or \idx{variant}. (See the definition of
\gls{IfTrackedLanguageFileExists} \pref{pg:filesearch} for further
details.)

The simplest scheme is to use the root language label (not the
dialect label) for the base language settings and use the \idx+{ISO}
codes for regional support.

For example, the file \ldf{mypackage}{english}:
\begin{codebox*}
\comment{identify this file:}
\gls{TrackLangProvidesResource}\marg{english}[2016/10/06 v1.0]
\codepar
\gls{TrackLangAddToCaptions}\marg{\comment{}
  \cmd{def}\cmd{fooname}\marg{Foo}\comment{}
  \cmd{def}\cmd{barname}\marg{Bar}\comment{}
}
\end{codebox*}
This sets up appropriate the \gls{captionsdialect} hook (if it's
found). For other hooks, such as \gls{datedialect}, use 
\gls{TrackLangAddToHook} or \gls{TrackLangRedefHook} instead.

With pre-v1.4 versions of \sty{tracklang}, the \idx{script} isn't included
in the file search. If it's needed then either require at least v1.4
or have a base \ext{ldf} file that tries to load a version for the
particular \idx{script} (which can be accessed with
\gls{CurrentTrackedDialectScript}).
Here's an example for a language with different writing systems.
The resource file for Serbian \ldf{mypackage}{serbian}:
\begin{codebox*}
\comment{identify file:}
\gls{TrackLangProvidesResource}\marg{serbian}[2016/10/06 v1.0]
\codepar
\gls{TrackLangRequestResource}\marg{serbian-\gls{CurrentTrackedDialectScript}}
\marg{}\comment{file not found, do something sensible here}
\end{codebox*}
The file \ldf{mypackage}{serbian-Latn} sets up
the Latin \idx{script} (\opt{Latn}):
\begin{codebox*}
\gls{TrackLangProvidesResource}\marg{serbian-Latn}[2016/10/06 v1.0]
\codepar
\gls{TrackLangAddToCaptions}\marg{\comment{}
  \cmd{def}\cmd{fooname}\marg{...}\comment{provide appropriate Latin translations}
  \cmd{def}\cmd{barname}\marg{...}\comment{}
}
\end{codebox*}
The file \ldf{mypackage}{serbian-Cyrl} sets up
the Cyrillic \idx{script} (\opt{Cyrl}):
\begin{codebox*}
\gls{TrackLangProvidesResource}\marg{serbian-Cyrl}[2016/10/06 v1.0]
\codepar
\gls{TrackLangAddToCaptions}\marg{\comment{}
  \cmd{def}\cmd{fooname}\marg{...}\comment{provide appropriate Cyrillic translations}
  \cmd{def}\cmd{barname}\marg{...}\comment{}
}
\end{codebox*}
With v1.4+ you just need \ldf{mypackage}{sr-Latn} and
\ldf{mypackage}{sr-Cyrl} for the regionless versions.

\section{Language Packages}
\label{sec:summary-langpkg}

Let's suppose now you're the developer of a package that 
sets up the language, hyphenation patterns and so on.
It would be really helpful to the locale-sensitive packages 
in \sectionref{sec:summary-localepkg} to know what languages
the document author has requested. You can use the
\sty{tracklang} package to identify this information
by tracking the requested localisation, so that other packages
can have a consistent way of querying it. (See also:
\dickimawhref{latex/tracklang/langpkg.shtml}{Integrating
\filefmt{tracklang.tex} into Language Packages}.)

Generic use:
\begin{codebox}
\gls{input} tracklang
\end{codebox}
Alternative \LaTeX\ use:
\begin{codebox}
\gls{RequirePackage}\marg{tracklang}[2019/11/30]\comment{v1.4}
\end{codebox}
Unlike \gls{input}, \gls{RequirePackage} will allow \sty{tracklang}
to pick up the document class options, but using \gls{RequirePackage}
will also trigger the tests for known language packages.
(If you want to find out if \sty{tracklang} has already been
loaded and locales have already been tracked, you can use the
same code as in the previous section.)

When a user requests a particular language through your package,
the simplest way of letting \sty{tracklang} know about it
is to use \gls{TrackPredefinedDialect} or \gls{TrackLanguageTag}.
For example, if the user requests \opt{british}, that's a
predefined dialect so you can just do:
\begin{codebox}
\gls{TrackPredefinedDialect}\marg{\opt{british}}
\end{codebox}
Alternatively
\begin{codebox}
\gls{TrackLanguageTag}\marg{\opt{en-GB}}
\end{codebox}
If your package uses caption hooks, then you can set up 
a mapping between \sty{tracklang}'s internal dialect label
and your caption label. For example, let's suppose the
closest match to English used in Malta (\opt{en-MT}) is the 
dialect \opt{UKenglish} (for example, the date format is 
similar between GB and MT):
\begin{codebox}
\gls{TrackLanguageTag}\marg{\opt{en-MT}}
\gls{SetTrackedDialectLabelMap}\marg{\gls{TrackLangLastTrackedDialect}}\marg{\opt{UKenglish}}
\cmd{def}\tklcaptions{UKenglish}\marg{\comment{}
  \cmd{def}\cmd{contentsname}\marg{Contents}\comment{}
  \comment{...}
}
\end{codebox}
(The predefined \opt{maltaenglish} option provided by
\sty{tracklang} automatically sets the mapping to
\opt{british}, but the above method will change that mapping
to \opt{UKenglish}.)

This now means that \gls{TrackLangAddToHook} and \gls{TrackLangRedefHook} commands can
find your language hooks. You don't need the map if your dialect
label is the same as \sty{tracklang}'s root language label
for that locale. For example:
\begin{codebox}
\gls{TrackLanguageTag}\marg{\opt{en-MT}}
\cmd{def}\tklcaptions{english}\marg{\comment{}
  \cmd{def}\cmd{contentsname}\marg{Contents}\comment{}
  \comment{...}
}
\end{codebox}

When the user switches language through commands like
\gls{selectlanguage} it would be useful to also use
\code{\gls{SetCurrentTrackedDialect}\margm{dialect}} to make it easier
for the document author or locale-sensitive packages to pick
up the current locale. The \meta{dialect} argument may be
\sty{tracklang}'s internal dialect label or the dialect
label you assigned with \gls{SetTrackedDialectLabelMap}. It
may also be the root language label, in which case
\sty{tracklang} will search for the last dialect to be
tracked with that language. For example:
\begin{codebox}
\cmd{def}\gls{selectlanguage}\#1\marg{\comment{}
  \gls{SetCurrentTrackedDialect}\marg{\#1}\comment{}
  \comment{set up hyphenation patterns etc}
}
\end{codebox}
See the example in \sectionref{sec:summary-doc} or the example in 
\dickimawhref{latex/tracklang/langpkg.shtml}{Integrating
\filefmt{tracklang.tex} into Language Packages}.

\chapter{Generic Use}
\label{sec:generic}

For plain \TeX\ you can input \file{tracklang.tex}:
\begin{codebox}
\gls{input} tracklang
\end{codebox}
or for \TeX\ formats that have an argument form for \gls{input}:
\begin{codebox}
\gls{input}\marg{tracklang}
\end{codebox}
As from version 1.3, you don't need to change the category
code of \idx{atletter} before loading \file{tracklang.tex}
as it will automatically be changed to 11 and switched
back at the end (if required).

The \LaTeX\ package \file{tracklang.sty} 
inputs the generic \TeX\ code in \file{tracklang.tex}, but before 
it does so it defines
\cmddef{@tracklang@declareoption}
to
\begin{compactcodebox*}
\gls{DeclareOption}\margm{dialect}\marg{\gls{TrackPredefinedDialect}\margm{dialect}}
\end{compactcodebox*}
If \gls{@tracklang@declareoption} isn't defined when
\file{tracklang.tex} is input, it will be defined to ignore its
argument.

This means that all the predefined languages and dialects
(\refoptstables) automatically become package options, so
the \file{tracklang.sty} package can pick up document class
options and add them to \sty{tracklang}'s internal list of tracked
document languages.

If you're not using \LaTeX, this option isn't available
although you can redefine 
\gls{@tracklang@declareoption}
to use something analogous to \gls{DeclareOption}, if appropriate.
Otherwise, the document languages need
to be explicitly identified (using any of the following commands)
so that \sty{tracklang} knows about them.

\cmddef{TrackPredefinedDialect}
This will add the predefined dialect and its associated \idx{ISO} codes to the list
of tracked document languages. The \meta{dialect label} may be any
of those listed in \refoptstables.

For example:
\begin{codebox}
\gls{input} tracklang
\gls{TrackPredefinedDialect}\marg{\opt{british}}
\end{codebox}
is the Plain \TeX\ alternative to:
\begin{codebox}
\cmd{documentclass}[\opt{british}]\marg{article}
\cmd{usepackage}\marg{tracklang}
\end{codebox}

Note that it's impractical to define every possible language
and region combination as it would significantly slow the
time taken to load \sty{tracklang} so, after version~1.3,
I don't intend adding any new predefined dialects. As from version
1.3, if you want to track a dialect that's not predefined by
\sty{tracklang}, then you can use:
\cmddef{TrackLocale}
If \meta{locale} is a recognised dialect, this is equivalent to
using \gls{TrackPredefinedDialect}, otherwise \meta{locale}
needs to be in one the following formats:
\begin{itemize}
\item \meta{\idx{ISO} lang}
\item \meta{\idx{ISO} lang}\idx{atmod}\meta{modifier}
\item \meta{\idx{ISO} lang}\idx{hyphensep}\meta{\idx{ISO} country}
\item \meta{\idx{ISO} lang}\idx{hyphensep}\meta{\idx{ISO} country}\idx{atmod}\meta{modifier}
\end{itemize}
where \meta{\idx{ISO} lang} is the \idxn{639-1} or \idx{639-2} code identifying
the language (lower case), \meta{\idx{ISO} country} is the \idx{3166-1}
\idx{ISO} code identifying the \idx{territory} (upper case) and 
\meta{modifier} is the \idx{modifier} or \idx{variant}. The hyphen
(\idx{hyphensep}) may be replaced by an underscore character 
(\idx{underscoresep}). \Idx{code-set} information in the
form \code{\idx{dotsep}\meta{codeset}} may optionally appear before the
\idx{modifier}. For example, 
\code{de\idx{hyphensep}DE\idx{dotsep}utf8\idx{atmod}new} (\idx{modifier} is
\optfmt{new}) or \code{en\idx{hyphensep}GB\idx{dotsep}utf8} (\idx{modifier} is missing).
The \idx{code-set} will be ignored if present, but it won't interfere
with the parsing.

For example:
\begin{codebox}
\gls{TrackLocale}\marg{de\idx{hyphensep}NA\idx{atmod}new}
\end{codebox}
indicates German in Namibia using the new spelling.

\begin{important}
If a language has different \idxn{639-2T} and \idx{639-2B} codes, then
the \qt{T} form should be used. (So for the above example,
\code{deu} may be used instead of \code{de}, but \code{ger}
won't be recognised.)
\end{important}

Alternatively, you can use
\cmddef{TrackLanguageTag}
where \meta{tag} is a regular, well-formed language tag or a recognised dialect
label. (Irregular grandfather tags aren't recognised.)
This command will fully expand \meta{tag}.
A warning is issued if the tag is empty.

If you want to first check that \meta{tag} includes a valid language
code, then you can instead use:
\cmddef{TrackIfKnownLanguage}
This will only track \meta{tag} (and then do \meta{success code}) if
\meta{tag} starts with a valid language code (or is a predefined
dialect) otherwise it will do \meta{fail code}. Both
\gls{TrackLanguageTag} and \gls{TrackIfKnownLanguage} will check if
\meta{tag} is a predefined option. (This saves parsing the tag if
it's recognised.)

For example:
\begin{codebox}
\gls{TrackLanguageTag}\marg{hy-Latn-IT-arevela}
Latn-ME: \gls{TrackIfKnownLanguage}\marg{Latn-ME}\marg{success}\marg{fail}.
brazilian: \gls{TrackIfKnownLanguage}\marg{brazilian}\marg{success}\marg{fail}.
\end{codebox}
This will track \optfmt{hy-Latn-IT-arevela} and \opt{brazilian}
(\optfmt{pt-BR}) but not \optfmt{Latn-ME} (because it doesn't contain a
valid language code) even though it's a valid \idx{script} and country
code. The above is just for illustrative purposes. Typically the
language tracking isn't performed within the document text.

The \sty{datetime2} package assumes that any unknown package option is a
language identifier. It could simply do:
\begin{compactcodebox}
\gls{TrackLanguageTag}\marg{\cmd{CurrentOption}}
\end{compactcodebox}
but users can make mistakes sometimes and this won't provide any
helpful information if they, for example, misspelt a package option
or forgot the \qt{\meta{key}=} part of a \keyval\
setting. Instead (as from v1.5.5) \sty{datetime2} now does:
\begin{compactcodebox}
\gls{TrackIfKnownLanguage}\marg{\cmd{CurrentOption}}
\marg{...}\comment{known language}
\marg{\cmd{PackageError}\marg{...}\marg{...}\marg{...}}
\end{compactcodebox}
This will now give the user some guidance. 

If \meta{tag} contains a sub-language tag, this will be set
as the \idx{639-3} code for the \emph{dialect} label. Note that this is
different to the root language codes which are set using the
language label. For example:
\begin{codebox}
\gls{TrackLanguageTag}\marg{zh-cmn-Hans-CN}
\end{codebox}
creates a new dialect with the label \code{zh\-cmn\-Hans\-CN}.
The root language \opt{chinese} has the \idx{639-1} code
\optfmt{zh} and the dialect \code{zh\-cmn\-Hans\-CN} has the
\idxn{639-3} code \optfmt{cmn}.
\begin{codebox}
ISO 639-1: \gls{TrackedIsoCodeFromLanguage}\marg{639-1}\marg{chinese}.
ISO 639-3: \gls{TrackedIsoCodeFromLanguage}\marg{639-3}\marg{zhcmnHansCN}.
\end{codebox}

Version 1.2 of \sty{texosquery} provides the command \gls{TeXOSQueryLangTag},
which may be used to fetch the operating system's regional
information as a language tag. These commands can be used as
follows:
\begin{codebox}
\gls{input} tracklang \comment{v1.3}
\gls{input} texosquery \comment{v1.2}
\codepar
\gls{TeXOSQueryLangTag}\marg{\cmd{langtag}}
\gls{TrackLanguageTag}\marg{\cmd{langtag}}
\end{codebox}
(If the \idx{shellescape} is disabled, \cmd{langtag} will be empty, which
will trigger a~warning but no errors.)

Some of the predefined root language options listed
in \tableref{tab:rootlangopts} have an associated region
(denoted by \fnregion).
If \gls{TrackLocale} is used with just the language \idx{ISO} code,
no region is tracked for that language. For example
\begin{codebox}
\gls{TrackLocale}\marg{\opt{manx}}
\end{codebox}
will track the \optfmt{IM} (Isle of Man) \idxn{3166-1} code but
\begin{codebox}
\gls{TrackLocale}\marg{gv}
\end{codebox}
won't track the region.
Similarly for \gls{TrackLanguageTag}.

(New to version 1.3.)
There's a similar command to \gls{TrackLocale} that doesn't take an argument:
\cmddef{TrackLangFromEnv}
If the \idx{shellescape} has been enabled or \gls{directlua} is
available, this will try to get the language information from the
system environment variables \envvar{LCALL} or \envvar{LANG} and, if
successful, track that.

Since \sty{tracklang} is neither able to look up the \idx{POSIX} locale
tables nor interpret file locales, if the result is \code{C} or
\code{POSIX} or starts with a forward slash \code{/} then
the locale value is treated as empty.

\begin{important}
Not all operating systems use environment variables for
the system locale information. For example, Windows stores the
locale information in the registry. In which case, consider
using \sty{texosquery}.
\end{important}

If the operating system locale can't be obtained from environment variables, then
\sty{tracklang} will use \gls{TeXOSQueryLocale} as a fallback if
\sty{texosquery} has been loaded. Since \sty{texosquery} requires
both the \idx{shellescape} and the Java runtime environment,
\sty{tracklang} doesn't automatically load it.

Plain \TeX\ example:
\begin{codebox}
\gls{input} texosquery
\gls{input} tracklang
\gls{TrackLangFromEnv}
\end{codebox}
Document build:
\begin{terminal}
\app{etex} \switch{shell-escape} \meta{filename}
\end{terminal}

\LaTeX\ example:
\begin{codebox}
\cmd{usepackage}\marg{texosquery}
\cmd{usepackage}\marg{tracklang}
\gls{TrackLangFromEnv}
\end{codebox}
Document build:
\begin{terminal}
\app{pdflatex} \switch{shell-escape} \meta{filename}
\end{terminal}

If the locale can't be determined, there will be warning messages.
These can be suppressed using
\cmddef{TrackLangShowWarningsfalse}
or switched back on again using
\cmddef{TrackLangShowWarningstrue}

For example, I have the environment variable \envvar{LANG} set to 
\code{en\idx{underscoresep}GB\idx{dotsep}utf8} on my Linux system so instead of
\begin{codebox}
\gls{TrackPredefinedDialect}\marg{\opt{british}}
\end{codebox}
I can use
\begin{codebox}
\gls{TrackLangFromEnv}
\end{codebox}

With \LaTeX\ documents I can do
\begin{codebox}
\cmd{documentclass}\marg{article}
\cmd{usepackage}\marg{tracklang}
\gls{TrackLangFromEnv}
\end{codebox}
However, this only helps subsequently loaded packages that
use \sty{tracklang} to determine the required regional 
settings. For example:
\begin{codebox}
\cmd{documentclass}\marg{article}
\cmd{usepackage}\marg{tracklang}
\gls{TrackLangFromEnv}
\cmd{usepackage}[useregional]\marg{datetime2}
\end{codebox}
In my case, with the \envvar{LANG} environment variable set to
\code{en\idx{underscoresep}GB\idx{dotsep}utf8} and the
\idx{shellescape} enabled, this automatically switches on the 
\opt{en-GB} date style.
Naturally this doesn't help locale-sensitive packages that don't use
\sty{tracklang}.

The \gls{TrackLangFromEnv} command also incidentally sets
\gls{TrackLangEnv}
to the value of the environment variable or empty if the
query was unsuccessful (for example, the \idx{shellescape} is
unavailable).

If the command:
\cmddef{TrackLangEnv}
is already defined before \gls{TrackLangFromEnv} is used, then the
environment variable won't be queried and the value of
\gls{TrackLangEnv} will be parsed instead.

\begin{important}
The parser which splits the locale string into 
its component parts first tries splitting on the underscore
\idx{underscoresep} with its usual category code~8, then tries splitting 
on a hyphen \idx{hyphensep} with category code~12, and then tries 
splitting on the underscore \idx{underscoresep} with category code~12.
\end{important}

For example:
\begin{codebox}
\cmd{def}\gls{TrackLangEnv}\marg{en-GB}
\gls{TrackLangFromEnv}
\end{codebox}
This doesn't perform a \idx{shellescape} since \gls{TrackLangEnv}
is already defined. In this case, you may just as well use:
\begin{codebox}
\gls{TrackLocale}\marg{en-GB}
\end{codebox}
(unless you happen to additionally require the component
commands that are set by \gls{TrackLangFromEnv}, see below.)

If the \idx{shellescape} is unavailable 
(for example, your \TeX\ installation prohibits it), you
can set this value when you invoke \TeX. For example,
if the document file is called \filefmt{myDoc.tex} (and it's
in Plain \TeX):
\begin{terminal}
\app{tex} "\idx{escbsl}def\idx{escbsl}\glscsname{TrackLangEnv}\marg{\idx{dollarenv}\envvar{LANG}}\idx{escbsl}\glscsname{input} myDoc"
\end{terminal}

The \gls{TrackLangFromEnv} command also happens to store the
component parts of the environment variable value in the
following commands. (These aren't provided by \gls{TrackLocale}.)
If the information is unavailable, the relevant commands will be set
to empty.

The language code is stored in:
\cmddef{TrackLangEnvLang}

The \idx{territory} (if present) is stored in:
\cmddef{TrackLangEnvTerritory}

The \idx{code-set} (if present) is stored in:
\cmddef{TrackLangEnvCodeSet}

The \idx{modifier} (if present) is stored in:
\cmddef{TrackLangEnvModifier}

If you want to query the language environment, but don't
want to track the result, you can just use:
\cmddef{TrackLangQueryEnv}
This only tries to fetch the value of the
language environment variable (and use \sty{texosquery} as
a fallback, if it has been loaded). It doesn't try to parse the 
result. The result is stored in \gls{TrackLangEnv} (empty if 
unsuccessful). Unlike \gls{TrackLangFromEnv}, this doesn't check if
\gls{TrackLangEnv} already exists. A warning will occur if the shell
escape is unavailable. For systems that store the locale information in
environment variables, this is more efficient than using
\sty{texosquery}'s \gls{TeXOSQueryLocale} command (which is what's
used as the fallback).

The above queries \envvar{LCALL} and, if that is unsuccessful,
then queries \envvar{LANG} (before optionally falling back on 
\sty{texosquery}). If you want another environment
variable tried after \envvar{LCALL} and before \envvar{LANG},
you can instead use:
\cmddef{TrackLangQueryOtherEnv}
For example, to also query \envvar{LCMONETARY}:
\begin{codebox}
\gls{TrackLangQueryOtherEnv}\marg{\envvar{LCMONETARY}}
\end{codebox}

Since this sets \gls{TrackLangEnv}, you can use it before
\gls{TrackLangFromEnv}. For example:
\begin{codebox}
\gls{TrackLangQueryOtherEnv}\marg{\envvar{LCMONETARY}}
\gls{TrackLangFromEnv}
\end{codebox}
Remember that if you only want to do the \idx{shellescape} if
\gls{TrackLangEnv} hasn't already been defined, you can test for this
first:
\begin{codebox}
\cmd{ifx}\gls{TrackLangEnv}\cmd{undefined}
  \gls{TrackLangQueryOtherEnv}\marg{\envvar{LCMONETARY}}
\cmd{fi}
\gls{TrackLangFromEnv}
\end{codebox}

It's also possible to just parse the value of \gls{TrackLangEnv}
without tracking the result using:
\cmddef{TrackLangParseFromEnv}
This is like \gls{TrackLangFromEnv} but assumes that 
\gls{TrackLangEnv} has already been set and doesn't track the 
result. The component parts are stored as for \gls{TrackLangFromEnv}.

Example (Plain \TeX):
\begin{codebox}
\gls{input} tracklang
\codepar
\cmd{def}\gls{TrackLangEnv}\marg{fr\idx{hyphensep}BE\idx{dotsep}utf8\idx{atmod}euro}
\codepar
\gls{TrackLangParseFromEnv}
\codepar
Language: \gls{TrackLangEnvLang}.
Territory: \gls{TrackLangEnvTerritory}.
Codeset: \gls{TrackLangEnvCodeSet}.
Modifier: \gls{TrackLangEnvModifier}.
Any tracked languages? \gls{AnyTrackedLanguages}\marg{Yes}\marg{No}.
\end{codebox}
This produces:
\begin{resultbox}
Language: fr. Territory: BE.  Codeset: utf8.  Modifier: euro.
Any tracked languages? No.
\end{resultbox}

Compare this with:
\begin{codebox}
\gls{input} tracklang
\codepar
\cmd{def}\gls{TrackLangEnv}\marg{fr\idx{hyphensep}BE\idx{dotsep}utf8\idx{atmod}euro}
\codepar
\gls{TrackLangFromEnv}
\codepar
Language: \gls{TrackLangEnvLang}.
Territory: \gls{TrackLangEnvTerritory}.
Codeset: \gls{TrackLangEnvCodeSet}.
Modifier: \gls{TrackLangEnvModifier}.
Any tracked languages? \gls{AnyTrackedLanguages}\marg{Yes}\marg{No}.
Tracked dialect(s):\comment{}
\gls{ForEachTrackedDialect}\marg{\cmd{thisdialect}}\marg{\cmd{space}\cmd{thisdialect}}.
\end{codebox}
This produces:

\begin{resultbox}
Language: fr. Territory: BE.  Codeset: utf8.  Modifier: euro.
Any tracked languages? Yes.
Tracked dialect(s): belgique.
\end{resultbox}

If \gls{TrackLangFromEnv} doesn't recognise the given language and
territory combination, it will define a new dialect and add that.

For example, \sty{tracklang} doesn't recognise \code{en-BE}, so
the sample document below defines a new dialect labelled
\code{enBEeuro}:
\begin{codebox}
\gls{input} tracklang
\codepar
\cmd{def}\gls{TrackLangEnv}\marg{en\idx{hyphensep}BE\idx{dotsep}utf8\idx{atmod}euro}
\codepar
\gls{TrackLangFromEnv}
\codepar
Language: \gls{TrackLangEnvLang}.
Territory: \gls{TrackLangEnvTerritory}.
Codeset: \gls{TrackLangEnvCodeSet}.
Modifier: \gls{TrackLangEnvModifier}.
Any tracked languages? \gls{AnyTrackedLanguages}\marg{Yes}\marg{No}.
Tracked dialect(s):\comment{}
\gls{ForEachTrackedDialect}\marg{\cmd{thisdialect}}\marg{\cmd{space}\cmd{thisdialect}}.
\end{codebox}
This now produces:
\begin{resultbox}
Language: en. Territory: BE.  Codeset: utf8.  Modifier: euro.
Any tracked languages? Yes.
Tracked dialect(s): enBEeuro.
\end{resultbox}

\chapter{Supplementary Packages}
\label{sec:supplpkgs}

In addition to the main \file{tracklang.tex} file and
\file{tracklang.sty} \LaTeX\ wrapper, the \sty{tracklang} package
also provides supplementary files for region and script mappings.

\filedef{tracklang-region-codes.tex}
This file is only loaded if a mapping is required between numeric
and alphabetic \idx{region} codes. If \gls{TrackLanguageTag}
encounters a numeric \idx{region} code, it will automatically input
\file{tracklang-region-codes.tex}, if it hasn't already been input.
This file provides the following commands.

\cmddef{TrackLangAlphaIIToNumericRegion}
Expands to the numeric code corresponding to the given alpha-2 code or
empty if no mapping has been supplied.

\cmddef{TrackLangNumericToAlphaIIRegion}
Expands to the alpha-2 code corresponding to the given numeric code or
empty if no mapping has been supplied.

\cmddef{TrackLangIfKnownAlphaIIRegion}
Expands to \meta{true} if there's an alpha-2 to numeric \idx{region}
code mapping, otherwise expands to \meta{false}.

\cmddef{TrackLangIfKnownNumericRegion}
Expands to \meta{true} if there's a numeric to alpha-2 \idx{region}
code mapping, otherwise expands to \meta{false}.

\cmddef{TrackLangAlphaIIIToNumericRegion}
Expands to the numeric code corresponding to the given alpha-3 code or
empty if no mapping has been supplied.

\cmddef{TrackLangNumericToAlphaIIIRegion}
Expands to the alpha-3 code corresponding to the given numeric code or
empty if no mapping has been supplied.

\cmddef{TrackLangIfKnownAlphaIIIRegion}
Expands to \meta{true} if there's an alpha-3 to numeric \idx{region}
code mapping, otherwise expands to \meta{false}.

Mappings are established with:
\cmddef{TrackLangRegionMap}
Predefined mappings are listed in \tableref{tab:regionmappings}.

When \file{tracklang-region-codes.tex} is input, it can load
additional files that provide supplementary mappings.

\cmddef{TrackLangAddExtraRegionFile}
This command adds the supplied \meta{file} to the list of extra
region code files that should be input by
\file{tracklang-region-codes.tex}, unless
\file{tracklang-region-codes.tex} has already been input, in which
case \meta{file} will be input straight away.

\filedef{tracklang-scripts.tex}
The \sty{tracklang-scripts} package provides information about
\idxn{15924} scripts. The file isn't automatically loaded. If
you want to use any of the commands provided in it you need to input
it.

Plain \TeX:
\begin{codebox}
\gls{input} tracklang-scripts
\end{codebox}
There's a simple wrapper package \file{tracklang-scripts.sty} for
\LaTeX\ users:
\begin{codebox}
\cmd{usepackage}\marg{tracklang-scripts}
\end{codebox}

\cmddef{TrackLangScriptMap}
Defines a mapping. The first argument is the four letter alpha code,
such as \opt{Latn} or \opt{Cyrl}. The second argument is the numeric
code. The third argument is the script's name, for example
\qt{Imperial Aramaic}. The fourth argument is the direction, which
may be one of: \optfmt{LR} (left-to-right), \optfmt{RL} (right-to-left),
\optfmt{TB} (top-to-bottom), \optfmt{varies} or \optfmt{inherited}.
The \meta{parent} argument is for the parent writing system, which
may be left blank (currently unsupported).

This command defines:
\cmddef{TrackLangScriptCode}
which expands to \meta{Code} for use with \gls{IfTrackedDialectIsScriptCs}.

See \tableref{tab:scriptmappings} for a summary of all the mappings 
that are provided by the file \file{tracklang-scripts.tex}.

\cmddef{TrackLangScriptAlphaToNumeric}
Expands to the numeric code corresponding to the given alpha code or
empty if no mapping.

\cmddef{TrackLangScriptIfKnownAlpha}
Expands to \meta{true} if there is a known alpha to numeric mapping
or \meta{false} otherwise.

\cmddef{TrackLangScriptNumericToAlpha}
Expands to the alpha code corresponding to the given numeric code or
empty if no mapping.

\cmddef{TrackLangScriptIfKnownNumeric}
Expands to \meta{true} if there is a known numeric to alpha mapping
or \meta{false} otherwise.

\cmddef{TrackLangScriptAlphaToName}
Expands to the name corresponding to the given alpha code or
empty if no mapping.

\cmddef{TrackLangScriptAlphaToDir}
Expands to the direction corresponding to the given alpha code or
empty if no mapping.

\cmddef{TrackLangScriptSetParent}
Sets the parent for the given alpha code.

\cmddef{TrackLangScriptGetParent}
Expands to the parent for the given alpha code or empty if no
mapping.

\cmddef{TrackLangScriptIfHasParent}
Expands to \meta{true} if the given alpha code has a parent 
or to \meta{false} otherwise. Note that if a parent is explicitly
set to empty with \gls{TrackLangScriptSetParent} then it will be
considered defined, but if the \meta{parent} argument was empty in 
\gls{TrackLangScriptMap}, then it will be undefined.

\cmddef{TrackLangAddExtraScriptFile}
This command adds \meta{file} to the list of extra script files that should
be input by \file{tracklang-scripts.tex}, unless 
\file{tracklang-scripts.tex} has already been input, in which
case \meta{file} will be input straight away.


\chapter{Detecting the User's Requested Languages}
\label{sec:user}

The \sty{tracklang} package tries to track the loaded languages and
the option names used to identify those languages. For want of a better
term, the language option names are referred to as dialects even if
they're only a synonym for the language rather than an actual
dialect.  For example, if the user
has requested \opt{british}, the \emph{root language} label is
\opt{english} and the dialect is \opt{british}, whereas if the
user requested \opt{UKenglish}, the root language label is
\opt{english} and the dialect is \opt{UKenglish}. The
exceptions to this are the \sty{tracklang} package options that have been
specified in the form \meta{iso lang}-\meta{iso country} (listed
in \tableref{tab:rootlangopts}). For
example, the package option \iso{british} behaves as though the
user requested the package option \opt{british}.

If \gls{TrackLocale} or \gls{TrackLangFromEnv} are used and the locale
isn't recognised a new dialect is created with the label formed from
the \idx{ISO} codes (and \idx{modifier}, if present). 
Similarly for \gls{TrackLanguageTag} a new
dialect is created with a label that's essentially the language tag
without the hyphen separators.  For example, 
\begin{codebox}
\gls{TrackLocale}\marg{xx\idx{hyphensep}YY}
\end{codebox}
will add a new dialect with the label \code{xxYY},
\begin{codebox}
\gls{TrackLocale}\marg{xx\idx{hyphensep}YY\idx{atmod}mod}
\end{codebox}
will add a new dialect with the label \code{xxYYmod} and 
\begin{codebox}
\gls{TrackLanguageTag}\marg{xx-Latn-YY}
\end{codebox}
will add a new dialect with the label \code{xxLatnYY}.

\begin{important}
If \gls{TrackLocale} or \gls{TrackLangFromEnv} find a \idx{modifier}, the 
value will be sanitized to allow it to be used as a label. If the
modifier is set explicitly using \gls{SetTrackedDialectModifier}, 
no sanitization is performed.
\end{important}

In addition to the root language label and the dialect identifier,
many of the language options also have corresponding \idx{ISO} codes. In
most cases there is an \idxn{639-1} or an \idxn{639-2} code (or both), and in some
cases there is an \idxn{3166-1} code identifying the dialect \idx{region}.
Where a language has different \idxn{639-2T} and \idx{639-2B} codes, 
the \qt{T} version is assumed.

When the \file{tracklang.sty} \LaTeX\ package is loaded, it first attempts to find the
language options through the package options supplied to
\sty{tracklang}. This means that any languages that have been
supplied in the document class options should get identified
(provided that the document class has used the standard option
declaration mechanism).  If no languages have been supplied in this
way, \file{tracklang.sty} then attempts to identify language settings in
the following order:
\begin{enumerate}
\item if \gls{bbl@loaded} is defined (\sty{babel}), \sty{tracklang}
will iterate over each label in that command definition;

\item if \gls{trans@languages} is defined (\sty{translator}), 
\sty{tracklang} will iterate over each label in that command
definition;

\item if \sty{ngerman} has been loaded, the \opt{ngerman} dialect
will be tracked;

\item if \sty{german} has been loaded, the \opt{german} root
language will be tracked;

\item if \sty{polyglossia} has been loaded:

 \begin{enumerate}
 \item if \gls{xpg@bcp@loaded} has been defined, \sty{tracklang}
will iterate over the \idx{BCP47} tags in that command definition;

 \item if \gls{xpg@loaded} has been defined, \sty{tracklang} will
iterate over each language label in that command definition;

 \item \sty{tracklang} will iterate over all \sty{tracklang} options
and test if the root language has been loaded.
 \end{enumerate}

\end{enumerate}
Note that this references internal commands provided by other
packages. Of these, only the \sty{polyglossia} commands are
documented in the package manual, and so are the only ones that can
be relied on.

Each identified language and dialect is added to the \emph{tracked
language} and \emph{tracked dialect} lists. Note that the tracked
language and tracked dialect are labels rather than proper nouns.
If a~dialect label is identical to its root language label, the
label will appear in both lists.

You can check whether or not any languages have been detected using:
\cmddef{AnyTrackedLanguages}
This will do \meta{true} if one or more languages have been
tracked otherwise it will do \meta{false}. (Each detected
dialect will automatically have the root language label added
to the tracked language list, if it's not already present.)

If you want to find out if any of the tracked dialects
matches a particular language tag, you can use:
\cmddef{GetTrackedDialectFromLanguageTag}
If successful, the supplied control sequence \meta{cs} is set to the
dialect label, otherwise \meta{cs} is set to empty. The test is for an exact
match on the root language, \idx{script}, sub-language, \idx{variant} and
\idx{region}. The control sequence \meta{cs} will be empty if none of the
tracked dialects matches all five of those elements. (If the script
isn't given explicitly, the default for that language is assumed.)
In the event that \meta{cs} is empty, you can now (as from v1.3.6)
get the closest match with:
\cmddef{TrackedDialectClosestSubMatch}
(which is set by \gls{GetTrackedDialectFromLanguageTag}).
This will be empty if no tracked dialects match on the root
language or if there's a tracked dialect label that exactly matches
the label formed by concatenating the language code, sub-language,
\idx{script}, \idx{region}, \idx{modifier} and \idx{variant}.

For example (Plain \TeX):
\begin{codebox}
\gls{input} tracklang
\gls{TrackLanguageTag}\marg{en-826}
Has en-Latn-GB been tracked?
\gls{GetTrackedDialectFromLanguageTag}\marg{en-Latn-GB}\marg{\cmd{thisdialect}}\comment{}
\cmd{ifx}\cmd{thisdialect}\cmd{empty}
 No!
\cmd{else}
 Yes! Dialect label: \cmd{thisdialect}.
\cmd{fi}
\cmd{bye}
\end{codebox}
This matches because the \idx{territory} code \numericcode{GB} is recognised as
equivalent to the code \opt{GB}, and the default \idx{script} for
\opt{english} is \opt{Latn}. In this case, the dialect
label is \opt{british}. Note that this doesn't require
the use of \gls{TrackLanguageTag} to track the dialect. 
It also works if the dialect has been tracked using other commands,
such as \gls{TrackLocale}.

Here's an example that doesn't have an exact match, but does have a
partial match:
\begin{codebox}
\gls{input} tracklang
\gls{TrackLanguageTag}\marg{de-CH-1996}
Has de-DE-1996 been tracked?
\gls{GetTrackedDialectFromLanguageTag}\marg{de-DE-1996}\marg{\cmd{thisdialect}}\comment{}
\cmd{ifx}\cmd{thisdialect}\cmd{empty}
 No!
  \cmd{ifx}\gls{TrackedDialectClosestSubMatch}\cmd{empty}
    No match on root language.
  \cmd{else}
    Closest match: \gls{TrackedDialectClosestSubMatch}.
  \cmd{fi}
\cmd{else}
 Yes! Dialect label: \cmd{thisdialect}.
\cmd{fi}
\cmd{bye}
\end{codebox}
In this case the result is:
\begin{resultbox}
Has de-DE-1996 been tracked? No! Closest match: nswissgerman.
\end{resultbox}

You can iterate through each tracked dialect using:
\cmddef{ForEachTrackedDialect}
At the start of each iteration, this sets the control sequence 
\meta{cs} to the tracked dialect and does \meta{body}.

You can iterate through each tracked language using:
\cmddef{ForEachTrackedLanguage}
At the start of each iteration, this sets the control sequence \meta{cs} to the 
tracked language and does \meta{body}.

The above for-loops use the same internal mechanism as \LaTeX's
\gls{@for} loop. Since this isn't defined by \TeX, a similar command
(\inlineglsdef{@tracklang@for}) will be defined that works in the same way.

The provided control sequence \meta{cs} is updated at the
start of each iteration to the current element. The loop is
terminated when this control sequence is set to \gls{@nil}. This
special control sequence should never been used as it's just a
marker and isn't actually defined. If you get an error message
stating that \gls{@nil} is undefined, then it's most likely due to a
loop control sequence being used outside the loop. This can occur if
the loop contains code that isn't expanded until later. For example,
if the loop code includes \gls{AtBeginDocument}, you need to ensure
that the loop control sequence is expanded before being added to the
hook.

You can test if a root language has been detected using:
\cmddef{IfTrackedLanguage}
where \meta{language-label} is the language label. If
true, this does \meta{true} otherwise it does \meta{false}.

You can test if a particular dialect has been detected using:
\cmddef{IfTrackedDialect}
where \meta{dialect-label} is the dialect label. If the root
language was explicitly specified, then it will also be detected as
a dialect.

For example:
\begin{codebox}
\cmd{documentclass}[\opt{british},\opt{dutch}]\marg{article}
\codepar
\cmd{usepackage}\marg{tracklang}
\codepar
\cbeg{document}
``english'' \gls{IfTrackedDialect}\marg{english}\marg{has}\marg{hasn't} been specified.
\codepar
``british'' \gls{IfTrackedDialect}\marg{british}\marg{has}\marg{hasn't} been specified.
\codepar
``flemish'' \gls{IfTrackedDialect}\marg{flemish}\marg{has}\marg{hasn't} been specified.
\codepar
``dutch'' \gls{IfTrackedDialect}\marg{dutch}\marg{has}\marg{hasn't} been specified.
\codepar
``english'' or an English variant 
\gls{IfTrackedLanguage}\marg{english}\marg{has}\marg{hasn't} been specified.
\cend{document}
\end{codebox}
This produces:
\begin{resultbox}
``english'' hasn't been specified.

``british'' has been specified.

``flemish'' hasn't been specified.

``dutch'' has been specified.

``english'' or an English variant has been specified.
\end{resultbox}

You can find the root language label for a given tracked dialect
using:
\cmddef{TrackedLanguageFromDialect}
If \meta{dialect} hasn't been defined this does nothing otherwise it
expands to the root language label.

You can find the tracked dialects from a given root language
using:
\cmddef{TrackedDialectsFromLanguage}
This will expand to a~comma-separated list of dialect labels
if the root language label has been defined, otherwise it
does nothing.

You can test if a language or dialect has a corresponding \idx+{ISO} code using:
\cmddef{IfTrackedLanguageHasIsoCode}
where \meta{code type} is the type of \idx{ISO} code (for example,
\idx{639-1} for root languages or \idx{3166-1} for regional
dialects), and \meta{label} is the language or dialect label.
Note that the \idx{639-3} may be set for the dialect
rather than root language for sub-languages parsed using
\gls{TrackLanguageTag}.

Alternatively, you can test if a particular \idx{ISO} code has been
defined using:
\cmddef{IfTrackedIsoCode}
where \meta{code type} is again the type of \idx{ISO} code (for example,
\idx{639-1} or \idx{3166-1}), and \meta{code} is the
particular code (for example, \opt{en} for \idxn{639-1} or
\opt{GB} for \idxn{3166-1}).

You can fetch the language (or dialect) label associated with a
given \idx{ISO} code using:
\cmddef{TrackedLanguageFromIsoCode}
This does nothing if the given \meta{code} for the given \idx{ISO}
\meta{code type} has not been defined, otherwise it expands
a~comma-separated list of language or dialect labels.

You can fetch the \idx{ISO} code for a given code type using:
\cmddef{TrackedIsoCodeFromLanguage}
where \meta{label} is the language or dialect label and \meta{code
type} is the \idx{ISO} code type (for example, \idx{639-1} or
\idx{3166-1}). Unlike \gls{TrackedLanguageFromIsoCode}, this
command only expands to a single label rather than a~comma-separated
list.

The above commands do nothing in the event of an unknown code or
code type,
so if you accidentally get the wrong code type, you won't get an error.
If you're unsure of the code type, you can use the following commands:
\cmddef{TwoLetterIsoCountryCode}
This expands to \idx{3166-1} and is used for the two-letter country codes.

\cmddef{TwoLetterIsoLanguageCode}
This expands to \idx{639-1} and is used for the two-letter root language codes.

\cmddef{ThreeLetterIsoLanguageCode}
This expands to \idx{639-2} and is used for the three-letter root language
codes.

\cmddef{ThreeLetterExtIsoLanguageCode}
This expands to \idx{639-3}. This code is only used for a root language if 
there's no \idx{639-1} or \idx{639-2} code. It may also be used for a
dialect if a sub-language part has been set in the language
tag parsed by \gls{TrackLanguageTag}.

The \cmd{Get\ldots} commands below are designed to be expandable.
If the supplied \meta{dialect} is unrecognised they expand to empty.
Remember that the dialect must first be identified as a tracked 
language for it to be recognised.

As from v1.3, the language tag for a given dialect can be obtained
using:
\cmddef{GetTrackedLanguageTag}
where \meta{dialect} is the label identifying the dialect.
Uses the \opt{und} (undetermined) code for unknown languages.

As from v1.3, each tracked dialect may also have an associated 
modifier, which can be fetched using:
\cmddef{GetTrackedDialectModifier}
where \meta{dialect} is the label identifying the dialect.
This value is typically obtained by parsing a \idx{POSIX} locale identifier
with \gls{TrackLocale} or \gls{TrackLangFromEnv} but may be set explicitly.
(See \sectionref{sec:langsty} for setting this value. Likewise for
the following commands.)

You can test if a dialect has an associated \idx{modifier} using:
\cmddef{IfHasTrackedDialectModifier}
If the dialect has an associated \idx{modifier} this does \meta{true}
otherwise it does \meta{false}.

For example:
\begin{codebox}
\cmd{documentclass}[\opt{british},\opt{francais},\opt{american},\opt{canadian},\opt{canadien},\opt{dutch}]\marg{article}
\codepar
\cmd{usepackage}\marg{tracklang}
\codepar
\cbeg{document}
Languages:
\gls{ForEachTrackedLanguage}\marg{\cmd{ThisLanguage}}\marg{\cmd{ThisLanguage}\cmd{space}
(ISO \gls{TwoLetterIsoLanguageCode}: 
``\gls{TrackedIsoCodeFromLanguage}\marg{\gls{TwoLetterIsoLanguageCode}}\marg{\cmd{ThisLanguage}}''). }
\codepar
Dialects:
\gls{ForEachTrackedDialect}\marg{\cmd{ThisDialect}}\marg{\cmd{ThisDialect}\cmd{space} 
(\gls{IfTrackedLanguageHasIsoCode}\marg{\gls{TwoLetterIsoCountryCode}}\marg{\cmd{ThisDialect}}\comment{}
 \marg{ISO \gls{TwoLetterIsoCountryCode}: 
  ``\gls{TrackedIsoCodeFromLanguage}\marg{\gls{TwoLetterIsoCountryCode}}\marg{\cmd{ThisDialect}}''}%
 \marg{no specific region};
root: \gls{TrackedLanguageFromDialect}\marg{\cmd{ThisDialect}}). }
\codepar
Language for ISO \gls{TwoLetterIsoCountryCode}\cmd{ }``GB'':
\gls{TrackedLanguageFromIsoCode}\marg{\gls{TwoLetterIsoCountryCode}}\marg{GB}.
\codepar
Language for ISO \gls{TwoLetterIsoCountryCode}\cmd{ }``CA'': 
\gls{TrackedLanguageFromIsoCode}\marg{\gls{TwoLetterIsoCountryCode}}\marg{CA}.
\codepar
Country ISO \gls{TwoLetterIsoCountryCode}\cmd{ }code for ``canadian'':
\gls{TrackedIsoCodeFromLanguage}\marg{\gls{TwoLetterIsoCountryCode}}\marg{canadian}.
\cend{document}
\end{codebox}
This produces:
\begin{resultbox}
Languages: english (ISO 639-1: ``en''). french (ISO 639-1: ``fr'').
dutch (ISO 639-1: ``nl'').

Dialects: american (ISO 3166-1: ``US''; root: english).
british (ISO 3166-1: ``GB''; root: english).
canadian (ISO 3166-1: ``CA''; root: english).
canadien (ISO 3166-1: ``CA''; root: french).
dutch (no specific region; root: dutch).
francais (no specific region; root: french).

Language for ISO 3166-1 ``GB'': british.

Language for ISO 3166-1 ``CA'': canadian,canadien.

Country ISO 3166-1 code for ``canadian'': CA.
\end{resultbox}

As from v1.3, each tracked dialect may also have an associated 
variant, which can be fetched using:
\cmddef{GetTrackedDialectVariant}
where \meta{dialect} is the label identifying the dialect.
This value is typically obtained by parsing a language tag
with \gls{TrackLanguageTag} but may be set explicitly.

You can test if a dialect has an associated variant using:
\cmddef{IfHasTrackedDialectVariant}

As from v1.3, each tracked dialect may also have an associated 
script, which can be fetched using:
\cmddef{GetTrackedDialectScript}
where \meta{dialect} is the label identifying the dialect.

You can test if a dialect has an associated script using:
\cmddef{IfHasTrackedDialectScript}
If the dialect has an associated script this does \meta{true}
otherwise it does \meta{false}. This information is provided
for language packages that need to know what script is required,
but there's no guarantee that the script will actually be set
in the document. Similarly for all the other attributes described
here.

Note that the script should be a recognised four-letter \idxn{15924}
code, such as \opt{Latn} or \opt{Cyrl}. If a~dialect
doesn't have an associated script then the default for the root
language should be assumed. For example, \opt{Latn} for English dialects or
\opt{Cyrl} for Russian dialects. The default script for
known languages can be obtained using:
\cmddef{TrackLangGetDefaultScript}
Most root languages have a default script, but there
are a few without one as it may depend on region, politics
or ideology.

There's a convenient expandable command for testing the script:
\cmddef{IfTrackedDialectIsScriptCs}
This tests if the given tracked dialect has an associated script and
compares the value with the replacement text of \meta{cs}.
If the dialect hasn't been explicitly assigned a script,
then test is performed against the default script for the root
language.

The supplementary package \sty{tracklang-scripts} provides some
additional commands relating to writing systems, including commands 
in the form \gls{TrackLangScriptCode} where
\meta{Code} is the \idxn{15924} four-letter code. If the dialect
doesn't have an associated script, \meta{false} is done.
This package isn't
loaded automatically, so you'll need to explicitly load it. The
generic code is in \file{tracklang-scripts.tex}:
\begin{codebox}
\gls{input} tracklang-scripts
\end{codebox}
There's a convenient \LaTeX\ wrapper \file{tracklang-scripts.sty}:
\begin{codebox}
\cmd{usepackage}\marg{tracklang-scripts}
\end{codebox}
See \sectionref{sec:supplpkgs} for further details of
that package.

For example, the following defines a command to check if
the given dialect should use a Latin \idx{script}:
\begin{codebox}
\gls{input} tracklang-scripts
\cmd{def}\cmd{islatin}\#1\#2\#3\marg{\comment{}
  \gls{IfTrackedDialectIsScriptCs}\marg{\#1}\marg{\tklscript{Latn}}\marg{\#2}\marg{\#3}\comment{}
}
\end{codebox}

\begin{important}
Note that the \idx{script} value doesn't mean that the document is
actually using that script. It means that this is the user's
\emph{desired} script, but whether that \idx{script} is actually set relies
on the appropriate settings in the relevant language package (such
as \sty{polyglossia}['s] \optfmt{script} key).
\end{important}

As from v1.3, each tracked dialect may also have a sub-language
identifier (for example, \optfmt{arevela}), which can be fetched
using:
\cmddef{GetTrackedDialectSubLang}
where \meta{dialect} is the label identifying the dialect.

You can test if a dialect has an associated sub-tag using:
\cmddef{IfHasTrackedDialectSubLang}
If the dialect has an associated sub-tag this does \meta{true}
otherwise it does \meta{false}.

As from v1.3, each tracked dialect may also have additional
information, which can be fetched using:
\cmddef{GetTrackedDialectAdditional}
where \meta{dialect} is the label identifying the dialect.

You can test if a dialect has additional information using:
\cmddef{IfHasTrackedDialectAdditional}
If the dialect has additional information this does \meta{true}
otherwise it does \meta{false}.

Most packages that implement multilingual support have a~set of
language definition files for each supported language or dialect.
It may be that only the root language is needed, if there are no
variations between that language's dialect (for the purposes of that
package), or it may be that separate definition files are required
for each dialect. However it can be awkward trying to map the
requested dialect or language label to the file name. Should, say,
the file containing the French code be called
\metametafilefmt{}{prefix}{\dhyphen french\dhyphen }{suffix}{} or 
\metametafilefmt{}{prefix}{\dhyphen frenchb\dhyphen }{suffix}{} or 
\metametafilefmt{}{prefix}{\dhyphen francais\dhyphen}{suffix}{}?
Should, say, the file containing the British English code be called
\metametafilefmt{}{prefix}{\dhyphen british\dhyphen }{suffix}{} or 
\metametafilefmt{}{prefix}{\dhyphen UKenglish\dhyphen }{suffix}{}?
If you want to modularise the language support for your package so
that each language module has a different maintainer will the
maintainers know what tag to use for their language?

\label{pg:filesearch}To help with this, \sty{tracklang} provides:
\cmddef{IfTrackedLanguageFileExists}
This attempts to find the file called
\meta{prefix}\meta{localeid}\meta{suffix} where \meta{localeid} is determined
from \meta{dialect} (see below). If the file is found then
\cmddef{CurrentTrackedTag}
is set to \meta{localeid} and \meta{true code} is done, otherwise
\meta{false code} is done.  If this command
is empty, then the dialect hasn't been detected. If the dialect
has been detected, but no file can be found, then
\gls{CurrentTrackedTag} is set to the final attempt at determining
\meta{localeid}.

There's a convenient shortcut command new to version 1.3:
\cmddef{TrackLangRequireDialect}
which uses \gls{IfTrackedLanguageFileExists} to input the resource
file if found. The prefix is given by \meta{pkgname}\code{-} and
the suffix is \code{.\ext+{ldf}}. A warning is issued if no resource file
is found. Note that while it makes sense for \meta{pkgname}
to be the same as the base name of the package that uses these
resource files, they don't have to be the same. This command
additionally defines:
\cmddef{TrackLangRequireDialectPrefix}
to \meta{pkgname}, which allows the prefix to be picked up by
resource file commands, such as \gls{TrackLangProvidesResource}
and \gls{TrackLangRequireResource}.  (See below.)

The optional argument \meta{load code} is the code that actually
inputs the required file. This defaults to
\begin{codebox}
\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}
\end{codebox}

The \gls{IfTrackedLanguageFileExists} command sets up the current
tracked dialect with:
\begin{compactcodebox*}
\gls{SetCurrentTrackedDialect}\marg{dialect}
\end{compactcodebox*}
which enables the following commands that may be used within 
\meta{true code} or \meta{false code}:
\cmddef{CurrentTrackedDialect}
Expands to the dialect label.

\cmddef{CurrentTrackedLanguage}
If the dialect hasn't been detected, this command will be empty,
otherwise it will expand to the root language label (which may
be the same as the dialect label).

\cmddef{CurrentTrackedRegion}
If the dialect hasn't been detected, this command will be empty.
If the dialect has been assigned an \idxn{3166-1} code,
\gls{CurrentTrackedRegion} will expand to that code, otherwise it
will be empty.

\cmddef{CurrentTrackedIsoCode}
If the dialect hasn't been detected, this command will be empty.
Otherwise it may be empty or it may expand to the
\idxn{639-1} or \idxn{639-2} or \idxn{639-3} code.

\cmddef{CurrentTrackedDialectModifier}
The dialect's modifier or empty if not set. (This is set but not
used in the set of possible \meta{localeid} values.)

\cmddef{CurrentTrackedDialectVariant}
The dialect's variant or empty if not set.

\cmddef{CurrentTrackedDialectSubLang}
The dialect's sub-language code or empty if not set.

\cmddef{CurrentTrackedDialectAdditional}
The dialect's additional information or empty if not set.

\cmddef{CurrentTrackedLanguageTag}
The dialect's language tag. Take care not to confuse this
with \gls{CurrentTrackedTag}.

\cmddef{CurrentTrackedDialectScript}
The dialect's script. If the dialect doesn't have the script set,
the default script for the language is used instead.

\gls{IfTrackedLanguageFileExists} behaves as follows:
\begin{itemize}
 \item If no dialect with the given label has been
  detected, the condition evaluates to \emph{false} and
 \gls{CurrentTrackedTag} is empty.

 \item If a dialect with the given label has been detected, then:
 \begin{itemize}
 \item For each possible \meta{localeid} in an ordered set of tags determined by
   the dialect label (see below), the first file matching
   \meta{prefix}\meta{localeid}\meta{suffix} that's found on
   \TeX's path results in the condition evaluating to \emph{true} and
   \gls{CurrentTrackedTag} is set to the current \meta{localeid} in the
   set. The rest of the set of possible values of \meta{localeid} is skipped.

 \item If no file matching \meta{prefix}\meta{localeid}\meta{suffix} is
   found on \TeX's path, then the condition evaluates to \emph{false}
   and \gls{CurrentTrackedTag} is set to the final \meta{localeid} in the
   set (the language label).
 \end{itemize}
\end{itemize}

The ordered set of possible values of \meta{localeid} is determined from
the given dialect.
\begin{important}
The ordering has changed in version 1.4, which now also includes the
\idx{script} and \idx{variant}. This new ordering should typically make the more
common combinations closer to the start of the search.
\end{important}
The possible values of \meta{localeid} are listed below in the order of priority used
by \gls{IfTrackedLanguageFileExists}. Note that the set may contain
repetitions (for example, if the dialect label is the same as the
root language label). If an item contains an element that hasn't
been set (such as the \idxn{639-3} code or a sub-language
\meta{sublang} or \idx{variant}) then
that item is skipped.
\begin{enumerate}
\item \meta{localeid} is just the value of \gls{CurrentTrackedLanguageTag}.

\item \meta{localeid} is just the dialect label.

\item \meta{localeid} is
\meta{ISO~639-1}\code{-}\meta{sublang}\code{-}\meta{script}\code{-}\meta{region}.

\item \meta{localeid} is
\meta{ISO~639-1}\code{-}\meta{script}\code{-}\meta{region}.

\item \meta{localeid} is
\meta{ISO~639-1}\code{-}\meta{sublang}\code{-}\meta{region} (if there's no script or if
the script is the default for the given language).
\meta{ISO~639-1}\code{-}\meta{region} (if there's no script or if
the script is the default for the given language).

\item \meta{localeid} is
\meta{ISO~639-1}\code{-}\meta{sublang}\code{-}\meta{script}.

\item \meta{localeid} is
\meta{ISO~639-1}\code{-}\meta{script}.

\item \meta{localeid} is \meta{ISO~639-1}\code{-}\meta{sublang}.

\item \meta{localeid} is just \meta{ISO~639-1}.

\item \meta{localeid} is
\meta{ISO~639-2}\code{-}\meta{sublang}\code{-}\meta{script}\code{-}\meta{region}.

\item \meta{localeid} is
\meta{ISO~639-2}\code{-}\meta{script}\code{-}\meta{region}.

\item \meta{localeid} is
\meta{ISO~639-2}\code{-}\meta{sublang}\code{-}\code{region} (if there's no script or if
the script is the default for the given language).
\meta{ISO~639-2}\code{-}\meta{region} (if there's no script or if
the script is the default for the given language).

\item \meta{localeid} is
\meta{ISO~639-2}\code{-}\meta{sublang}\code{-}\meta{script}.

\item \meta{localeid} is
\meta{ISO~639-2}\code{-}\meta{script}.

\item \meta{localeid} is \meta{ISO~639-2}\code{-}\meta{sublang}.
\item \meta{localeid} is just \meta{ISO~639-2}.

\item \meta{localeid} is
\meta{ISO~639-3}\code{-}\meta{sublang}\code{-}\meta{script}\code{-}\meta{region}.

\item \meta{localeid} is
\meta{ISO~639-3}\code{-}\meta{script}\code{-}\meta{region}.

\item \meta{localeid} is
\meta{ISO~639-3}\code{-}\meta{sublang}\code{-}\meta{region} (if there's no script or if
the script is the default for the given language).
\meta{ISO~639-3}\code{-}\meta{region} (if there's no script or if
the script is the default for the given language).

\item \meta{localeid} is
\meta{ISO~639-3}\code{-}\meta{sublang}\code{-}\meta{script}.

\item \meta{localeid} is
\meta{ISO~639-3}\code{-}\meta{script}.

\item \meta{localeid} is \meta{ISO~639-3}\code{-}\meta{sublang}.

\item \meta{localeid} is just \meta{ISO~639-3}.

\item \meta{localeid} is just \meta{region}.

\item \meta{localeid} is
\meta{ISO~639-1}\code{-}\meta{sublang}\code{-}\meta{variant}
or \meta{ISO~639-1}\code{-}\meta{variant} if \meta{sublang} is missing.

\item \meta{localeid} is
\meta{ISO~639-2}\code{-}\meta{sublang}\code{-}\meta{variant}
or \meta{ISO~639-2}\code{-}\meta{variant} if \meta{sublang} is missing.

\item \meta{localeid} is
\meta{ISO~639-3}\code{-}\meta{sublang}\code{-}\meta{variant}
or \meta{ISO~639-3}\code{-}\meta{variant} if \meta{sublang} is missing.

\item \meta{localeid} is just the value of \gls{CurrentTrackedLanguage}
(the root language label).
\end{enumerate}

For example (pre v1.3):
\begin{codebox}
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedDialect}\marg{\cmd{ThisDialect}}\comment{}
  \marg{\comment{try to load the language file for this dialect}
    \gls{IfTrackedLanguageFileExists}\marg{\cmd{ThisDialect}}\comment{}
    \marg{mypackage-}\comment{file prefix}
    \marg{.ldf}\comment{file suffix}
    \marg{\gls{input} mypackage-\gls{CurrentTrackedTag}.ldf}\comment{file found}
    \marg{\comment{file not found}
      \cmd{PackageWarning}\marg{mypackage}\marg{No support for language
       `\cmd{ThisDialect}'}\comment{}
    }\comment{}
  }\comment{}
}
\marg{\comment{no languages detected so use defaults}
}
\end{codebox}
With version 1.3 onwards, this can be written more concisely as:
\begin{codebox}
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedDialect}\marg{\cmd{ThisDialect}}\comment{}
  \marg{\comment{try to load the language file for this dialect}
    \gls{TrackLangRequireDialect}\marg{mypackage}\marg{\cmd{ThisDialect}}\comment{}
  }\comment{}
}
\marg{\comment{no languages detected so use defaults}
}
\end{codebox}
which additionally enables the \sty{tracklang} version 1.3 commands described below,
such as \gls{TrackLangRequireResource}.

\plabel{pg.britishfilesearch}%
If, for example, \cmd{ThisDialect} is \opt{british}, then the file search will
be in the order:
\begin{enumerate}
\item \ldf{mypackage}{en-GB} (language tag)
\item \ldf{mypackage}{british} (dialect label)

\item \ldf{mypackage}{en-Latn-GB} (\idx{639-1} language code,
\idx{script}, \idx{region})
\item \ldf{mypackage}{en-GB} (\idx{639-1} language code,
\idx{region})
\item \ldf{mypackage}{en-Latn} (\idx{639-1} language code,
\idx{script})
\item \ldf{mypackage}{en} (\idx{639-1} language code)

\item \ldf{mypackage}{eng-Latn-GB} (\idx{639-2} language
code, \idx{script}, \idx{region})
\item \ldf{mypackage}{eng-GB} (\idx{639-2} language code,
\idx{region})
\item \ldf{mypackage}{eng-Latn} (\idx{639-2} language code,
\idx{script})
\item \ldf{mypackage}{eng} (\idx{639-2} language code)

\item \ldf{mypackage}{GB} (\idx{region})
\item \ldf{mypackage}{english} (language label)
\end{enumerate}

If, for example, \cmd{ThisDialect} is \opt{naustrian}, then the file search will
be in the order:
\begin{enumerate}
\item \ldf{mypackage}{de-AT-1996} (language tag)
\item \ldf{mypackage}{naustrian} (dialect label)

\item \ldf{mypackage}{de-Latn-AT} (\idx{639-1} language code,
\idx{script}, \idx{region})
\item \ldf{mypackage}{de-AT} (\idx{639-1} language code,
\idx{region})
\item \ldf{mypackage}{de-Latn} (\idx{639-1} language code,
\idx{script})
\item \ldf{mypackage}{de} (\idx{639-1} language code)

\item \ldf{mypackage}{deu-Latn-AT} (\idx{639-2} language
code, \idx{script}, \idx{region})
\item \ldf{mypackage}{deu-AT} (\idx{639-2} language code,
\idx{region})
\item \ldf{mypackage}{deu-Latn} (\idx{639-2} language code,
\idx{script})
\item \ldf{mypackage}{deu} (\idx{639-2} language code)

\item \ldf{mypackage}{AT} (\idx{region})

\item \ldf{mypackage}{de-1996} (\idx{639-1} language code,
\idx{variant})
\item \ldf{mypackage}{deu-1996} (\idx{639-2} language code,
\idx{variant})

\item \ldf{mypackage}{german} (language label)
\end{enumerate}

If, for example, \cmd{ThisDialect} is \opt{francais}, then the file search will
be in the order: 
\begin{enumerate}
\item \ldf{mypackage}{fr} (language tag)
\item \ldf{mypackage}{francais} (dialect label)
\item \ldf{mypackage}{fr-Latn} (\idx{639-1} language code,
\idx{script})
\item \ldf{mypackage}{fr} (\idx{639-1} language code)
\item \ldf{mypackage}{fra-Latn} (\idx{639-2} language code,
\idx{script})
\item \ldf{mypackage}{fra} (\idx{639-2} language code)
\item \ldf{mypackage}{french} (language)
\end{enumerate}
This is because the predefined \opt{francais} option has no
region assigned to it. Be careful if the dialect label is the actual
root language. For example, if \cmd{ThisDialect} is \opt{french},
then the file search will be in the order:
\begin{enumerate}
\item \ldf{mypackage}{fr} (language tag)
\item \ldf{mypackage}{french} (dialect label)
\item \ldf{mypackage}{fr-Latn} (\idx{639-1} language code,
\idx{script})
\item \ldf{mypackage}{fr} (\idx{639-1} language code)
\item \ldf{mypackage}{fra-Latn} (\idx{639-2} language code,
\idx{script})
\item \ldf{mypackage}{fra} (\idx{639-2} language code)
\item \ldf{mypackage}{french} (language)
\end{enumerate}
Note that the last try will always fail in this case since if the
file exists, it will be found on the second try.

If the dialect label is identical to the root language label then it
means that all associated information is the default
for that language. For example, in the above case of \opt{french},
the script is \opt{Latn} and the region is unspecified. The root
language label can therefore be used as the fallback in the event of
no other match but for the specific case where the dialect is
identical to the root language then all unnecessary file name checks
can be skipped.

If you're only providing support for the root languages (pre v1.3):
\begin{codebox}
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedLanguage}\marg{\cmd{ThisLanguage}}\comment{}
  \marg{\comment{try to load the language file for this root language}
    \gls{IfTrackedLanguageFileExists}\marg{\cmd{ThisLanguage}}\comment{}
    \marg{mypackage-}\comment{file prefix}
    \marg{.ldf}\comment{file suffix}
    \marg{\gls{input} mypackage-\gls{CurrentTrackedTag}.ldf}\comment{file found}
    \marg{\comment{file not found}
      \cmd{PackageWarning}\marg{mypackage}\marg{No support for language
       `\cmd{ThisLanguage}'}\comment{}
    }\comment{}
  }\comment{}
}
\marg{\comment{no languages detected so use defaults}
}
\end{codebox}
With version 1.3 onwards, this can be written more concisely as:
\begin{codebox}
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedLanguage}\marg{\cmd{ThisLanguage}}\comment{}
  \marg{\comment{try to load the language file for this root language}
    \gls{TrackLangRequireDialect}\marg{mypackage}\marg{\cmd{ThisLanguage}}\comment{}
  }\comment{}
}
\marg{\comment{no languages detected so use defaults}
}
\end{codebox}
which additionally enables the commands described below.
Note that in this case, if more than one dialect for the same
language has been tracked, only the hooks for the last dialect for
that language will be adjusted, so it's usually best to iterate over
the dialects.

The following \cmd{TrackLang\ldots Resource\ldots} commands may 
only be used in resource files that are loaded using
\gls{TrackLangRequireDialect}. An error will occur if the file is
input through some other method.

Within the resource file \localemetafile{pkgname}, 
you can identify the file using (new to version 1.3):
\cmddef{TrackLangProvidesResource}
where \meta{tag} is the locale identifier.

If \gls{ProvidesFile} is defined (through the \LaTeX\ kernel) this is
used, otherwise a simplified generic alternative is used that's 
suitable for other \TeX\ formats.

The resource file can load another resource file 
\localemetametafile{pkgname}{tag}, 
using (new to version 1.3):
\cmddef{TrackLangRequireResource}
For example, the dialect file \ldf{foo}{en-GB} might need to
load the root language resource file \ldf{foo}{english}:
\begin{codebox}
\comment{(In file \ldf{foo}{en-GB})}
\comment{Declare this regional file:}
\gls{TrackLangProvidesResource}\marg{en-GB}
\comment{load root language file \ldf{foo}{english}:}
\gls{TrackLangRequireResource}\marg{english}
\end{codebox}
If \ldf{foo}{english} is also identified with
\gls{TrackLangProvidesResource}, this will ensure that it's only
loaded once.

It may be that you want to load a file depending on the input
encoding. The \sty{inputenc} package defines
\gls{inputencodingname}, but this is only used with \pdfLaTeX. To
avoid repeated tests to determine whether or not \gls{inputencodingname}
has been defined, you can use:
\cmddef{TrackLangEncodingName}
This will expand to \code{utf8} if \gls{inputencodingname} hasn't
been defined, otherwise it will expand to \gls{inputencodingname}.
For example:
\begin{codebox}
\gls{InputIfFileExists}\marg{foo-\gls{TrackLangEncodingName}.ldf}
\marg{\comment{support available for the document encoding}
}
\marg{\comment{no support for the document encoding}
}
\end{codebox}

If you require the resource file and want to perform
\meta{code1} if it's loaded at this point or \meta{code2} if it's
already been loaded then you can use:
\cmddef{TrackLangRequireResourceOrDo}

If you want to load a resource file if it exists (without an
error if it doesn't exist), then you can use
\cmddef{TrackLangRequestResource}
If the file doesn't exist, \meta{not found code} is done.

\begin{important}
Note that these \cmd{\ldots Resource\ldots} commands are only
permitted within the resource files. They are internally enabled
through \gls{TrackLangRequireDialect}.
\end{important}

The above restriction on the resource files loaded through
\gls{TrackLangRequireDialect}, and the fact that it internally uses
\gls{IfTrackedLanguageFileExists}, means that commands like
\gls{CurrentTrackedLanguage} or \gls{CurrentTrackedDialect} may be
used in those files. This means that the name of the captions hook
can be obtained through them. (Remember that the file
\ldf{foo}{en-GB} might have been loaded with, say, the
\opt{british} dialect or with the synonymous \opt{UKenglish}
dialect or with a dialect label that doesn't have a corresponding
caption hook, such as \optfmt{enGBLatn}.)

The \sty{polyglossia} package has language caption hooks in the form 
\tklcaptions{\meta{language}} (where \meta{language} is the root language
label) whereas \sty{babel} has dialect captions hooks
in the form \gls{captionsdialect} (where \meta{dialect} is the
dialect label). This leads to a rather
cumbersome set of conditionals:
\begin{compactcodebox}
\cmd{ifcsundef}\marg{captions\gls{CurrentTrackedLanguage}}
\marg{\comment{}
  \cmd{ifcsundef}\marg{captions\gls{CurrentTrackedDialect}}\comment{}
  \marg{}\comment{}
  \marg{\comment{}
    \cmd{csgappto}\marg{captions\gls{CurrentTrackedDialect}}\marg{\comment{}
      \comment{code to append to hook}
    }\comment{}
  }\comment{}
}\comment{}
\marg{\comment{}
  \cmd{csgappto}\marg{captions\gls{CurrentTrackedLanguage}}\marg{\comment{}
    \comment{code to append to hook}
  }\comment{}
}
\comment{do code now to initialise}
\end{compactcodebox}
Note that the above has been simplified through the use of
\sty{etoolbox} commands, which isn't suitable for generic use.
It also doesn't query the mapping from \sty{tracklang}['s] dialect
label to the closest matching \sty{babel} dialect label.

Instead, \sty{tracklang} provides a command
to perform this set of conditionals using generic code:
\cmddef{TrackLangAddToHook}
where \meta{code} is the code to append to the \meta{type} hook.
This always performs \meta{code} after testing for the hook in case
the hook is undefined or has already been called (for example, \sty{ngerman} uses
\tklcaptions{ngerman} when the package is loaded, not at the start of
the document).

Note that this command is enabled through
\gls{TrackLangRequireDialect} so should only be used inside resource
files.

Since \optfmt{captions} is a commonly used hook type, there's 
a~shortcut command provided:
\cmddef{TrackLangAddToCaptions}
This is equivalent to
\begin{compactcodebox}
\gls{TrackLangAddToHook}\margm{code}\marg{captions}
\end{compactcodebox}

There may be some hooks, such as \gls{datedialect}, that need
redefining rather than appending to, so there's an
analogous command:
\cmddef{TrackLangRedefHook}
which will redefined the hook to do \meta{code}.

Note that no expansion is performed on \meta{code} when appending or
redefining a hook.

\section{Examples}
\label{sec:examples}

The examples in this section illustrate the above commands.

\subsection{\filefmt{animals.sty}}
\label{sec:animals}

This example is for a trivial package called \file{animals.sty}
that defines three textual commands: \cmd{catname}, \cmd{dogname}
and \cmd{ladybirdname}. The default values are: \qt{cat}, \qt{dog} and
\qt{bishy-barney-bee}.\footnote{Thass Broad Norfolk, my bewties
\code{:-P}}
The supported languages are defined in files
\localefile{animals}.

Here's the code for \file{animals.sty}:
\begin{codebox}
\comment{Example package animals.sty}
\cmd{NeedsTeXFormat}\marg{LaTeX2e}
\cmd{ProvidesPackage}\marg{animals}
\codepar
\cmd{RequirePackage}\marg{tracklang}[2019/11/30]\comment{v1.4}
\codepar
\comment{Any undeclared options are language settings:}
\codepar
\cmd{DeclareOption}*\marg{\comment{}
 \gls{TrackIfKnownLanguage}\marg{\cmd{CurrentOption}}\comment{}
 \marg{\comment{successful}
  \cmd{PackageInfo}\marg{animals}\marg{Tracking language `\cmd{CurrentOption}'}\comment{}
 }\comment{}
 \marg{\comment{failed}
   \cmd{PackageError}\marg{animals}\comment{}
   \marg{Unknown language specification `\cmd{CurrentOption}'}\comment{}
   \marg{You need to supply either a known dialect label 
    or a valid language tag}\comment{}
 }\comment{}
}
\codepar
\cmd{ProcessOptions}
\codepar
\comment{Default definitions}
\cmd{newcommand}\cmd{catname}\marg{cat}
\cmd{newcommand}\cmd{dogname}\marg{dog}
\cmd{newcommand}\cmd{ladybirdname}\marg{bishy-barney-bee}
\codepar
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedDialect}\marg{\cmd{this@dialect}}\marg{\comment{}
    \gls{TrackLangRequireDialect}\marg{animals}\marg{\cmd{this@dialect}}\comment{}
  }\comment{}
}
\marg{\comment{no tracked languages, default already set up}
}
\codepar
\cmd{endinput}
\end{codebox}
Here's a Plain \TeX\ version that picks up the language from the
locale environment variable:
\begin{codebox}
\gls{input} tracklang
\codepar
\gls{TrackLangFromEnv}
\codepar
\comment{Default definitions}
\cmd{def}\cmd{catname}\marg{cat}
\cmd{def}\cmd{dogname}\marg{dog}
\cmd{def}\cmd{ladybirdname}\marg{bishy-barney-bee}
\codepar
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedDialect}\marg{\cmd{thisdialect}}\marg{\comment{}
    \gls{TrackLangRequireDialect}\marg{animals}\marg{\cmd{thisdialect}}\comment{}
  }\comment{}
}
\marg{\comment{no tracked languages, default already set up}
}
\end{codebox}
In the event that a user or supplementary package for some 
reason wants to load a resource
file for a language that hasn't been tracked, it might be worth
providing a command for this purpose:
\begin{codebox}
\cmd{newcommand}*\marg{\cmd{RequireAnimalsDialect}}[1]\marg{\comment{}
  \gls{TrackLangRequireDialect}\marg{animals}\marg{\#1}\comment{}
}
\end{codebox}
The loop can then be changed to:
\begin{codebox}
\gls{ForEachTrackedDialect}\marg{\cmd{this@dialect}}\marg{\comment{}
  \cmd{RequireAnimalsDialect}\cmd{this@dialect}
}\comment{}
\end{codebox}

The \ldf{animals}{english} file valid for both the Plain \TeX\
and \LaTeX\ formats contains:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{english}
\codepar
\cmd{def}\cmd{englishanimals}\marg{\comment{}
  \cmd{def}\cmd{catname}\marg{cat}\comment{}
  \cmd{def}\cmd{dogname}\marg{dog}\comment{}
  \cmd{def}\cmd{ladybirdname}\marg{bishy-barney-bee}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{englishanimals}}
\end{codebox}
The \ldf{animals}{en-GB} file contains:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{en-GB}
\gls{TrackLangRequireResource}\marg{english}
\codepar
\cmd{def}\cmd{enGBanimals}\marg{\comment{}
  \cmd{englishanimals}
  \cmd{def}\cmd{ladybirdname}\marg{ladybird}\comment{}
}
\gls{TrackLangAddToCaptions}\marg{\cmd{enGBanimals}}
\end{codebox}
The \ldf{animals}{en-US} file contains:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{en-US}
\gls{TrackLangRequireResource}\marg{english}
\codepar
\cmd{def}\cmd{enUSanimals}\marg{\comment{}
  \cmd{englishanimals}
  \cmd{def}\cmd{ladybirdname}\marg{ladybug}\comment{}
}
\gls{TrackLangAddToCaptions}\marg{\cmd{enUSanimals}}
\end{codebox}
Here's a German version in the file \ldf{animals}{german}:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{german}
\codepar
\cmd{def}\cmd{germananimals}\marg{\comment{}
  \cmd{def}\cmd{catname}\marg{Katze}\comment{}
  \cmd{def}\cmd{dogname}\marg{Hund}\comment{}
  \cmd{def}\cmd{ladybirdname}\marg{Marienk\cmd{"}afer}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{germananimals}}
\end{codebox}

This means that if \sty{babel} or \sty{polyglossia} are loaded, the
redefinitions are automatically performed whenever the language is
changed, but if there's no caption mechanism the user can switch
the fixed names using the \cmd{\ldots animals} commands.

Here's an example \LaTeX\ document that doesn't have any caption
hooks:
\begin{codebox}
\cmd{documentclass}[\opt{english},\opt{german}]\marg{article}
\codepar
\cmd{usepackage}\marg{animals}
\codepar
\cbeg{document}
\cmd{englishanimals}
\codepar
\cmd{catname}.
\cmd{dogname}.
\cmd{ladybirdname}.
\codepar
\cmd{germananimals}
\codepar
\cmd{catname}.
\cmd{dogname}.
\cmd{ladybirdname}.
\cend{document}
\end{codebox}
Here's a \sty{babel} example document:
\begin{codebox}
\cmd{documentclass}[\opt{american},\opt{german},\opt{british}]\marg{article}
\codepar
\cmd{usepackage}\marg{babel}
\cmd{usepackage}\marg{animals}
\codepar
\cbeg{document}
\cmd{selectlanguage}\marg{american}
\codepar
\cmd{catname}.
\cmd{dogname}.
\cmd{ladybirdname}.
\codepar
\cmd{selectlanguage}\marg{german}
\codepar
\cmd{catname}.
\cmd{dogname}.
\cmd{ladybirdname}.
\codepar
\cmd{selectlanguage}\marg{british}
\codepar
\cmd{catname}.
\cmd{dogname}.
\cmd{ladybirdname}.
\cend{document}
\end{codebox}

There is some redundancy with the above resource files. Consider the
\sty{babel} example above. The \opt{american} dialect is the
first option, so in that case \ldf{animals}{en-US} is loaded
followed by \ldf{animals}{english}. This means that the
\tklcaptions{american} hook now includes
\begin{codebox}
\cmd{englishanimals}
\cmd{enUSanimals}
\end{codebox}
Since \cmd{enUSanimals} includes \cmd{englishanimals}, there is
redundant code. However, when the \opt{british} dialect is
processed, this loads the file \ldf{animals}{en-GB} but not
the file \ldf{animals}{english} (since it's already been loaded). This
means that \tklcaptions{british} contains \cmd{enGBanimals} but not 
\cmd{englishanimals}.

If this redundancy is an issue (for example, there are so many
redefinitions needed that it significantly slows the document build
process), then it can be addressed with the following modifications.
The \ldf{animals}{en-GB} file is now:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{en-GB}
\codepar
\cmd{def}\cmd{enGBanimals}\marg{\comment{}
  \cmd{englishanimals}
  \cmd{def}\cmd{ladybirdname}\marg{ladybird}\comment{}
}
\codepar
\gls{TrackLangRequireResourceOrDo}\marg{english}\comment{}
\marg{
  \gls{TrackLangAddToCaptions}\marg{\comment{}
    \cmd{def}\cmd{ladybirdname}\marg{ladybird}\comment{}
  }\comment{}
}
\marg{
  \gls{TrackLangAddToCaptions}\marg{\cmd{enGBanimals}}
}
\end{codebox}
The \ldf{animals}{en-US} file is now:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{en-US}
\codepar
\cmd{providecommand}*\marg{\cmd{enUSanimals}}\marg{\comment{}
  \cmd{englishanimals}
  \cmd{renewcommand}*\marg{\cmd{ladybirdname}}\marg{ladybug}\comment{}
}
\codepar
\gls{TrackLangRequireResourceOrDo}\marg{english}
\marg{
  \gls{TrackLangAddToCaptions}\marg{\comment{}
    \cmd{renewcommand}*\marg{\cmd{ladybirdname}}\marg{ladybird}\comment{}
  }\comment{}
}
\marg{
  \gls{TrackLangAddToCaptions}\marg{\cmd{enUSanimals}}
}
\end{codebox}
This means that the document that has the dialects listed in the
order \opt{american}, \opt{british} now has
\begin{codebox}
\cmd{englishanimals}
\cmd{def}\cmd{ladybirdname}\marg{ladybird}
\end{codebox}
in the \tklcaptions{british} hook and just \cmd{enUSanimals} in the
\tklcaptions{american} hook, which has removed most of the redundancy.

Note that \sty{polyglossia} has a \tklcaptions{english} hook but not
\tklcaptions{american} or \tklcaptions{british}, so this code doesn't
allow for switching between variants of the same language with
\sty{polyglossia}.

\subsection{\filefmt{regions.sty}}
\label{sec:regions}

\glsadd{file.regions.sty}%
\phyperref{Earlier}{pg.britishfilesearch}, I~mentioned the search order for
\gls{IfTrackedLanguageFileExists} where if, for example, the dialect
is \opt{british}, the file search (v1.4+) will be:
\begin{enumerate}
\item \ldf{mypackage}{en-GB} (language tag)
\item \ldf{mypackage}{british} (dialect label)

\item \ldf{mypackage}{en-Latn-GB} (\idx{639-1} language code,
\idx{script}, \idx{region})
\item \ldf{mypackage}{en-GB} (\idx{639-1} language code,
\idx{region})
\item \ldf{mypackage}{en-Latn} (\idx{639-1} language code,
\idx{script})
\item \ldf{mypackage}{en} (\idx{639-1} language code)

\item \ldf{mypackage}{eng-Latn-GB} (\idx{639-2} language
code, \idx{script}, \idx{region})
\item \ldf{mypackage}{eng-GB} (\idx{639-2} language code,
\idx{region})
\item \ldf{mypackage}{eng-Latn} (\idx{639-2} language code,
\idx{script})
\item \ldf{mypackage}{eng} (\idx{639-2} language code)

\item \ldf{mypackage}{GB} (\idx{region})
\item \ldf{mypackage}{english} (language label)
\end{enumerate}
You may have wondered why
\ldf{mypackage}{GB} is included in the search given that some
countries have multiple official languages, which means that the country code on its
own may not indicate the language.

The reason for including just the country code as the \meta{localeid} in the 
file search is to allow for region rather than language dependent
settings. For example, suppose I~want to write a package that needs
to know whether to use imperial or metric measurements in the
document, but I also want to provide multilingual support. The
language alone won't tell me whether to use imperial or metric (for
example, the US uses imperial and the UK uses metric for most
product attributes). I could provide \ext+{ldf} files for every
language and region combination, but this would result in a lot
redundancy.

\gls{TrackLangRequireDialect} has an optional argument for adjusting
the way the resource files are loaded. Suppose I have
\localefile{regions} resource files, then
\begin{codebox}
\gls{TrackLangRequireDialect}\marg{regions}\marg{\cmd{this@dialect}}
\end{codebox}
loads the resource file for the dialect given by \cmd{this@dialect}
using:
\begin{compactcodebox}
\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}
\end{compactcodebox}
I can use the optional argument to also load the resource file for the
root language as well:
\begin{codebox}%
\comment{custom file loader for regions.sty}
\cmd{newcommand}*\marg{\cmd{RequireRegionsDialect}}[1]\marg{\comment{}
 \gls{TrackLangRequireDialect}
   \oarg{\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}\comment{}
    \gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedLanguage}}\comment{}
   }\comment{}
   \marg{regions}\marg{\#1}\comment{}
}
\end{codebox}
Now the dialect \opt{british} can load both
\ldf{regions}{GB} and \ldf{regions}{english}.

The example package (\file{regions.sty}) below illustrates this.
\begin{codebox}
\comment{Example package regions.sty}
\cmd{NeedsTeXFormat}\marg{LaTeX2e}
\cmd{ProvidesPackage}\marg{regions}
\codepar
\gls{RequirePackage}\marg{tracklang}[2016/10/07]\comment{v1.3+}
\codepar
\cmd{DeclareOption}*\marg{\gls{TrackLanguageTag}\marg{\cmd{CurrentOption}}}
\cmd{ProcessOptions}
\codepar
\cmd{newcommand}*\marg{\cmd{weightunit}}\marg{kg}
\cmd{newcommand}*\marg{\cmd{lengthunit}}\marg{mm}
\cmd{newcommand}*\marg{\cmd{currencyunit}}\marg{EUR}
\codepar
\cmd{newcommand}*\marg{\cmd{unitname}}\marg{units}
\codepar
\cmd{newcommand}*\marg{\cmd{RequireRegionsDialect}}[1]\marg{\comment{}
 \gls{TrackLangRequireDialect}
  \oarg{\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}\comment{}
   \gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedLanguage}}\comment{}
  }\comment{}
  \marg{regions}\marg{\#1}\comment{}
}
\codepar
\gls{AnyTrackedLanguages}
\marg{\comment{}
 \gls{ForEachTrackedDialect}\marg{\cmd{this@dialect}}\marg{\comment{}
   \cmd{RequireRegionsDialect}\cmd{this@dialect}
 }\comment{}
}
\marg{\comment{no tracked languages, default already set up}
}
\codepar
\cmd{endinput}
\end{codebox}
There are separate \ext{ldf} files for region and language.
First are the regions.

\begin{itemize}
\item \ldf{regions}{BE} (Belgium):
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{BE}
\codepar
\cmd{providecommand}*\marg{\cmd{BEunits}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{weightunit}}\marg{kg}\comment{}
  \cmd{renewcommand}*\marg{\cmd{lengthunit}}\marg{mm}\comment{}
  \cmd{renewcommand}*\marg{\cmd{currencyunit}}\marg{EUR}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{BEunits}}
\end{codebox}

\item \ldf{regions}{CA} (Canada):
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{CA}
\codepar
\cmd{providecommand}*\marg{\cmd{CAunits}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{weightunit}}\marg{kg}\comment{}
  \cmd{renewcommand}*\marg{\cmd{lengthunit}}\marg{mm}\comment{}
  \cmd{renewcommand}*\marg{\cmd{currencyunit}}\marg{CAD}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{CAunits}}
\end{codebox}

\item \ldf{regions}{GB} (Great Britain):
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{GB}
\codepar
\cmd{providecommand}*\marg{\cmd{GBunits}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{weightunit}}\marg{kg}\comment{}
  \cmd{renewcommand}*\marg{\cmd{lengthunit}}\marg{mm}\comment{}
  \cmd{renewcommand}*\marg{\cmd{currencyunit}}\marg{GBP}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{GBunits}}
\end{codebox}

\item \ldf{regions}{US} (USA):
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{US}
\codepar
\cmd{providecommand}*\marg{\cmd{USunits}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{weightunit}}\marg{lb}\comment{}
  \cmd{renewcommand}*\marg{\cmd{lengthunit}}\marg{in}\comment{}
  \cmd{renewcommand}*\marg{\cmd{currencyunit}}\marg{USD}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{USunits}}
\end{codebox}
\end{itemize}
Now the language files:

\begin{itemize}
\item \ldf{regions}{dutch}:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{dutch}
\codepar
\cmd{providecommand}*\marg{\cmd{dutchnames}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{unitname}}\marg{meeteenheden}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{dutchnames}}
\end{codebox}

\item \ldf{regions}{english}:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{english}
\codepar
\cmd{providecommand}*\marg{\cmd{englishnames}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{unitname}}\marg{units}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{englishnames}}
\end{codebox}

\item \ldf{regions}{french}:
\begin{codebox}
\cmd{TrackLangProvidesResource}\marg{french}
\codepar
\cmd{providecommand}*\marg{\cmd{frenchnames}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{unitname}}\marg{unit\cmd{'}es}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{frenchnames}}
\end{codebox}

\item \ldf{regions}{german}:
\begin{codebox}
\gls{TrackLangProvidesResource}\marg{french}
\codepar
\cmd{providecommand}*\marg{\cmd{germannames}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{unitname}}\marg{Ma\cmd{ss} einheiten}\comment{}
}
\codepar
\gls{TrackLangAddToCaptions}\marg{\cmd{germannames}}
\end{codebox}
\end{itemize}

Here's an example document that uses this package:
\begin{codebox}
\cmd{documentclass}[\opt{canadien}]\marg{article}
\codepar
\cmd{usepackage}\marg{regions}
\codepar
\cbeg{document}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\cend{document}
\end{codebox}

This works because the \meta{localeid} search looks for the
country code before the root language label. However, this will fail if 
the dialect label is the same as a root language label that has an
associated territory, marked with \fnregion\ in
\tableref{tab:rootlangopts}, as then it will be picked up before the
country code.

In the above example, 
\ldf{regions}{CA} is matched rather than
\ldf{regions}{french}, so \ldf{regions}{CA} is loaded by
\begin{compactcodebox}
\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}
\end{compactcodebox}
After this, the language file \ldf{regions}{french} is then loaded:
\begin{compactcodebox}
\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedLanguage}}
\end{compactcodebox}

This assumes that there's a country code \ext{ldf} file
available. This example needs a little modification to use default
units in case the region is missing:
\begin{codebox}
\comment{Modified example package regions.sty}
\cmd{NeedsTeXFormat}\marg{LaTeX2e}
\cmd{ProvidesPackage}\marg{regions}
\codepar
\comment{Pass all options to \file{tracklang.sty}:}
\cmd{DeclareOption}*\marg{\cmd{PassOptionsToPackage}\marg{\cmd{CurrentOption}}\marg{tracklang}}
\cmd{ProcessOptions}
\codepar
\gls{RequirePackage}\marg{tracklang}
\codepar
\cmd{newcommand}*\marg{\cmd{weightunit}}\marg{kg}
\cmd{newcommand}*\marg{\cmd{lengthunit}}\marg{mm}
\cmd{newcommand}*\marg{\cmd{currencyunit}}\marg{EUR}
\codepar
\cmd{newcommand}*\marg{\cmd{unitname}}\marg{units}
\codepar
\cmd{newcommand}*\marg{\cmd{defaultunits}}\marg{\comment{}
  \cmd{renewcommand}*\marg{\cmd{weightunit}}\marg{kg}\comment{}
  \cmd{renewcommand}*\marg{\cmd{lengthunit}}\marg{mm}\comment{}
  \cmd{renewcommand}*\marg{\cmd{currencyunit}}\marg{EUR}\comment{}
}
\codepar
\cmd{newcommand}*\marg{\cmd{RequireRegionsDialect}}[1]\marg{\comment{}
  \gls{TrackLangRequireDialect}
   \oarg{\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}\comment{}
     \cmd{ifx}\gls{CurrentTrackedTag}\gls{CurrentTrackedLanguage}
       \gls{TrackLangAddToCaptions}\marg{\cmd{defaultunits}}\comment{}
     \cmd{else}
       \gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedLanguage}}\comment{}
     \cmd{fi}
   }\comment{}
   \marg{regions}\marg{\#1}\comment{}
}
\codepar
\gls{AnyTrackedLanguages}
\marg{\comment{}
  \gls{ForEachTrackedDialect}\marg{\cmd{this@dialect}}{\comment{}
    \cmd{RequireRegionsDialect}\cmd{this@dialect}
  }\comment{}
}
\marg{\comment{no tracked languages, default already set up}
}
\codepar
\cmd{endinput}
\end{codebox} 
Note that we still have a problem for dialect labels that are
identical to root language labels with an associated territory (such
as \opt{manx}). This case can be checked with the following
adjustment:
\begin{codebox}
\cmd{newcommand}*\marg{\cmd{RequireRegionsDialect}}[1]\marg{\comment{}
  \gls{TrackLangRequireDialect}
  \oarg{\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}\comment{}
   \cmd{ifx}\gls{CurrentTrackedTag}\gls{CurrentTrackedLanguage}
     \cmd{ifx}\gls{CurrentTrackedRegion}\cmd{empty}
       \gls{TrackLangAddToCaptions}\marg{\cmd{defaultunits}}\comment{}
     \cmd{else}
       \gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedRegion}}\comment{}
     \cmd{fi}
   \cmd{else}
     \gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedLanguage}}\comment{}
   \cmd{fi}
  }\comment{}
  \marg{regions}\marg{\#1}\comment{}
}
\end{codebox}
In the case where both the dialect and root language label are
\opt{manx} with the resource files \ldf{regions}{manx}
and \ldf{regions}{IM}, then \gls{CurrentTrackedTag} will be
\opt{manx} (the dialect label) so \ldf{regions}{manx} will
be loaded with:
\begin{compactcodebox}
\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedTag}}
\end{compactcodebox}
In this case \gls{CurrentTrackedRegion} is \code{IM} (that is, it's
not empty) so then \ldf{regions}{IM} will be loaded with:
\begin{compactcodebox}
\gls{TrackLangRequireResource}\marg{\gls{CurrentTrackedRegion}}
\end{compactcodebox}

Here's another document that sets up dialects with
\sty{tracklang} labels that aren't recognised by \sty{babel}.
This means that there's no corresponding \gls{captionsdialect} hook
for either the dialect label or the root language label,
so mappings need to be defined from the \sty{tracklang} dialect
label to the matching \sty{babel} dialect label.

\begin{codebox}
\cmd{documentclass}\marg{article}
\codepar
\cmd{usepackage}\marg{tracklang}
\codepar
\gls{TrackLanguageTag}\marg{de-US-1996}
\gls{SetTrackedDialectLabelMap}\marg{\gls{TrackLangLastTrackedDialect}}\marg{ngerman}
\codepar
\gls{TrackLanguageTag}\marg{en-MT}
\gls{SetTrackedDialectLabelMap}\marg{\gls{TrackLangLastTrackedDialect}}\marg{UKenglish}
\codepar
\cmd{usepackage}[main=ngerman,UKenglish]\marg{babel}
\cmd{usepackage}\marg{regions}
\codepar
\cbeg{document}
\gls{selectlanguage}\marg{ngerman}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\gls{selectlanguage}\marg{UKenglish}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\cend{document}
\end{codebox}
This produces:
\begin{resultbox}
Ma\ss einheiten: lb, in, USD.

units: kg, mm, EUR.
\end{resultbox}
Compare this with:
\begin{codebox}
\cmd{documentclass}\marg{article}
\codepar
\cmd{usepackage}[main=ngerman,UKenglish]\marg{babel}
\cmd{usepackage}\marg{regions}
\codepar
\cbeg{document}
\gls{selectlanguage}\marg{ngerman}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\gls{selectlanguage}\marg{UKenglish}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\cend{document}
\end{codebox}
which produces:
\begin{resultbox}
Ma\ss einheiten: kg, mm, EUR.

units: kg, mm, GBP.
\end{resultbox}

Note that these mappings aren't needed if \sty{babel}
is loaded with the root language labels instead. For example:
\begin{codebox}
\cmd{documentclass}\marg{article}
\codepar
\cmd{usepackage}\marg{tracklang}
\codepar
\gls{TrackLanguageTag}\marg{de-US-1996}
\gls{SetTrackedDialectLabelMap}\marg{\gls{TrackLangLastTrackedDialect}}\marg{ngerman}
\codepar
\gls{TrackLanguageTag}\marg{en-MT}
\codepar
\cmd{usepackage}[main=ngerman,english]\marg{babel}
\cmd{usepackage}\marg{regions}
\codepar
\cbeg{document}
\gls{selectlanguage}\marg{ngerman}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\gls{selectlanguage}\marg{english}
\codepar
\cmd{unitname}: \cmd{weightunit}, \cmd{lengthunit}, \cmd{currencyunit}.
\codepar
\cend{document}
\end{codebox}
No mapping is required for the \opt{en-MT} locale as
it can pick up \tklcaptions{english} when \gls{TrackLangAddToHook}
(used by \gls{TrackLangAddToCaptions})
queries the root language label after failing to find the
language hook from the dialect label.

Some of the predefined \sty{tracklang} dialects come with
a mapping to the closest matching \sty{babel} dialect label.
For example, the option \opt{ngermanDE} listed in
\tableref{tab:nonisoopts} automatically provides a mapping
to \opt{ngerman}. Since a \sty{tracklang} dialect label 
can only map to one \sty{babel} label, this can be problematic
for synonymous labels such as
\opt{british}\slash\opt{UKenglish} or
\opt{american}\slash\opt{USenglish}. The default mappings used
by \sty{tracklang} are shown in \tableref{tab:nonisoopts}.

\chapter{Adding Support for Language Tracking}
\label{sec:langsty}

If you are writing a package that \emph{sets up} the document languages (rather
than a package that provides multilingual support if the user has
already loaded a language package) then you can load \sty{tracklang}
and use the commands below to help other packages track your
provided languages. (See also:
\dickimawhref{latex/tracklang/langpkg.shtml}{Integrating
\filefmt{tracklang.tex} into Language Packages}.)

The \sty{tracklang} package can be loaded using
\begin{codebox}
\gls{input} tracklang
\end{codebox}
or (\LaTeX\ only)
\begin{codebox}
\gls{RequirePackage}\marg{tracklang}
\end{codebox}

When using \LaTeX, there's a difference between the two.
The first case prevents \sty{tracklang} from picking up
the document class options but skips the check for known
language packages. This check is redundant since your package is
the language package, so you need to decide whether or
not to allow the user to set up the localisation information
through the document class options.

There's a hook that, if defined, is performed by
\file{tracklang.sty} after the package options have been loaded but
before known language packages are checked:
\cmddef{@tracklang@prelangpkgcheck@hook}

If you prefer \gls{RequirePackage} over \gls{input} but you want to make 
\file{tracklang.sty} skip the check for known
language packages then (as from v1.3.8) define the pre-language
package check hook as follows:
\begin{codebox}
\cmd{providecommand}\gls{@tracklang@prelangpkgcheck@hook}\marg{\cmd{endinput}}
\gls{RequirePackage}\marg{tracklang}[2019/10/06]\comment{v1.3.8+}
\end{codebox}
This will still pick up languages supplied through the
document class options.

If you just use \gls{input}, there's a test at the start of
\file{tracklang.tex} to determine if it's already been loaded, so
you don't need to worry if the document has already input it.

To integrate \sty{tracklang} into your language package, you need 
to consider the following steps:
\begin{enumerate}
\item Does \sty{tracklang} define your supported \idxn{15924} language
scripts in the \file{tracklang-scripts.tex} file?

If yes, then skip this step. Otherwise create a file with the
relevant \gls{TrackLangScriptMap} command for each unknown script and identify
this new file with \gls{TrackLangAddExtraScriptFile} (see
\sectionref{sec:newscripts}). This usually
won't be necessary unless you have a custom script or a child script
(a script that's a sub-category of another script).

\item Does \sty{tracklang} recognise the root language?

If yes, then skip this step.

If your package is setting up a language that \sty{tracklang}
doesn't recognise then you will need to define the root language
using \gls{TrackLangNewLanguage} (see \sectionref{sec:newlanguages}).

This usually won't be the case as \sty{tracklang} should support all
languages that have an official \idxn{639-1} alpha-2 code.

If you simply have a different label from \sty{tracklang}
identifying the root language, then you can just set up your label
as a dialect using \gls{TrackLangProvidePredefinedDialect}.

\item Does \sty{tracklang} define the relevant \idxn{3166-1} region codes
in the \file{tracklang-region-codes.tex} file?

If yes, then skip this step. Otherwise create a file with the
relevant \gls{TrackLangRegionMap} command for each new region and
identify this new file with \gls{TrackLangAddExtraRegionFile} (see
\sectionref{sec:newregions}). This usually won't be necessary as
\sty{tracklang} should recognise all countries that have an alpha-2
region code, but you may require it if you need a broader region,
such as EU.

\item Do you want to define some convenient dialect labels that can
be used with \gls{TrackPredefinedDialect}?

If no, then skip this step. Otherwise you can use
\gls{TrackLangProvidePredefinedLanguage} for root languages
and \gls{TrackLangProvidePredefinedDialect} for dialects with
additional information, such as a region, sub-language or script
(see \sectionref{sec:definelabels}).

\item In your language initialisation code, add the \sty{tracklang}
code to track the particular dialect (for example, use
\gls{TrackPredefinedDialect} for recognised dialect labels or
use the \csmetafmt{AddTracked}{Xxx}{} set of commands). See
\sectionref{sec:initnewlang}.

\item In your language selection code (such as \gls{selectlanguage}), add
\gls{SetCurrentTrackedDialect}\margm{label} to allow the document
author to easily query the current localisation settings (such as
the region). See \sectionref{sec:selectlanguage}.
\end{enumerate}

\section{Initialising a New Language or Dialect}
\label{sec:initnewlang}

When the user requests a particular dialect through your language
package, you can notify \sty{tracklang} of this choice using
\begin{compactcodebox*}
\gls{TrackPredefinedDialect}\margm{dialect label}
\end{compactcodebox*}
provided the dialect label is recognised by \sty{tracklang} (all those
listed in \refoptstables).

If there's no matching dialect predefined by \sty{tracklang}, you
can just use \gls{TrackLocale} or \gls{TrackLanguageTag} 
(described in \sectionref{sec:generic}) 
with the appropriate \idx{ISO} codes \emph{if you're not providing caption
hooks}.

If you are providing a captions hook mechanism
in the form \gls{captionsdialect}, then if \meta{dialect}
doesn't match the corresponding \sty{tracklang} dialect label,
you can provide a mapping using
\gls{SetTrackedDialectLabelMap}, described below.

\section{Switching Language or Dialect}
\label{sec:selectlanguage}

When the document author switches to a different language or
dialect, the current localisation information can be set with:
\cmddef{SetCurrentTrackedDialect}
where \meta{dialect} may the \sty{tracklang} dialect label,
or the mapped label previously set through \gls{SetTrackedDialectLabelMap},
described below, or the language label (in which case the
last dialect to be tracked with that root language will
be assumed).

This will make the following commands available which may be
of use to other packages:
\begin{itemize}
\item\gls{CurrentTrackedDialect} The dialect label recognised
by \sty{tracklang} (which may not be the same as \meta{dialect}).

\item\gls{CurrentTrackedLanguage}
The root language label used by \sty{tracklang}.

\item\gls{CurrentTrackedDialectModifier} The dialect modifier.

\item\gls{CurrentTrackedDialectVariant} The dialect variant.

\item\gls{CurrentTrackedDialectScript} The dialect script.
Note that if \sty{tracklang-scripts} is also loaded, this allows the
script direction to be accessed using
\begin{codebox}
\gls{TrackLangScriptAlphaToDir}\marg{\gls{CurrentTrackedDialectScript}}
\end{codebox}
See \sectionref{sec:supplpkgs} for further details.

\item\gls{CurrentTrackedDialectSubLang} The dialect sub-language
code.

\item\gls{GetTrackedDialectAdditional} The dialect's additional
information.

\item\gls{CurrentTrackedIsoCode} The dialect's root language 
\idx{ISO} code. (The first found in the sequence \idx{639-1},
\idx{639-2}, \idx{639-3}.)

\item\gls{CurrentTrackedRegion} The dialect's \idxn{3166-1} region 
code.

\item\gls{CurrentTrackedLanguageTag} The dialect's language tag.

\end{itemize}
(Without this automated use of \gls{SetCurrentTrackedDialect},
the same information can be picked up using commands
like \gls{GetTrackedDialectScript}, but that's less convenient,
especially if \gls{languagename} needs to be converted
to \meta{dialect}. See the accompanying sample file
\filefmt{sample-setlang.tex} for an example.)

\section{Defining New Scripts}
\label{sec:newscripts}

The \file{tracklang-scripts.tex} file isn't automatically loaded,
but if it is then, as from v1.4, it contains a hook at the end of
the file that can be used to load additional files that define
supplementary scripts. This entails creating a file called, say,
\filefmt{mypackage-scripts.tex} that contains:
\begin{compactcodebox*}
\gls{TrackLangScriptMap}\margm{alpha code}\margm{numeric code}\margm{name}\margm{direction}\margm{parent script}
\end{compactcodebox*}
The first argument \meta{alpha code} is the four-letter ISO~15924 code (such as
\opt{Latn}), the second argument is the numeric code (such as
215), the third argument \meta{name} is the name of the script (such
as \optfmt{Latin}), the fourth argument is the direction (such as
\optfmt{LR} for left-to-right) and the final argument is the parent
script (leave blank if there's no parent). Note that this command will override any previous
mapping for those codes. No check is performed to determine if they
have already been defined.

The supplementary file should be identified with:
\begin{compactcodebox*}
\gls{TrackLangAddExtraScriptFile}\margm{filename}
\end{compactcodebox*}

Additional information can be found in \sectionref{sec:supplpkgs}.

\section{Defining New Regions}
\label{sec:newregions}

The \file{tracklang-region-codes.tex} file isn't automatically loaded,
but if it is then, as from v1.4, it contains a hook at the end of
the file that can be used to load additional files that define
supplementary regions. This entails creating a file called, say,
\filefmt{mypackage-regions.tex} that contains:
\begin{compactcodebox*}
\gls{TrackLangRegionMap}\margm{numeric code}\margm{alpha-2
code}\margm{alpha-3 code}
\end{compactcodebox*}
where the first argument is the numeric region code (such as 826),
the second argument is the alpha-2 region code (such as \code{GB})
and the third argument is the alpha-3 region code (such as
\code{GBR}). Note that this command will override any previous
mapping for those codes. No check is performed to determine if they
have already been defined.

The supplementary file should be identified with:
\begin{compactcodebox*}
\gls{TrackLangAddExtraRegionFile}\margm{filename}
\end{compactcodebox*}

Additional information can be found in \sectionref{sec:supplpkgs}.

\section{Defining a New Language}
\label{sec:newlanguages}

(New to version 1.3.)
If the root language isn't recognised by \sty{tracklang}
(not listed in \tableref{tab:rootlangopts}), then
it can be defined (but not tracked at this point) using:
\cmddef{TrackLangNewLanguage}
where \meta{language label} is the root language label, 
\meta{639-1 code} is the \idxn{639-1} code for that language (may be
empty if there isn't one), \meta{639-2 (T)} is the \idxn{639-2T}
code for that language (may be empty if there isn't one),
\meta{639-2 (B)} is the \idxn{639-2B} code for that language (may be
empty if it's the same as \meta{639-2 (T)}), \meta{639-3} is the 
\idxn{639-3} code for that language (empty if the same as the 
\idx{639-2} code), \meta{3166-1} is the territory \idxn{3166-1} code for 
languages that are only spoken in one territory (should be empty if
the language is spoken in multiple territories), and \meta{default
script} is the default script (empty if disputed or varies according
to region).

You can then track this language using: 
\cmddef{AddTrackedDialect}
for dialects (where \meta{dialect label} is the dialect label and
\meta{root language label} is the root language label) or, if 
no regional variant is needed, you can instead use:
\cmddef{AddTrackedLanguage}
This is equivalent to 
\begin{compactcodebox}
\gls{AddTrackedDialect}\margm{root language label}\margm{root language label}
\end{compactcodebox}
Note that \gls{AddTrackedDialect} defines:
\cmddef{TrackLangLastTrackedDialect}
to the dialect label, which makes it easier to reference the last
dialect to be tracked.

\section{Defining New \styfmt{tracklang} Labels}
\label{sec:definelabels}

A dialect label may be predefined with associated information that
allows that particular combination to be easily tracked with
\gls{TrackPredefinedDialect}. In the case of a dialect label that
only requires the information provided in \gls{TrackLangNewLanguage}
you can use:
\cmddef{TrackLangProvidePredefinedLanguage}
where \meta{language label} corresponds to the language label used in
\gls{TrackLangNewLanguage}. This allows
\begin{compactcodebox*}
\gls{TrackPredefinedDialect}\margm{label}
\end{compactcodebox*}
to not only track the root language but also the associated ISO codes.

If the dialect label doesn't match the root language label then use:
\cmddef{TrackLangProvidePredefinedDialect}
where \meta{dialect label} is the new \sty{tracklang} dialect label,
\marg{root language label} is the \sty{tracklang} root language label,
\meta{region} is the \idxn{3166-1} region code (may be empty),
\meta{modifier} is the \idx{modifier} (may be empty), \meta{variant}
is the \idx{variant} information (may be empty), \meta{map} is your
package's language label that corresponds to the \sty{tracklang}
dialect label supplied in the first argument (may be empty if
identical), and \meta{script} is the \idxn{15924} alpha-4 script code
(may be empty if it's the same as the default script for the root
language).

For compatibility with pre version 1.3, 
if the dialect isn't predefined by
\sty{tracklang}, then you can use:
\begin{compactcodebox*}
\gls{AddTrackedDialect}\marg{dialect}\marg{root language label}
\end{compactcodebox*}
where \meta{root language label} is the label for the dialect's root
language (\tableref{tab:rootlangopts}) and \meta{dialect} matches
the captions hook. If the dialect is already in the tracked dialect
list, it won't be added again. If the root language is already in
the tracked language list, it won't be added again. As from version
1.3 this additionally defines
\gls{TrackLangLastTrackedDialect}
to \meta{dialect} for convenient reference if required.
Note that \gls{AddTrackedDialect} is internally used by commands like
\gls{TrackPredefinedDialect}, \gls{TrackLocale} and
\gls{TrackLanguageTag}.

(New to version 1.3.) Many of the \sty{tracklang} dialect
labels don't have a corresponding match in various language packages. For 
example, \sty{tracklang} provides \opt{ngermanDE} but the
closest match in \sty{babel} is \opt{ngerman}. This means that
the caption hook \tklcaptions{ngerman} can't be accessed
through:
\begin{compactcodebox}
\cmd{csname} captions\gls{CurrentTrackedDialect}\cmd{endcsname}
\end{compactcodebox}
in the resource files. In this case, a mapping may be defined
between the \sty{tracklang} dialect label and the closest
matching label used by the language hooks. This is done through
\cmddef{SetTrackedDialectLabelMap}
where \meta{tracklang-label} is the \sty{tracklang} label and
\meta{hook-label} is the language hook label. For example:
\begin{compactcodebox*}
\gls{TrackLanguageTag}\marg{de-AR-1996}
\gls{SetTrackedDialectLabelMap}\marg{\gls{TrackLangLastTrackedDialect}}\marg{ngerman}
\end{compactcodebox*}
Since \gls{TrackLanguageTag} internally uses \gls{AddTrackedDialect}
the dialect label created by \sty{tracklang} can be accessed
using \gls{TrackLangLastTrackedDialect}. This means that
\gls{TrackLangAddToCaptions} can now find the \tklcaptions{ngerman}
hook even though the \sty{tracklang} dialect label isn't \opt{ngerman}.

(New to version 1.3.)
If the root language label is recognised by \sty{tracklang}, you
can add the \idx{ISO} codes using:
\cmddef{AddTrackedLanguageIsoCodes}

As from v1.3, you can also provide a modifier for a given
dialect using:
\cmddef{SetTrackedDialectModifier}
where \meta{dialect} is the dialect label and \meta{value}
is the modifier value. For example:
\begin{compactcodebox*}
\gls{AddTrackedDialect}\marg{oldgerman}\marg{\opt{german}}
\gls{AddTrackedLanguageIsoCodes}\marg{german}
\gls{SetTrackedDialectModifier}\marg{oldgerman}\marg{old}
\end{compactcodebox*}

Note that no sanitization is performed on \meta{value} when the
modifier is set explicitly through \gls{SetTrackedDialectModifier},
since it's assumed that any package that specifically sets the
modifier in this way is using a sensible labelling system. If the
modifier is obtained through commands like \gls{TrackLocale}, then
the modifier is sanitized as the value may have been obtained from
the operating system and there's no guarantee that it won't contain
problematic characters.

The \idx{modifier} is typically obtained by parsing locale information in
\idx{POSIX} format.
\begin{compactcodebox*}
\meta{language}[\idx{underscoresep}\meta{territory}][\idx{dotsep}\meta{codeset}][\idx{atmod}\meta{modifier}]
\end{compactcodebox*}
whereas the \idx{variant} is typically obtained by parsing the language
tag.

The information provided in the commands below (such as the script)
are typically obtained by parsing the language tag. For example,
with Serbian in the Latin alphabet the modifier would be \optfmt{latin}
whereas the script would be \opt{Latn}:
\begin{codebox*}
\gls{AddTrackedDialect}\marg{serbianlatin}\marg{\opt{serbian}}
\gls{AddTrackedLanguageIsoCodes}\marg{\opt{serbian}}
\gls{SetTrackedDialectModifier}\marg{serbianlatin}\marg{latin}
\gls{SetTrackedDialectScript}\marg{serbianlatin}\marg{\opt{Latn}}
\end{codebox*}

As from v1.3, you can provide a script (for example,
\opt{Latn} or \opt{Cyrl}) using:
\cmddef{SetTrackedDialectScript}
where \meta{dialect} is the dialect label and \meta{value} is the
\idxn{15924} alpha-4 script identifier. For example:
\begin{codebox*}
\gls{AddTrackedDialect}\marg{serbiancyrl}\marg{\opt{serbian}}
\gls{AddTrackedLanguageIsoCodes}\marg{serbian}
\gls{SetTrackedDialectScript}\marg{serbiancyrl}\marg{\opt{Cyrl}}
\end{codebox*}

As from v1.3, you can provide a variant for a given
dialect using:
\cmddef{SetTrackedDialectVariant}
For example:
\begin{codebox*}
\gls{AddTrackedDialect}\marg{german1901}\marg{german}
\gls{SetTrackedDialectVariant}\marg{german1901}\marg{1901}
\end{codebox*}

As from v1.3, you can also provide a sub-language using:
\cmddef{SetTrackedDialectSubLang}
where \meta{dialect} is the dialect label and \meta{value} is the
code. For example:
\begin{codebox*}
\gls{AddTrackedDialect}\marg{mandarin}\marg{\opt{chinese}}
\gls{AddTrackedLanguageIsoCodes}\marg{\opt{chinese}}
\gls{SetTrackedDialectSubLang}\marg{mandarin}\marg{cmn}
\gls{AddTrackedIsoLanguage}\marg{639-3}\marg{cmn}\marg{mandarin}
\end{codebox*}

As from v1.3, you can also provide additional information using:
\cmddef{SetTrackedDialectAdditional}
where \meta{dialect} is the dialect label and \meta{value} is the
additional information.

\section{Example (\filefmt{alien.sty})}
\label{sec:examplenewlang}

Suppose I want to create a language package \file{alien.sty} that defines the
\optfmt{martian} language with regional dialects
\optfmt{lowermartian} and \optfmt{uppermartian}. First, let's
suppose that \sty{tracklang} recognises the root language
\optfmt{martian}:
\begin{codebox}
\cmd{ProvidesPackage}\marg{alien}
\codepar
\gls{input}{tracklang}\comment{v1.3}
\codepar
\cmd{DeclareOption}\marg{martian}\marg{\comment{}
 \gls{TrackPredefinedDialect}\marg{martian}
}
\cmd{DeclareOption}\marg{lowermartian}\marg{\comment{}
 \gls{AddTrackedDialect}\marg{lowermartian}\marg{martian}
 \gls{AddTrackedLanguageIsoCodes}\marg{martian}
 \gls{AddTrackedIsoLanguage}\marg{3166-1}\marg{YY}\marg{lowermartian}
 \comment{other attributes such as}
 \comment{\gls{SetTrackedDialectVariant}\marg{lowermartian}\marg{...}}
}
\cmd{DeclareOption}\marg{uppermartian}\marg{\comment{}
 \gls{AddTrackedDialect}\marg{uppermartian}\marg{martian}
 \gls{AddTrackedLanguageIsoCodes}\marg{martian}
 \gls{AddTrackedIsoLanguage}\marg{3166-1}\marg{XX}\marg{uppermartian}
 \comment{other attributes such as}
 \comment{\gls{SetTrackedDialectVariant}\marg{uppermartian}\marg{...}}
}
\codepar
\cmd{ProcessOptions}
\codepar
\cmd{newcommand}*\marg{\gls{selectlanguage}}[1]\marg{\comment{}
 \cmd{def}\gls{languagename}\marg{\#1}\comment{}
 \comment{other stuff}
 \gls{SetCurrentTrackedDialect}\marg{\#1}\comment{} 
}
\codepar
\gls{AnyTrackedLanguages}
\marg{
 \gls{ForEachTrackedDialect}\marg{\cmd{thisdialect}}
 \marg{\comment{}
  \gls{TrackLangRequireDialect}\marg{alien}\marg{\cmd{thisdialect}}
 }
}
\end{codebox}
The caption commands and language set up are in the files
\localefile{alien} as in the examples from
\sectionref{sec:examples}. This allows for the user having already
loaded \sty{tracklang} before \sty{alien} and used \gls{TrackLangFromEnv} to pick up
the locale from the operating system's environment variables.
(For example, they may have \envvar{LANG} set to
\code{xx\idx{underscoresep}YY}.)

The resource files may need to set the mapping between the
\sty{tracklang} dialect label and the \sty{alien} dialect
label. For example, in \ldf{alien}{xx-YY}:
\begin{codebox*}
\gls{TrackLangProvidesResource}\marg{xx-YY}
\codepar
\gls{TrackLangRequireResource}\marg{martian}\comment{load common elements}
\codepar
\cmd{newcommand}\marg{\tklcaptions{lowermartian}}\marg{\comment{}
 \tklcaptions{martian}
 \cmd{def}\cmd{contentsname}\marg{X'flurp}\comment{regional variation}
}
\codepar
\gls{SetTrackedDialectLabelMap}\marg{\gls{CurrentTrackedDialect}}\marg{lowermartian}
\end{codebox*}

Now let's consider the case where \sty{tracklang} doesn't know
about the \optfmt{martian} language. In this case the user can't 
track the dialect until the root language has been defined, so the
user can't use \gls{TrackLangFromEnv} before using the \sty{alien}
package.

With \sty{tracklang} v1.3. The new root language can be defined
with a minor adjustment to the above code:
\begin{codebox*}
\cmd{ProvidesPackage}\marg{alien}
\codepar
\gls{input}\marg{tracklang}\comment{needs v1.3}
\codepar
\gls{TrackLangIfKnownLang}\marg{martian}
\marg{}\comment{tracklang already knows about the martian language}
\marg{
 \comment{tracklang doesn't known about the martian language, so define it}
 \comment{with \idxn{639-1} (xx) and \idxn{639-2} (xxx) codes:}
 \gls{TrackLangNewLanguage}\marg{martian}\marg{xx}\marg{xxx}\marg{}\marg{}\marg{}\marg{\opt{Latn}}
}
\end{codebox*}
The rest is as before.

Now other package writers who want to provide support
for the Martian dialects can easily detect which language options
the user requested through my package, \emph{without needing to know
anything about my \sty{alien} package}.

\part{Summaries}
\appendix

\chapter{Region and Script Mappings}
\label{sec:regscriptmappings}

Region mappings are listed in \tableref{tab:regionmappings}, and
script mappings are listed in \tableref{tab:scriptmappings}.

\printunsrttable[type=index,
 title={Region Mappings},other={alpha3},blocks=2,
 block-style={name-other-desc},label={tab:regionmappings},
 init={%
 \renewcommand{\glstableNameTarget}[1]{\inlineglsdef[optdef]{##1}}%
 \renewcommand{\glstableiffilter}[3]{\glsifcategory{##1}{region}{##3}{##2}}%
 \renewcommand{\glstablenameheader}{Alpha-2}%
 \renewcommand{\glstableotherheader}{Alpha-3}%
 \renewcommand{\glstabledescheader}{Numeric}%
 \renewcommand{\glstableDesc}{\numerictag}%
}
]

\printunsrttable[type=index,clearpage,par=ragged,
 title={Script Mappings},other=userii,blocks=1,
 block-style={name-symbol-other-desc},label={tab:scriptmappings},
 init={%
 \renewcommand{\glstableNameTarget}[1]{\inlineglsdef[optdef]{##1}}%
 \renewcommand{\glstableiffilter}[3]{\glsifcategory{##1}{script}{##3}{##2}}%
 \renewcommand{\glstablenameheader}{Alpha-2}%
 \renewcommand{\glstablesymbolheader}{Numeric}%
 \renewcommand{\glstableSymbol}{\numerictag}%
 \renewcommand{\glstableotherheader}{Direction}%
}
]

\backmatter
\printterms
\printsummary

\renewcommand{\fnregion}{}%
\glsdefpostname{isolangregion}{ (option)}%
\glsdefpostname{rootlang}{ (root language)}%
\glsdefpostname{isocode}{ (\idx{ISO} code)}%
\glsdefpostname{noniso}{ (option)}%
\glsdefpostname{region}{ (region)}%
\glsdefpostname{script}{ (script)}%
\glsdefpostname{application}{ (application)}%
\printuserguideindex 

\end{document}