fair-gettext 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +78 -0
- data/README.rdoc +245 -0
- data/Rakefile +234 -0
- data/bin/rgettext +23 -0
- data/bin/rmsgfmt +22 -0
- data/bin/rmsgmerge +22 -0
- data/gettext.gemspec +40 -0
- data/lib/gettext/cgi.rb +37 -0
- data/lib/gettext/core_ext/iconv.rb +110 -0
- data/lib/gettext/core_ext/string.rb +84 -0
- data/lib/gettext/parser/erb.rb +3 -0
- data/lib/gettext/parser/glade.rb +3 -0
- data/lib/gettext/parser/ruby.rb +172 -0
- data/lib/gettext/tools/rgettext.rb +248 -0
- data/lib/gettext/tools/rmsgfmt.rb +84 -0
- data/lib/gettext/tools/rmsgmerge.rb +498 -0
- data/lib/gettext/tools.rb +202 -0
- data/lib/gettext/utils.rb +37 -0
- data/lib/gettext/version.rb +12 -0
- data/lib/gettext.rb +310 -0
- data/po/bg/rgettext.po +134 -0
- data/po/bs/rgettext.po +135 -0
- data/po/ca/rgettext.po +133 -0
- data/po/cs/rgettext.po +136 -0
- data/po/de/rgettext.po +141 -0
- data/po/el/rgettext.po +132 -0
- data/po/eo/rgettext.po +133 -0
- data/po/es/rgettext.po +134 -0
- data/po/et/rgettext.po +131 -0
- data/po/fr/rgettext.po +137 -0
- data/po/hr/rgettext.po +135 -0
- data/po/hu/rgettext.po +133 -0
- data/po/it/rgettext.po +134 -0
- data/po/ja/rgettext.po +134 -0
- data/po/ko/rgettext.po +133 -0
- data/po/lv/rgettext.po +134 -0
- data/po/nb/rgettext.po +135 -0
- data/po/nl/rgettext.po +134 -0
- data/po/pt_BR/rgettext.po +136 -0
- data/po/rgettext.pot +125 -0
- data/po/ru/rgettext.po +135 -0
- data/po/sr/rgettext.po +134 -0
- data/po/sv/rgettext.po +127 -0
- data/po/ua/rgettext.po +138 -0
- data/po/vi/rgettext.po +132 -0
- data/po/zh/rgettext.po +133 -0
- data/po/zh_TW/rgettext.po +132 -0
- data/samples/README +16 -0
- data/samples/cgi/README +43 -0
- data/samples/cgi/Rakefile +27 -0
- data/samples/cgi/cookie.cgi +64 -0
- data/samples/cgi/gettext.css +116 -0
- data/samples/cgi/helloerb.rhtml +28 -0
- data/samples/cgi/helloerb1.cgi +58 -0
- data/samples/cgi/helloerb2.cgi +51 -0
- data/samples/cgi/hellolib.rb +18 -0
- data/samples/cgi/http.rb +49 -0
- data/samples/cgi/index.cgi +111 -0
- data/samples/cgi/other.rhtml +20 -0
- data/samples/cgi/po/bg/helloerb1.po +59 -0
- data/samples/cgi/po/bg/helloerb2.po +51 -0
- data/samples/cgi/po/bg/hellolib.po +23 -0
- data/samples/cgi/po/bg/main.po +83 -0
- data/samples/cgi/po/bs/helloerb1.po +59 -0
- data/samples/cgi/po/bs/helloerb2.po +51 -0
- data/samples/cgi/po/bs/hellolib.po +23 -0
- data/samples/cgi/po/bs/main.po +83 -0
- data/samples/cgi/po/ca/helloerb1.po +59 -0
- data/samples/cgi/po/ca/helloerb2.po +51 -0
- data/samples/cgi/po/ca/hellolib.po +23 -0
- data/samples/cgi/po/ca/main.po +83 -0
- data/samples/cgi/po/cs/helloerb1.po +61 -0
- data/samples/cgi/po/cs/helloerb2.po +52 -0
- data/samples/cgi/po/cs/hellolib.po +25 -0
- data/samples/cgi/po/cs/main.po +85 -0
- data/samples/cgi/po/de/helloerb1.po +61 -0
- data/samples/cgi/po/de/helloerb2.po +52 -0
- data/samples/cgi/po/de/hellolib.po +24 -0
- data/samples/cgi/po/de/main.po +86 -0
- data/samples/cgi/po/el/helloerb1.po +60 -0
- data/samples/cgi/po/el/helloerb2.po +51 -0
- data/samples/cgi/po/el/hellolib.po +23 -0
- data/samples/cgi/po/el/main.po +84 -0
- data/samples/cgi/po/eo/helloerb1.po +60 -0
- data/samples/cgi/po/eo/helloerb2.po +52 -0
- data/samples/cgi/po/eo/hellolib.po +24 -0
- data/samples/cgi/po/eo/main.po +84 -0
- data/samples/cgi/po/es/helloerb1.po +59 -0
- data/samples/cgi/po/es/helloerb2.po +50 -0
- data/samples/cgi/po/es/hellolib.po +22 -0
- data/samples/cgi/po/es/main.po +83 -0
- data/samples/cgi/po/fr/helloerb1.po +59 -0
- data/samples/cgi/po/fr/helloerb2.po +51 -0
- data/samples/cgi/po/fr/hellolib.po +22 -0
- data/samples/cgi/po/fr/main.po +85 -0
- data/samples/cgi/po/helloerb1.pot +60 -0
- data/samples/cgi/po/helloerb2.pot +52 -0
- data/samples/cgi/po/hellolib.pot +24 -0
- data/samples/cgi/po/hr/helloerb1.po +59 -0
- data/samples/cgi/po/hr/helloerb2.po +51 -0
- data/samples/cgi/po/hr/hellolib.po +23 -0
- data/samples/cgi/po/hr/main.po +83 -0
- data/samples/cgi/po/hu/helloerb1.po +59 -0
- data/samples/cgi/po/hu/helloerb2.po +51 -0
- data/samples/cgi/po/hu/hellolib.po +23 -0
- data/samples/cgi/po/hu/main.po +82 -0
- data/samples/cgi/po/it/helloerb1.po +60 -0
- data/samples/cgi/po/it/helloerb2.po +52 -0
- data/samples/cgi/po/it/hellolib.po +24 -0
- data/samples/cgi/po/it/main.po +84 -0
- data/samples/cgi/po/ja/helloerb1.po +60 -0
- data/samples/cgi/po/ja/helloerb2.po +52 -0
- data/samples/cgi/po/ja/hellolib.po +24 -0
- data/samples/cgi/po/ja/main.po +85 -0
- data/samples/cgi/po/ko/helloerb1.po +59 -0
- data/samples/cgi/po/ko/helloerb2.po +51 -0
- data/samples/cgi/po/ko/hellolib.po +23 -0
- data/samples/cgi/po/ko/main.po +84 -0
- data/samples/cgi/po/lv/helloerb1.po +65 -0
- data/samples/cgi/po/lv/helloerb2.po +52 -0
- data/samples/cgi/po/lv/hellolib.po +24 -0
- data/samples/cgi/po/lv/main.po +77 -0
- data/samples/cgi/po/main.pot +80 -0
- data/samples/cgi/po/nb/helloerb1.po +60 -0
- data/samples/cgi/po/nb/helloerb2.po +52 -0
- data/samples/cgi/po/nb/hellolib.po +24 -0
- data/samples/cgi/po/nb/main.po +84 -0
- data/samples/cgi/po/nl/helloerb1.po +61 -0
- data/samples/cgi/po/nl/helloerb2.po +52 -0
- data/samples/cgi/po/nl/hellolib.po +24 -0
- data/samples/cgi/po/nl/main.po +86 -0
- data/samples/cgi/po/pt_BR/helloerb1.po +59 -0
- data/samples/cgi/po/pt_BR/helloerb2.po +51 -0
- data/samples/cgi/po/pt_BR/hellolib.po +23 -0
- data/samples/cgi/po/pt_BR/main.po +84 -0
- data/samples/cgi/po/ru/helloerb1.po +58 -0
- data/samples/cgi/po/ru/helloerb2.po +50 -0
- data/samples/cgi/po/ru/hellolib.po +22 -0
- data/samples/cgi/po/ru/main.po +82 -0
- data/samples/cgi/po/sr/helloerb1.po +60 -0
- data/samples/cgi/po/sr/helloerb2.po +52 -0
- data/samples/cgi/po/sr/hellolib.po +24 -0
- data/samples/cgi/po/sr/main.po +80 -0
- data/samples/cgi/po/ua/helloerb1.po +62 -0
- data/samples/cgi/po/ua/helloerb2.po +54 -0
- data/samples/cgi/po/ua/hellolib.po +26 -0
- data/samples/cgi/po/ua/main.po +84 -0
- data/samples/cgi/po/vi/helloerb1.po +65 -0
- data/samples/cgi/po/vi/helloerb2.po +52 -0
- data/samples/cgi/po/vi/hellolib.po +24 -0
- data/samples/cgi/po/vi/main.po +77 -0
- data/samples/cgi/po/zh/helloerb1.po +60 -0
- data/samples/cgi/po/zh/helloerb2.po +52 -0
- data/samples/cgi/po/zh/hellolib.po +24 -0
- data/samples/cgi/po/zh/main.po +80 -0
- data/samples/cgi/po/zh_TW/helloerb1.po +67 -0
- data/samples/cgi/po/zh_TW/helloerb2.po +54 -0
- data/samples/cgi/po/zh_TW/hellolib.po +26 -0
- data/samples/cgi/po/zh_TW/main.po +79 -0
- data/samples/hello.rb +36 -0
- data/samples/hello2.rb +23 -0
- data/samples/hello_glade2.glade +70 -0
- data/samples/hello_glade2.rb +25 -0
- data/samples/hello_gtk2.rb +27 -0
- data/samples/hello_noop.rb +31 -0
- data/samples/hello_plural.rb +26 -0
- data/samples/hello_tk.rb +19 -0
- data/samples/makemo.rb +4 -0
- data/samples/po/bg/hello.po +24 -0
- data/samples/po/bg/hello2.po +31 -0
- data/samples/po/bg/hello_glade2.po +31 -0
- data/samples/po/bg/hello_gtk.po +23 -0
- data/samples/po/bg/hello_noop.po +27 -0
- data/samples/po/bg/hello_plural.po +25 -0
- data/samples/po/bg/hello_tk.po +23 -0
- data/samples/po/bs/hello.po +23 -0
- data/samples/po/bs/hello2.po +31 -0
- data/samples/po/bs/hello_glade2.po +31 -0
- data/samples/po/bs/hello_gtk.po +23 -0
- data/samples/po/bs/hello_noop.po +27 -0
- data/samples/po/bs/hello_plural.po +26 -0
- data/samples/po/bs/hello_tk.po +23 -0
- data/samples/po/ca/hello.po +23 -0
- data/samples/po/ca/hello2.po +31 -0
- data/samples/po/ca/hello_glade2.po +31 -0
- data/samples/po/ca/hello_gtk.po +23 -0
- data/samples/po/ca/hello_noop.po +27 -0
- data/samples/po/ca/hello_plural.po +25 -0
- data/samples/po/ca/hello_tk.po +23 -0
- data/samples/po/cs/hello.po +23 -0
- data/samples/po/cs/hello2.po +31 -0
- data/samples/po/cs/hello_glade2.po +37 -0
- data/samples/po/cs/hello_gtk.po +23 -0
- data/samples/po/cs/hello_noop.po +27 -0
- data/samples/po/cs/hello_plural.po +26 -0
- data/samples/po/cs/hello_tk.po +23 -0
- data/samples/po/de/hello.po +20 -0
- data/samples/po/de/hello2.po +28 -0
- data/samples/po/de/hello_glade2.po +27 -0
- data/samples/po/de/hello_gtk.po +20 -0
- data/samples/po/de/hello_noop.po +24 -0
- data/samples/po/de/hello_plural.po +25 -0
- data/samples/po/de/hello_tk.po +20 -0
- data/samples/po/el/hello.po +23 -0
- data/samples/po/el/hello2.po +31 -0
- data/samples/po/el/hello_glade2.po +31 -0
- data/samples/po/el/hello_gtk.po +22 -0
- data/samples/po/el/hello_noop.po +27 -0
- data/samples/po/el/hello_plural.po +25 -0
- data/samples/po/el/hello_tk.po +23 -0
- data/samples/po/eo/hello.po +23 -0
- data/samples/po/eo/hello2.po +31 -0
- data/samples/po/eo/hello_glade2.po +32 -0
- data/samples/po/eo/hello_gtk.po +23 -0
- data/samples/po/eo/hello_noop.po +27 -0
- data/samples/po/eo/hello_plural.po +26 -0
- data/samples/po/eo/hello_tk.po +24 -0
- data/samples/po/es/hello.po +21 -0
- data/samples/po/es/hello2.po +28 -0
- data/samples/po/es/hello_glade2.po +28 -0
- data/samples/po/es/hello_gtk.po +20 -0
- data/samples/po/es/hello_noop.po +24 -0
- data/samples/po/es/hello_plural.po +23 -0
- data/samples/po/es/hello_tk.po +20 -0
- data/samples/po/fr/hello.po +18 -0
- data/samples/po/fr/hello2.po +26 -0
- data/samples/po/fr/hello_glade2.po +27 -0
- data/samples/po/fr/hello_gtk.po +18 -0
- data/samples/po/fr/hello_noop.po +22 -0
- data/samples/po/fr/hello_plural.po +21 -0
- data/samples/po/fr/hello_tk.po +18 -0
- data/samples/po/hello.pot +23 -0
- data/samples/po/hello2.pot +31 -0
- data/samples/po/hello_glade2.pot +32 -0
- data/samples/po/hello_gtk.pot +23 -0
- data/samples/po/hello_noop.pot +27 -0
- data/samples/po/hello_plural.pot +26 -0
- data/samples/po/hello_tk.pot +24 -0
- data/samples/po/hr/hello.po +23 -0
- data/samples/po/hr/hello2.po +31 -0
- data/samples/po/hr/hello_glade2.po +31 -0
- data/samples/po/hr/hello_gtk.po +23 -0
- data/samples/po/hr/hello_noop.po +27 -0
- data/samples/po/hr/hello_plural.po +26 -0
- data/samples/po/hr/hello_tk.po +23 -0
- data/samples/po/hu/hello.po +22 -0
- data/samples/po/hu/hello2.po +30 -0
- data/samples/po/hu/hello_glade2.po +31 -0
- data/samples/po/hu/hello_gtk.po +22 -0
- data/samples/po/hu/hello_noop.po +26 -0
- data/samples/po/hu/hello_plural.po +25 -0
- data/samples/po/hu/hello_tk.po +23 -0
- data/samples/po/it/hello.po +20 -0
- data/samples/po/it/hello2.po +28 -0
- data/samples/po/it/hello_glade2.po +28 -0
- data/samples/po/it/hello_gtk.po +21 -0
- data/samples/po/it/hello_noop.po +24 -0
- data/samples/po/it/hello_plural.po +23 -0
- data/samples/po/it/hello_tk.po +21 -0
- data/samples/po/ja/hello.po +20 -0
- data/samples/po/ja/hello2.po +28 -0
- data/samples/po/ja/hello_glade2.po +26 -0
- data/samples/po/ja/hello_gtk.po +19 -0
- data/samples/po/ja/hello_noop.po +23 -0
- data/samples/po/ja/hello_plural.po +21 -0
- data/samples/po/ja/hello_tk.po +19 -0
- data/samples/po/ko/hello.po +18 -0
- data/samples/po/ko/hello2.po +26 -0
- data/samples/po/ko/hello_glade2.po +29 -0
- data/samples/po/ko/hello_gtk.po +18 -0
- data/samples/po/ko/hello_noop.po +22 -0
- data/samples/po/ko/hello_plural.po +25 -0
- data/samples/po/ko/hello_tk.po +19 -0
- data/samples/po/lv/hello.po +24 -0
- data/samples/po/lv/hello2.po +32 -0
- data/samples/po/lv/hello_glade2.po +38 -0
- data/samples/po/lv/hello_gtk.po +24 -0
- data/samples/po/lv/hello_noop.po +28 -0
- data/samples/po/lv/hello_plural.po +26 -0
- data/samples/po/lv/hello_tk.po +24 -0
- data/samples/po/nb/hello.po +23 -0
- data/samples/po/nb/hello2.po +31 -0
- data/samples/po/nb/hello_glade2.po +31 -0
- data/samples/po/nb/hello_gtk.po +23 -0
- data/samples/po/nb/hello_noop.po +27 -0
- data/samples/po/nb/hello_plural.po +26 -0
- data/samples/po/nb/hello_tk.po +24 -0
- data/samples/po/nl/hello.po +24 -0
- data/samples/po/nl/hello2.po +32 -0
- data/samples/po/nl/hello_glade2.po +31 -0
- data/samples/po/nl/hello_gtk.po +24 -0
- data/samples/po/nl/hello_noop.po +28 -0
- data/samples/po/nl/hello_plural.po +25 -0
- data/samples/po/nl/hello_tk.po +24 -0
- data/samples/po/pt_BR/hello.po +21 -0
- data/samples/po/pt_BR/hello2.po +29 -0
- data/samples/po/pt_BR/hello_glade2.po +29 -0
- data/samples/po/pt_BR/hello_gtk.po +21 -0
- data/samples/po/pt_BR/hello_noop.po +25 -0
- data/samples/po/pt_BR/hello_plural.po +23 -0
- data/samples/po/pt_BR/hello_tk.po +21 -0
- data/samples/po/ru/hello.po +22 -0
- data/samples/po/ru/hello2.po +30 -0
- data/samples/po/ru/hello_glade2.po +30 -0
- data/samples/po/ru/hello_gtk.po +22 -0
- data/samples/po/ru/hello_noop.po +26 -0
- data/samples/po/ru/hello_plural.po +28 -0
- data/samples/po/ru/hello_tk.po +22 -0
- data/samples/po/sr/hello.po +22 -0
- data/samples/po/sr/hello2.po +30 -0
- data/samples/po/sr/hello_glade2.po +32 -0
- data/samples/po/sr/hello_gtk.po +22 -0
- data/samples/po/sr/hello_noop.po +26 -0
- data/samples/po/sr/hello_plural.po +26 -0
- data/samples/po/sr/hello_tk.po +24 -0
- data/samples/po/sv/hello.po +20 -0
- data/samples/po/sv/hello2.po +28 -0
- data/samples/po/sv/hello_glade2.po +28 -0
- data/samples/po/sv/hello_gtk.po +20 -0
- data/samples/po/sv/hello_noop.po +24 -0
- data/samples/po/sv/hello_plural.po +23 -0
- data/samples/po/sv/hello_tk.po +20 -0
- data/samples/po/test.rb +11 -0
- data/samples/po/ua/hello.po +22 -0
- data/samples/po/ua/hello2.po +30 -0
- data/samples/po/ua/hello_glade2.po +34 -0
- data/samples/po/ua/hello_gtk.po +22 -0
- data/samples/po/ua/hello_noop.po +26 -0
- data/samples/po/ua/hello_plural.po +29 -0
- data/samples/po/ua/hello_tk.po +26 -0
- data/samples/po/vi/hello.po +23 -0
- data/samples/po/vi/hello2.po +31 -0
- data/samples/po/vi/hello_glade2.po +38 -0
- data/samples/po/vi/hello_gtk.po +23 -0
- data/samples/po/vi/hello_noop.po +27 -0
- data/samples/po/vi/hello_plural.po +26 -0
- data/samples/po/vi/hello_tk.po +24 -0
- data/samples/po/zh/hello.po +23 -0
- data/samples/po/zh/hello2.po +31 -0
- data/samples/po/zh/hello_glade2.po +31 -0
- data/samples/po/zh/hello_gtk.po +23 -0
- data/samples/po/zh/hello_noop.po +27 -0
- data/samples/po/zh/hello_plural.po +25 -0
- data/samples/po/zh/hello_tk.po +23 -0
- data/samples/po/zh_TW/hello.po +26 -0
- data/samples/po/zh_TW/hello2.po +34 -0
- data/samples/po/zh_TW/hello_glade2.po +40 -0
- data/samples/po/zh_TW/hello_gtk.po +25 -0
- data/samples/po/zh_TW/hello_noop.po +30 -0
- data/samples/po/zh_TW/hello_plural.po +28 -0
- data/samples/po/zh_TW/hello_tk.po +26 -0
- data/src/poparser.ry +217 -0
- data/test/README +1 -0
- data/test/Rakefile +17 -0
- data/test/po/cr/plural.po +23 -0
- data/test/po/da/plural.po +22 -0
- data/test/po/da/plural_error.po +22 -0
- data/test/po/fr/plural.po +28 -0
- data/test/po/fr/plural_error.po +20 -0
- data/test/po/fr/test1.po +23 -0
- data/test/po/fr/test2.po +19 -0
- data/test/po/ir/plural.po +23 -0
- data/test/po/ja/npgettext.po +46 -0
- data/test/po/ja/nsgettext.po +65 -0
- data/test/po/ja/pgettext.po +41 -0
- data/test/po/ja/plural.po +28 -0
- data/test/po/ja/plural_error.po +20 -0
- data/test/po/ja/rubyparser.po +43 -0
- data/test/po/ja/sgettext.po +47 -0
- data/test/po/ja/test1.po +23 -0
- data/test/po/ja/test2.po +19 -0
- data/test/po/la/plural.po +23 -0
- data/test/po/la/plural_error.po +21 -0
- data/test/po/li/plural.po +23 -0
- data/test/po/po/plural.po +23 -0
- data/test/po/sl/plural.po +24 -0
- data/test/test_class_info.rb +83 -0
- data/test/test_gettext.rb +311 -0
- data/test/test_parser.rb +158 -0
- data/test/test_string.rb +65 -0
- data/test/test_textdomain_multi.rb +80 -0
- data/test/test_textdomain_toplevel.rb +42 -0
- data/test/testlib/N_.rb +66 -0
- data/test/testlib/erb.rhtml +15 -0
- data/test/testlib/erb.rxml +16 -0
- data/test/testlib/gettext.rb +113 -0
- data/test/testlib/gladeparser.glade +183 -0
- data/test/testlib/helper.rb +11 -0
- data/test/testlib/multi_textdomain.rb +131 -0
- data/test/testlib/ngettext.rb +79 -0
- data/test/testlib/npgettext.rb +31 -0
- data/test/testlib/nsgettext.rb +42 -0
- data/test/testlib/pgettext.rb +36 -0
- data/test/testlib/sgettext.rb +46 -0
- data/test/testlib/simple.rb +14 -0
- metadata +496 -0
@@ -0,0 +1,248 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
=begin
|
3
|
+
rgettext.rb - Generate a .pot file.
|
4
|
+
|
5
|
+
Copyright (C) 2003-2009 Masao Mutoh
|
6
|
+
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
|
7
|
+
|
8
|
+
Yasushi Shoji <yashi at atmark-techno.com>
|
9
|
+
Masao Mutoh <mutomasa at gmail.com>
|
10
|
+
|
11
|
+
You may redistribute it and/or modify it under the same
|
12
|
+
license terms as Ruby or LGPL.
|
13
|
+
=end
|
14
|
+
|
15
|
+
require 'optparse'
|
16
|
+
require 'gettext'
|
17
|
+
require 'rbconfig'
|
18
|
+
|
19
|
+
module GetText
|
20
|
+
|
21
|
+
module RGetText #:nodoc:
|
22
|
+
extend GetText
|
23
|
+
|
24
|
+
bindtextdomain("rgettext")
|
25
|
+
|
26
|
+
# constant values
|
27
|
+
VERSION = GetText::VERSION
|
28
|
+
|
29
|
+
@ex_parsers = []
|
30
|
+
[
|
31
|
+
["glade.rb", "GladeParser"],
|
32
|
+
["erb.rb", "ErbParser"],
|
33
|
+
# ["ripper.rb", "RipperParser"],
|
34
|
+
["ruby.rb", "RubyParser"] # Default parser.
|
35
|
+
].each do |f, klass|
|
36
|
+
begin
|
37
|
+
require "gettext/tools/parser/#{f}"
|
38
|
+
@ex_parsers << GetText.const_get(klass)
|
39
|
+
rescue
|
40
|
+
$stderr.puts _("'%{klass}' is ignored.") % {:klass => klass}
|
41
|
+
$stderr.puts $! if $DEBUG
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module_function
|
46
|
+
|
47
|
+
# Add an option parser
|
48
|
+
# the option parser module requires to have target?(file) and parser(file, ary) method.
|
49
|
+
#
|
50
|
+
# require 'gettext/tools/rgettext'
|
51
|
+
# module FooParser
|
52
|
+
# module_function
|
53
|
+
# def target?(file)
|
54
|
+
# File.extname(file) == '.foo' # *.foo file only.
|
55
|
+
# end
|
56
|
+
# def parse(file, ary)
|
57
|
+
# :
|
58
|
+
# return ary # [["msgid1", "foo.rb:200"], ["msgid2", "bar.rb:300", "baz.rb:400"], ...]
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# GetText::RGetText.add_parser(FooParser)
|
63
|
+
def add_parser(klass)
|
64
|
+
@ex_parsers.insert(0, klass)
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_pot_header # :nodoc:
|
68
|
+
time = Time.now.strftime("%Y-%m-%d %H:%M")
|
69
|
+
off = Time.now.utc_offset
|
70
|
+
sign = off <= 0 ? '-' : '+'
|
71
|
+
time += sprintf('%s%02d%02d', sign, *(off.abs / 60).divmod(60))
|
72
|
+
|
73
|
+
<<TITLE
|
74
|
+
# SOME DESCRIPTIVE TITLE.
|
75
|
+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
76
|
+
# This file is distributed under the same license as the PACKAGE package.
|
77
|
+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
78
|
+
#
|
79
|
+
#, fuzzy
|
80
|
+
msgid ""
|
81
|
+
msgstr ""
|
82
|
+
"Project-Id-Version: PACKAGE VERSION\\n"
|
83
|
+
"POT-Creation-Date: #{time}\\n"
|
84
|
+
"PO-Revision-Date: #{time}\\n"
|
85
|
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
|
86
|
+
"Language-Team: LANGUAGE <LL@li.org>\\n"
|
87
|
+
"MIME-Version: 1.0\\n"
|
88
|
+
"Content-Type: text/plain; charset=UTF-8\\n"
|
89
|
+
"Content-Transfer-Encoding: 8bit\\n"
|
90
|
+
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"
|
91
|
+
TITLE
|
92
|
+
end
|
93
|
+
|
94
|
+
#PARSE HERE
|
95
|
+
def generate_pot(paths) # :nodoc:
|
96
|
+
pomessages = parse(paths)
|
97
|
+
str = ""
|
98
|
+
|
99
|
+
pomessages.each do |target|
|
100
|
+
unless target.to_po_str.include? "[private]"
|
101
|
+
str << target.to_po_str
|
102
|
+
end
|
103
|
+
end
|
104
|
+
str
|
105
|
+
end
|
106
|
+
|
107
|
+
def generate_private_pot(paths)
|
108
|
+
pomessages = parse(paths)
|
109
|
+
private_str = ""
|
110
|
+
|
111
|
+
pomessages.each do |target|
|
112
|
+
if target.to_po_str.include? "[private]"
|
113
|
+
private_str << target.to_po_str
|
114
|
+
end
|
115
|
+
end
|
116
|
+
private_str
|
117
|
+
end
|
118
|
+
|
119
|
+
def parse(paths) # :nodoc:
|
120
|
+
pomessages = []
|
121
|
+
paths.each do |path|
|
122
|
+
begin
|
123
|
+
@ex_parsers.each do |klass|
|
124
|
+
if klass.target?(path)
|
125
|
+
if klass.method(:parse).arity == 1
|
126
|
+
targets = klass.parse(path)
|
127
|
+
else
|
128
|
+
# For backward compatibility.
|
129
|
+
targets = klass.parse(path, [])
|
130
|
+
end
|
131
|
+
|
132
|
+
targets.each{|pomessage|
|
133
|
+
if pomessage.kind_of? Array
|
134
|
+
pomessage = PoMessage.new_from_ary(pomessage)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Save the previous target.
|
138
|
+
existing = pomessages.find_index {|t| t == pomessage}
|
139
|
+
if existing
|
140
|
+
pomessage = pomessages[existing].merge(pomessage)
|
141
|
+
pomessages[existing] = pomessage
|
142
|
+
else
|
143
|
+
pomessages << pomessage
|
144
|
+
end
|
145
|
+
}
|
146
|
+
break
|
147
|
+
end
|
148
|
+
end
|
149
|
+
rescue
|
150
|
+
puts _("Error parsing %{path}") % {:path => path}
|
151
|
+
raise
|
152
|
+
end
|
153
|
+
end
|
154
|
+
pomessages
|
155
|
+
end
|
156
|
+
|
157
|
+
def check_options # :nodoc:
|
158
|
+
output = STDOUT
|
159
|
+
|
160
|
+
opts = OptionParser.new
|
161
|
+
opts.banner = _("Usage: %s input.rb [-r parser.rb] [-o output.pot]") % $0
|
162
|
+
opts.separator("")
|
163
|
+
opts.separator(_("Extract translatable strings from given input files."))
|
164
|
+
opts.separator("")
|
165
|
+
opts.separator(_("Specific options:"))
|
166
|
+
|
167
|
+
opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
|
168
|
+
unless FileTest.exist? out
|
169
|
+
output = File.new(File.expand_path(out), "w+")
|
170
|
+
else
|
171
|
+
$stderr.puts(_("File '%s' already exists.") % out)
|
172
|
+
exit 1
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
opts.on("-r", "--require=library", _("require the library before executing rgettext")) do |out|
|
177
|
+
require out
|
178
|
+
end
|
179
|
+
|
180
|
+
opts.on("-d", "--debug", _("run in debugging mode")) do
|
181
|
+
$DEBUG = true
|
182
|
+
end
|
183
|
+
|
184
|
+
opts.on_tail("--version", _("display version information and exit")) do
|
185
|
+
puts "#{$0} #{VERSION}"
|
186
|
+
puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
187
|
+
exit
|
188
|
+
end
|
189
|
+
|
190
|
+
opts.parse!(ARGV)
|
191
|
+
|
192
|
+
if ARGV.size == 0
|
193
|
+
puts opts.help
|
194
|
+
exit 1
|
195
|
+
end
|
196
|
+
|
197
|
+
[ARGV, output]
|
198
|
+
end
|
199
|
+
|
200
|
+
def run(paths = nil, out = STDOUT, private_out)
|
201
|
+
if paths.is_a? String
|
202
|
+
paths = [paths]
|
203
|
+
elsif ! paths
|
204
|
+
paths, out = check_options
|
205
|
+
end
|
206
|
+
|
207
|
+
if paths.size == 0
|
208
|
+
raise ArgumentError, _("no input files")
|
209
|
+
end
|
210
|
+
|
211
|
+
if ((out.is_a? String) and (private_out.is_a? String))
|
212
|
+
File.open(File.expand_path(out), "w+") do |file|
|
213
|
+
file.puts generate_pot_header
|
214
|
+
file.puts generate_pot(paths)
|
215
|
+
end
|
216
|
+
File.open(File.expand_path(private_out), "w+") do |file|
|
217
|
+
file.puts generate_pot_header
|
218
|
+
file.puts generate_private_pot(paths)
|
219
|
+
end
|
220
|
+
else
|
221
|
+
out.puts generate_pot_header
|
222
|
+
out.puts generate_pot(paths)
|
223
|
+
private_out.puts generate_pot_header
|
224
|
+
private_out.puts generate_private_pot(paths)
|
225
|
+
end
|
226
|
+
self
|
227
|
+
end
|
228
|
+
end
|
229
|
+
extend self
|
230
|
+
# Creates a po-file from targetfiles(ruby-script-files, .rhtml files, glade-2 XML files),
|
231
|
+
# then output the result to out. If no parameter is set, it behaves same as command line tools(rgettet).
|
232
|
+
#
|
233
|
+
# This function is a part of GetText.create_pofiles.
|
234
|
+
# Usually you don't need to call this function directly.
|
235
|
+
#
|
236
|
+
# * paths: An Array of po-file paths or nil.
|
237
|
+
# * out: output IO or output path.
|
238
|
+
# * Returns: self
|
239
|
+
def rgettext(paths = nil, out = STDOUT, private_out)
|
240
|
+
RGetText.run(paths, out, private_out)
|
241
|
+
self
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
if $0 == __FILE__
|
246
|
+
GetText.rgettext
|
247
|
+
# GetText.rgettext($0, "tmp.txt")
|
248
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
=begin
|
2
|
+
rmsgfmt.rb - Generate a .mo
|
3
|
+
|
4
|
+
Copyright (C) 2003-2009 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby or LGPL.
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'optparse'
|
11
|
+
require 'fileutils'
|
12
|
+
require 'gettext'
|
13
|
+
require 'gettext/tools/poparser'
|
14
|
+
require 'rbconfig'
|
15
|
+
|
16
|
+
module GetText
|
17
|
+
|
18
|
+
module RMsgfmt #:nodoc:
|
19
|
+
extend GetText
|
20
|
+
extend self
|
21
|
+
|
22
|
+
bindtextdomain "rgettext"
|
23
|
+
|
24
|
+
def run(targetfile = nil, output_path = nil) # :nodoc:
|
25
|
+
unless targetfile
|
26
|
+
targetfile, output_path = check_options
|
27
|
+
end
|
28
|
+
unless targetfile
|
29
|
+
raise ArgumentError, _("no input files")
|
30
|
+
end
|
31
|
+
unless output_path
|
32
|
+
output_path = "messages.mo"
|
33
|
+
end
|
34
|
+
|
35
|
+
parser = PoParser.new
|
36
|
+
data = MOFile.new
|
37
|
+
|
38
|
+
parser.parse_file(targetfile, data)
|
39
|
+
data.save_to_file(output_path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_options # :nodoc:
|
43
|
+
output = nil
|
44
|
+
|
45
|
+
opts = OptionParser.new
|
46
|
+
opts.banner = _("Usage: %s input.po [-o output.mo]" % $0)
|
47
|
+
opts.separator("")
|
48
|
+
opts.separator(_("Generate binary message catalog from textual translation description."))
|
49
|
+
opts.separator("")
|
50
|
+
opts.separator(_("Specific options:"))
|
51
|
+
|
52
|
+
opts.on("-o", "--output=FILE", _("write output to specified file")) do |out|
|
53
|
+
output = out
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on_tail("--version", _("display version information and exit")) do
|
57
|
+
puts "#{$0} #{GetText::VERSION}"
|
58
|
+
puts "#{File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
opts.parse!(ARGV)
|
62
|
+
|
63
|
+
if ARGV.size == 0
|
64
|
+
puts opts.help
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
[ARGV[0], output]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Creates a mo-file from a targetfile(po-file), then output the result to out.
|
73
|
+
# If no parameter is set, it behaves same as command line tools(rmsgfmt).
|
74
|
+
# * targetfile: An Array of po-files or nil.
|
75
|
+
# * output_path: output path.
|
76
|
+
# * Returns: the MOFile object.
|
77
|
+
def rmsgfmt(targetfile = nil, output_path = nil)
|
78
|
+
RMsgfmt.run(targetfile, output_path)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if $0 == __FILE__ then
|
83
|
+
GetText.rmsgfmt
|
84
|
+
end
|