gettext 3.2.9 → 3.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +276 -198
  3. data/Rakefile +7 -4
  4. data/doc/text/news.md +451 -0
  5. data/gettext.gemspec +10 -7
  6. data/lib/gettext/locale_path.rb +17 -9
  7. data/lib/gettext/mo.rb +12 -19
  8. data/lib/gettext/po.rb +4 -4
  9. data/lib/gettext/po_entry.rb +47 -27
  10. data/lib/gettext/po_parser.rb +65 -59
  11. data/lib/gettext/text_domain.rb +1 -1
  12. data/lib/gettext/text_domain_manager.rb +6 -5
  13. data/lib/gettext/tools/msgcat.rb +9 -2
  14. data/lib/gettext/tools/msginit.rb +226 -54
  15. data/lib/gettext/tools/msgmerge.rb +24 -6
  16. data/lib/gettext/tools/parser/erb.rb +9 -1
  17. data/lib/gettext/tools/parser/erubi.rb +88 -0
  18. data/lib/gettext/tools/parser/glade.rb +38 -40
  19. data/lib/gettext/tools/parser/gtk_builder_ui_definitions.rb +129 -0
  20. data/lib/gettext/tools/parser/ruby.rb +288 -221
  21. data/lib/gettext/tools/task.rb +4 -5
  22. data/lib/gettext/tools/xgettext.rb +21 -10
  23. data/lib/gettext/version.rb +3 -3
  24. data/locale/bg/LC_MESSAGES/gettext.mo +0 -0
  25. data/locale/bs/LC_MESSAGES/gettext.mo +0 -0
  26. data/locale/ca/LC_MESSAGES/gettext.mo +0 -0
  27. data/locale/cs/LC_MESSAGES/gettext.mo +0 -0
  28. data/locale/de/LC_MESSAGES/gettext.mo +0 -0
  29. data/locale/el/LC_MESSAGES/gettext.mo +0 -0
  30. data/locale/eo/LC_MESSAGES/gettext.mo +0 -0
  31. data/locale/es/LC_MESSAGES/gettext.mo +0 -0
  32. data/locale/et/LC_MESSAGES/gettext.mo +0 -0
  33. data/locale/fr/LC_MESSAGES/gettext.mo +0 -0
  34. data/locale/hr/LC_MESSAGES/gettext.mo +0 -0
  35. data/locale/hu/LC_MESSAGES/gettext.mo +0 -0
  36. data/locale/it/LC_MESSAGES/gettext.mo +0 -0
  37. data/locale/ja/LC_MESSAGES/gettext.mo +0 -0
  38. data/locale/ko/LC_MESSAGES/gettext.mo +0 -0
  39. data/locale/lv/LC_MESSAGES/gettext.mo +0 -0
  40. data/locale/nb/LC_MESSAGES/gettext.mo +0 -0
  41. data/locale/nl/LC_MESSAGES/gettext.mo +0 -0
  42. data/locale/pt_BR/LC_MESSAGES/gettext.mo +0 -0
  43. data/locale/ru/LC_MESSAGES/gettext.mo +0 -0
  44. data/locale/sr/LC_MESSAGES/gettext.mo +0 -0
  45. data/locale/uk/LC_MESSAGES/gettext.mo +0 -0
  46. data/locale/vi/LC_MESSAGES/gettext.mo +0 -0
  47. data/locale/zh/LC_MESSAGES/gettext.mo +0 -0
  48. data/locale/zh_TW/LC_MESSAGES/gettext.mo +0 -0
  49. data/po/bg/gettext.edit.po +81 -572
  50. data/po/bg/gettext.po +7 -409
  51. data/po/bs/gettext.edit.po +81 -572
  52. data/po/bs/gettext.po +7 -409
  53. data/po/ca/gettext.edit.po +81 -572
  54. data/po/ca/gettext.po +7 -409
  55. data/po/cs/gettext.edit.po +81 -572
  56. data/po/cs/gettext.po +7 -409
  57. data/po/de/gettext.edit.po +81 -572
  58. data/po/de/gettext.po +7 -409
  59. data/po/el/gettext.edit.po +81 -572
  60. data/po/el/gettext.po +7 -409
  61. data/po/eo/gettext.edit.po +81 -572
  62. data/po/eo/gettext.po +7 -409
  63. data/po/es/gettext.edit.po +81 -572
  64. data/po/es/gettext.po +7 -409
  65. data/po/et/gettext.edit.po +81 -572
  66. data/po/et/gettext.po +7 -409
  67. data/po/fr/gettext.edit.po +81 -572
  68. data/po/fr/gettext.po +7 -409
  69. data/po/gettext.pot +93 -645
  70. data/po/hr/gettext.edit.po +81 -572
  71. data/po/hr/gettext.po +7 -409
  72. data/po/hu/gettext.edit.po +81 -572
  73. data/po/hu/gettext.po +7 -409
  74. data/po/it/gettext.edit.po +81 -572
  75. data/po/it/gettext.po +7 -409
  76. data/po/ja/gettext.edit.po +83 -574
  77. data/po/ja/gettext.po +9 -411
  78. data/po/ko/gettext.edit.po +81 -572
  79. data/po/ko/gettext.po +7 -409
  80. data/po/lv/gettext.edit.po +81 -572
  81. data/po/lv/gettext.po +7 -409
  82. data/po/nb/gettext.edit.po +81 -572
  83. data/po/nb/gettext.po +7 -409
  84. data/po/nl/gettext.edit.po +81 -572
  85. data/po/nl/gettext.po +7 -409
  86. data/po/pt_BR/gettext.edit.po +81 -572
  87. data/po/pt_BR/gettext.po +7 -409
  88. data/po/ru/gettext.edit.po +81 -572
  89. data/po/ru/gettext.po +7 -409
  90. data/po/sr/gettext.edit.po +81 -572
  91. data/po/sr/gettext.po +7 -409
  92. data/po/sv/gettext.edit.po +81 -572
  93. data/po/sv/gettext.po +7 -409
  94. data/po/uk/gettext.edit.po +81 -572
  95. data/po/uk/gettext.po +7 -409
  96. data/po/vi/gettext.edit.po +81 -572
  97. data/po/vi/gettext.po +7 -409
  98. data/po/zh/gettext.edit.po +81 -572
  99. data/po/zh/gettext.po +7 -409
  100. data/po/zh_TW/gettext.edit.po +81 -572
  101. data/po/zh_TW/gettext.po +7 -409
  102. data/samples/cgi/po/helloerb1.pot +3 -3
  103. data/samples/cgi/po/helloerb2.pot +3 -3
  104. data/samples/cgi/po/hellolib.pot +3 -3
  105. data/samples/cgi/po/main.pot +3 -3
  106. data/samples/po/bg/hello_gtk_builder.edit.po +15 -0
  107. data/samples/po/bg/hello_gtk_builder.po +12 -0
  108. data/samples/po/bs/hello_gtk_builder.edit.po +15 -0
  109. data/samples/po/bs/hello_gtk_builder.po +12 -0
  110. data/samples/po/ca/hello_gtk_builder.edit.po +15 -0
  111. data/samples/po/ca/hello_gtk_builder.po +12 -0
  112. data/samples/po/cs/hello_gtk_builder.edit.po +15 -0
  113. data/samples/po/cs/hello_gtk_builder.po +12 -0
  114. data/samples/po/de/hello_gtk_builder.edit.po +15 -0
  115. data/samples/po/de/hello_gtk_builder.po +12 -0
  116. data/samples/po/el/hello_gtk_builder.edit.po +15 -0
  117. data/samples/po/el/hello_gtk_builder.po +12 -0
  118. data/samples/po/eo/hello_gtk_builder.edit.po +15 -0
  119. data/samples/po/eo/hello_gtk_builder.po +12 -0
  120. data/samples/po/es/hello_gtk_builder.edit.po +15 -0
  121. data/samples/po/es/hello_gtk_builder.po +12 -0
  122. data/samples/po/fr/hello_gtk_builder.edit.po +15 -0
  123. data/samples/po/fr/hello_gtk_builder.po +12 -0
  124. data/samples/po/hello.pot +3 -3
  125. data/samples/po/hello2.pot +4 -4
  126. data/samples/po/hello_glade2.pot +8 -5
  127. data/samples/po/hello_gtk2.pot +4 -4
  128. data/samples/po/hello_gtk_builder.pot +18 -4
  129. data/samples/po/hello_noop.pot +4 -4
  130. data/samples/po/hello_plural.pot +4 -4
  131. data/samples/po/hello_tk.pot +4 -4
  132. data/samples/po/hr/hello_gtk_builder.edit.po +15 -0
  133. data/samples/po/hr/hello_gtk_builder.po +12 -0
  134. data/samples/po/hu/hello_gtk_builder.edit.po +15 -0
  135. data/samples/po/hu/hello_gtk_builder.po +12 -0
  136. data/samples/po/it/hello_gtk_builder.edit.po +15 -0
  137. data/samples/po/it/hello_gtk_builder.po +12 -0
  138. data/samples/po/ja/hello_gtk_builder.edit.po +15 -0
  139. data/samples/po/ja/hello_gtk_builder.po +12 -0
  140. data/samples/po/ko/hello_gtk_builder.edit.po +15 -0
  141. data/samples/po/ko/hello_gtk_builder.po +12 -0
  142. data/samples/po/lv/hello_gtk_builder.edit.po +15 -0
  143. data/samples/po/lv/hello_gtk_builder.po +12 -0
  144. data/samples/po/nb/hello_gtk_builder.edit.po +15 -0
  145. data/samples/po/nb/hello_gtk_builder.po +12 -0
  146. data/samples/po/nl/hello_gtk_builder.edit.po +15 -0
  147. data/samples/po/nl/hello_gtk_builder.po +12 -0
  148. data/samples/po/pt_BR/hello_gtk_builder.edit.po +15 -0
  149. data/samples/po/pt_BR/hello_gtk_builder.po +12 -0
  150. data/samples/po/ru/hello_gtk_builder.edit.po +15 -0
  151. data/samples/po/ru/hello_gtk_builder.po +12 -0
  152. data/samples/po/sr/hello_gtk_builder.edit.po +15 -0
  153. data/samples/po/sr/hello_gtk_builder.po +12 -0
  154. data/samples/po/sv/hello_gtk_builder.edit.po +15 -0
  155. data/samples/po/sv/hello_gtk_builder.po +12 -0
  156. data/samples/po/uk/hello_gtk_builder.edit.po +15 -0
  157. data/samples/po/uk/hello_gtk_builder.po +12 -0
  158. data/samples/po/vi/hello_gtk_builder.edit.po +15 -0
  159. data/samples/po/vi/hello_gtk_builder.po +12 -0
  160. data/samples/po/zh/hello_gtk_builder.edit.po +15 -0
  161. data/samples/po/zh/hello_gtk_builder.po +12 -0
  162. data/samples/po/zh_TW/hello_gtk_builder.edit.po +15 -0
  163. data/samples/po/zh_TW/hello_gtk_builder.po +12 -0
  164. data/src/po_parser.ry +48 -42
  165. data/test/fixtures/_/backtick.rb +30 -0
  166. data/test/fixtures/_/block_parameter.rb +2 -2
  167. data/test/fixtures/_/double_quote_in_double_quote.rb +2 -2
  168. data/test/fixtures/_/double_quote_in_single_quote.rb +2 -2
  169. data/test/fixtures/_/literal_concatenation_with_continuation_line.rb +2 -2
  170. data/test/fixtures/_/middle_new_line.rb +2 -2
  171. data/test/fixtures/_/multiple_lines_literal.rb +2 -2
  172. data/test/fixtures/_/multiple_messages_in_same_line.rb +2 -2
  173. data/test/fixtures/_/multiple_same_messages.rb +2 -2
  174. data/test/fixtures/_/one_line.rb +2 -2
  175. data/test/fixtures/_/one_new_line.rb +2 -2
  176. data/test/fixtures/_/percent_strings.rb +55 -0
  177. data/test/fixtures/_/pipe.rb +32 -0
  178. data/test/{gettext-test-utils.rb → fixtures/_/quoted_symbol.rb} +13 -23
  179. data/test/fixtures/_.rb +10 -1
  180. data/test/fixtures/erb/case.rhtml +16 -0
  181. data/test/fixtures/erb/minus.rhtml +12 -0
  182. data/test/fixtures/erb/non_ascii.rhtml +1 -0
  183. data/test/fixtures/glade/3.glade +63 -0
  184. data/test/fixtures/gtk_builder_ui_definitions.ui +68 -0
  185. data/test/fixtures/multi_text_domain.rb +12 -12
  186. data/test/fixtures/np_.rb +1 -1
  187. data/test/fixtures/ns_/custom.rb +2 -2
  188. data/test/fixtures/ns_.rb +1 -1
  189. data/test/fixtures/p_.rb +1 -1
  190. data/test/fixtures/ruby/percent_lower_i.rb +1 -0
  191. data/test/fixtures/ruby/percent_lower_w.rb +1 -0
  192. data/test/fixtures/ruby/percent_upper_i.rb +1 -0
  193. data/test/fixtures/ruby/percent_upper_w.rb +1 -0
  194. data/test/fixtures/s_/custom.rb +2 -2
  195. data/test/fixtures/s_.rb +1 -1
  196. data/test/fixtures/simple.rb +5 -1
  197. data/test/fixtures/upper_nn_.rb +77 -0
  198. data/test/helper.rb +99 -0
  199. data/test/locale/fr/LC_MESSAGES/plural_error.mo +0 -0
  200. data/test/locale/fr/LC_MESSAGES/test1.mo +0 -0
  201. data/test/locale/fr_BE/LC_MESSAGES/test1.mo +0 -0
  202. data/test/locale/fr_BE_Foo/LC_MESSAGES/test1.mo +0 -0
  203. data/test/locale/ja/LC_MESSAGES/_.mo +0 -0
  204. data/test/po/_.pot +28 -4
  205. data/test/po/backslash.pot +6 -4
  206. data/test/po/fr/plural_error.po +7 -0
  207. data/test/po/fr/test1.po +7 -0
  208. data/test/po/fr_BE/test1.po +24 -0
  209. data/test/po/fr_BE_Foo/test1.po +20 -0
  210. data/test/po/hello.pot +3 -3
  211. data/test/po/ja/_.edit.po +27 -3
  212. data/test/po/ja/_.po +20 -2
  213. data/test/po/ja/hello.edit.po +0 -1
  214. data/test/po/non_ascii.pot +4 -4
  215. data/test/po/np_.pot +8 -5
  216. data/test/po/ns_.pot +6 -4
  217. data/test/po/p_.pot +3 -3
  218. data/test/po/s_.pot +6 -4
  219. data/test/po/untranslated.pot +4 -4
  220. data/test/run-test.rb +2 -3
  221. data/test/test_class_info.rb +8 -9
  222. data/test/test_gettext.rb +30 -1
  223. data/test/test_locale_path.rb +12 -4
  224. data/test/test_parser.rb +113 -25
  225. data/test/test_po_entry.rb +21 -17
  226. data/test/test_po_parser.rb +49 -4
  227. data/test/test_string.rb +9 -5
  228. data/test/tools/parser/test_glade.rb +91 -0
  229. data/test/tools/parser/test_gtk_builder_ui_definitions.rb +63 -0
  230. data/test/tools/parser/test_ruby.rb +76 -39
  231. data/test/tools/test_msgcat.rb +21 -1
  232. data/test/tools/test_msginit.rb +82 -3
  233. data/test/tools/test_msgmerge.rb +81 -6
  234. data/test/tools/test_xgettext.rb +106 -5
  235. metadata +82 -34
  236. data/lib/gettext/tools/parser/haml.rb +0 -61
  237. /data/test/fixtures/{gladeparser.glade → glade/2.glade} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13883b8d492d53e408231de7f5bf3e36a1a444e297e123522a94e611ba7b2d6e
4
- data.tar.gz: 485a83e66be18f847d88560936b7826c13f3976e285d72b2f4e9308d6f64b070
3
+ metadata.gz: 737177cc120acfd0387fdb23761ea8bf324a490b1d4b94f8edce692d22decad7
4
+ data.tar.gz: 67e7d803c3d9fc924e47d0b612cee9ac329eec67784c8e6e63763886f4602be0
5
5
  SHA512:
6
- metadata.gz: 0df714cec0bfae433307d8fe28fbcac6cac227e758417f2fc947dd17bfd4f94faf54ff023a4b1fa3f9dce9b9eab40f20dbead58dc91b66c479b7312a69a29459
7
- data.tar.gz: 3fac02f1a5234eff622aa43947384b974e53d993acc3a18730896780a29a750bd1db9af809ae9171b93a4a03c9d13a0991647aeeb458c38d45264b4c5d4e26e1
6
+ metadata.gz: f12a1f4f550947c5ed4628674f39d8a39857e56e461643ba102ded0f3344ed4015981a6ba13d10c9d411c7bfcdd7ba0c652642bfaaf3fa7a7d9e61f810e96cb3
7
+ data.tar.gz: 2db766ca9d05099d92d366b36a257c618c3524e404f6da5a2488cd401b3704373098e87424593ed200383087434e5115359e13abd90ddd25abe099b13e68620a
data/README.md CHANGED
@@ -1,285 +1,363 @@
1
- # gettext - gettext for Ruby
1
+ # gettext
2
+ *gettext for Ruby*
2
3
 
3
- HELP US: Please fix markup of this file. This file's markup is
4
- migrated from RDoc format. But some RDoc markups still exist.
4
+ [![Gem Version](https://badge.fury.io/rb/gettext.svg)](https://badge.fury.io/rb/gettext)
5
+ [![Build Status](https://travis-ci.org/ruby-gettext/gettext.svg?branch=master)](https://travis-ci.org/ruby-gettext/gettext)
5
6
 
6
- NOTE: Gettext gem 3.0.0 removed many deprecated APIs and improves
7
- internal APIs. We want to keep backward compatibility as much as
8
- possible but some existing codes may be broken by gettext gem API
9
- change. If your code breaks by gettext gem 3.0.0, please report your
10
- problem. We will fix the problem and release a new version.
7
+ > **NOTE:**
8
+ > Gettext gem 3.0.0 removed many deprecated APIs and improves internal APIs.
9
+ > We want to keep backward compatibility as much as possible but some existing codes may be broken by gettext gem API change.
10
+ > If your code breaks by gettext gem 3.0.0, please report your problem.
11
+ > We will fix the problem and release a new version.
11
12
 
12
- https://github.com/ruby-gettext/gettext is the official gettext gem
13
- repository. It is moved from https://github.com/mutoh/gettext . Mutoh
14
- agreed with the move.
13
+ > https://github.com/ruby-gettext/gettext is the official gettext gem repository.
14
+ > It is moved from https://github.com/mutoh/gettext .
15
+ > Mutoh agreed with the move.
15
16
 
16
- Gettext gem is a pure Ruby Localization(L10n) library and tool
17
- which is modeled after the GNU gettext package.
17
+ Gettext gem is a pure Ruby Localization(L10n) library and tool which is modeled after the GNU gettext package.
18
18
 
19
- This library was called as "Ruby-GetText-Package". Since 2.3.0, this
20
- library is called just "gettext". You can call this library as
21
- "gettext gem" or "Ruby gettext" to distinguish from GNU gettext.
19
+ This library was called as "Ruby-GetText-Package".
20
+ Since 2.3.0, this library is called just "gettext".
21
+ You can call this library as "gettext gem" or "Ruby gettext" to distinguish from GNU gettext.
22
22
 
23
- This library translates original messages to localized
24
- messages using client-side locale information(environment
25
- variable or CGI variable).
23
+ This library translates original messages to localized messages using client-side locale information(environment variable or CGI variable).
26
24
 
27
- The tools for developers support creating, useing, and modifying
28
- localized message files(message catalogs).
25
+ The tools for developers support creating, useing, and modifying localized message files(message catalogs).
29
26
 
30
- ((**Rails**))
31
27
  Rails support has been removed.
32
28
 
33
- ## Website
34
-
35
- * [Homepage](http://ruby-gettext.github.io/)
36
- * on [GitHub](http://github.com/ruby-gettext/gettext)
29
+ ## Table of Contents
30
+
31
+ * [Features](#features)
32
+ * [Requirements](#requirements)
33
+ * [Installation](#installation)
34
+ * [Usage](#usage)
35
+ * [Translation](#translation)
36
+ * [`_()`](#_-basic-translation-method)
37
+ * [`n_()`](#n_-pluralized)
38
+ * [`p_()`](#p_-context-aware)
39
+ * [`s_()`](#s_-without-context)
40
+ * [Combinations](#combinations)
41
+ * [`N_()`, `Nn_()`](#n_-nn_-makes-dynamic-translation-messages-readable-for-the-gettext-parser)
42
+ * [Bind textdomains to the classes](#bind-textdomains-to-the-classes)
43
+ * [Locale](#locale)
44
+ * [License](#license)
45
+ * [Translators](#translators)
46
+ * [Maintainer](#maintainer)
47
+ * [Links](#links)
37
48
 
38
49
  ## Features
39
50
 
40
- * Translate singular/plural messages with simple APIs(similar to GNU gettext)
41
-
42
- * Thread safety. Message resources are shared from all threads, but
43
- returns translated messages of the current thread's locale.
44
-
51
+ * Translate singular/plural messages with simple APIs (similar to GNU gettext)
52
+ * Thread safety. Message resources are shared from all threads, but returns translated messages of the current thread's locale.
45
53
  * Tools to find message IDs
46
- * Extract message IDs to po-files using rxgettext from
54
+ * Extract message IDs to `po`-files using `rxgettext` from
47
55
  * ruby scripts
48
- * glade-2 XML file(.glade)
49
- * ERB file(.rhtml, .erb)
56
+ * glade-2 XML file (`.glade`)
57
+ * ERB file (`.rhtml`, `.erb`)
50
58
  * Anything (with your own parsers)
51
- * The po-files are compatible to GNU gettext.
52
-
53
- * rmsgfmt creates a mo-file from a po-file.
54
- The mo-file is compatible to GNU gettext(msgfmt).
55
-
56
- * Using rxgettext/rmsgfmt as Rake tasks
57
-
59
+ * The `po`-files are compatible with GNU gettext.
60
+ * `rmsgfmt` creates a `mo`-file from a `po`-file.
61
+ The `mo`-file is compatible with GNU gettext (`msgfmt`).
62
+ * Using `rxgettext`/`rmsgfmt` as Rake tasks
58
63
  * textdomain's scope is adapt to ruby class/module mechanism.
59
64
  * A class/module can have plural textdomains.
60
65
  * a message is looked up in its class/module and ancestors.
61
-
62
66
  * CGI support (gettext/cgi)
63
67
  * Locale is retrieved from client informations using Ruby-Locale.
64
- (HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, QUERY_STRING(lang), Cookies(lang)).
68
+ (`HTTP_ACCEPT_LANGUAGE`, `HTTP_ACCEPT_CHARSET`, `QUERY_STRING` (lang), Cookies (lang)).
65
69
 
66
70
  ## Requirements
67
71
 
68
- * [Ruby 1.9.3 or later](http://www.ruby-lang.org)
72
+ * [Ruby](http://www.ruby-lang.org) 1.9.3 or later
69
73
  * [RubyGems](http://www.rubygems.org/)
70
- * [locale gem](http://ruby-gettext.github.io/)
71
- * $ gem install locale
72
- * (for development only)
73
- * [Racc-1.4.3 or later](http://rubygems.org/gems/racc)
74
- * (for compiling src/rmsgfmt.ry only)
74
+ * [locale](http://ruby-gettext.github.io/) gem
75
+ ```shell
76
+ gem install locale
77
+ ```
78
+
79
+ For development:
80
+
81
+ * [Racc](http://rubygems.org/gems/racc) 1.4.3 or later (for compiling `src/rmsgfmt.ry` only)
75
82
 
76
- ## Install
83
+ ## Installation
77
84
 
78
- * Uninstall old gettext if exists. (You need to do this when updating 1.93.0 -> 2.0.1)
85
+ Uninstall old gettext if exists. (You need to do this when updating 1.93.0 -> 2.0.1)
79
86
 
80
- (sudo/su on POSIX system)
81
- gem uninstall gettext
87
+ ```shell
88
+ # sudo/su on POSIX system
89
+ gem uninstall gettext
90
+ ```
82
91
 
83
- * gem
92
+ ### RubyGems
84
93
 
85
- #from rubyforge
86
- (sudo/su on POSIX system)
87
- gem install gettext
94
+ ```shell
95
+ # sudo/su on POSIX system
96
+ gem install gettext
97
+ ```
88
98
 
89
- * download tar-ball
99
+ ### Download tar-ball
90
100
 
91
- # De-Compress archive and enter its top directory.
92
- (sudo/su on POSIX system)
93
- ruby setup.rb
101
+ ```shell
102
+ # De-Compress archive and enter its top directory.
103
+ # sudo/su on POSIX system
104
+ ruby setup.rb
105
+ ```
94
106
 
95
- You can also install files in your favorite directory by
96
- supplying setup.rb some options. Try `ruby setup.rb --help`.
107
+ You can also install files in your favorite directory by supplying setup.rb some options.
108
+ Try `ruby setup.rb --help`.
97
109
 
98
110
  ## Usage
99
111
 
100
112
  ### Translation
101
113
 
102
- - _: Basic translation method
114
+ #### `_()` or `gettext()`: basic translation method
103
115
 
104
- Translates the message.
116
+ Translates the message, using the `msgid` if a translation is not found.
105
117
 
106
- _("Hello")
118
+ ```ruby
119
+ _("Hello") => "Bonjour" # Found
120
+ ```
107
121
 
108
- The gettext methods comes in 3 combinable flavors
122
+ This translation will appear in the po or pot file as:
109
123
 
110
- - n: Pluralized
124
+ ```
125
+ msgid: "Hello"
126
+ msgstr: "Bonjour"
127
+ ```
111
128
 
112
- Returns singular or plural form, depending on how many you have.
129
+ When a translation is not found it, it will return the `msgid`. This is a core
130
+ benefit of gettext and applies to all its translation methods.
113
131
 
114
- n_("Apple", "%{num} Apples", 3)
115
- n_(["Apple", "%{num} Apples"], 3)
132
+ ```ruby
133
+ _("Hello") => "Hello" # Not Found
134
+ ```
116
135
 
117
- - p: context aware
136
+ Additional gettext methods come in 3 combinable flavors:
118
137
 
119
- A context is a prefix to your translation, usefull when one word has different meanings, depending on its context.
138
+ #### `n_()` or `ngettext()`: pluralized
120
139
 
121
- p_("Printer","Open") <=> p_("File","Open")
122
- is the same as s_("Printer|Open") <=> s_("File|Open")
140
+ Returns singular or plural form, depending on how many you have.
123
141
 
124
- - s: without context
142
+ ```ruby
143
+ n_("Apple", "%{num} Apples", n) => "3 Pommes" # When n = 3
144
+ n_("Apple", "%{num} Apple", n) => "Pomme" # When n = 1
145
+ n_(["Apple", "%{num} Apple"], n) => "Pomme" # 2 arg variation
146
+ ```
125
147
 
126
- If a translation could not be found, return the msgid without context.
148
+ This translation will appear in the po or pot file as:
127
149
 
128
- s_("Printer|Open") => "Öffnen" #translation found
129
- s_("Printer|Open") => "Open" #translation not found
150
+ ```
151
+ msgid "Apple"
152
+ msgid_plural "%{num} Apples"
153
+ msgstr[0] "Pomme"
154
+ msgstr[1] "#{num} Pommes"
155
+ ```
130
156
 
131
- - combinations
157
+ #### `p_()` or `pgettext()`: context aware
132
158
 
133
- np_("Fruit", "Apple", "%{num} Apples", 3)
134
- ns_("Fruit|Apple","%{num} Apples", 3)
159
+ A context is a prefix to your translation, useful when one word has different meanings, depending on its context.
135
160
 
136
- np_(["Fruit","Apple","%{num} Apples"], 3)
137
- ns_(["Fruit|Apple","%{num} Apples"], 3)
161
+ ```ruby
162
+ p_("Printer","Open") => "Öffnen" #translation found
163
+ p_("Printer","Open") => "Open" #translation not found
164
+ ```
138
165
 
139
- - N_, Nn_: Makes dynamic translation messages readable for the gettext parser.
166
+ This translation will appear in the po or pot file as:
140
167
 
141
- `_(fruit)` cannot be understood by the gettext parser. To help the parser find all your translations,
142
- you can add `fruit = N_("Apple")` which does not translate, but tells the parser: "Apple" needs translation.
168
+ ```
169
+ msgctxt "Printer"
170
+ msgid "Open"
171
+ msgstr "Öffnen"
172
+ ```
143
173
 
144
- fruit = N_("Apple") # same as fruit = "Apple"
145
- _(fruit) # does a normal translation
174
+ Note that the parser when sorting by `msgid` will strictly sort by the `msgid` ignoring
175
+ the `msgctxt`. If you prefer to sort with the `msgctxt` you should consider the
176
+ `s_()` method.
146
177
 
147
- fruits = Nn_("Apple", "%{num} Apples")
148
- n_(fruits, 3)
178
+ #### `s_()` or `sgettext()`: without context
149
179
 
150
- ### Bind textdomains to the classes.
180
+ The `s_()` method is very similar to the `p_()` method except that the context is
181
+ inside the msgid.
151
182
 
152
- A textdomain has a translation file in each language.
153
- A module/class can have multi textdomains. This means the
154
- libraries/applications can have their own textdomains.
183
+ ```ruby
184
+ s_("Printer|Open") => "Öffnen" #translation found
185
+ s_("Printer|Open") => "Open" #translation not found
186
+ ```
187
+
188
+ ```
189
+ msgid "Printer|Open"
190
+ msgstr "Öffnen"
191
+ ```
192
+
193
+ Note the the parser when sorting by `msgid` will take the context into consideration
194
+ as it is part of the `msgid` unlike the `p_()` method.
195
+
196
+ Your preference of using `s_()` or `p_()` will depend on your translation workflow and process.
197
+
198
+ #### Combinations
199
+
200
+ You can combine `n_()` with either `p_()` or `s_()`.
201
+
202
+ #### `np_()` or `npgettext()`: context aware pluralized
203
+
204
+ ```ruby
205
+ np_("Fruit", "Apple", "%{num} Apples", 3)
206
+ np_(["Fruit","Apple","%{num} Apples"], 3) # 2 arg variation
207
+ ```
155
208
 
156
- class Foo
157
- include GetText
158
- bindtextdomain "your_app_domain_name"
159
- end
209
+ ```
210
+ msgctxt "Fruit"
211
+ msgid "Apple"
212
+ msgid_plural "%{num} Apples"
213
+ msgstr[0] ""
214
+ msgstr[1] ""
215
+ ```
160
216
 
161
- class Book
162
- include GetText
163
- bindtextdomain "general"
164
- bindtextdomain "book"
165
- end
217
+ #### `sp_()` or `spgettext()`: context aware pluralized
218
+
219
+
220
+ ```ruby
221
+ ns_("Fruit|Apple","%{num} Apples", 3)
222
+ ns_(["Fruit|Apple","%{num} Apples"], 3) # 2 arg variation
223
+ ```
224
+
225
+ ```
226
+ msgid "Fruit|Apple"
227
+ msgid_plural "%{num} Apples"
228
+ msgstr[0] ""
229
+ msgstr[1] ""
230
+ ```
231
+
232
+ #### `N_()` and `Nn_()`: makes dynamic translation messages readable for the gettext parser
233
+
234
+ `_(fruit)` cannot be understood by the gettext parser.
235
+ To help the parser find all your translations, you can add `fruit = N_("Apple")` which does not translate, but tells the parser: "Apple" needs translation.
236
+
237
+ ```ruby
238
+ fruit = N_("Apple") # same as fruit = "Apple"
239
+ _(fruit) # does a normal translation
240
+
241
+ fruits = Nn_("Apple", "%{num} Apples")
242
+ n_(fruits, 3)
243
+ ```
244
+
245
+ ### Interpolating translations
246
+
247
+ This is not a feature of gettext but worth noting. You can interpolate translated strings with the ruby String `%` operator.
248
+
249
+ ```ruby
250
+ N_("active"); N_("inactive"); N_("paused") # possible value of status for parser to find.
251
+ _("Your account is %{account_state}.") % { account_state: _(status) }
252
+ ```
253
+
254
+
255
+ ### Bind textdomains to the classes
256
+
257
+ A textdomain has a translation file in each language.
258
+ A module/class can have multiple textdomains.
259
+ This means the libraries/applications can have their own textdomains.
260
+
261
+ ```ruby
262
+ class Foo
263
+ include GetText
264
+ bindtextdomain "your_app_domain_name"
265
+ end
266
+
267
+ class Book
268
+ include GetText
269
+ bindtextdomain "general"
270
+ bindtextdomain "book"
271
+ end
272
+ ```
166
273
 
167
274
  ### Locale
168
275
 
169
276
  If you need to set the locale by yourself, then use:
170
277
 
171
- GetText.locale = "en_US" # translate into english from now on
172
- GetText.locale # => en_US
278
+ ```ruby
279
+ GetText.locale = "en_US" # translate into english from now on
280
+ GetText.locale # => en_US
281
+ ```
173
282
 
174
283
  Or
175
284
 
176
- include GetText
177
- set_locale "en_US"
285
+ ```ruby
286
+ include GetText
287
+ set_locale "en_US"
288
+ ```
178
289
 
179
- For more details and options, have a look at the samples folder or
180
- consult the [tutorial](http://www.yotabanana.com/hiki/ruby-gettext-howto.html).
290
+ For more details and options, have a look at the samples folder.
181
291
 
182
292
  ## License
183
293
 
184
- This program is licenced under the same licence as Ruby(See doc/text/ruby-license.txt) or
185
- LGPL(Lesser General Public License: doc/text/lgpl-3.0.txt or http://www.gnu.org/licenses/lgpl-3.0.txt).
186
-
187
- * mofile.rb
188
- * Copyright (C) 2001-2009 Masao Mutoh `<mutoh at highwhay.ne.jp>`
189
- * Copyright (C) 2001,2002 Masahiro Sakai `<s01397ms at sfc.keio.ac.jp>`
294
+ This program is licenced under the same licence as Ruby (See `doc/text/ruby-license.txt`) or
295
+ LGPL (Lesser General Public License: `doc/text/lgpl-3.0.txt` or http://www.gnu.org/licenses/lgpl-3.0.txt).
190
296
 
191
- * gettext.rb
192
- * Copyright (C) 2001-2009 Masao Mutoh `<mutoh at highwhay.ne.jp>`
193
- * Copyright (C) 2001,2002 Masahiro Sakai `<s01397ms at sfc.keio.ac.jp>`
297
+ `mofile.rb`
298
+ ```
299
+ Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
300
+ Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
301
+ ```
194
302
 
195
- * rxgettext
196
- * Copyright (C) 2001-2009 Masao Mutoh `<mutoh at highwhay.ne.jp>`
197
- * Copyright (C) 2001,2002 Yasushi Shoji `<yashi at atmark-techno.com>`
303
+ `gettext.rb`
304
+ ```
305
+ Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
306
+ Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
307
+ ```
198
308
 
199
- * Others
200
- * Copyright (C) 2001-2009 Masao Mutoh `<mutoh at highwhay.ne.jp>`
309
+ `rxgettext`
310
+ ```
311
+ Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
312
+ Copyright (C) 2001,2002 Yasushi Shoji <yashi at atmark-techno.com>
313
+ ```
201
314
 
315
+ Others
316
+ ```
317
+ Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
318
+ ```
202
319
 
203
320
  ## Translators
204
321
 
205
- * Bosnian(bs) - Sanjin Sehic `<saserr at gmail.com>`
206
- * Bulgarian(bg) - Sava Chankov `<sava.chankov at gmail.com>`
207
- * Catalan(ca) - Ramon Salvadó `<rsalvado at gnuine.com>`
208
- * Chinese(Simplified)(zh_CN)
209
- * Yang Bob `<bob.yang.dev at gmail.com>` (current)
210
- * Yingfeng `<blogyingfeng at gmail.com>`
211
- * Chinese(Traditional)(zh_TW)
212
- * Yang Bob `<bob.yang.dev at gmail.com>` (current)
213
- * LIN CHUNG-YI `<xmarsh at gmail.com>`
214
- * Croatian(hr) - Sanjin Sehic `<saserr at gmail.com>`
215
- * Czech(cs) - Karel Miarka `<kajism at yahoo.com>`
216
- * Dutch(nl) - Menno Jonkers `<ruby-gettext at jonkers.com>`
217
- * Esperanto(eo) - Malte Milatz `<malte at gmx-topmail.de>`
218
- * Estonian(et) - Erkki Eilonen `<erkki at itech.ee>`
219
- * French(fr)
220
- * Vincent Isambart `<vincent.isambart at gmail.com>` (current)
221
- * David Sulc `<davidsulc at gmail.com>`
222
- * Laurent Sansonetti `<laurent.sansonetti at gmail.com>`
223
- * German(de)
224
- * Patrick Lenz `<patrick at limited-overload.de>` (current)
225
- * Detlef Reichl `<detlef.reichl at gmx.org>`
226
- * Sven Herzberg `<herzi at abi02.de>`
227
- * Sascha Ebach `<se at digitale-wertschoepfung.de>`
228
- * Greek(el) - Vassilis Rizopoulos `<damphyr at gmx.net>`
229
- * Hungarian(hu) - Tamás Tompa `<tompata at gmail.com>`
230
- * Italian(it)
231
- * Marco Lazzeri `<marco.lazzeri at gmail.com>`
232
- * Gabriele Renzi `<surrender_it at yahoo.it>`
233
- * Japanese(ja) - Masao Mutoh `<mutomasa at gmail.com>`
234
- * Korean(ko) - Gyoung-Yoon Noh `<nohmad at gmail.com>`
235
- * Latvian(lv) - Aivars Akots `<aivars.akots at gmail.com>`
236
- * Norwegian(nb) - Runar Ingebrigtsen `<runar at mopo.no>`
237
- * Portuguese(Brazil)(pt_BR)
238
- * Antonio S. de A. Terceiro `<terceiro at softwarelivre.org>` (current)
239
- * Joao Pedrosa `<joaopedrosa at gmail.com>`
240
- * Russian(ru) - Yuri Kozlov `<kozlov.y at gmail.com>`
241
- * Serbian(sr) - Slobodan Paunović" `<slobodan.paunovic at gmail.com>`
242
- * Spanish(es)
243
- * David Espada `<davinci at escomposlinux.org>` (current)
244
- * David Moreno Garza `<damog at damog.net>`
245
- * Swedish(sv) - Nikolai Weibull `<mailing-lists.ruby-talk at rawuncut.elitemail.org>`
246
- * Ukrainian(uk) - Alex Rootoff `<rootoff at pisem.net>`
247
- * Vietnamese(vi) - Ngoc Dao Thanh `<ngocdaothanh at gmail.com>`
248
-
249
- ## Status of translations
250
-
251
- * Bosnian(bs) - 1.90.0 (old)
252
- * Bulgarian(bg) - 2.0.1
253
- * Catalan(ca) - 2.0.1
254
- * Croatian(hr) - 1.90.0 (old)
255
- * Chinese(zh_CN) - 2.0.1
256
- * Chinese(zh_TW) - 2.0.1
257
- * Czech(cs) - 1.9.0 (old)
258
- * Dutch(nl) - 1.90.0 (old)
259
- * English(default) - 2.1.0
260
- * Esperanto(eo) - 2.0.1
261
- * Estonian(et) - 2.0.1
262
- * French(fr) - 2.0.1
263
- * German(de) - 2.0.1
264
- * Greek(el) - 2.0.1
265
- * Hungarian(hu) - 2.0.1
266
- * Italian(it) - 1.6.0 (old)
267
- * Japanese(ja) - 2.1.0
268
- * Korean(ko) - 1.9.0 (old)
269
- * Latvian(lv) - 2.0.1
270
- * Norwegian(nb) - 2.0.1
271
- * Portuguese(Brazil)(pt_BR) - 2.0.1
272
- * Russian(ru) - 2.0.1
273
- * Serbian(sr) - 2.0.1
274
- * Spanish(es) - 2.0.1
275
- * Swedish(sv) - 0.8.0 (too much old)
276
- * Ukrainian(uk) - 2.0.1
277
- * Vietnamese(vi) - 2.0.1
322
+ | Language | Translator | Status |
323
+ | --- | --- | --- |
324
+ | Bosnian (bs) | Sanjin Sehic `<saserr at gmail.com>` | 1.90.0 (old) |
325
+ | Bulgarian (bg) | Sava Chankov `<sava.chankov at gmail.com>` | 2.0.1 |
326
+ | Catalan (ca) | Ramon Salvadó `<rsalvado at gnuine.com>` | 2.0.1 |
327
+ | Chinese (Simplified)(zh_CN) | Yang Bob `<bob.yang.dev at gmail.com>` *(current)* <br> Yingfeng `<blogyingfeng at gmail.com>` | 2.0.1 |
328
+ | Chinese (Traditional)(zh_TW) | Yang Bob `<bob.yang.dev at gmail.com>` *(current)* <br> Lin Chung-Yi `<xmarsh at gmail.com>` | 2.0.1 |
329
+ | Croatian (hr) | Sanjin Sehic `<saserr at gmail.com>` | 1.90.0 (old) |
330
+ | Czech (cs) | Karel Miarka `<kajism at yahoo.com>` | 1.9.0 (old) |
331
+ | Dutch (nl) | Menno Jonkers `<ruby-gettext at jonkers.com>` | 1.90.0 (old) |
332
+ | English (default) | | 2.1.0 |
333
+ | Esperanto (eo) | Malte Milatz `<malte at gmx-topmail.de>` | 2.0.1 |
334
+ | Estonian (et) | Erkki Eilonen `<erkki at itech.ee>` | 2.0.1 |
335
+ | French (fr) | Vincent Isambart `<vincent.isambart at gmail.com>` *(current)* <br> David Sulc `<davidsulc at gmail.com>` <br> Laurent Sansonetti `<laurent.sansonetti at gmail.com>` | 2.0.1 |
336
+ | German (de) | Patrick Lenz `<patrick at limited-overload.de>` *(current)* <br> Detlef Reichl `<detlef.reichl at gmx.org>` <br> Sven Herzberg `<herzi at abi02.de>` <br> Sascha Ebach `<se at digitale-wertschoepfung.de>` | 2.0.1 |
337
+ | Greek (el) | Vassilis Rizopoulos `<damphyr at gmx.net>` | 2.0.1 |
338
+ | Hungarian (hu) | Tamás Tompa `<tompata at gmail.com>` | 2.0.1 |
339
+ | Italian (it) | Marco Lazzeri `<marco.lazzeri at gmail.com>` <br> Gabriele Renzi `<surrender_it at yahoo.it>` | 1.6.0 (old) |
340
+ | Japanese (ja) | Masao Mutoh `<mutomasa at gmail.com>` | 2.1.0 |
341
+ | Korean (ko) | Gyoung-Yoon Noh `<nohmad at gmail.com>` | 1.9.0 (old)|
342
+ | Latvian (lv) | Aivars Akots `<aivars.akots at gmail.com>` | 2.0.1 |
343
+ | Norwegian (nb) | Runar Ingebrigtsen `<runar at mopo.no>` | 2.0.1 |
344
+ | Portuguese (Brazil)(pt_BR) | Antonio S. de A. Terceiro `<terceiro at softwarelivre.org>` *(current)* <br> Joao Pedrosa `<joaopedrosa at gmail.com>` | 2.0.1 |
345
+ | Russian (ru) | Yuri Kozlov `<kozlov.y at gmail.com>` | 2.0.1 |
346
+ | Serbian (sr) | Slobodan Paunović `<slobodan.paunovic at gmail.com>` | 2.0.1 |
347
+ | Spanish (es) | David Espada `<davinci at escomposlinux.org>` *(current)* <br> David Moreno Garza `<damog at damog.net>` | 2.0.1 |
348
+ | Swedish (sv) | Nikolai Weibull `<mailing-lists.ruby-talk at rawuncut.elitemail.org>` | 0.8.0 (very old) |
349
+ | Ukrainian (uk) | Alex Rootoff `<rootoff at pisem.net>` | 2.0.1 |
350
+ | Vietnamese (vi) | Ngoc Dao Thanh `<ngocdaothanh at gmail.com>` | 2.0.1 |
278
351
 
279
352
  ## Maintainer
280
353
 
281
354
  * Kouhei Sutou `<kou@clear-code.com>`
282
355
 
283
- ### Old maintainer
356
+ Old maintainer
284
357
 
285
358
  * Masao Mutoh `<mutomasa at gmail.com>`
359
+
360
+ ## Links
361
+
362
+ * [Homepage](https://ruby-gettext.github.io/)
363
+ * [GitHub](https://github.com/ruby-gettext/gettext)
data/Rakefile CHANGED
@@ -49,18 +49,17 @@ end
49
49
 
50
50
  po_parser_ry_path = "src/po_parser.ry"
51
51
  file po_parser_rb_path => po_parser_ry_path do
52
- racc = File.join(Gem.bindir, "racc")
52
+ racc_spec = Gem::Specification.find_by_name("racc")
53
+ racc = File.join(racc_spec.bin_dir, racc_spec.executable)
53
54
  tempfile = Tempfile.new("gettext-po-parser")
54
55
  ruby(racc, "-g", po_parser_ry_path, "-o", tempfile.path)
55
56
 
56
57
  File.open(po_parser_rb_path, "w") do |po_parser_rb|
57
58
  po_parser_rb.puts(<<-EOH)
58
- # -*- coding: utf-8 -*-
59
- #
60
59
  # po_parser.rb - Generate a .mo
61
60
  #
62
61
  # Copyright (C) 2003-2009 Masao Mutoh <mutomasa at gmail.com>
63
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
62
+ # Copyright (C) 2012-2023 Sutou Kouhei <kou@clear-code.com>
64
63
  #
65
64
  # You may redistribute it and/or modify it under the same
66
65
  # license terms as Ruby or LGPL.
@@ -85,6 +84,10 @@ end
85
84
  xgettext_options = ["--add-comments=TRANSLATORS:"]
86
85
  GetText::Tools::Task.define do |task|
87
86
  task.spec = spec
87
+ task.files = task.files.reject do |file|
88
+ file.start_with?("samples/") or
89
+ file.start_with?("test/")
90
+ end
88
91
  task.xgettext_options.concat(xgettext_options)
89
92
  end
90
93