1. ------------------------------------------------------------------------------ 
  2. --                  GtkAda - Ada95 binding for Gtk+/Gnome                   -- 
  3. --                                                                          -- 
  4. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  5. --                     Copyright (C) 1998-2014, AdaCore                     -- 
  6. --                                                                          -- 
  7. -- This library is free software;  you can redistribute it and/or modify it -- 
  8. -- under terms of the  GNU General Public License  as published by the Free -- 
  9. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  10. -- version. This library is distributed in the hope that it will be useful, -- 
  11. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  12. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  13. --                                                                          -- 
  14. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  15. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  16. -- version 3.1, as published by the Free Software Foundation.               -- 
  17. --                                                                          -- 
  18. -- You should have received a copy of the GNU General Public License and    -- 
  19. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  20. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  21. -- <http://www.gnu.org/licenses/>.                                          -- 
  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 recommended 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 pieces of information, 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 recommended 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 (-"I18n 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. --  User setup 
  104. --  ========== 
  105. -- 
  106. --  To change the current locale setting, use the environment variables 
  107. --  "LANG". For example, to switch to the french locale using 
  108. --  bash: 
  109. -- 
  110. --  $ export LANG=fr_FR 
  111. -- 
  112. --  Depending on the specific implementation of gettext, the following 
  113. --  environment variables may be set to change the default settings of locale 
  114. --  parameters: 
  115. -- 
  116. --    - LANG Specifies locale name. 
  117. -- 
  118. --    - LC_MESSAGES 
  119. --          Specifies messaging locale, and if present overrides 
  120. --          LANG for messages. 
  121. -- 
  122. --    - TEXTDOMAIN 
  123. --          Specifies the text domain name, which is identical to 
  124. --          the message object filename without .mo suffix. 
  125. -- 
  126. --    - TEXTDOMAINDIR 
  127. --          Specifies the pathname to the message database, and if 
  128. --          present replaces the default (e.g /usr/lib/locale on Solaris, 
  129. --          /usr/share/locale on Linux). 
  130. -- 
  131. --  See the gettext documentation of your specific OS for more details. 
  132. -- 
  133. --  </description> 
  134.  
  135. with Glib; 
  136.  
  137. package Gtkada.Intl is 
  138.    pragma Preelaborate; 
  139.  
  140.    function Gettext (Msg : Glib.UTF8_String) return Glib.UTF8_String; 
  141.    --  Look up Msg in the current default message catalog. 
  142.    --  Use the current locale as specified by LC_MESSAGES. If not found, return 
  143.    --  Msg itself (the default text). 
  144.  
  145.    function Dgettext 
  146.      (Domain : String; Msg : Glib.UTF8_String) return Glib.UTF8_String; 
  147.    --  Look up Msg in the Domain message catalog for the current locale. 
  148.  
  149.    function "-" (Msg : Glib.UTF8_String) return Glib.UTF8_String; 
  150.    --  Shortcut for Dgettext ("GtkAda", Msg) 
  151.  
  152.    function Dcgettext 
  153.      (Domain : String; Msg : Glib.UTF8_String; Category : Integer) 
  154.       return Glib.UTF8_String; 
  155.    --  Look up Msg in the Domain message catalog for the Category locale. 
  156.  
  157.    function Default_Text_Domain return String; 
  158.    --  Return the current default message catalog. 
  159.  
  160.    procedure Text_Domain (Domain : String := ""); 
  161.    --  Set the current default message catalog to Domain. 
  162.    --  If Domain is "", reset to the default of "messages". 
  163.  
  164.    procedure Bind_Text_Domain (Domain : String; Dirname : String); 
  165.    --  Specify that the Domain message catalog will be found in Dirname. 
  166.    --  This overrides the default system locale data base. 
  167.    --  Dirname will generally be the installation prefix for your application. 
  168.  
  169.    procedure Setlocale; 
  170.    --  This procedure must be called before any other subprogram in this 
  171.    --  package. It will initialize internal variables based on the environment 
  172.    --  variables. 
  173.  
  174. end Gtkada.Intl;