Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52b
     from gettext.texi on 27 November 2006 -->

<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
<TITLE>GNU gettext utilities - 15  Other Programming Languages</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_14.html">previous</A>, <A HREF="gettext_16.html">next</A>, <A HREF="gettext_25.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC229" HREF="gettext_toc.html#TOC229">15  Other Programming Languages</A></H1>

<P>
While the presentation of <CODE>gettext</CODE> focuses mostly on C and
implicitly applies to C++ as well, its scope is far broader than that:
Many programming languages, scripting languages and other textual data
like GUI resources or package descriptions can make use of the gettext
approach.

</P>



<H2><A NAME="SEC230" HREF="gettext_toc.html#TOC230">15.1  The Language Implementor's View</A></H2>
<P>
<A NAME="IDX1111"></A>
<A NAME="IDX1112"></A>

</P>
<P>
All programming and scripting languages that have the notion of strings
are eligible to supporting <CODE>gettext</CODE>.  Supporting <CODE>gettext</CODE>
means the following:

</P>

<OL>
<LI>

You should add to the language a syntax for translatable strings.  In
principle, a function call of <CODE>gettext</CODE> would do, but a shorthand
syntax helps keeping the legibility of internationalized programs.  For
example, in C we use the syntax <CODE>_("string")</CODE>, and in GNU awk we use
the shorthand <CODE>_"string"</CODE>.

<LI>

You should arrange that evaluation of such a translatable string at
runtime calls the <CODE>gettext</CODE> function, or performs equivalent
processing.

<LI>

Similarly, you should make the functions <CODE>ngettext</CODE>,
<CODE>dcgettext</CODE>, <CODE>dcngettext</CODE> available from within the language.
These functions are less often used, but are nevertheless necessary for
particular purposes: <CODE>ngettext</CODE> for correct plural handling, and
<CODE>dcgettext</CODE> and <CODE>dcngettext</CODE> for obeying other locale
environment variables than <CODE>LC_MESSAGES</CODE>, such as <CODE>LC_TIME</CODE> or
<CODE>LC_MONETARY</CODE>.  For these latter functions, you need to make the
<CODE>LC_*</CODE> constants, available in the C header <CODE>&#60;locale.h&#62;</CODE>,
referenceable from within the language, usually either as enumeration
values or as strings.

<LI>

You should allow the programmer to designate a message domain, either by
making the <CODE>textdomain</CODE> function available from within the
language, or by introducing a magic variable called <CODE>TEXTDOMAIN</CODE>.
Similarly, you should allow the programmer to designate where to search
for message catalogs, by providing access to the <CODE>bindtextdomain</CODE>
function.

<LI>

You should either perform a <CODE>setlocale (LC_ALL, "")</CODE> call during
the startup of your language runtime, or allow the programmer to do so.
Remember that gettext will act as a no-op if the <CODE>LC_MESSAGES</CODE> and
<CODE>LC_CTYPE</CODE> locale facets are not both set.

<LI>

A programmer should have a way to extract translatable strings from a
program into a PO file.  The GNU <CODE>xgettext</CODE> program is being
extended to support very different programming languages.  Please
contact the GNU <CODE>gettext</CODE> maintainers to help them doing this.  If
the string extractor is best integrated into your language's parser, GNU
<CODE>xgettext</CODE> can function as a front end to your string extractor.

<LI>

The language's library should have a string formatting facility where
the arguments of a format string are denoted by a positional number or a
name.  This is needed because for some languages and some messages with
more than one substitutable argument, the translation will need to
output the substituted arguments in different order.  See section <A HREF="gettext_4.html#SEC17">4.6  Special Comments preceding Keywords</A>.

<LI>

If the language has more than one implementation, and not all of the
implementations use <CODE>gettext</CODE>, but the programs should be portable
across implementations, you should provide a no-i18n emulation, that
makes the other implementations accept programs written for yours,
without actually translating the strings.

<LI>

To help the programmer in the task of marking translatable strings,
which is sometimes performed using the Emacs PO mode (see section <A HREF="gettext_4.html#SEC16">4.5  Marking Translatable Strings</A>),
you are welcome to
contact the GNU <CODE>gettext</CODE> maintainers, so they can add support for
your language to <TT>&lsquo;po-mode.el&rsquo;</TT>.
</OL>

<P>
On the implementation side, three approaches are possible, with
different effects on portability and copyright:

</P>

<UL>
<LI>

You may integrate the GNU <CODE>gettext</CODE>'s <TT>&lsquo;intl/&rsquo;</TT> directory in
your package, as described in section <A HREF="gettext_13.html#SEC196">13  The Maintainer's View</A>.  This allows you to
have internationalization on all kinds of platforms.  Note that when you
then distribute your package, it legally falls under the GNU General
Public License, and the GNU project will be glad about your contribution
to the Free Software pool.

<LI>

You may link against GNU <CODE>gettext</CODE> functions if they are found in
the C library.  For example, an autoconf test for <CODE>gettext()</CODE> and
<CODE>ngettext()</CODE> will detect this situation.  For the moment, this test
will succeed on GNU systems and not on other platforms.  No severe
copyright restrictions apply.

<LI>

You may emulate or reimplement the GNU <CODE>gettext</CODE> functionality.
This has the advantage of full portability and no copyright
restrictions, but also the drawback that you have to reimplement the GNU
<CODE>gettext</CODE> features (such as the <CODE>LANGUAGE</CODE> environment
variable, the locale aliases database, the automatic charset conversion,
and plural handling).
</UL>



<H2><A NAME="SEC231" HREF="gettext_toc.html#TOC231">15.2  The Programmer's View</A></H2>

<P>
For the programmer, the general procedure is the same as for the C
language.  The Emacs PO mode marking supports other languages, and the GNU
<CODE>xgettext</CODE> string extractor recognizes other languages based on the
file extension or a command-line option.  In some languages,
<CODE>setlocale</CODE> is not needed because it is already performed by the
underlying language runtime.

</P>


<H2><A NAME="SEC232" HREF="gettext_toc.html#TOC232">15.3  The Translator's View</A></H2>

<P>
The translator works exactly as in the C language case.  The only
difference is that when translating format strings, she has to be aware
of the language's particular syntax for positional arguments in format
strings.

</P>



<H3><A NAME="SEC233" HREF="gettext_toc.html#TOC233">15.3.1  C Format Strings</A></H3>

<P>
C format strings are described in POSIX (IEEE P1003.1 2001), section
XSH 3 fprintf(),
<A HREF="http://www.opengroup.org/onlinepubs/007904975/functions/fprintf.html">http://www.opengroup.org/onlinepubs/007904975/functions/fprintf.html</A>.
See also the fprintf() manual page,
<A HREF="http://www.linuxvalley.it/encyclopedia/ldp/manpage/man3/printf.3.php">http://www.linuxvalley.it/encyclopedia/ldp/manpage/man3/printf.3.php</A>,
<A HREF="http://informatik.fh-wuerzburg.de/student/i510/man/printf.html">http://informatik.fh-wuerzburg.de/student/i510/man/printf.html</A>.

</P>
<P>
Although format strings with positions that reorder arguments, such as

</P>

<PRE>
"Only %2$d bytes free on '%1$s'."
</PRE>

<P>
which is semantically equivalent to

</P>

<PRE>
"'%s' has only %d bytes free."
</PRE>

<P>
are a POSIX/XSI feature and not specified by ISO C 99, translators can rely
on this reordering ability: On the few platforms where <CODE>printf()</CODE>,
<CODE>fprintf()</CODE> etc. don't support this feature natively, <TT>&lsquo;libintl.a&rsquo;</TT>
or <TT>&lsquo;libintl.so&rsquo;</TT> provides replacement functions, and GNU <CODE>&#60;libintl.h&#62;</CODE>
activates these replacement functions automatically.

</P>
<P>
<A NAME="IDX1113"></A>
<A NAME="IDX1114"></A>
As a special feature for Farsi (Persian) and maybe Arabic, translators can
insert an <SAMP>&lsquo;I&rsquo;</SAMP> flag into numeric format directives.  For example, the
translation of <CODE>"%d"</CODE> can be <CODE>"%Id"</CODE>.  The effect of this flag,
on systems with GNU <CODE>libc</CODE>, is that in the output, the ASCII digits are
replaced with the <SAMP>&lsquo;outdigits&rsquo;</SAMP> defined in the <CODE>LC_CTYPE</CODE> locale
facet.  On other systems, the <CODE>gettext</CODE> function removes this flag,
so that it has no effect.

</P>
<P>
Note that the programmer should <EM>not</EM> put this flag into the
untranslated string.  (Putting the <SAMP>&lsquo;I&rsquo;</SAMP> format directive flag into an
<VAR>msgid</VAR> string would lead to undefined behaviour on platforms without
glibc when NLS is disabled.)

</P>


<H3><A NAME="SEC234" HREF="gettext_toc.html#TOC234">15.3.2  Objective C Format Strings</A></H3>

<P>
Objective C format strings are like C format strings.  They support an
additional format directive: "$@", which when executed consumes an argument
of type <CODE>Object *</CODE>.

</P>


<H3><A NAME="SEC235" HREF="gettext_toc.html#TOC235">15.3.3  Shell Format Strings</A></H3>

<P>
Shell format strings, as supported by GNU gettext and the <SAMP>&lsquo;envsubst&rsquo;</SAMP>
program, are strings with references to shell variables in the form
<CODE>$<VAR>variable</VAR></CODE> or <CODE>${<VAR>variable</VAR>}</CODE>.  References of the form
<CODE>${<VAR>variable</VAR>-<VAR>default</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>:-<VAR>default</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>=<VAR>default</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>:=<VAR>default</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>+<VAR>replacement</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>:+<VAR>replacement</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>?<VAR>ignored</VAR>}</CODE>,
<CODE>${<VAR>variable</VAR>:?<VAR>ignored</VAR>}</CODE>,
that would be valid inside shell scripts, are not supported.  The
<VAR>variable</VAR> names must consist solely of alphanumeric or underscore
ASCII characters, not start with a digit and be nonempty; otherwise such
a variable reference is ignored.

</P>


<H3><A NAME="SEC236" HREF="gettext_toc.html#TOC236">15.3.4  Python Format Strings</A></H3>

<P>
Python format strings are described in
Python Library reference /
2. Built-in Types, Exceptions and Functions /
2.2. Built-in Types /
2.2.6. Sequence Types /
2.2.6.2. String Formatting Operations.
<A HREF="http://www.python.org/doc/2.2.1/lib/typesseq-strings.html">http://www.python.org/doc/2.2.1/lib/typesseq-strings.html</A>.

</P>


<H3><A NAME="SEC237" HREF="gettext_toc.html#TOC237">15.3.5  Lisp Format Strings</A></H3>

<P>
Lisp format strings are described in the Common Lisp HyperSpec,
chapter 22.3 Formatted Output,
<A HREF="http://www.lisp.org/HyperSpec/Body/sec_22-3.html">http://www.lisp.org/HyperSpec/Body/sec_22-3.html</A>.

</P>


<H3><A NAME="SEC238" HREF="gettext_toc.html#TOC238">15.3.6  Emacs Lisp Format Strings</A></H3>

<P>
Emacs Lisp format strings are documented in the Emacs Lisp reference,
section Formatting Strings,
<A HREF="http://www.gnu.org/manual/elisp-manual-21-2.8/html_chapter/elisp_4.html#SEC75">http://www.gnu.org/manual/elisp-manual-21-2.8/html_chapter/elisp_4.html#SEC75</A>.
Note that as of version 21, XEmacs supports numbered argument specifications
in format strings while FSF Emacs doesn't.

</P>


<H3><A NAME="SEC239" HREF="gettext_toc.html#TOC239">15.3.7  librep Format Strings</A></H3>

<P>
librep format strings are documented in the librep manual, section
Formatted Output,
<A HREF="http://librep.sourceforge.net/librep-manual.html#Formatted%20Output">http://librep.sourceforge.net/librep-manual.html#Formatted%20Output</A>,
<A HREF="http://www.gwinnup.org/research/docs/librep.html#SEC122">http://www.gwinnup.org/research/docs/librep.html#SEC122</A>.

</P>


<H3><A NAME="SEC240" HREF="gettext_toc.html#TOC240">15.3.8  Scheme Format Strings</A></H3>

<P>
Scheme format strings are documented in the SLIB manual, section
Format Specification.

</P>


<H3><A NAME="SEC241" HREF="gettext_toc.html#TOC241">15.3.9  Smalltalk Format Strings</A></H3>

<P>
Smalltalk format strings are described in the GNU Smalltalk documentation,
class <CODE>CharArray</CODE>, methods <SAMP>&lsquo;bindWith:&rsquo;</SAMP> and
<SAMP>&lsquo;bindWithArguments:&rsquo;</SAMP>.
<A HREF="http://www.gnu.org/software/smalltalk/gst-manual/gst_68.html#SEC238">http://www.gnu.org/software/smalltalk/gst-manual/gst_68.html#SEC238</A>.
In summary, a directive starts with <SAMP>&lsquo;%&rsquo;</SAMP> and is followed by <SAMP>&lsquo;%&rsquo;</SAMP>
or a nonzero digit (<SAMP>&lsquo;1&rsquo;</SAMP> to <SAMP>&lsquo;9&rsquo;</SAMP>).

</P>


<H3><A NAME="SEC242" HREF="gettext_toc.html#TOC242">15.3.10  Java Format Strings</A></H3>

<P>
Java format strings are described in the JDK documentation for class
<CODE>java.text.MessageFormat</CODE>,
<A HREF="http://java.sun.com/j2se/1.4/docs/api/java/text/MessageFormat.html">http://java.sun.com/j2se/1.4/docs/api/java/text/MessageFormat.html</A>.
See also the ICU documentation
<A HREF="http://oss.software.ibm.com/icu/apiref/classMessageFormat.html">http://oss.software.ibm.com/icu/apiref/classMessageFormat.html</A>.

</P>


<H3><A NAME="SEC243" HREF="gettext_toc.html#TOC243">15.3.11  C# Format Strings</A></H3>

<P>
C# format strings are described in the .NET documentation for class
<CODE>System.String</CODE> and in
<A HREF="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpConFormattingOverview.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpConFormattingOverview.asp</A>.

</P>


<H3><A NAME="SEC244" HREF="gettext_toc.html#TOC244">15.3.12  awk Format Strings</A></H3>

<P>
awk format strings are described in the gawk documentation, section
Printf,
<A HREF="http://www.gnu.org/manual/gawk/html_node/Printf.html#Printf">http://www.gnu.org/manual/gawk/html_node/Printf.html#Printf</A>.

</P>


<H3><A NAME="SEC245" HREF="gettext_toc.html#TOC245">15.3.13  Object Pascal Format Strings</A></H3>

<P>
Where is this documented?

</P>


<H3><A NAME="SEC246" HREF="gettext_toc.html#TOC246">15.3.14  YCP Format Strings</A></H3>

<P>
YCP sformat strings are described in the libycp documentation
<A HREF="file:/usr/share/doc/packages/libycp/YCP-builtins.html">file:/usr/share/doc/packages/libycp/YCP-builtins.html</A>.
In summary, a directive starts with <SAMP>&lsquo;%&rsquo;</SAMP> and is followed by <SAMP>&lsquo;%&rsquo;</SAMP>
or a nonzero digit (<SAMP>&lsquo;1&rsquo;</SAMP> to <SAMP>&lsquo;9&rsquo;</SAMP>).

</P>


<H3><A NAME="SEC247" HREF="gettext_toc.html#TOC247">15.3.15  Tcl Format Strings</A></H3>

<P>
Tcl format strings are described in the <TT>&lsquo;format.n&rsquo;</TT> manual page,
<A HREF="http://www.scriptics.com/man/tcl8.3/TclCmd/format.htm">http://www.scriptics.com/man/tcl8.3/TclCmd/format.htm</A>.

</P>


<H3><A NAME="SEC248" HREF="gettext_toc.html#TOC248">15.3.16  Perl Format Strings</A></H3>

<P>
There are two kinds format strings in Perl: those acceptable to the
Perl built-in function <CODE>printf</CODE>, labelled as <SAMP>&lsquo;perl-format&rsquo;</SAMP>,
and those acceptable to the <CODE>libintl-perl</CODE> function <CODE>__x</CODE>,
labelled as <SAMP>&lsquo;perl-brace-format&rsquo;</SAMP>.

</P>
<P>
Perl <CODE>printf</CODE> format strings are described in the <CODE>sprintf</CODE>
section of <SAMP>&lsquo;man perlfunc&rsquo;</SAMP>.

</P>
<P>
Perl brace format strings are described in the
<TT>&lsquo;Locale::TextDomain(3pm)&rsquo;</TT> manual page of the CPAN package
libintl-perl.  In brief, Perl format uses placeholders put between
braces (<SAMP>&lsquo;{&rsquo;</SAMP> and <SAMP>&lsquo;}&rsquo;</SAMP>).  The placeholder must have the syntax
of simple identifiers.

</P>


<H3><A NAME="SEC249" HREF="gettext_toc.html#TOC249">15.3.17  PHP Format Strings</A></H3>

<P>
PHP format strings are described in the documentation of the PHP function
<CODE>sprintf</CODE>, in <TT>&lsquo;phpdoc/manual/function.sprintf.html&rsquo;</TT> or
<A HREF="http://www.php.net/manual/en/function.sprintf.php">http://www.php.net/manual/en/function.sprintf.php</A>.

</P>


<H3><A NAME="SEC250" HREF="gettext_toc.html#TOC250">15.3.18  GCC internal Format Strings</A></H3>

<P>
These format strings are used inside the GCC sources.  In such a format
string, a directive starts with <SAMP>&lsquo;%&rsquo;</SAMP>, is optionally followed by a
size specifier <SAMP>&lsquo;l&rsquo;</SAMP>, an optional flag <SAMP>&lsquo;+&rsquo;</SAMP>, another optional flag
<SAMP>&lsquo;#&rsquo;</SAMP>, and is finished by a specifier: <SAMP>&lsquo;%&rsquo;</SAMP> denotes a literal
percent sign, <SAMP>&lsquo;c&rsquo;</SAMP> denotes a character, <SAMP>&lsquo;s&rsquo;</SAMP> denotes a string,
<SAMP>&lsquo;i&rsquo;</SAMP> and <SAMP>&lsquo;d&rsquo;</SAMP> denote an integer, <SAMP>&lsquo;o&rsquo;</SAMP>, <SAMP>&lsquo;u&rsquo;</SAMP>, <SAMP>&lsquo;x&rsquo;</SAMP>
denote an unsigned integer, <SAMP>&lsquo;.*s&rsquo;</SAMP> denotes a string preceded by a
width specification, <SAMP>&lsquo;H&rsquo;</SAMP> denotes a <SAMP>&lsquo;location_t *&rsquo;</SAMP> pointer,
<SAMP>&lsquo;D&rsquo;</SAMP> denotes a general declaration, <SAMP>&lsquo;F&rsquo;</SAMP> denotes a function
declaration, <SAMP>&lsquo;T&rsquo;</SAMP> denotes a type, <SAMP>&lsquo;A&rsquo;</SAMP> denotes a function argument,
<SAMP>&lsquo;C&rsquo;</SAMP> denotes a tree code, <SAMP>&lsquo;E&rsquo;</SAMP> denotes an expression, <SAMP>&lsquo;L&rsquo;</SAMP>
denotes a programming language, <SAMP>&lsquo;O&rsquo;</SAMP> denotes a binary operator,
<SAMP>&lsquo;P&rsquo;</SAMP> denotes a function parameter, <SAMP>&lsquo;Q&rsquo;</SAMP> denotes an assignment
operator, <SAMP>&lsquo;V&rsquo;</SAMP> denotes a const/volatile qualifier.

</P>


<H3><A NAME="SEC251" HREF="gettext_toc.html#TOC251">15.3.19  Qt Format Strings</A></H3>

<P>
Qt format strings are described in the documentation of the QString class
<A HREF="file:/usr/lib/qt-3.0.5/doc/html/qstring.html">file:/usr/lib/qt-3.0.5/doc/html/qstring.html</A>.
In summary, a directive consists of a <SAMP>&lsquo;%&rsquo;</SAMP> followed by a digit. The same
directive cannot occur more than once in a format string.

</P>


<H3><A NAME="SEC252" HREF="gettext_toc.html#TOC252">15.3.20  Boost Format Strings</A></H3>

<P>
Boost format strings are described in the documentation of the
<CODE>boost::format</CODE> class, at
<A HREF="http://www.boost.org/libs/format/doc/format.html">http://www.boost.org/libs/format/doc/format.html</A>.
In summary, a directive has either the same syntax as in a C format string,
such as <SAMP>&lsquo;%1$+5d&rsquo;</SAMP>, or may be surrounded by vertical bars, such as
<SAMP>&lsquo;%|1$+5d|&rsquo;</SAMP> or <SAMP>&lsquo;%|1$+5|&rsquo;</SAMP>, or consists of just an argument number
between percent signs, such as <SAMP>&lsquo;%1%&rsquo;</SAMP>.

</P>


<H2><A NAME="SEC253" HREF="gettext_toc.html#TOC253">15.4  The Maintainer's View</A></H2>

<P>
For the maintainer, the general procedure differs from the C language
case in two ways.

</P>

<UL>
<LI>

For those languages that don't use GNU gettext, the <TT>&lsquo;intl/&rsquo;</TT> directory
is not needed and can be omitted.  This means that the maintainer calls the
<CODE>gettextize</CODE> program without the <SAMP>&lsquo;--intl&rsquo;</SAMP> option, and that he
invokes the <CODE>AM_GNU_GETTEXT</CODE> autoconf macro via
<SAMP>&lsquo;AM_GNU_GETTEXT([external])&rsquo;</SAMP>.

<LI>

If only a single programming language is used, the <CODE>XGETTEXT_OPTIONS</CODE>
variable in <TT>&lsquo;po/Makevars&rsquo;</TT> (see section <A HREF="gettext_13.html#SEC203">13.4.3  <TT>&lsquo;Makevars&rsquo;</TT> in <TT>&lsquo;po/&rsquo;</TT></A>) should be adjusted to
match the <CODE>xgettext</CODE> options for that particular programming language.
If the package uses more than one programming language with <CODE>gettext</CODE>
support, it becomes necessary to change the POT file construction rule
in <TT>&lsquo;po/Makefile.in.in&rsquo;</TT>.  It is recommended to make one <CODE>xgettext</CODE>
invocation per programming language, each with the options appropriate for
that language, and to combine the resulting files using <CODE>msgcat</CODE>.
</UL>



<H2><A NAME="SEC254" HREF="gettext_toc.html#TOC254">15.5  Individual Programming Languages</A></H2>



<H3><A NAME="SEC255" HREF="gettext_toc.html#TOC255">15.5.1  C, C++, Objective C</A></H3>
<P>
<A NAME="IDX1115"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
gcc, gpp, gobjc, glibc, gettext

<DT>File extension
<DD>
For C: <CODE>c</CODE>, <CODE>h</CODE>.
<BR>For C++: <CODE>C</CODE>, <CODE>c++</CODE>, <CODE>cc</CODE>, <CODE>cxx</CODE>, <CODE>cpp</CODE>, <CODE>hpp</CODE>.
<BR>For Objective C: <CODE>m</CODE>.

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>_("abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE>, <CODE>ngettext</CODE>,
<CODE>dngettext</CODE>, <CODE>dcngettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE> function

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>setlocale
<DD>
Programmer must call <CODE>setlocale (LC_ALL, "")</CODE>

<DT>Prerequisite
<DD>
<CODE>#include &#60;libintl.h&#62;</CODE>
<BR><CODE>#include &#60;locale.h&#62;</CODE>
<BR><CODE>#define _(string) gettext (string)</CODE>

<DT>Use or emulate GNU gettext
<DD>
Use

<DT>Extractor
<DD>
<CODE>xgettext -k_</CODE>

<DT>Formatting with positions
<DD>
<CODE>fprintf "%2$d %1$d"</CODE>
<BR>In C++: <CODE>autosprintf "%2$d %1$d"</CODE>
(see section ‘Introduction’ in <CITE>GNU autosprintf</CITE>)

<DT>Portability
<DD>
autoconf (gettext.m4) and #if ENABLE_NLS

<DT>po-mode marking
<DD>
yes
</DL>

<P>
The following examples are available in the <TT>&lsquo;examples&rsquo;</TT> directory:
<CODE>hello-c</CODE>, <CODE>hello-c-gnome</CODE>, <CODE>hello-c++</CODE>, <CODE>hello-c++-qt</CODE>, 
<CODE>hello-c++-kde</CODE>, <CODE>hello-c++-gnome</CODE>, <CODE>hello-c++-wxwidgets</CODE>,
<CODE>hello-objc</CODE>, <CODE>hello-objc-gnustep</CODE>, <CODE>hello-objc-gnome</CODE>.

</P>


<H3><A NAME="SEC256" HREF="gettext_toc.html#TOC256">15.5.2  sh - Shell Script</A></H3>
<P>
<A NAME="IDX1116"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
bash, gettext

<DT>File extension
<DD>
<CODE>sh</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>, <CODE>'abc'</CODE>, <CODE>abc</CODE>

<DT>gettext shorthand
<DD>
<CODE>"`gettext \"abc\"`"</CODE>

<DT>gettext/ngettext functions
<DD>
<A NAME="IDX1117"></A>
<A NAME="IDX1118"></A>
<CODE>gettext</CODE>, <CODE>ngettext</CODE> programs
<BR><CODE>eval_gettext</CODE>, <CODE>eval_ngettext</CODE> shell functions

<DT>textdomain
<DD>
<A NAME="IDX1119"></A>
environment variable <CODE>TEXTDOMAIN</CODE>

<DT>bindtextdomain
<DD>
<A NAME="IDX1120"></A>
environment variable <CODE>TEXTDOMAINDIR</CODE>

<DT>setlocale
<DD>
automatic

<DT>Prerequisite
<DD>
<CODE>. gettext.sh</CODE>

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
---

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-sh</CODE>.

</P>



<H4><A NAME="SEC257" HREF="gettext_toc.html#TOC257">15.5.2.1  Preparing Shell Scripts for Internationalization</A></H4>
<P>
<A NAME="IDX1121"></A>

</P>
<P>
Preparing a shell script for internationalization is conceptually similar
to the steps described in section <A HREF="gettext_4.html#SEC11">4  Preparing Program Sources</A>.  The concrete steps for shell
scripts are as follows.

</P>

<OL>
<LI>

Insert the line


<PRE>
. gettext.sh
</PRE>

near the top of the script.  <CODE>gettext.sh</CODE> is a shell function library
that provides the functions
<CODE>eval_gettext</CODE> (see section <A HREF="gettext_15.html#SEC262">15.5.2.6  Invoking the <CODE>eval_gettext</CODE> function</A>) and
<CODE>eval_ngettext</CODE> (see section <A HREF="gettext_15.html#SEC263">15.5.2.7  Invoking the <CODE>eval_ngettext</CODE> function</A>).
You have to ensure that <CODE>gettext.sh</CODE> can be found in the <CODE>PATH</CODE>.

<LI>

Set and export the <CODE>TEXTDOMAIN</CODE> and <CODE>TEXTDOMAINDIR</CODE> environment
variables.  Usually <CODE>TEXTDOMAIN</CODE> is the package or program name, and
<CODE>TEXTDOMAINDIR</CODE> is the absolute pathname corresponding to
<CODE>$prefix/share/locale</CODE>, where <CODE>$prefix</CODE> is the installation location.


<PRE>
TEXTDOMAIN=@PACKAGE@
export TEXTDOMAIN
TEXTDOMAINDIR=@LOCALEDIR@
export TEXTDOMAINDIR
</PRE>

<LI>

Prepare the strings for translation, as described in section <A HREF="gettext_4.html#SEC14">4.3  Preparing Translatable Strings</A>.

<LI>

Simplify translatable strings so that they don't contain command substitution
(<CODE>"`...`"</CODE> or <CODE>"$(...)"</CODE>), variable access with defaulting (like
<CODE>${<VAR>variable</VAR>-<VAR>default</VAR>}</CODE>), access to positional arguments
(like <CODE>$0</CODE>, <CODE>$1</CODE>, ...) or highly volatile shell variables (like
<CODE>$?</CODE>). This can always be done through simple local code restructuring.
For example,


<PRE>
echo "Usage: $0 [OPTION] FILE..."
</PRE>

becomes


<PRE>
program_name=$0
echo "Usage: $program_name [OPTION] FILE..."
</PRE>

Similarly,


<PRE>
echo "Remaining files: `ls | wc -l`"
</PRE>

becomes


<PRE>
filecount="`ls | wc -l`"
echo "Remaining files: $filecount"
</PRE>

<LI>

For each translatable string, change the output command <SAMP>&lsquo;echo&rsquo;</SAMP> or
<SAMP>&lsquo;$echo&rsquo;</SAMP> to <SAMP>&lsquo;gettext&rsquo;</SAMP> (if the string contains no references to
shell variables) or to <SAMP>&lsquo;eval_gettext&rsquo;</SAMP> (if it refers to shell variables),
followed by a no-argument <SAMP>&lsquo;echo&rsquo;</SAMP> command (to account for the terminating
newline). Similarly, for cases with plural handling, replace a conditional
<SAMP>&lsquo;echo&rsquo;</SAMP> command with an invocation of <SAMP>&lsquo;ngettext&rsquo;</SAMP> or
<SAMP>&lsquo;eval_ngettext&rsquo;</SAMP>, followed by a no-argument <SAMP>&lsquo;echo&rsquo;</SAMP> command.

When doing this, you also need to add an extra backslash before the dollar
sign in references to shell variables, so that the <SAMP>&lsquo;eval_gettext&rsquo;</SAMP>
function receives the translatable string before the variable values are
substituted into it. For example,


<PRE>
echo "Remaining files: $filecount"
</PRE>

becomes


<PRE>
eval_gettext "Remaining files: \$filecount"; echo
</PRE>

If the output command is not <SAMP>&lsquo;echo&rsquo;</SAMP>, you can make it use <SAMP>&lsquo;echo&rsquo;</SAMP>
nevertheless, through the use of backquotes. However, note that inside
backquotes, backslashes must be doubled to be effective (because the
backquoting eats one level of backslashes). For example, assuming that
<SAMP>&lsquo;error&rsquo;</SAMP> is a shell function that signals an error,


<PRE>
error "file not found: $filename"
</PRE>

is first transformed into


<PRE>
error "`echo \"file not found: \$filename\"`"
</PRE>

which then becomes


<PRE>
error "`eval_gettext \"file not found: \\\$filename\"`"
</PRE>

</OL>



<H4><A NAME="SEC258" HREF="gettext_toc.html#TOC258">15.5.2.2  Contents of <CODE>gettext.sh</CODE></A></H4>

<P>
<CODE>gettext.sh</CODE>, contained in the run-time package of GNU gettext, provides
the following:

</P>

<UL>
<LI>$echo

The variable <CODE>echo</CODE> is set to a command that outputs its first argument
and a newline, without interpreting backslashes in the argument string.

<LI>eval_gettext

See section <A HREF="gettext_15.html#SEC262">15.5.2.6  Invoking the <CODE>eval_gettext</CODE> function</A>.

<LI>eval_ngettext

See section <A HREF="gettext_15.html#SEC263">15.5.2.7  Invoking the <CODE>eval_ngettext</CODE> function</A>.
</UL>



<H4><A NAME="SEC259" HREF="gettext_toc.html#TOC259">15.5.2.3  Invoking the <CODE>gettext</CODE> program</A></H4>

<P>
<A NAME="IDX1122"></A>
<A NAME="IDX1123"></A>

<PRE>
gettext [<VAR>option</VAR>] [[<VAR>textdomain</VAR>] <VAR>msgid</VAR>]
gettext [<VAR>option</VAR>] -s [<VAR>msgid</VAR>]...
</PRE>

<P>
<A NAME="IDX1124"></A>
The <CODE>gettext</CODE> program displays the native language translation of a
textual message.

</P>
<P>
<STRONG>Arguments</STRONG>

</P>
<DL COMPACT>

<DT><SAMP>&lsquo;-d <VAR>textdomain</VAR>&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--domain=<VAR>textdomain</VAR>&rsquo;</SAMP>
<DD>
<A NAME="IDX1125"></A>
<A NAME="IDX1126"></A>
Retrieve translated messages from <VAR>textdomain</VAR>.  Usually a <VAR>textdomain</VAR>
corresponds to a package, a program, or a module of a program.

<DT><SAMP>&lsquo;-e&rsquo;</SAMP>
<DD>
<A NAME="IDX1127"></A>
Enable expansion of some escape sequences.  This option is for compatibility
with the <SAMP>&lsquo;echo&rsquo;</SAMP> program or shell built-in.  The escape sequences
<SAMP>&lsquo;\a&rsquo;</SAMP>, <SAMP>&lsquo;\b&rsquo;</SAMP>, <SAMP>&lsquo;\c&rsquo;</SAMP>, <SAMP>&lsquo;\f&rsquo;</SAMP>, <SAMP>&lsquo;\n&rsquo;</SAMP>, <SAMP>&lsquo;\r&rsquo;</SAMP>, <SAMP>&lsquo;\t&rsquo;</SAMP>,
<SAMP>&lsquo;\v&rsquo;</SAMP>, <SAMP>&lsquo;\\&rsquo;</SAMP>, and <SAMP>&lsquo;\&rsquo;</SAMP> followed by one to three octal digits, are
interpreted like the System V <SAMP>&lsquo;echo&rsquo;</SAMP> program did.

<DT><SAMP>&lsquo;-E&rsquo;</SAMP>
<DD>
<A NAME="IDX1128"></A>
This option is only for compatibility with the <SAMP>&lsquo;echo&rsquo;</SAMP> program or shell
built-in.  It has no effect.

<DT><SAMP>&lsquo;-h&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--help&rsquo;</SAMP>
<DD>
<A NAME="IDX1129"></A>
<A NAME="IDX1130"></A>
Display this help and exit.

<DT><SAMP>&lsquo;-n&rsquo;</SAMP>
<DD>
<A NAME="IDX1131"></A>
Suppress trailing newline.  By default, <CODE>gettext</CODE> adds a newline to
the output.

<DT><SAMP>&lsquo;-V&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--version&rsquo;</SAMP>
<DD>
<A NAME="IDX1132"></A>
<A NAME="IDX1133"></A>
Output version information and exit.

<DT><SAMP>&lsquo;[<VAR>textdomain</VAR>] <VAR>msgid</VAR>&rsquo;</SAMP>
<DD>
Retrieve translated message corresponding to <VAR>msgid</VAR> from <VAR>textdomain</VAR>.

</DL>

<P>
If the <VAR>textdomain</VAR> parameter is not given, the domain is determined from
the environment variable <CODE>TEXTDOMAIN</CODE>.  If the message catalog is not
found in the regular directory, another location can be specified with the
environment variable <CODE>TEXTDOMAINDIR</CODE>.

</P>
<P>
When used with the <CODE>-s</CODE> option the program behaves like the <SAMP>&lsquo;echo&rsquo;</SAMP>
command.  But it does not simply copy its arguments to stdout.  Instead those
messages found in the selected catalog are translated.

</P>


<H4><A NAME="SEC260" HREF="gettext_toc.html#TOC260">15.5.2.4  Invoking the <CODE>ngettext</CODE> program</A></H4>

<P>
<A NAME="IDX1134"></A>
<A NAME="IDX1135"></A>

<PRE>
ngettext [<VAR>option</VAR>] [<VAR>textdomain</VAR>] <VAR>msgid</VAR> <VAR>msgid-plural</VAR> <VAR>count</VAR>
</PRE>

<P>
<A NAME="IDX1136"></A>
The <CODE>ngettext</CODE> program displays the native language translation of a
textual message whose grammatical form depends on a number.

</P>
<P>
<STRONG>Arguments</STRONG>

</P>
<DL COMPACT>

<DT><SAMP>&lsquo;-d <VAR>textdomain</VAR>&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--domain=<VAR>textdomain</VAR>&rsquo;</SAMP>
<DD>
<A NAME="IDX1137"></A>
<A NAME="IDX1138"></A>
Retrieve translated messages from <VAR>textdomain</VAR>.  Usually a <VAR>textdomain</VAR>
corresponds to a package, a program, or a module of a program.

<DT><SAMP>&lsquo;-e&rsquo;</SAMP>
<DD>
<A NAME="IDX1139"></A>
Enable expansion of some escape sequences.  This option is for compatibility
with the <SAMP>&lsquo;gettext&rsquo;</SAMP> program.  The escape sequences
<SAMP>&lsquo;\a&rsquo;</SAMP>, <SAMP>&lsquo;\b&rsquo;</SAMP>, <SAMP>&lsquo;\c&rsquo;</SAMP>, <SAMP>&lsquo;\f&rsquo;</SAMP>, <SAMP>&lsquo;\n&rsquo;</SAMP>, <SAMP>&lsquo;\r&rsquo;</SAMP>, <SAMP>&lsquo;\t&rsquo;</SAMP>,
<SAMP>&lsquo;\v&rsquo;</SAMP>, <SAMP>&lsquo;\\&rsquo;</SAMP>, and <SAMP>&lsquo;\&rsquo;</SAMP> followed by one to three octal digits, are
interpreted like the System V <SAMP>&lsquo;echo&rsquo;</SAMP> program did.

<DT><SAMP>&lsquo;-E&rsquo;</SAMP>
<DD>
<A NAME="IDX1140"></A>
This option is only for compatibility with the <SAMP>&lsquo;gettext&rsquo;</SAMP> program.  It has
no effect.

<DT><SAMP>&lsquo;-h&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--help&rsquo;</SAMP>
<DD>
<A NAME="IDX1141"></A>
<A NAME="IDX1142"></A>
Display this help and exit.

<DT><SAMP>&lsquo;-V&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--version&rsquo;</SAMP>
<DD>
<A NAME="IDX1143"></A>
<A NAME="IDX1144"></A>
Output version information and exit.

<DT><SAMP>&lsquo;<VAR>textdomain</VAR>&rsquo;</SAMP>
<DD>
Retrieve translated message from <VAR>textdomain</VAR>.

<DT><SAMP>&lsquo;<VAR>msgid</VAR> <VAR>msgid-plural</VAR>&rsquo;</SAMP>
<DD>
Translate <VAR>msgid</VAR> (English singular) / <VAR>msgid-plural</VAR> (English plural).

<DT><SAMP>&lsquo;<VAR>count</VAR>&rsquo;</SAMP>
<DD>
Choose singular/plural form based on this value.

</DL>

<P>
If the <VAR>textdomain</VAR> parameter is not given, the domain is determined from
the environment variable <CODE>TEXTDOMAIN</CODE>.  If the message catalog is not
found in the regular directory, another location can be specified with the
environment variable <CODE>TEXTDOMAINDIR</CODE>.

</P>


<H4><A NAME="SEC261" HREF="gettext_toc.html#TOC261">15.5.2.5  Invoking the <CODE>envsubst</CODE> program</A></H4>

<P>
<A NAME="IDX1145"></A>
<A NAME="IDX1146"></A>

<PRE>
envsubst [<VAR>option</VAR>] [<VAR>shell-format</VAR>]
</PRE>

<P>
<A NAME="IDX1147"></A>
<A NAME="IDX1148"></A>
<A NAME="IDX1149"></A>
The <CODE>envsubst</CODE> program substitutes the values of environment variables.

</P>
<P>
<STRONG>Operation mode</STRONG>

</P>
<DL COMPACT>

<DT><SAMP>&lsquo;-v&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--variables&rsquo;</SAMP>
<DD>
<A NAME="IDX1150"></A>
<A NAME="IDX1151"></A>
Output the variables occurring in <VAR>shell-format</VAR>.

</DL>

<P>
<STRONG>Informative output</STRONG>

</P>
<DL COMPACT>

<DT><SAMP>&lsquo;-h&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--help&rsquo;</SAMP>
<DD>
<A NAME="IDX1152"></A>
<A NAME="IDX1153"></A>
Display this help and exit.

<DT><SAMP>&lsquo;-V&rsquo;</SAMP>
<DD>
<DT><SAMP>&lsquo;--version&rsquo;</SAMP>
<DD>
<A NAME="IDX1154"></A>
<A NAME="IDX1155"></A>
Output version information and exit.

</DL>

<P>
In normal operation mode, standard input is copied to standard output,
with references to environment variables of the form <CODE>$VARIABLE</CODE> or
<CODE>${VARIABLE}</CODE> being replaced with the corresponding values.  If a
<VAR>shell-format</VAR> is given, only those environment variables that are
referenced in <VAR>shell-format</VAR> are substituted; otherwise all environment
variables references occurring in standard input are substituted.

</P>
<P>
These substitutions are a subset of the substitutions that a shell performs
on unquoted and double-quoted strings.  Other kinds of substitutions done
by a shell, such as <CODE>${<VAR>variable</VAR>-<VAR>default</VAR>}</CODE> or
<CODE>$(<VAR>command-list</VAR>)</CODE> or <CODE>`<VAR>command-list</VAR>`</CODE>, are not performed
by the <CODE>envsubst</CODE> program, due to security reasons.

</P>
<P>
When <CODE>--variables</CODE> is used, standard input is ignored, and the output
consists of the environment variables that are referenced in
<VAR>shell-format</VAR>, one per line.

</P>


<H4><A NAME="SEC262" HREF="gettext_toc.html#TOC262">15.5.2.6  Invoking the <CODE>eval_gettext</CODE> function</A></H4>

<P>
<A NAME="IDX1156"></A>

<PRE>
eval_gettext <VAR>msgid</VAR>
</PRE>

<P>
<A NAME="IDX1157"></A>
This function outputs the native language translation of a textual message,
performing dollar-substitution on the result.  Note that only shell variables
mentioned in <VAR>msgid</VAR> will be dollar-substituted in the result.

</P>


<H4><A NAME="SEC263" HREF="gettext_toc.html#TOC263">15.5.2.7  Invoking the <CODE>eval_ngettext</CODE> function</A></H4>

<P>
<A NAME="IDX1158"></A>

<PRE>
eval_ngettext <VAR>msgid</VAR> <VAR>msgid-plural</VAR> <VAR>count</VAR>
</PRE>

<P>
<A NAME="IDX1159"></A>
This function outputs the native language translation of a textual message
whose grammatical form depends on a number, performing dollar-substitution
on the result.  Note that only shell variables mentioned in <VAR>msgid</VAR> or
<VAR>msgid-plural</VAR> will be dollar-substituted in the result.

</P>


<H3><A NAME="SEC264" HREF="gettext_toc.html#TOC264">15.5.3  bash - Bourne-Again Shell Script</A></H3>
<P>
<A NAME="IDX1160"></A>

</P>
<P>
GNU <CODE>bash</CODE> 2.0 or newer has a special shorthand for translating a
string and substituting variable values in it: <CODE>$"msgid"</CODE>.  But
the use of this construct is <STRONG>discouraged</STRONG>, due to the security
holes it opens and due to its portability problems.

</P>
<P>
The security holes of <CODE>$"..."</CODE> come from the fact that after looking up
the translation of the string, <CODE>bash</CODE> processes it like it processes
any double-quoted string: dollar and backquote processing, like <SAMP>&lsquo;eval&rsquo;</SAMP>
does.

</P>

<OL>
<LI>

In a locale whose encoding is one of BIG5, BIG5-HKSCS, GBK, GB18030, SHIFT_JIS,
JOHAB, some double-byte characters have a second byte whose value is
<CODE>0x60</CODE>.  For example, the byte sequence <CODE>\xe0\x60</CODE> is a single
character in these locales.  Many versions of <CODE>bash</CODE> (all versions
up to bash-2.05, and newer versions on platforms without <CODE>mbsrtowcs()</CODE>
function) don't know about character boundaries and see a backquote character
where there is only a particular Chinese character.  Thus it can start
executing part of the translation as a command list.  This situation can occur
even without the translator being aware of it: if the translator provides
translations in the UTF-8 encoding, it is the <CODE>gettext()</CODE> function which
will, during its conversion from the translator's encoding to the user's
locale's encoding, produce the dangerous <CODE>\x60</CODE> bytes.

<LI>

A translator could - voluntarily or inadvertently - use backquotes
<CODE>"`...`"</CODE> or dollar-parentheses <CODE>"$(...)"</CODE> in her translations.
The enclosed strings would be executed as command lists by the shell.
</OL>

<P>
The portability problem is that <CODE>bash</CODE> must be built with
internationalization support; this is normally not the case on systems
that don't have the <CODE>gettext()</CODE> function in libc.

</P>


<H3><A NAME="SEC265" HREF="gettext_toc.html#TOC265">15.5.4  Python</A></H3>
<P>
<A NAME="IDX1161"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
python

<DT>File extension
<DD>
<CODE>py</CODE>

<DT>String syntax
<DD>
<CODE>'abc'</CODE>, <CODE>u'abc'</CODE>, <CODE>r'abc'</CODE>, <CODE>ur'abc'</CODE>,
<BR><CODE>"abc"</CODE>, <CODE>u"abc"</CODE>, <CODE>r"abc"</CODE>, <CODE>ur"abc"</CODE>,
<BR><CODE>”'abc”'</CODE>, <CODE>u”'abc”'</CODE>, <CODE>r”'abc”'</CODE>, <CODE>ur”'abc”'</CODE>,
<BR><CODE>"""abc"""</CODE>, <CODE>u"""abc"""</CODE>, <CODE>r"""abc"""</CODE>, <CODE>ur"""abc"""</CODE>

<DT>gettext shorthand
<DD>
<CODE>_('abc')</CODE> etc.

<DT>gettext/ngettext functions
<DD>
<CODE>gettext.gettext</CODE>, <CODE>gettext.dgettext</CODE>,
<CODE>gettext.ngettext</CODE>, <CODE>gettext.dngettext</CODE>,
also <CODE>ugettext</CODE>, <CODE>ungettext</CODE>

<DT>textdomain
<DD>
<CODE>gettext.textdomain</CODE> function, or
<CODE>gettext.install(<VAR>domain</VAR>)</CODE> function

<DT>bindtextdomain
<DD>
<CODE>gettext.bindtextdomain</CODE> function, or
<CODE>gettext.install(<VAR>domain</VAR>,<VAR>localedir</VAR>)</CODE> function

<DT>setlocale
<DD>
not used by the gettext emulation

<DT>Prerequisite
<DD>
<CODE>import gettext</CODE>

<DT>Use or emulate GNU gettext
<DD>
emulate

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>'...%(ident)d...' % { 'ident': value }</CODE>

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-python</CODE>.

</P>


<H3><A NAME="SEC266" HREF="gettext_toc.html#TOC266">15.5.5  GNU clisp - Common Lisp</A></H3>
<P>
<A NAME="IDX1162"></A>
<A NAME="IDX1163"></A>
<A NAME="IDX1164"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
clisp 2.28 or newer

<DT>File extension
<DD>
<CODE>lisp</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>(_ "abc")</CODE>, <CODE>(ENGLISH "abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>i18n:gettext</CODE>, <CODE>i18n:ngettext</CODE>

<DT>textdomain
<DD>
<CODE>i18n:textdomain</CODE>

<DT>bindtextdomain
<DD>
<CODE>i18n:textdomaindir</CODE>

<DT>setlocale
<DD>
automatic

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext -k_ -kENGLISH</CODE>

<DT>Formatting with positions
<DD>
<CODE>format "~1@*~D ~0@*~D"</CODE>

<DT>Portability
<DD>
On platforms without gettext, no translation.

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-clisp</CODE>.

</P>


<H3><A NAME="SEC267" HREF="gettext_toc.html#TOC267">15.5.6  GNU clisp C sources</A></H3>
<P>
<A NAME="IDX1165"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
clisp

<DT>File extension
<DD>
<CODE>d</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>ENGLISH ? "abc" : ""</CODE>
<BR><CODE>GETTEXT("abc")</CODE>
<BR><CODE>GETTEXTL("abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>clgettext</CODE>, <CODE>clgettextl</CODE>

<DT>textdomain
<DD>
---

<DT>bindtextdomain
<DD>
---

<DT>setlocale
<DD>
automatic

<DT>Prerequisite
<DD>
<CODE>#include "lispbibl.c"</CODE>

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>clisp-xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>fprintf "%2$d %1$d"</CODE>

<DT>Portability
<DD>
On platforms without gettext, no translation.

<DT>po-mode marking
<DD>
---
</DL>



<H3><A NAME="SEC268" HREF="gettext_toc.html#TOC268">15.5.7  Emacs Lisp</A></H3>
<P>
<A NAME="IDX1166"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
emacs, xemacs

<DT>File extension
<DD>
<CODE>el</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>(_"abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>dgettext</CODE> (xemacs only)

<DT>textdomain
<DD>
<CODE>domain</CODE> special form (xemacs only)

<DT>bindtextdomain
<DD>
<CODE>bind-text-domain</CODE> function (xemacs only)

<DT>setlocale
<DD>
automatic

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>format "%2$d %1$d"</CODE>

<DT>Portability
<DD>
Only XEmacs.  Without <CODE>I18N3</CODE> defined at build time, no translation.

<DT>po-mode marking
<DD>
---
</DL>



<H3><A NAME="SEC269" HREF="gettext_toc.html#TOC269">15.5.8  librep</A></H3>
<P>
<A NAME="IDX1167"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
librep 0.15.3 or newer

<DT>File extension
<DD>
<CODE>jl</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>(_"abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE> function

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>setlocale
<DD>
---

<DT>Prerequisite
<DD>
<CODE>(require 'rep.i18n.gettext)</CODE>

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>format "%2$d %1$d"</CODE>

<DT>Portability
<DD>
On platforms without gettext, no translation.

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-librep</CODE>.

</P>


<H3><A NAME="SEC270" HREF="gettext_toc.html#TOC270">15.5.9  GNU guile - Scheme</A></H3>
<P>
<A NAME="IDX1168"></A>
<A NAME="IDX1169"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
guile

<DT>File extension
<DD>
<CODE>scm</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>(_ "abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>ngettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE>

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE>

<DT>setlocale
<DD>
<CODE>(catch #t (lambda () (setlocale LC_ALL "")) (lambda args #f))</CODE>

<DT>Prerequisite
<DD>
<CODE>(use-modules (ice-9 format))</CODE>

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext -k_</CODE>

<DT>Formatting with positions
<DD>
---

<DT>Portability
<DD>
On platforms without gettext, no translation.

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-guile</CODE>.

</P>


<H3><A NAME="SEC271" HREF="gettext_toc.html#TOC271">15.5.10  GNU Smalltalk</A></H3>
<P>
<A NAME="IDX1170"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
smalltalk

<DT>File extension
<DD>
<CODE>st</CODE>

<DT>String syntax
<DD>
<CODE>'abc'</CODE>

<DT>gettext shorthand
<DD>
<CODE>NLS ? 'abc'</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>LcMessagesDomain&#62;&#62;#at:</CODE>, <CODE>LcMessagesDomain&#62;&#62;#at:plural:with:</CODE>

<DT>textdomain
<DD>
<CODE>LcMessages&#62;&#62;#domain:localeDirectory:</CODE> (returns a <CODE>LcMessagesDomain</CODE>
object).<BR>
Example: <CODE>I18N Locale default messages domain: 'gettext' localeDirectory: /usr/local/share/locale'</CODE>

<DT>bindtextdomain
<DD>
<CODE>LcMessages&#62;&#62;#domain:localeDirectory:</CODE>, see above.

<DT>setlocale
<DD>
Automatic if you use <CODE>I18N Locale default</CODE>.

<DT>Prerequisite
<DD>
<CODE>PackageLoader fileInPackage: 'I18N'!</CODE>

<DT>Use or emulate GNU gettext
<DD>
emulate

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>'%1 %2' bindWith: 'Hello' with: 'world'</CODE>

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory:
<CODE>hello-smalltalk</CODE>.

</P>


<H3><A NAME="SEC272" HREF="gettext_toc.html#TOC272">15.5.11  Java</A></H3>
<P>
<A NAME="IDX1171"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
java, java2

<DT>File extension
<DD>
<CODE>java</CODE>

<DT>String syntax
<DD>
"abc"

<DT>gettext shorthand
<DD>
_("abc")

<DT>gettext/ngettext functions
<DD>
<CODE>GettextResource.gettext</CODE>, <CODE>GettextResource.ngettext</CODE>

<DT>textdomain
<DD>
---, use <CODE>ResourceBundle.getResource</CODE> instead

<DT>bindtextdomain
<DD>
---, use CLASSPATH instead

<DT>setlocale
<DD>
automatic

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
---, uses a Java specific message catalog format

<DT>Extractor
<DD>
<CODE>xgettext -k_</CODE>

<DT>Formatting with positions
<DD>
<CODE>MessageFormat.format "{1,number} {0,number}"</CODE>

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
Before marking strings as internationalizable, uses of the string
concatenation operator need to be converted to <CODE>MessageFormat</CODE>
applications.  For example, <CODE>"file "+filename+" not found"</CODE> becomes
<CODE>MessageFormat.format("file {0} not found", new Object[] { filename })</CODE>.
Only after this is done, can the strings be marked and extracted.

</P>
<P>
GNU gettext uses the native Java internationalization mechanism, namely
<CODE>ResourceBundle</CODE>s.  There are two formats of <CODE>ResourceBundle</CODE>s:
<CODE>.properties</CODE> files and <CODE>.class</CODE> files.  The <CODE>.properties</CODE>
format is a text file which the translators can directly edit, like PO
files, but which doesn't support plural forms.  Whereas the <CODE>.class</CODE>
format is compiled from <CODE>.java</CODE> source code and can support plural
forms (provided it is accessed through an appropriate API, see below).

</P>
<P>
To convert a PO file to a <CODE>.properties</CODE> file, the <CODE>msgcat</CODE>
program can be used with the option <CODE>--properties-output</CODE>.  To convert
a <CODE>.properties</CODE> file back to a PO file, the <CODE>msgcat</CODE> program
can be used with the option <CODE>--properties-input</CODE>.  All the tools
that manipulate PO files can work with <CODE>.properties</CODE> files as well,
if given the <CODE>--properties-input</CODE> and/or <CODE>--properties-output</CODE>
option.

</P>
<P>
To convert a PO file to a ResourceBundle class, the <CODE>msgfmt</CODE> program
can be used with the option <CODE>--java</CODE> or <CODE>--java2</CODE>.  To convert a
ResourceBundle back to a PO file, the <CODE>msgunfmt</CODE> program can be used
with the option <CODE>--java</CODE>.

</P>
<P>
Two different programmatic APIs can be used to access ResourceBundles.
Note that both APIs work with all kinds of ResourceBundles, whether
GNU gettext generated classes, or other <CODE>.class</CODE> or <CODE>.properties</CODE>
files.

</P>

<OL>
<LI>

The <CODE>java.util.ResourceBundle</CODE> API.

In particular, its <CODE>getString</CODE> function returns a string translation.
Note that a missing translation yields a <CODE>MissingResourceException</CODE>.

This has the advantage of being the standard API.  And it does not require
any additional libraries, only the <CODE>msgcat</CODE> generated <CODE>.properties</CODE>
files or the <CODE>msgfmt</CODE> generated <CODE>.class</CODE> files.  But it cannot do
plural handling, even if the resource was generated by <CODE>msgfmt</CODE> from
a PO file with plural handling.

<LI>

The <CODE>gnu.gettext.GettextResource</CODE> API.

Reference documentation in Javadoc 1.1 style format
is in the <A HREF="javadoc1/tree.html">javadoc1 directory</A> and
in Javadoc 2 style format
in the <A HREF="javadoc2/index.html">javadoc2 directory</A>.

Its <CODE>gettext</CODE> function returns a string translation.  Note that when
a translation is missing, the <VAR>msgid</VAR> argument is returned unchanged.

This has the advantage of having the <CODE>ngettext</CODE> function for plural
handling.

<A NAME="IDX1172"></A>
To use this API, one needs the <CODE>libintl.jar</CODE> file which is part of
the GNU gettext package and distributed under the LGPL.
</OL>

<P>
Three examples, using the second API, are available in the <TT>&lsquo;examples&rsquo;</TT>
directory: <CODE>hello-java</CODE>, <CODE>hello-java-awt</CODE>, <CODE>hello-java-swing</CODE>.

</P>
<P>
Now, to make use of the API and define a shorthand for <SAMP>&lsquo;getString&rsquo;</SAMP>,
there are three idioms that you can choose from:

</P>

<UL>
<LI>

(This one assumes Java 1.5 or newer.)
In a unique class of your project, say <SAMP>&lsquo;Util&rsquo;</SAMP>, define a static variable
holding the <CODE>ResourceBundle</CODE> instance and the shorthand:


<PRE>
private static ResourceBundle myResources =
  ResourceBundle.getBundle("domain-name");
public static String _(String s) {
  return myResources.getString(s);
}
</PRE>

All classes containing internationalized strings then contain


<PRE>
import static Util._;
</PRE>

and the shorthand is used like this:


<PRE>
System.out.println(_("Operation completed."));
</PRE>

<LI>

In a unique class of your project, say <SAMP>&lsquo;Util&rsquo;</SAMP>, define a static variable
holding the <CODE>ResourceBundle</CODE> instance:


<PRE>
public static ResourceBundle myResources =
  ResourceBundle.getBundle("domain-name");
</PRE>

All classes containing internationalized strings then contain


<PRE>
private static ResourceBundle res = Util.myResources;
private static String _(String s) { return res.getString(s); }
</PRE>

and the shorthand is used like this:


<PRE>
System.out.println(_("Operation completed."));
</PRE>

<LI>

You add a class with a very short name, say <SAMP>&lsquo;S&rsquo;</SAMP>, containing just the
definition of the resource bundle and of the shorthand:


<PRE>
public class S {
  public static ResourceBundle myResources =
    ResourceBundle.getBundle("domain-name");
  public static String _(String s) {
    return myResources.getString(s);
  }
}
</PRE>

and the shorthand is used like this:


<PRE>
System.out.println(S._("Operation completed."));
</PRE>

</UL>

<P>
Which of the three idioms you choose, will depend on whether your project
requires portability to Java versions prior to Java 1.5 and, if so, whether
copying two lines of codes into every class is more acceptable in your project
than a class with a single-letter name.

</P>


<H3><A NAME="SEC273" HREF="gettext_toc.html#TOC273">15.5.12  C#</A></H3>
<P>
<A NAME="IDX1173"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
pnet, pnetlib 0.6.2 or newer, or mono 0.29 or newer

<DT>File extension
<DD>
<CODE>cs</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>, <CODE>@"abc"</CODE>

<DT>gettext shorthand
<DD>
_("abc")

<DT>gettext/ngettext functions
<DD>
<CODE>GettextResourceManager.GetString</CODE>,
<CODE>GettextResourceManager.GetPluralString</CODE>

<DT>textdomain
<DD>
<CODE>new GettextResourceManager(domain)</CODE>

<DT>bindtextdomain
<DD>
---, compiled message catalogs are located in subdirectories of the directory
containing the executable

<DT>setlocale
<DD>
automatic

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
---, uses a C# specific message catalog format

<DT>Extractor
<DD>
<CODE>xgettext -k_</CODE>

<DT>Formatting with positions
<DD>
<CODE>String.Format "{1} {0}"</CODE>

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
Before marking strings as internationalizable, uses of the string
concatenation operator need to be converted to <CODE>String.Format</CODE>
invocations.  For example, <CODE>"file "+filename+" not found"</CODE> becomes
<CODE>String.Format("file {0} not found", filename)</CODE>.
Only after this is done, can the strings be marked and extracted.

</P>
<P>
GNU gettext uses the native C#/.NET internationalization mechanism, namely
the classes <CODE>ResourceManager</CODE> and <CODE>ResourceSet</CODE>.  Applications
use the <CODE>ResourceManager</CODE> methods to retrieve the native language
translation of strings.  An instance of <CODE>ResourceSet</CODE> is the in-memory
representation of a message catalog file.  The <CODE>ResourceManager</CODE> loads
and accesses <CODE>ResourceSet</CODE> instances as needed to look up the
translations.

</P>
<P>
There are two formats of <CODE>ResourceSet</CODE>s that can be directly loaded by
the C# runtime: <CODE>.resources</CODE> files and <CODE>.dll</CODE> files.

</P>

<UL>
<LI>

The <CODE>.resources</CODE> format is a binary file usually generated through the
<CODE>resgen</CODE> or <CODE>monoresgen</CODE> utility, but which doesn't support plural
forms.  <CODE>.resources</CODE> files can also be embedded in .NET <CODE>.exe</CODE> files.
This only affects whether a file system access is performed to load the message
catalog; it doesn't affect the contents of the message catalog.

<LI>

On the other hand, the <CODE>.dll</CODE> format is a binary file that is compiled
from <CODE>.cs</CODE> source code and can support plural forms (provided it is
accessed through the GNU gettext API, see below).
</UL>

<P>
Note that these .NET <CODE>.dll</CODE> and <CODE>.exe</CODE> files are not tied to a
particular platform; their file format and GNU gettext for C# can be used
on any platform.

</P>
<P>
To convert a PO file to a <CODE>.resources</CODE> file, the <CODE>msgfmt</CODE> program
can be used with the option <SAMP>&lsquo;--csharp-resources&rsquo;</SAMP>.  To convert a
<CODE>.resources</CODE> file back to a PO file, the <CODE>msgunfmt</CODE> program can be
used with the option <SAMP>&lsquo;--csharp-resources&rsquo;</SAMP>.  You can also, in some cases,
use the <CODE>resgen</CODE> program (from the <CODE>pnet</CODE> package) or the
<CODE>monoresgen</CODE> program (from the <CODE>mono</CODE>/<CODE>mcs</CODE> package).  These
programs can also convert a <CODE>.resources</CODE> file back to a PO file.  But
beware: as of this writing (January 2004), the <CODE>monoresgen</CODE> converter is
quite buggy and the <CODE>resgen</CODE> converter ignores the encoding of the PO
files.

</P>
<P>
To convert a PO file to a <CODE>.dll</CODE> file, the <CODE>msgfmt</CODE> program can be
used with the option <CODE>--csharp</CODE>.  The result will be a <CODE>.dll</CODE> file
containing a subclass of <CODE>GettextResourceSet</CODE>, which itself is a subclass
of <CODE>ResourceSet</CODE>.  To convert a <CODE>.dll</CODE> file containing a
<CODE>GettextResourceSet</CODE> subclass back to a PO file, the <CODE>msgunfmt</CODE>
program can be used with the option <CODE>--csharp</CODE>.

</P>
<P>
The advantages of the <CODE>.dll</CODE> format over the <CODE>.resources</CODE> format
are:

</P>

<OL>
<LI>

Freedom to localize: Users can add their own translations to an application
after it has been built and distributed.  Whereas when the programmer uses
a <CODE>ResourceManager</CODE> constructor provided by the system, the set of
<CODE>.resources</CODE> files for an application must be specified when the
application is built and cannot be extended afterwards.

<LI>

Plural handling: A message catalog in <CODE>.dll</CODE> format supports the plural
handling function <CODE>GetPluralString</CODE>.  Whereas <CODE>.resources</CODE> files can
only contain data and only support lookups that depend on a single string.

<LI>

The <CODE>GettextResourceManager</CODE> that loads the message catalogs in
<CODE>.dll</CODE> format also provides for inheritance on a per-message basis.
For example, in Austrian (<CODE>de_AT</CODE>) locale, translations from the German
(<CODE>de</CODE>) message catalog will be used for messages not found in the
Austrian message catalog.  This has the consequence that the Austrian
translators need only translate those few messages for which the translation
into Austrian differs from the German one.  Whereas when working with
<CODE>.resources</CODE> files, each message catalog must provide the translations
of all messages by itself.

<LI>

The <CODE>GettextResourceManager</CODE> that loads the message catalogs in
<CODE>.dll</CODE> format also provides for a fallback: The English <VAR>msgid</VAR> is
returned when no translation can be found.  Whereas when working with
<CODE>.resources</CODE> files, a language-neutral <CODE>.resources</CODE> file must
explicitly be provided as a fallback.
</OL>

<P>
On the side of the programmatic APIs, the programmer can use either the
standard <CODE>ResourceManager</CODE> API and the GNU <CODE>GettextResourceManager</CODE>
API.  The latter is an extension of the former, because
<CODE>GettextResourceManager</CODE> is a subclass of <CODE>ResourceManager</CODE>.

</P>

<OL>
<LI>

The <CODE>System.Resources.ResourceManager</CODE> API.

This API works with resources in <CODE>.resources</CODE> format.

The creation of the <CODE>ResourceManager</CODE> is done through

<PRE>
  new ResourceManager(domainname, Assembly.GetExecutingAssembly())
</PRE>


The <CODE>GetString</CODE> function returns a string's translation.  Note that this
function returns null when a translation is missing (i.e. not even found in
the fallback resource file).

<LI>

The <CODE>GNU.Gettext.GettextResourceManager</CODE> API.

This API works with resources in <CODE>.dll</CODE> format.

Reference documentation is in the
<A HREF="csharpdoc/index.html">csharpdoc directory</A>.

The creation of the <CODE>ResourceManager</CODE> is done through

<PRE>
  new GettextResourceManager(domainname)
</PRE>

The <CODE>GetString</CODE> function returns a string's translation.  Note that when
a translation is missing, the <VAR>msgid</VAR> argument is returned unchanged.

The <CODE>GetPluralString</CODE> function returns a string translation with plural
handling, like the <CODE>ngettext</CODE> function in C.

<A NAME="IDX1174"></A>
To use this API, one needs the <CODE>GNU.Gettext.dll</CODE> file which is part of
the GNU gettext package and distributed under the LGPL.
</OL>

<P>
You can also mix both approaches: use the
<CODE>GNU.Gettext.GettextResourceManager</CODE> constructor, but otherwise use
only the <CODE>ResourceManager</CODE> type and only the <CODE>GetString</CODE> method.
This is appropriate when you want to profit from the tools for PO files,
but don't want to change an existing source code that uses
<CODE>ResourceManager</CODE> and don't (yet) need the <CODE>GetPluralString</CODE> method.

</P>
<P>
Two examples, using the second API, are available in the <TT>&lsquo;examples&rsquo;</TT>
directory: <CODE>hello-csharp</CODE>, <CODE>hello-csharp-forms</CODE>.

</P>
<P>
Now, to make use of the API and define a shorthand for <SAMP>&lsquo;GetString&rsquo;</SAMP>,
there are two idioms that you can choose from:

</P>

<UL>
<LI>

In a unique class of your project, say <SAMP>&lsquo;Util&rsquo;</SAMP>, define a static variable
holding the <CODE>ResourceManager</CODE> instance:


<PRE>
public static GettextResourceManager MyResourceManager =
  new GettextResourceManager("domain-name");
</PRE>

All classes containing internationalized strings then contain


<PRE>
private static GettextResourceManager Res = Util.MyResourceManager;
private static String _(String s) { return Res.GetString(s); }
</PRE>

and the shorthand is used like this:


<PRE>
Console.WriteLine(_("Operation completed."));
</PRE>

<LI>

You add a class with a very short name, say <SAMP>&lsquo;S&rsquo;</SAMP>, containing just the
definition of the resource manager and of the shorthand:


<PRE>
public class S {
  public static GettextResourceManager MyResourceManager =
    new GettextResourceManager("domain-name");
  public static String _(String s) {
     return MyResourceManager.GetString(s);
  }
}
</PRE>

and the shorthand is used like this:


<PRE>
Console.WriteLine(S._("Operation completed."));
</PRE>

</UL>

<P>
Which of the two idioms you choose, will depend on whether copying two lines
of codes into every class is more acceptable in your project than a class
with a single-letter name.

</P>


<H3><A NAME="SEC274" HREF="gettext_toc.html#TOC274">15.5.13  GNU awk</A></H3>
<P>
<A NAME="IDX1175"></A>
<A NAME="IDX1176"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
gawk 3.1 or newer

<DT>File extension
<DD>
<CODE>awk</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>_"abc"</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>dcgettext</CODE>, missing <CODE>dcngettext</CODE> in gawk-3.1.0

<DT>textdomain
<DD>
<CODE>TEXTDOMAIN</CODE> variable

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>setlocale
<DD>
automatic, but missing <CODE>setlocale (LC_MESSAGES, "")</CODE> in gawk-3.1.0

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>printf "%2$d %1$d"</CODE> (GNU awk only)

<DT>Portability
<DD>
On platforms without gettext, no translation.  On non-GNU awks, you must
define <CODE>dcgettext</CODE>, <CODE>dcngettext</CODE> and <CODE>bindtextdomain</CODE>
yourself.

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-gawk</CODE>.

</P>


<H3><A NAME="SEC275" HREF="gettext_toc.html#TOC275">15.5.14  Pascal - Free Pascal Compiler</A></H3>
<P>
<A NAME="IDX1177"></A>
<A NAME="IDX1178"></A>
<A NAME="IDX1179"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
fpk

<DT>File extension
<DD>
<CODE>pp</CODE>, <CODE>pas</CODE>

<DT>String syntax
<DD>
<CODE>'abc'</CODE>

<DT>gettext shorthand
<DD>
automatic

<DT>gettext/ngettext functions
<DD>
---, use <CODE>ResourceString</CODE> data type instead

<DT>textdomain
<DD>
---, use <CODE>TranslateResourceStrings</CODE> function instead

<DT>bindtextdomain
<DD>
---, use <CODE>TranslateResourceStrings</CODE> function instead

<DT>setlocale
<DD>
automatic, but uses only LANG, not LC_MESSAGES or LC_ALL

<DT>Prerequisite
<DD>
<CODE>{$mode delphi}</CODE> or <CODE>{$mode objfpc}</CODE><BR><CODE>uses gettext;</CODE>

<DT>Use or emulate GNU gettext
<DD>
emulate partially

<DT>Extractor
<DD>
<CODE>ppc386</CODE> followed by <CODE>xgettext</CODE> or <CODE>rstconv</CODE>

<DT>Formatting with positions
<DD>
<CODE>uses sysutils;</CODE><BR><CODE>format "%1:d %0:d"</CODE>

<DT>Portability
<DD>
?

<DT>po-mode marking
<DD>
---
</DL>

<P>
The Pascal compiler has special support for the <CODE>ResourceString</CODE> data
type.  It generates a <CODE>.rst</CODE> file.  This is then converted to a
<CODE>.pot</CODE> file by use of <CODE>xgettext</CODE> or <CODE>rstconv</CODE>.  At runtime,
a <CODE>.mo</CODE> file corresponding to translations of this <CODE>.pot</CODE> file
can be loaded using the <CODE>TranslateResourceStrings</CODE> function in the
<CODE>gettext</CODE> unit.

</P>
<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-pascal</CODE>.

</P>


<H3><A NAME="SEC276" HREF="gettext_toc.html#TOC276">15.5.15  wxWidgets library</A></H3>
<P>
<A NAME="IDX1180"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
wxGTK, gettext

<DT>File extension
<DD>
<CODE>cpp</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>_("abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>wxLocale::GetString</CODE>, <CODE>wxGetTranslation</CODE>

<DT>textdomain
<DD>
<CODE>wxLocale::AddCatalog</CODE>

<DT>bindtextdomain
<DD>
<CODE>wxLocale::AddCatalogLookupPathPrefix</CODE>

<DT>setlocale
<DD>
<CODE>wxLocale::Init</CODE>, <CODE>wxSetLocale</CODE>

<DT>Prerequisite
<DD>
<CODE>#include &#60;wx/intl.h&#62;</CODE>

<DT>Use or emulate GNU gettext
<DD>
emulate, see <CODE>include/wx/intl.h</CODE> and <CODE>src/common/intl.cpp</CODE>

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
wxString::Format supports positions if and only if the system has
<CODE>wprintf()</CODE>, <CODE>vswprintf()</CODE> functions and they support positions
according to POSIX.

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
yes
</DL>



<H3><A NAME="SEC277" HREF="gettext_toc.html#TOC277">15.5.16  YCP - YaST2 scripting language</A></H3>
<P>
<A NAME="IDX1181"></A>
<A NAME="IDX1182"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
libycp, libycp-devel, yast2-core, yast2-core-devel

<DT>File extension
<DD>
<CODE>ycp</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>_("abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>_()</CODE> with 1 or 3 arguments

<DT>textdomain
<DD>
<CODE>textdomain</CODE> statement

<DT>bindtextdomain
<DD>
---

<DT>setlocale
<DD>
---

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>sformat "%2 %1"</CODE>

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-ycp</CODE>.

</P>


<H3><A NAME="SEC278" HREF="gettext_toc.html#TOC278">15.5.17  Tcl - Tk's scripting language</A></H3>
<P>
<A NAME="IDX1183"></A>
<A NAME="IDX1184"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
tcl

<DT>File extension
<DD>
<CODE>tcl</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>[_ "abc"]</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>::msgcat::mc</CODE>

<DT>textdomain
<DD>
---

<DT>bindtextdomain
<DD>
---, use <CODE>::msgcat::mcload</CODE> instead

<DT>setlocale
<DD>
automatic, uses LANG, but ignores LC_MESSAGES and LC_ALL

<DT>Prerequisite
<DD>
<CODE>package require msgcat</CODE>
<BR><CODE>proc _ {s} {return [::msgcat::mc $s]}</CODE>

<DT>Use or emulate GNU gettext
<DD>
---, uses a Tcl specific message catalog format

<DT>Extractor
<DD>
<CODE>xgettext -k_</CODE>

<DT>Formatting with positions
<DD>
<CODE>format "%2\$d %1\$d"</CODE>

<DT>Portability
<DD>
fully portable

<DT>po-mode marking
<DD>
---
</DL>

<P>
Two examples are available in the <TT>&lsquo;examples&rsquo;</TT> directory:
<CODE>hello-tcl</CODE>, <CODE>hello-tcl-tk</CODE>.

</P>
<P>
Before marking strings as internationalizable, substitutions of variables
into the string need to be converted to <CODE>format</CODE> applications.  For
example, <CODE>"file $filename not found"</CODE> becomes
<CODE>[format "file %s not found" $filename]</CODE>.
Only after this is done, can the strings be marked and extracted.
After marking, this example becomes
<CODE>[format [_ "file %s not found"] $filename]</CODE> or
<CODE>[msgcat::mc "file %s not found" $filename]</CODE>.  Note that the
<CODE>msgcat::mc</CODE> function implicitly calls <CODE>format</CODE> when more than one
argument is given.

</P>


<H3><A NAME="SEC279" HREF="gettext_toc.html#TOC279">15.5.18  Perl</A></H3>
<P>
<A NAME="IDX1185"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
perl

<DT>File extension
<DD>
<CODE>pl</CODE>, <CODE>PL</CODE>, <CODE>pm</CODE>, <CODE>cgi</CODE>

<DT>String syntax
<DD>

<UL>

<LI><CODE>"abc"</CODE>

<LI><CODE>'abc'</CODE>

<LI><CODE>qq (abc)</CODE>

<LI><CODE>q (abc)</CODE>

<LI><CODE>qr /abc/</CODE>

<LI><CODE>qx (/bin/date)</CODE>

<LI><CODE>/pattern match/</CODE>

<LI><CODE>?pattern match?</CODE>

<LI><CODE>s/substitution/operators/</CODE>

<LI><CODE>$tied_hash{"message"}</CODE>

<LI><CODE>$tied_hash_reference-&#62;{"message"}</CODE>

<LI>etc., issue the command <SAMP>&lsquo;man perlsyn&rsquo;</SAMP> for details

</UL>

<DT>gettext shorthand
<DD>
<CODE>__</CODE> (double underscore)

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE>, <CODE>ngettext</CODE>,
<CODE>dngettext</CODE>, <CODE>dcngettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE> function

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>bind_textdomain_codeset
<DD>
<CODE>bind_textdomain_codeset</CODE> function

<DT>setlocale
<DD>
Use <CODE>setlocale (LC_ALL, "");</CODE>

<DT>Prerequisite
<DD>
<CODE>use POSIX;</CODE>
<BR><CODE>use Locale::TextDomain;</CODE> (included in the package libintl-perl
which is available on the Comprehensive Perl Archive Network CPAN,
http://www.cpan.org/).

<DT>Use or emulate GNU gettext
<DD>
platform dependent: gettext_pp emulates, gettext_xs uses GNU gettext

<DT>Extractor
<DD>
<CODE>xgettext -k__ -k\$__ -k%__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -kN__ -k</CODE>

<DT>Formatting with positions
<DD>
Both kinds of format strings support formatting with positions.
<BR><CODE>printf "%2\$d %1\$d", ...</CODE> (requires Perl 5.8.0 or newer)
<BR><CODE>__expand("[new] replaces [old]", old =&#62; $oldvalue, new =&#62; $newvalue)</CODE>

<DT>Portability
<DD>
The <CODE>libintl-perl</CODE> package is platform independent but is not
part of the Perl core.  The programmer is responsible for
providing a dummy implementation of the required functions if the 
package is not installed on the target system.

<DT>po-mode marking
<DD>
---

<DT>Documentation
<DD>
Included in <CODE>libintl-perl</CODE>, available on CPAN
(http://www.cpan.org/).

</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-perl</CODE>.

</P>
<P>
<A NAME="IDX1186"></A>

</P>
<P>
The <CODE>xgettext</CODE> parser backend for Perl differs significantly from
the parser backends for other programming languages, just as Perl
itself differs significantly from other programming languages.  The
Perl parser backend offers many more string marking facilities than
the other backends but it also has some Perl specific limitations, the
worst probably being its imperfectness.

</P>



<H4><A NAME="SEC280" HREF="gettext_toc.html#TOC280">15.5.18.1  General Problems Parsing Perl Code</A></H4>

<P>
It is often heard that only Perl can parse Perl.  This is not true.
Perl cannot be <EM>parsed</EM> at all, it can only be <EM>executed</EM>.
Perl has various built-in ambiguities that can only be resolved at runtime.

</P>
<P>
The following example may illustrate one common problem:

</P>

<PRE>
print gettext "Hello World!";
</PRE>

<P>
Although this example looks like a bullet-proof case of a function
invocation, it is not:

</P>

<PRE>
open gettext, "&#62;testfile" or die;
print gettext "Hello world!"
</PRE>

<P>
In this context, the string <CODE>gettext</CODE> looks more like a
file handle.  But not necessarily:

</P>

<PRE>
use Locale::Messages qw (:libintl_h);
open gettext "&#62;testfile" or die;
print gettext "Hello world!";
</PRE>

<P>
Now, the file is probably syntactically incorrect, provided that the module
<CODE>Locale::Messages</CODE> found first in the Perl include path exports a
function <CODE>gettext</CODE>.  But what if the module
<CODE>Locale::Messages</CODE> really looks like this?

</P>

<PRE>
use vars qw (*gettext);

1;
</PRE>

<P>
In this case, the string <CODE>gettext</CODE> will be interpreted as a file
handle again, and the above example will create a file <TT>&lsquo;testfile&rsquo;</TT>
and write the string “Hello world!” into it.  Even advanced
control flow analysis will not really help:

</P>

<PRE>
if (0.5 &#60; rand) {
   eval "use Sane";
} else {
   eval "use InSane";
}
print gettext "Hello world!";
</PRE>

<P>
If the module <CODE>Sane</CODE> exports a function <CODE>gettext</CODE> that does
what we expect, and the module <CODE>InSane</CODE> opens a file for writing
and associates the <EM>handle</EM> <CODE>gettext</CODE> with this output
stream, we are clueless again about what will happen at runtime.  It is
completely unpredictable.  The truth is that Perl has so many ways to
fill its symbol table at runtime that it is impossible to interpret a
particular piece of code without executing it.

</P>
<P>
Of course, <CODE>xgettext</CODE> will not execute your Perl sources while
scanning for translatable strings, but rather use heuristics in order
to guess what you meant.

</P>
<P>
Another problem is the ambiguity of the slash and the question mark.
Their interpretation depends on the context:

</P>

<PRE>
# A pattern match.
print "OK\n" if /foobar/;

# A division.
print 1 / 2;

# Another pattern match.
print "OK\n" if ?foobar?;

# Conditional.
print $x ? "foo" : "bar";
</PRE>

<P>
The slash may either act as the division operator or introduce a
pattern match, whereas the question mark may act as the ternary
conditional operator or as a pattern match, too.  Other programming
languages like <CODE>awk</CODE> present similar problems, but the consequences of a
misinterpretation are particularly nasty with Perl sources.  In <CODE>awk</CODE>
for instance, a statement can never exceed one line and the parser
can recover from a parsing error at the next newline and interpret
the rest of the input stream correctly.  Perl is different, as a
pattern match is terminated by the next appearance of the delimiter
(the slash or the question mark) in the input stream, regardless of
the semantic context.  If a slash is really a division sign but
mis-interpreted as a pattern match, the rest of the input file is most
probably parsed incorrectly.

</P>
<P>
If you find that <CODE>xgettext</CODE> fails to extract strings from
portions of your sources, you should therefore look out for slashes
and/or question marks preceding these sections.  You may have come
across a bug in <CODE>xgettext</CODE>'s Perl parser (and of course you
should report that bug).  In the meantime you should consider to
reformulate your code in a manner less challenging to <CODE>xgettext</CODE>.

</P>


<H4><A NAME="SEC281" HREF="gettext_toc.html#TOC281">15.5.18.2  Which keywords will xgettext look for?</A></H4>
<P>
<A NAME="IDX1187"></A>

</P>
<P>
Unless you instruct <CODE>xgettext</CODE> otherwise by invoking it with one
of the options <CODE>--keyword</CODE> or <CODE>-k</CODE>, it will recognize the
following keywords in your Perl sources:

</P>

<UL>

<LI><CODE>gettext</CODE>

<LI><CODE>dgettext</CODE>

<LI><CODE>dcgettext</CODE>

<LI><CODE>ngettext:1,2</CODE>

The first (singular) and the second (plural) argument will be
extracted.

<LI><CODE>dngettext:1,2</CODE>

The first (singular) and the second (plural) argument will be
extracted.

<LI><CODE>dcngettext:1,2</CODE>

The first (singular) and the second (plural) argument will be
extracted.

<LI><CODE>gettext_noop</CODE>

<LI><CODE>%gettext</CODE>

The keys of lookups into the hash <CODE>%gettext</CODE> will be extracted.

<LI><CODE>$gettext</CODE>

The keys of lookups into the hash reference <CODE>$gettext</CODE> will be extracted.

</UL>



<H4><A NAME="SEC282" HREF="gettext_toc.html#TOC282">15.5.18.3  How to Extract Hash Keys</A></H4>
<P>
<A NAME="IDX1188"></A>

</P>
<P>
Translating messages at runtime is normally performed by looking up the
original string in the translation database and returning the
translated version.  The “natural” Perl implementation is a hash
lookup, and, of course, <CODE>xgettext</CODE> supports such practice.

</P>

<PRE>
print __"Hello world!";
print $__{"Hello world!"};
print $__-&#62;{"Hello world!"};
print $$__{"Hello world!"};
</PRE>

<P>
The above four lines all do the same thing.  The Perl module 
<CODE>Locale::TextDomain</CODE> exports by default a hash <CODE>%__</CODE> that
is tied to the function <CODE>__()</CODE>.  It also exports a reference
<CODE>$__</CODE> to <CODE>%__</CODE>.

</P>
<P>
If an argument to the <CODE>xgettext</CODE> option <CODE>--keyword</CODE>,
resp. <CODE>-k</CODE> starts with a percent sign, the rest of the keyword is
interpreted as the name of a hash.  If it starts with a dollar
sign, the rest of the keyword is interpreted as a reference to a
hash.

</P>
<P>
Note that you can omit the quotation marks (single or double) around
the hash key (almost) whenever Perl itself allows it:

</P>

<PRE>
print $gettext{Error};
</PRE>

<P>
The exact rule is: You can omit the surrounding quotes, when the hash
key is a valid C (!) identifier, i.e. when it starts with an
underscore or an ASCII letter and is followed by an arbitrary number
of underscores, ASCII letters or digits.  Other Unicode characters
are <EM>not</EM> allowed, regardless of the <CODE>use utf8</CODE> pragma.

</P>


<H4><A NAME="SEC283" HREF="gettext_toc.html#TOC283">15.5.18.4  What are Strings And Quote-like Expressions?</A></H4>
<P>
<A NAME="IDX1189"></A>

</P>
<P>
Perl offers a plethora of different string constructs.  Those that can
be used either as arguments to functions or inside braces for hash
lookups are generally supported by <CODE>xgettext</CODE>.  

</P>

<UL>
<LI><STRONG>double-quoted strings</STRONG>

<BR>

<PRE>
print gettext "Hello World!";
</PRE>

<LI><STRONG>single-quoted strings</STRONG>

<BR>

<PRE>
print gettext 'Hello World!';
</PRE>

<LI><STRONG>the operator qq</STRONG>

<BR>

<PRE>
print gettext qq |Hello World!|;
print gettext qq &#60;E-mail: &#60;guido\@imperia.net&#62;&#62;;
</PRE>

The operator <CODE>qq</CODE> is fully supported.  You can use arbitrary
delimiters, including the four bracketing delimiters (round, angle,
square, curly) that nest.

<LI><STRONG>the operator q</STRONG>

<BR>

<PRE>
print gettext q |Hello World!|;
print gettext q &#60;E-mail: &#60;guido@imperia.net&#62;&#62;;
</PRE>

The operator <CODE>q</CODE> is fully supported.  You can use arbitrary
delimiters, including the four bracketing delimiters (round, angle,
square, curly) that nest.

<LI><STRONG>the operator qx</STRONG>

<BR>

<PRE>
print gettext qx ;LANGUAGE=C /bin/date;
print gettext qx [/usr/bin/ls | grep '^[A-Z]*'];
</PRE>

The operator <CODE>qx</CODE> is fully supported.  You can use arbitrary
delimiters, including the four bracketing delimiters (round, angle,
square, curly) that nest.

The example is actually a useless use of <CODE>gettext</CODE>.  It will
invoke the <CODE>gettext</CODE> function on the output of the command
specified with the <CODE>qx</CODE> operator.  The feature was included
in order to make the interface consistent (the parser will extract
all strings and quote-like expressions).

<LI><STRONG>here documents</STRONG>

<BR>

<PRE>
print gettext &#60;&#60;'EOF';
program not found in $PATH
EOF

print ngettext &#60;&#60;EOF, &#60;&#60;"EOF";
one file deleted
EOF
several files deleted
EOF
</PRE>

Here-documents are recognized.  If the delimiter is enclosed in single
quotes, the string is not interpolated.  If it is enclosed in double
quotes or has no quotes at all, the string is interpolated.

Delimiters that start with a digit are not supported!

</UL>



<H4><A NAME="SEC284" HREF="gettext_toc.html#TOC284">15.5.18.5  Invalid Uses Of String Interpolation</A></H4>
<P>
<A NAME="IDX1190"></A>

</P>
<P>
Perl is capable of interpolating variables into strings.  This offers
some nice features in localized programs but can also lead to
problems.

</P>
<P>
A common error is a construct like the following:

</P>

<PRE>
print gettext "This is the program $0!\n";
</PRE>

<P>
Perl will interpolate at runtime the value of the variable <CODE>$0</CODE>
into the argument of the <CODE>gettext()</CODE> function.  Hence, this
argument is not a string constant but a variable argument (<CODE>$0</CODE>
is a global variable that holds the name of the Perl script being
executed).  The interpolation is performed by Perl before the string
argument is passed to <CODE>gettext()</CODE> and will therefore depend on
the name of the script which can only be determined at runtime.
Consequently, it is almost impossible that a translation can be looked
up at runtime (except if, by accident, the interpolated string is found
in the message catalog).

</P>
<P>
The <CODE>xgettext</CODE> program will therefore terminate parsing with a fatal
error if it encounters a variable inside of an extracted string.  In
general, this will happen for all kinds of string interpolations that
cannot be safely performed at compile time.  If you absolutely know
what you are doing, you can always circumvent this behavior:

</P>

<PRE>
my $know_what_i_am_doing = "This is program $0!\n";
print gettext $know_what_i_am_doing;
</PRE>

<P>
Since the parser only recognizes strings and quote-like expressions,
but not variables or other terms, the above construct will be
accepted.  You will have to find another way, however, to let your
original string make it into your message catalog.

</P>
<P>
If invoked with the option <CODE>--extract-all</CODE>, resp. <CODE>-a</CODE>,
variable interpolation will be accepted.  Rationale: You will
generally use this option in order to prepare your sources for
internationalization.

</P>
<P>
Please see the manual page <SAMP>&lsquo;man perlop&rsquo;</SAMP> for details of strings and
quote-like expressions that are subject to interpolation and those
that are not.  Safe interpolations (that will not lead to a fatal
error) are:

</P>

<UL>

<LI>the escape sequences <CODE>\t</CODE> (tab, HT, TAB), <CODE>\n</CODE>

(newline, NL), <CODE>\r</CODE> (return, CR), <CODE>\f</CODE> (form feed, FF),
<CODE>\b</CODE> (backspace, BS), <CODE>\a</CODE> (alarm, bell, BEL), and <CODE>\e</CODE>
(escape, ESC).

<LI>octal chars, like <CODE>\033</CODE>

<BR>
Note that octal escapes in the range of 400-777 are translated into a 
UTF-8 representation, regardless of the presence of the <CODE>use utf8</CODE> pragma.

<LI>hex chars, like <CODE>\x1b</CODE>

<LI>wide hex chars, like <CODE>\x{263a}</CODE>

<BR>
Note that this escape is translated into a UTF-8 representation,
regardless of the presence of the <CODE>use utf8</CODE> pragma.

<LI>control chars, like <CODE>\c[</CODE> (CTRL-[)

<LI>named Unicode chars, like <CODE>\N{LATIN CAPITAL LETTER C WITH CEDILLA}</CODE>

<BR>
Note that this escape is translated into a UTF-8 representation,
regardless of the presence of the <CODE>use utf8</CODE> pragma.
</UL>

<P>
The following escapes are considered partially safe:

</P>

<UL>

<LI><CODE>\l</CODE> lowercase next char

<LI><CODE>\u</CODE> uppercase next char

<LI><CODE>\L</CODE> lowercase till \E

<LI><CODE>\U</CODE> uppercase till \E

<LI><CODE>\E</CODE> end case modification

<LI><CODE>\Q</CODE> quote non-word characters till \E

</UL>

<P>
These escapes are only considered safe if the string consists of
ASCII characters only.  Translation of characters outside the range
defined by ASCII is locale-dependent and can actually only be performed 
at runtime; <CODE>xgettext</CODE> doesn't do these locale-dependent translations
at extraction time.

</P>
<P>
Except for the modifier <CODE>\Q</CODE>, these translations, albeit valid,
are generally useless and only obfuscate your sources.  If a
translation can be safely performed at compile time you can just as
well write what you mean.

</P>


<H4><A NAME="SEC285" HREF="gettext_toc.html#TOC285">15.5.18.6  Valid Uses Of String Interpolation</A></H4>
<P>
<A NAME="IDX1191"></A>

</P>
<P>
Perl is often used to generate sources for other programming languages
or arbitrary file formats.  Web applications that output HTML code
make a prominent example for such usage.

</P>
<P>
You will often come across situations where you want to intersperse
code written in the target (programming) language with translatable
messages, like in the following HTML example:

</P>

<PRE>
print gettext &#60;&#60;EOF;
&#60;h1&#62;My Homepage&#60;/h1&#62;
&#60;script language="JavaScript"&#62;&#60;!--
for (i = 0; i &#60; 100; ++i) {
    alert ("Thank you so much for visiting my homepage!");
}
//--&#62;&#60;/script&#62;
EOF
</PRE>

<P>
The parser will extract the entire here document, and it will appear
entirely in the resulting PO file, including the JavaScript snippet
embedded in the HTML code.  If you exaggerate with constructs like 
the above, you will run the risk that the translators of your package 
will look out for a less challenging project.  You should consider an 
alternative expression here:

</P>

<PRE>
print &#60;&#60;EOF;
&#60;h1&#62;$gettext{"My Homepage"}&#60;/h1&#62;
&#60;script language="JavaScript"&#62;&#60;!--
for (i = 0; i &#60; 100; ++i) {
    alert ("$gettext{'Thank you so much for visiting my homepage!'}");
}
//--&#62;&#60;/script&#62;
EOF
</PRE>

<P>
Only the translatable portions of the code will be extracted here, and
the resulting PO file will begrudgingly improve in terms of readability.

</P>
<P>
You can interpolate hash lookups in all strings or quote-like
expressions that are subject to interpolation (see the manual page
<SAMP>&lsquo;man perlop&rsquo;</SAMP> for details).  Double interpolation is invalid, however:

</P>

<PRE>
# TRANSLATORS: Replace "the earth" with the name of your planet.
print gettext qq{Welcome to $gettext-&#62;{"the earth"}};
</PRE>

<P>
The <CODE>qq</CODE>-quoted string is recognized as an argument to <CODE>xgettext</CODE> in
the first place, and checked for invalid variable interpolation.  The
dollar sign of hash-dereferencing will therefore terminate the parser 
with an “invalid interpolation” error.

</P>
<P>
It is valid to interpolate hash lookups in regular expressions:

</P>

<PRE>
if ($var =~ /$gettext{"the earth"}/) {
   print gettext "Match!\n";
}
s/$gettext{"U. S. A."}/$gettext{"U. S. A."} $gettext{"(dial +0)"}/g;
</PRE>



<H4><A NAME="SEC286" HREF="gettext_toc.html#TOC286">15.5.18.7  When To Use Parentheses</A></H4>
<P>
<A NAME="IDX1192"></A>

</P>
<P>
In Perl, parentheses around function arguments are mostly optional.
<CODE>xgettext</CODE> will always assume that all
recognized keywords (except for hashes and hash references) are names
of properly prototyped functions, and will (hopefully) only require
parentheses where Perl itself requires them.  All constructs in the
following example are therefore ok to use:

</P>

<PRE>
print gettext ("Hello World!\n");
print gettext "Hello World!\n";
print dgettext ($package =&#62; "Hello World!\n");
print dgettext $package, "Hello World!\n";

# The "fat comma" =&#62; turns the left-hand side argument into a
# single-quoted string!
print dgettext smellovision =&#62; "Hello World!\n";

# The following assignment only works with prototyped functions.
# Otherwise, the functions will act as "greedy" list operators and
# eat up all following arguments.
my $anonymous_hash = {
   planet =&#62; gettext "earth",
   cakes =&#62; ngettext "one cake", "several cakes", $n,
   still =&#62; $works,
};
# The same without fat comma:
my $other_hash = {
   'planet', gettext "earth",
   'cakes', ngettext "one cake", "several cakes", $n,
   'still', $works,
};

# Parentheses are only significant for the first argument.
print dngettext 'package', ("one cake", "several cakes", $n), $discarded;
</PRE>



<H4><A NAME="SEC287" HREF="gettext_toc.html#TOC287">15.5.18.8  How To Grok with Long Lines</A></H4>
<P>
<A NAME="IDX1193"></A>

</P>
<P>
The necessity of long messages can often lead to a cumbersome or
unreadable coding style.  Perl has several options that may prevent
you from writing unreadable code, and
<CODE>xgettext</CODE> does its best to do likewise.  This is where the dot
operator (the string concatenation operator) may come in handy:

</P>

<PRE>
print gettext ("This is a very long"
               . " message that is still"
               . " readable, because"
               . " it is split into"
               . " multiple lines.\n");
</PRE>

<P>
Perl is smart enough to concatenate these constant string fragments
into one long string at compile time, and so is
<CODE>xgettext</CODE>.  You will only find one long message in the resulting
POT file.

</P>
<P>
Note that the future Perl 6 will probably use the underscore
(<SAMP>&lsquo;_&rsquo;</SAMP>) as the string concatenation operator, and the dot 
(<SAMP>&lsquo;.&rsquo;</SAMP>) for dereferencing.  This new syntax is not yet supported by
<CODE>xgettext</CODE>.

</P>
<P>
If embedded newline characters are not an issue, or even desired, you
may also insert newline characters inside quoted strings wherever you
feel like it:

</P>

<PRE>
print gettext ("&#60;em&#62;In HTML output
embedded newlines are generally no
problem, since adjacent whitespace
is always rendered into a single
space character.&#60;/em&#62;");
</PRE>

<P>
You may also consider to use here documents:

</P>

<PRE>
print gettext &#60;&#60;EOF;
&#60;em&#62;In HTML output
embedded newlines are generally no
problem, since adjacent whitespace
is always rendered into a single
space character.&#60;/em&#62;
EOF
</PRE>

<P>
Please do not forget that the line breaks are real, i.e. they
translate into newline characters that will consequently show up in
the resulting POT file.

</P>


<H4><A NAME="SEC288" HREF="gettext_toc.html#TOC288">15.5.18.9  Bugs, Pitfalls, And Things That Do Not Work</A></H4>
<P>
<A NAME="IDX1194"></A>

</P>
<P>
The foregoing sections should have proven that
<CODE>xgettext</CODE> is quite smart in extracting translatable strings from
Perl sources.  Yet, some more or less exotic constructs that could be
expected to work, actually do not work.  

</P>
<P>
One of the more relevant limitations can be found in the
implementation of variable interpolation inside quoted strings.  Only
simple hash lookups can be used there:

</P>

<PRE>
print &#60;&#60;EOF;
$gettext{"The dot operator"
          . " does not work"
          . "here!"}
Likewise, you cannot @{[ gettext ("interpolate function calls") ]}
inside quoted strings or quote-like expressions.
EOF
</PRE>

<P>
This is valid Perl code and will actually trigger invocations of the
<CODE>gettext</CODE> function at runtime.  Yet, the Perl parser in
<CODE>xgettext</CODE> will fail to recognize the strings.  A less obvious
example can be found in the interpolation of regular expressions:

</P>

<PRE>
s/&#60;!--START_OF_WEEK--&#62;/gettext ("Sunday")/e;
</PRE>

<P>
The modifier <CODE>e</CODE> will cause the substitution to be interpreted as
an evaluable statement.  Consequently, at runtime the function
<CODE>gettext()</CODE> is called, but again, the parser fails to extract the
string “Sunday”.  Use a temporary variable as a simple workaround if
you really happen to need this feature:

</P>

<PRE>
my $sunday = gettext "Sunday";
s/&#60;!--START_OF_WEEK--&#62;/$sunday/;
</PRE>

<P>
Hash slices would also be handy but are not recognized:

</P>

<PRE>
my @weekdays = @gettext{'Sunday', 'Monday', 'Tuesday', 'Wednesday',
                        'Thursday', 'Friday', 'Saturday'};
# Or even:
@weekdays = @gettext{qw (Sunday Monday Tuesday Wednesday Thursday
                         Friday Saturday) };
</PRE>

<P>
This is perfectly valid usage of the tied hash <CODE>%gettext</CODE> but the
strings are not recognized and therefore will not be extracted.

</P>
<P>
Another caveat of the current version is its rudimentary support for
non-ASCII characters in identifiers.  You may encounter serious
problems if you use identifiers with characters outside the range of
'A'-'Z', 'a'-'z', '0'-'9' and the underscore '_'.

</P>
<P>
Maybe some of these missing features will be implemented in future
versions, but since you can always make do without them at minimal effort,
these todos have very low priority.

</P>
<P>
A nasty problem are brace format strings that already contain braces
as part of the normal text, for example the usage strings typically
encountered in programs:

</P>

<PRE>
die "usage: $0 {OPTIONS} FILENAME...\n";
</PRE>

<P>
If you want to internationalize this code with Perl brace format strings,
you will run into a problem:

</P>

<PRE>
die __x ("usage: {program} {OPTIONS} FILENAME...\n", program =&#62; $0);
</PRE>

<P>
Whereas <SAMP>&lsquo;{program}&rsquo;</SAMP> is a placeholder, <SAMP>&lsquo;{OPTIONS}&rsquo;</SAMP>
is not and should probably be translated. Yet, there is no way to teach
the Perl parser in <CODE>xgettext</CODE> to recognize the first one, and leave
the other one alone.

</P>
<P>
There are two possible work-arounds for this problem.  If you are
sure that your program will run under Perl 5.8.0 or newer (these
Perl versions handle positional parameters in <CODE>printf()</CODE>) or
if you are sure that the translator will not have to reorder the arguments
in her translation -- for example if you have only one brace placeholder
in your string, or if it describes a syntax, like in this one --, you can
mark the string as <CODE>no-perl-brace-format</CODE> and use <CODE>printf()</CODE>:

</P>

<PRE>
# xgettext: no-perl-brace-format
die sprintf ("usage: %s {OPTIONS} FILENAME...\n", $0);
</PRE>

<P>
If you want to use the more portable Perl brace format, you will have to do
put placeholders in place of the literal braces:

</P>

<PRE>
die __x ("usage: {program} {[}OPTIONS{]} FILENAME...\n",
         program =&#62; $0, '[' =&#62; '{', ']' =&#62; '}');
</PRE>

<P>
Perl brace format strings know no escaping mechanism.  No matter how this
escaping mechanism looked like, it would either give the programmer a
hard time, make translating Perl brace format strings heavy-going, or
result in a performance penalty at runtime, when the format directives
get executed.  Most of the time you will happily get along with
<CODE>printf()</CODE> for this special case.

</P>


<H3><A NAME="SEC289" HREF="gettext_toc.html#TOC289">15.5.19  PHP Hypertext Preprocessor</A></H3>
<P>
<A NAME="IDX1195"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
mod_php4, mod_php4-core, phpdoc

<DT>File extension
<DD>
<CODE>php</CODE>, <CODE>php3</CODE>, <CODE>php4</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>, <CODE>'abc'</CODE>

<DT>gettext shorthand
<DD>
<CODE>_("abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE>; starting with PHP 4.2.0
also <CODE>ngettext</CODE>, <CODE>dngettext</CODE>, <CODE>dcngettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE> function

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>setlocale
<DD>
Programmer must call <CODE>setlocale (LC_ALL, "")</CODE>

<DT>Prerequisite
<DD>
---

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
<CODE>xgettext</CODE>

<DT>Formatting with positions
<DD>
<CODE>printf "%2\$d %1\$d"</CODE>

<DT>Portability
<DD>
On platforms without gettext, the functions are not available.

<DT>po-mode marking
<DD>
---
</DL>

<P>
An example is available in the <TT>&lsquo;examples&rsquo;</TT> directory: <CODE>hello-php</CODE>.

</P>


<H3><A NAME="SEC290" HREF="gettext_toc.html#TOC290">15.5.20  Pike</A></H3>
<P>
<A NAME="IDX1196"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
roxen

<DT>File extension
<DD>
<CODE>pike</CODE>

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
---

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE> function

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>setlocale
<DD>
<CODE>setlocale</CODE> function

<DT>Prerequisite
<DD>
<CODE>import Locale.Gettext;</CODE>

<DT>Use or emulate GNU gettext
<DD>
use

<DT>Extractor
<DD>
---

<DT>Formatting with positions
<DD>
---

<DT>Portability
<DD>
On platforms without gettext, the functions are not available.

<DT>po-mode marking
<DD>
---
</DL>



<H3><A NAME="SEC291" HREF="gettext_toc.html#TOC291">15.5.21  GNU Compiler Collection sources</A></H3>
<P>
<A NAME="IDX1197"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
gcc

<DT>File extension
<DD>
<CODE>c</CODE>, <CODE>h</CODE>.

<DT>String syntax
<DD>
<CODE>"abc"</CODE>

<DT>gettext shorthand
<DD>
<CODE>_("abc")</CODE>

<DT>gettext/ngettext functions
<DD>
<CODE>gettext</CODE>, <CODE>dgettext</CODE>, <CODE>dcgettext</CODE>, <CODE>ngettext</CODE>,
<CODE>dngettext</CODE>, <CODE>dcngettext</CODE>

<DT>textdomain
<DD>
<CODE>textdomain</CODE> function

<DT>bindtextdomain
<DD>
<CODE>bindtextdomain</CODE> function

<DT>setlocale
<DD>
Programmer must call <CODE>setlocale (LC_ALL, "")</CODE>

<DT>Prerequisite
<DD>
<CODE>#include "intl.h"</CODE>

<DT>Use or emulate GNU gettext
<DD>
Use

<DT>Extractor
<DD>
<CODE>xgettext -k_</CODE>

<DT>Formatting with positions
<DD>
---

<DT>Portability
<DD>
Uses autoconf macros

<DT>po-mode marking
<DD>
yes
</DL>



<H2><A NAME="SEC292" HREF="gettext_toc.html#TOC292">15.6  Internationalizable Data</A></H2>

<P>
Here is a list of other data formats which can be internationalized
using GNU gettext.

</P>



<H3><A NAME="SEC293" HREF="gettext_toc.html#TOC293">15.6.1  POT - Portable Object Template</A></H3>

<DL COMPACT>

<DT>RPMs
<DD>
gettext

<DT>File extension
<DD>
<CODE>pot</CODE>, <CODE>po</CODE>

<DT>Extractor
<DD>
<CODE>xgettext</CODE>
</DL>



<H3><A NAME="SEC294" HREF="gettext_toc.html#TOC294">15.6.2  Resource String Table</A></H3>
<P>
<A NAME="IDX1198"></A>

</P>
<DL COMPACT>

<DT>RPMs
<DD>
fpk

<DT>File extension
<DD>
<CODE>rst</CODE>

<DT>Extractor
<DD>
<CODE>xgettext</CODE>, <CODE>rstconv</CODE>
</DL>



<H3><A NAME="SEC295" HREF="gettext_toc.html#TOC295">15.6.3  Glade - GNOME user interface description</A></H3>

<DL COMPACT>

<DT>RPMs
<DD>
glade, libglade, glade2, libglade2, intltool

<DT>File extension
<DD>
<CODE>glade</CODE>, <CODE>glade2</CODE>

<DT>Extractor
<DD>
<CODE>xgettext</CODE>, <CODE>libglade-xgettext</CODE>, <CODE>xml-i18n-extract</CODE>, <CODE>intltool-extract</CODE>
</DL>

<P><HR><P>
Go to the <A HREF="gettext_1.html">first</A>, <A HREF="gettext_14.html">previous</A>, <A HREF="gettext_16.html">next</A>, <A HREF="gettext_25.html">last</A> section, <A HREF="gettext_toc.html">table of contents</A>.
</BODY>
</HTML>