#[1]RSS 2.0 [2]RSS .92 [3]Atom 0.3 [4]Echoreply Computers, Science, Technology, Xen Virtualization, Hosting, The Internet, Geekdom And More * [5]Site Home * [6]Blog Home * [7]RSS * [8]Contact * [9]Legal [10]Interesting internationalization Posted on September 18, 2008 Filed Under [11]Programming | I've been having a rather enjoyable discussion with [12]Lorenzo Bettini, the author of GNU [13]Gengetopt and [14]Gengen. If you are not familiar with Gengetopt, its a tool that simplifies generating the code required for programs to accept options. I [15]talked about gengetopt a while back on this blog. The discussion surrounds support for internationalization, which simply means a program printing output in whatever language your system is using. A very popular means to accomplish this is the GNU gettext library, or its counterpart in various other operating systems. Disclamer, if you do not care about C standards and common UNIX programming, this post will probably bore you to tears. However, your welcome to read on if only to discover how much I value life in boring geeky flavors :) Recently, while working on HelenOS I found the need to implement getopt. I'm working on something a lot like busybox, but from scratch. Rather than re-invent the getopt wheel yet again, I dove into the source code of GNU getopt as well as the various *BSD implementations to find the one that was easiest to port. One thing that stood out at me was that most implementations declared error strings and formats as static, English strings. A week later, a proposal to add gettext support came across the gengetopt mailing list. I voted to not include it because the resulting output would be at best mixed, as error strings in basic C89/C99 libc are hard coded, usually in English. The getopt family of functions are an interesting corner case, most core libc functions never print anything ... they just exit with some value and set a global errno to inform the calling function of what went wrong. Its then up to the calling function to (use or not use) something like gettext to display the information in the appropriate language. This got me thinking .. if we're making a truly modern operating system based on C89/C99 .. internationalization must be easy to leverage. Talking with Lorenzo, some interesting ideas came to light. Gettext is a great tool, however it introduces dependencies on shared objects (or requires static linking). Simply parsing command line arguments should not introduce additional dependencies. Additionally, standard libc should not favor one internationalization library over another, therefore its just not practical to include internationalization in standard libc. However, stuff in libc that prints strings can remain friendly to internationalization by simply requiring one tiny additional step - have the programmer register a callback function that gets all output instead of printing to the error file descriptor directly in libc. For instance, a modern getopt might look like this: void getopt_callback(int level, char *format, int line) { switch (level) { case GETOPT_EOK: fprintf(stdout, "line %d of getopt.c says %s", line, format); break; case GETOPT_EFAIL: fprintf(stderr, "line %d of getopt.c says %s", line, format); break; } return; } int main(int argc, char **argv) { int c, opt_ind; getopt_register_callback(getopt_callback); for (c = 0, optind = 0, opt_ind = 0; c != -1;) { c = getopt_long(argc, argv, "f:o:O", long_options, &opt_ind); ...... As we can see, the getopt implementation does not actually print anything, it allows the callback function to handle that. One could very easily use internationalization tools within the callback, if they wanted to do so. This goes (basically) for anything in core libc that prints anything. The callback may be better typed as something like getopt_callback_t. This seems to be the favorable approach. Of course, getopt would feature its own static callback that printed the strings as-is if the calling function did not register one, this keeps from breaking existing use. After I finish some other tasks, I am going to take a stroll through the HelenOS userspace generic libc to see if getopt is the only case where this should be implemented. At the least, I'll implement this getopt method there so that programs can be fully internationalized. This also shows the virtue of not using printf() directly when you can avoid it. Writing your own functions to print warnings or messages allows someone else (even you) to go back and make only a few minor changes in order for your program to support any language. Working on a new OS that aims to be fully modern presents interesting opportunities to pick things apart. Hopefully, this didn't put you to sleep :) [16]Share this post [17]Submit to Bloglines [18]Submit to Del.icio.us [19]Submit to digg [20]Submit to Facebook [21]Submit to Google Bookmarks [22]Submit to reddit [23]Submit to Slashdot [24]Submit to Stumble Upon [25]Submit to SphereIt [26]Submit to Technorati [27]Submit to Yahoo My Web [28]Hide Sites You might also enjoy reading: * [29]For Concurrency Issues, There Is Music (0) * [30]The Great Microkernel Debate (2) * [31]Xen And Single System Images (0) Tags: [32]helenos, [33]Ideas, [34]interesting, [35]Programming Comments Leave a Reply (NoFollow Free!) Name or nickname(required) ________________________________________ Email Address (kept private)(required) ________________________________________ Website ________________________________________ XHTML: You can use these tags:
__________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ Submit Comment * Recently written + [36]For Concurrency Issues, There Is Music + [37]Django And The Admin Anthem + [38]The Great Microkernel Debate + [39]Xen And Single System Images + [40]Yes, I'm Still Alive + [41]Please adopt /etc/vendor + [42]My list for 2009 + [43]Web pages as graphs * Me According To Ohloh [44]Ohloh profile for Tim Post * Read By Description + [45]Free Software + [46]ohno + [47]haha + [48]GNU + [49]Programming + [50]thinking out loud + [51]interesting + [52]Linux * Twitter + Writing proof of concept code, I may have a new (full time) opportunity. [53]11 days ago + My kernel's OOM killer has become sentient and self aware [54]12 days ago + Wrapping up nexgent for its first alpha release [55]69 days ago * + Blogs I frequent o [56]Corey Henderson o [57]Jakub Jermar o [58]John Hawks o [59]Pavel Rimsky + Current Projects o [60]Ext3cow o [61]Gridnix o [62]HelenOS o [63]My HG Repository o [64]SRCE o [65]Xen Guests + For Developers o [66]Blue - A Programming Language o [67]Mercurial o [68]ShareSource o [69]Stackoverflow * Archives + [70]March 2009 + [71]February 2009 + [72]January 2009 + [73]December 2008 + [74]November 2008 + [75]October 2008 + [76]September 2008 + [77]August 2008 + [78]July 2008 + [79]June 2008 + [80]May 2008 + [81]April 2008 + [82]March 2008 + [83]February 2008 + [84]January 2008 + [85]December 2007 + [86]November 2007 + [87]October 2007 + [88]September 2007 * Penguin * Search + ____________________ * Categories + [89]Better Living + [90]Blogeting + [91]Computing + [92]Free Software + [93]Future Presents + [94]Gizmos + [95]GNU + [96]Humor + [97]Ideas + [98]Linux + [99]Neat Things + [100]Parenting + [101]Programming + [102]Rants + [103]Science + [104]The Web Hosting Industry + [105]Travels + [106]Uncategorized + [107]Xen * Misc + [108]Log in [109]Valid XHTML Copyright © 2007 Tim Post - All Rights Reserved The views and opinions expressed on this web site are my own and not necessarily those of my employers or affiliates. Theme made from [110]many free design elements, [111]powered by Wordpress. References 1. http://echoreply.us/tech/feed/ 2. http://echoreply.us/tech/feed/rss/ 3. http://echoreply.us/tech/feed/atom/ 4. http://echoreply.us/tech/ 5. http://echoreply.us/ 6. http://echoreply.us/tech/ 7. http://echoreply.us/tech/feed/rss2/ 8. http://echoreply.us/tech/contact/ 9. http://echoreply.us/tech/legal/ 10. http://echoreply.us/tech/2008/09/18/interesting-internationalization/ 11. http://echoreply.us/tech/category/programming/ 12. http://www.lorenzobettini.it/ 13. http://www.gnu.org/software/gengetopt/gengetopt.html 14. http://www.gnu.org/software/gengen/ 15. http://echoreply.us/tech/2008/01/08/fun-with-gengetopt/ 16. file://localhost/home/abaumann/projects/WolfBones/docs/i18n/Interesting%20internationalization%20|%20Echoreply.html 17. http://www.bloglines.com/sub/http://echoreply.us/tech/2008/09/18/interesting-internationalization/ 18. http://del.icio.us/post?url=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 19. http://digg.com/submit?phase=2&url=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 20. http://www.facebook.com/sharer.php?u=http://echoreply.us/tech/2008/09/18/interesting-internationalization/ 21. http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 22. http://reddit.com/submit?url=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 23. http://slashdot.org/bookmark.pl?url=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 24. http://www.stumbleupon.com/submit.php?url=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 25. http://www.sphere.com/search?q=sphereit:http://echoreply.us/tech/2008/09/18/interesting-internationalization/&title=Interesting+internationalization 26. http://www.technorati.com/faves?add=http://echoreply.us/tech/2008/09/18/interesting-internationalization/ 27. http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://echoreply.us/tech/2008/09/18/interesting-internationalization/&t=Interesting+internationalization 28. file://localhost/home/abaumann/projects/WolfBones/docs/i18n/Interesting%20internationalization%20|%20Echoreply.html 29. http://echoreply.us/tech/2009/03/05/for-concurrency-issues-there-is-music/ 30. http://echoreply.us/tech/2009/02/19/the-great-microkernel-debate/ 31. http://echoreply.us/tech/2009/02/19/xen-and-single-system-images/ 32. http://echoreply.us/tech/tag/helenos/ 33. http://echoreply.us/tech/tag/ideas/ 34. http://echoreply.us/tech/tag/interesting/ 35. http://echoreply.us/tech/tag/programming/ 36. http://echoreply.us/tech/2009/03/05/for-concurrency-issues-there-is-music/ 37. http://echoreply.us/tech/2009/02/19/django-and-the-admin-anthem/ 38. http://echoreply.us/tech/2009/02/19/the-great-microkernel-debate/ 39. http://echoreply.us/tech/2009/02/19/xen-and-single-system-images/ 40. http://echoreply.us/tech/2009/02/19/yes-im-still-alive/ 41. http://echoreply.us/tech/2009/01/05/please-adopt-etcvendor/ 42. http://echoreply.us/tech/2008/12/30/my-list-for-2009/ 43. http://echoreply.us/tech/2008/12/28/web-pages-as-graphs/ 44. http://www.ohloh.net/accounts/20338?ref=Detailed 45. http://echoreply.us/tech/tag/free-software/ 46. http://echoreply.us/tech/tag/ohno/ 47. http://echoreply.us/tech/tag/haha/ 48. http://echoreply.us/tech/tag/gnu/ 49. http://echoreply.us/tech/tag/programming/ 50. http://echoreply.us/tech/tag/thinking-out-loud/ 51. http://echoreply.us/tech/tag/interesting/ 52. http://echoreply.us/tech/tag/linux/ 53. http://twitter.com/tinkertim/statuses/1273136035 54. http://twitter.com/tinkertim/statuses/1273063132 55. http://twitter.com/tinkertim/statuses/1095308437 56. http://cormander.com/ 57. http://jakubsuniversalblog.blogspot.com/ 58. http://johnhawks.net/weblog/ 59. http://helenos-blog.pavel-rimsky.cz/ 60. http://www.ext3cow.com/ 61. http://gridnix.org/ 62. http://www.helenos.org/ 63. http://echoreply.us/hg/index.php 64. http://srce.echoreply.us/ 65. http://sharesource.org/project/xguests/ 66. http://www.lechak.info/blue/ 67. http://www.selenic.com/mercurial/wiki/ 68. http://sharesource.org/ 69. http://stackoverflow.com/ 70. http://echoreply.us/tech/2009/03/ 71. http://echoreply.us/tech/2009/02/ 72. http://echoreply.us/tech/2009/01/ 73. http://echoreply.us/tech/2008/12/ 74. http://echoreply.us/tech/2008/11/ 75. http://echoreply.us/tech/2008/10/ 76. http://echoreply.us/tech/2008/09/ 77. http://echoreply.us/tech/2008/08/ 78. http://echoreply.us/tech/2008/07/ 79. http://echoreply.us/tech/2008/06/ 80. http://echoreply.us/tech/2008/05/ 81. http://echoreply.us/tech/2008/04/ 82. http://echoreply.us/tech/2008/03/ 83. http://echoreply.us/tech/2008/02/ 84. http://echoreply.us/tech/2008/01/ 85. http://echoreply.us/tech/2007/12/ 86. http://echoreply.us/tech/2007/11/ 87. http://echoreply.us/tech/2007/10/ 88. http://echoreply.us/tech/2007/09/ 89. http://echoreply.us/tech/category/better-living/ 90. http://echoreply.us/tech/category/blogeting/ 91. http://echoreply.us/tech/category/computing/ 92. http://echoreply.us/tech/category/free-software/ 93. http://echoreply.us/tech/category/planned-projects/ 94. http://echoreply.us/tech/category/gizmos/ 95. http://echoreply.us/tech/category/gnu/ 96. http://echoreply.us/tech/category/humor/ 97. http://echoreply.us/tech/category/ideas/ 98. http://echoreply.us/tech/category/linux/ 99. http://echoreply.us/tech/category/neat-things/ 100. http://echoreply.us/tech/category/parenting/ 101. http://echoreply.us/tech/category/programming/ 102. http://echoreply.us/tech/category/rants/ 103. http://echoreply.us/tech/category/science/ 104. http://echoreply.us/tech/category/the-web-hosting-industry/ 105. http://echoreply.us/tech/category/travels/ 106. http://echoreply.us/tech/category/uncategorized/ 107. http://echoreply.us/tech/category/xen/ 108. http://echoreply.us/tech/wp-login.php 109. http://validator.w3.org/check?uri=referer 110. http://echoreply.us/design_credits.html 111. http://wordpress.org/