README.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. cage
  2. Table of Contents
  3. ─────────────────
  4. 1. Prerequisites:
  5. 2. Installation:
  6. 3. Usage
  7. .. 1. Extracting translatable strings:
  8. .. 2. Locating GNU message catalog files
  9. .. 3. Simple example
  10. 4. String utils
  11. 5. Old version incompatibility
  12. 6. Bugs and issues
  13. .. 1. Known issues
  14. 7. License
  15. 8. NO WARRANTY
  16. 9. Contributors:
  17. [http://quickdocs.org/badge/cl-i18n.svg]
  18. [http://quickdocs.org/badge/cl-i18n.svg] <http://quickdocs.org/cl-i18n/>
  19. 1 Prerequisites:
  20. ════════════════
  21. • ASDF
  22. • uiop (if your ASDF version is < 3)
  23. • cl-ppcre
  24. • alexandria
  25. • babel
  26. 2 Installation:
  27. ═══════════════
  28. The best way to get cl-i18n working is using the excellent [quicklisp]
  29. ┌────
  30. │ (ql:quickload "cl-i18n")
  31. └────
  32. [quicklisp] <http://www.quicklisp.org/>
  33. 3 Usage
  34. ═══════
  35. This library can load translations from file formats of the following
  36. types:
  37. • [GNU gettext] text file (AKA PO files);
  38. • [GNU gettext] binary file (AKA MO files);
  39. • [Universal Terminology eXchange] format
  40. • its native file formats (essentially a Common lisp S-exp).
  41. Check the `examples/' directory for an usage example.
  42. [GNU gettext] <https://www.gnu.org/software/gettext/>
  43. [Universal Terminology eXchange]
  44. <https://web.archive.org/web/20190407131733/https://www.aamt.info/english/utx/index.htm>
  45. 3.1 Extracting translatable strings:
  46. ────────────────────────────────────
  47. ┌────
  48. │ ;; define two convenience functions
  49. │ (defun _ (a) (cl-i18n:translate a))
  50. │ (defun n_ (s f n) (cl-i18n:ntranslate s f n))
  51. │ (cl-i18n-utils:gen-translation-file "/src/" "klingon.lisp"
  52. │ :ext "lisp$"
  53. │ :prefix-re "\\(_\\s+")
  54. │ (cl-i18n-utils:gen-translation-file "/src/" "klingon.lisp"
  55. │ :ext "lisp$"
  56. │ :prefix-re "\\(n_\\s+")
  57. └────
  58. Will extract all `(_…' strings from all the files in directory `/src'
  59. which name ends in "lisp" and set up a basic translation resource in
  60. klingon.lisp (*Note: the output file if exists will be overwritten*).
  61. To make it work with CL-WHO, use the “str” directive, as in
  62. ┌────
  63. │ (with-html-output *out*
  64. │ (:p (str (_ "Peace and love!"))))
  65. └────
  66. Please note that the library can accept gettext MO or PO files so
  67. nothing prevents you using GNU xgettext to extracts strings that needs
  68. to be translated and use its output as translation file.
  69. 3.2 Locating GNU message catalog files
  70. ──────────────────────────────────────
  71. According to [GNU gettext manual] the path to the catalog is system
  72. dipendent, the function /search-mo-repository/ will try to figure out
  73. where that catalog *could* be; but its implementation is slow, memory
  74. consuming and sometimes fails (i.e. crash).
  75. [GNU gettext manual]
  76. <https://www.gnu.org/software/gettext/manual/gettext.html#Locating-Catalogs>
  77. 3.3 Simple example
  78. ──────────────────
  79. Here is a way similar to GNU gettext style API; please note we are
  80. assuming `/usr/share/locale/' as the path where the catalog can be
  81. found and foo.mo is there.
  82. We also let the library guess the right locale with `find-locale'.
  83. ┌────
  84. │ (let ((*translation-file-root* "/usr/share/locale/"))
  85. │ (load-language "foo" :locale (find-locale))
  86. │ (format t "~a~%" (_ "Browse"))
  87. │ (format t "~a~%" (_ "Save as...")))
  88. └────
  89. 4 String utils
  90. ══════════════
  91. During the development of this library I have implemented a couple of
  92. string functions that I think could be useful beyond i18n.
  93. cl-i18n-utils:levenshtein-distance (string1 string2)
  94. Compute the levenshtein distance (i. e. how much are similars)
  95. between two strings
  96. cl-i18n-utils:fuzzy-match (…)
  97. Performs a Smith-Waterman affinity search. See:
  98. <https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm>
  99. 5 Old version incompatibility
  100. ═════════════════════════════
  101. This version deeply changed the file format of the translation table,
  102. however you can convert from the old format to the new one with:
  103. ┌────
  104. │ (cl-i18n-utils:convert-save-dictionary oldfile-path new-filepath)
  105. └────
  106. *Note: the output file if exists will be overwritten*
  107. 6 Bugs and issues
  108. ═════════════════
  109. Please file bug report on the [issue tracker].
  110. [issue tracker] <https://notabug.org/cage/cl-i18n/issues>
  111. 6.1 Known issues
  112. ────────────────
  113. • Documentation is missing;
  114. • Source code is mostly undocumented;
  115. • PO file parser is slow.
  116. 7 License
  117. ═════════
  118. This library is released under Lisp Lesser General Public license (see
  119. COPYING.LESSER file)
  120. Examples are released under GPL version 3 or later
  121. `doc/internals/pofiles_grammar' is © 2012 cage and is licensed under
  122. Creative Commons Attribution-ShareAlike 3.0 Unported
  123. File /function-name.lisp/ was got from [cl-store] © 2004 Sean Ross and
  124. included here with the original license stated below.
  125. Copyright (c) 2004 Sean Ross All rights reserved.
  126. Redistribution and use in source and binary forms, with or without
  127. modification, are permitted provided that the following conditions are
  128. met:
  129. 1. Redistributions of source code must retain the above copyright
  130. notice, this list of conditions and the following disclaimer.
  131. 2. Redistributions in binary form must reproduce the above copyright
  132. notice, this list of conditions and the following disclaimer in the
  133. documentation and/or other materials provided with the
  134. distribution.
  135. 3. The names of the authors and contributors may not be used to
  136. endorse or promote products derived from this software without
  137. specific prior written permission.
  138. THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS''
  139. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  140. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  141. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS
  142. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  143. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  144. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  145. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  146. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  147. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  148. IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  149. [cl-store] <http://common-lisp.net/project/cl-store/>
  150. 8 NO WARRANTY
  151. ═════════════
  152. This library is distributed in the hope that it will be useful, but
  153. WITHOUT ANY WARRANTY; without even the implied warranty of
  154. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  155. Lesser General Public License for more details.
  156. 9 Contributors:
  157. ═══════════════
  158. • Leslie P. Polzer (base)
  159. • Vilson Vieira (string extractor)
  160. • Cage (developer and maintainer)