1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --      Copyright (C) 2000 E. Briot, J. Brobecker and A. Charlet     -- 
  5. --                Copyright (C) 2000-2003 ACT-Europe                 -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. -- 
  27. --  This package provides support for string internationalization using the 
  28. --  libintl library. 
  29. -- 
  30. --  Developer setup 
  31. --  =============== 
  32. -- 
  33. --  To provide internationalization in your application, you must install a 
  34. --  number of files along with your application, and modify your code to 
  35. --  highlight the strings to translate. This translation is based on the 
  36. --  gettext() library. Reading its documentation is recommanded since it 
  37. --  explains best practices for handling translations. 
  38. -- 
  39. --  Preparing your code 
  40. --  =================== 
  41. -- 
  42. --  Gettext needs to information to locate the translation files: a language, 
  43. --  as setup by the user (see User Setup below), and a domain, hard-coded in 
  44. --  the application. The domain is the name of your application. Given these 
  45. --  two informations, the translation file will be found in: 
  46. --     $prefix/<lang>/LC_MESSAGES/<domain>.mo 
  47. -- 
  48. --  Where $prefix is either one of the standard search paths, or specified 
  49. --  through a call to Bind_Text_Domain. 
  50. -- 
  51. --  Although the user can simply specify which language to use by setting one 
  52. --  environment variable, they are in fact several other setup to be done, so 
  53. --  that the C library properly handles date format for instance. This is done 
  54. --  through a call to Setlocale. 
  55. -- 
  56. --  An application can be associated with several domains, although it is 
  57. --  generally recommanded to have one default domain, specify through a call to 
  58. --  Text_Domain. Each string can then be translated through a call to Gettext, 
  59. --  without specifying the domain every time. 
  60. --  A convenient shortcut is provided in the form of the "-" operator. 
  61. -- 
  62. --  As a result, typical code would look like: 
  63. --    begin 
  64. --       Setlocale; 
  65. --       Text_Domain ("application"); 
  66. --       Bind_Text_Domain ("application", "/usr/local/share/locale"); 
  67. --       ... 
  68. --       Put_Line (-"Internalized string"); 
  69. --    end; 
  70. -- 
  71. --  Preparing and installing the translation files 
  72. --  =============================================== 
  73. -- 
  74. --  The Gtkada distribution comes with a convenient script named 
  75. --  build_skeleton.pl, which you can run on your application to extract all the 
  76. --  strings that should be translated. See the "po/" directory in GtkAda, as 
  77. --  well as the Makefile in this directory. 
  78. -- 
  79. --  Running "make refresh" will reparse all the source files in your 
  80. --  application, and create (or update if they already exist) one file .po for 
  81. --  each language registered in the Makefile. 
  82. -- 
  83. --  You would then translate each of the string indicated my "msgid", by 
  84. --  modifying the lines starting with "msgstr". 
  85. -- 
  86. --  Once this is done, running the msgfmt tool through "make install" will 
  87. --  generate a <lang>.mo binary file, which should be copied in the directory 
  88. --     $prefix/<lang>/LC_MESSAGES/<domain>.mo 
  89. -- 
  90. --  The translation files can also be created fully by hand. 
  91. --  Here is a sample translation file that can be used as an input for msgfmt: 
  92. -- 
  93. --  # gtkada-fr.po 
  94. --  msgid  "Help" 
  95. --  msgstr "Aide" 
  96. -- 
  97. --  msgid  "Yes" 
  98. --  msgstr "Oui" 
  99. -- 
  100. --  $ msgfmt gtkada-fr.po -o gtkada-fr.gmo 
  101. --  $ cp gtkada-fr.gmo /usr/share/locale/fr/LC_MESSAGES/gtkada.mo 
  102. -- 
  103. --  If your program uses GtkAda, there are also a number of strings that need 
  104. --  to be translated in that library. The recommanded approach is to merge the 
  105. --  .po files found in the GtkAda distribution in the "po/" directory, and use 
  106. --  the tool msgmerge to merge these into your applications' translation file. 
  107. -- 
  108. --  User setup 
  109. --  ========== 
  110. -- 
  111. --  To change the current locale setting, use the environment variables 
  112. --  "LANG". For example, to switch to the french locale using 
  113. --  bash: 
  114. -- 
  115. --  $ export LANG=fr_FR 
  116. -- 
  117. --  Depending on the specific implementation of gettext, the following 
  118. --  environment variables may be set to change the default settings of locale 
  119. --  parameters: 
  120. -- 
  121. --    - LANG Specifies locale name. 
  122. -- 
  123. --    - LC_MESSAGES 
  124. --          Specifies messaging locale, and if present overrides 
  125. --          LANG for messages. 
  126. -- 
  127. --    - TEXTDOMAIN 
  128. --          Specifies the text domain name, which is identical to 
  129. --          the message object filename without .mo suffix. 
  130. -- 
  131. --    - TEXTDOMAINDIR 
  132. --          Specifies the pathname to the message database, and if 
  133. --          present replaces the default (e.g /usr/lib/locale on Solaris, 
  134. --          /usr/share/locale on Linux). 
  135. -- 
  136. --  See the gettext documentation of your specific OS for more details. 
  137. -- 
  138. --  </description> 
  139.  
  140. with Glib; 
  141.  
  142. package Gtkada.Intl is 
  143.    pragma Preelaborate; 
  144.  
  145.    function Gettext (Msg : Glib.UTF8_String) return Glib.UTF8_String; 
  146.    --  Look up Msg in the current default message catalog. 
  147.    --  Use the current locale as specified by LC_MESSAGES. If not found, return 
  148.    --  Msg itself (the default text). 
  149.  
  150.    function Dgettext 
  151.      (Domain : String; Msg : Glib.UTF8_String) return Glib.UTF8_String; 
  152.    --  Look up Msg in the Domain message catalog for the current locale. 
  153.  
  154.    function "-" (Msg : Glib.UTF8_String) return Glib.UTF8_String; 
  155.    --  Shortcut for Dgettext ("GtkAda", Msg) 
  156.  
  157.    function Dcgettext 
  158.      (Domain : String; Msg : Glib.UTF8_String; Category : Integer) 
  159.       return Glib.UTF8_String; 
  160.    --  Look up Msg in the Domain message catalog for the Category locale. 
  161.  
  162.    function Default_Text_Domain return String; 
  163.    --  Return the current default message catalog. 
  164.  
  165.    procedure Text_Domain (Domain : String := ""); 
  166.    --  Set the current default message catalog to Domain. 
  167.    --  If Domain is "", reset to the default of "messages". 
  168.  
  169.    procedure Bind_Text_Domain (Domain : String; Dirname : String); 
  170.    --  Specify that the Domain message catalog will be found in Dirname. 
  171.    --  This overrides the default system locale data base. 
  172.    --  Dirname will generally be the installation prefix for your application. 
  173.  
  174.    procedure Setlocale; 
  175.    --  This procedure must be called before any other subprogram in this 
  176.    --  package. It will initialize internal variables based on the environment 
  177.    --  variables. 
  178.  
  179. end Gtkada.Intl;