ofm_gettext 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/COPYING +56 -0
  2. data/ChangeLog-1 +2016 -0
  3. data/NEWS-1 +414 -0
  4. data/gettext.gemspec +7 -8
  5. data/lib/gettext/runtime/class_info.rb +69 -0
  6. data/lib/gettext/runtime/locale_path.rb +123 -0
  7. data/lib/gettext/runtime/mofile.rb +332 -0
  8. data/lib/gettext/runtime/textdomain.rb +179 -0
  9. data/lib/gettext/runtime/textdomain_group.rb +26 -0
  10. data/lib/gettext/runtime/textdomain_manager.rb +214 -0
  11. data/lib/gettext/tools/parser/erb.rb +54 -0
  12. data/lib/gettext/tools/parser/glade.rb +100 -0
  13. data/lib/gettext/tools/parser/ruby.rb +226 -0
  14. data/lib/gettext/tools/pomessage.rb +199 -0
  15. data/lib/gettext/tools/poparser.rb +358 -0
  16. data/po/uk/rgettext.po +143 -0
  17. data/samples/cgi/po/uk/helloerb1.po +62 -0
  18. data/samples/cgi/po/uk/helloerb2.po +54 -0
  19. data/samples/cgi/po/uk/hellolib.po +26 -0
  20. data/samples/cgi/po/uk/main.po +84 -0
  21. data/samples/po/uk/hello.po +22 -0
  22. data/samples/po/uk/hello2.po +30 -0
  23. data/samples/po/uk/hello_glade2.po +34 -0
  24. data/samples/po/uk/hello_gtk.po +22 -0
  25. data/samples/po/uk/hello_noop.po +26 -0
  26. data/samples/po/uk/hello_plural.po +29 -0
  27. data/samples/po/uk/hello_tk.po +26 -0
  28. data/test/po/ja/test3.po +19 -0
  29. data/test/po/li/plural_error.po +27 -0
  30. data/test/test_locale_path.rb +76 -0
  31. data/test/test_po_generation.rb +22 -0
  32. data/test/test_pomessage.rb +101 -0
  33. data/test/test_textdomain_bind.rb +39 -0
  34. data/test/test_thread.rb +43 -0
  35. data/test/tools/files/app.pot +0 -0
  36. data/test/tools/files/de/app.po +0 -0
  37. data/test/tools/files/en/app.po +0 -0
  38. data/test/tools/files/en/test.po +21 -0
  39. data/test/tools/files/simple_1.po +2 -0
  40. data/test/tools/files/simple_2.po +2 -0
  41. data/test/tools/files/simple_translation.rb +3 -0
  42. data/test/tools/files/version.po +7 -0
  43. data/test/tools/test.pot +21 -0
  44. data/test/tools/test_tools.rb +63 -0
  45. metadata +380 -335
@@ -0,0 +1,27 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR ORGANIZATION
3
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
+ #
5
+ #, fuzzy
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: PACKAGE VERSION\n"
9
+ "POT-Creation-Date: 2002-10-21 15:32:15+0900\n"
10
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12
+ "Language-Team: LANGUAGE <LL@li.org>\n"
13
+ "MIME-Version: 1.0\n"
14
+ "Content-Type: text/plain; charset=US-ASCII\n"
15
+ "Content-Transfer-Encoding: ENCODING\n"
16
+ "Plural-Forms: nplurals=0; plural=EXPRESSION;\n"
17
+
18
+ #: hello_plural.rb:11
19
+ msgid "first"
20
+ msgid_plural "second"
21
+ msgstr[0] "li_first"
22
+
23
+ #: hello_plural.rb:13
24
+ msgid "one"
25
+ msgid_plural "two"
26
+ msgstr[0] "li_one"
27
+ msgstr[1] "li_two"
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ require 'testlib/helper.rb'
4
+ require 'testlib/simple'
5
+
6
+ class TestLocalePath < Test::Unit::TestCase
7
+ def setup
8
+ GetText.locale = "ja_JP.eucJP"
9
+ GetText::LocalePath.clear
10
+ end
11
+
12
+ def test_locale_path
13
+ test = Simple.new
14
+ assert_equal("japanese", test.test)
15
+ prefix = GetText::LocalePath::CONFIG_PREFIX
16
+ default_locale_dirs = [
17
+ "./locale/%{lang}/LC_MESSAGES/%{name}.mo",
18
+ "./locale/%{lang}/%{name}.mo",
19
+ "#{Config::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
20
+ "#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
21
+ "#{prefix}/share/locale/%{lang}/LC_MESSAGES/%{name}.mo",
22
+ "#{prefix}/local/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
23
+ ].uniq
24
+ assert_equal(default_locale_dirs, GetText::LocalePath::DEFAULT_RULES)
25
+ new_path = "/foo/%{lang}/%{name}.mo"
26
+ GetText::LocalePath.add_default_rule(new_path)
27
+ assert_equal([new_path] + default_locale_dirs, GetText::LocalePath::DEFAULT_RULES)
28
+ end
29
+
30
+ def test_initialize_with_topdir
31
+ testdir = File.dirname(File.expand_path(__FILE__))
32
+ path = GetText::LocalePath.new("test1", "#{testdir}/locale")
33
+ assert_equal path.locale_paths, { "ja" => "#{testdir}/locale/ja/LC_MESSAGES/test1.mo",
34
+ "fr" => "#{testdir}/locale/fr/LC_MESSAGES/test1.mo"}
35
+ assert_equal path.current_path(Locale::Tag.parse("ja")), "#{testdir}/locale/ja/LC_MESSAGES/test1.mo"
36
+ assert_equal path.current_path(Locale::Tag.parse("ja-JP")), "#{testdir}/locale/ja/LC_MESSAGES/test1.mo"
37
+ assert_equal path.current_path(Locale::Tag.parse("ja_JP.UTF-8")), "#{testdir}/locale/ja/LC_MESSAGES/test1.mo"
38
+ assert_equal path.current_path(Locale::Tag.parse("en")), nil
39
+ end
40
+
41
+ def test_supported_locales
42
+ testdir = File.dirname(File.expand_path(__FILE__))
43
+ path = GetText::LocalePath.new("test1", "#{testdir}/locale")
44
+ assert_equal ["fr", "ja"], path.supported_locales
45
+
46
+ path = GetText::LocalePath.new("plural", "#{testdir}/locale")
47
+ assert_equal ["cr", "da", "fr", "ir", "ja", "la", "li", "po", "sl"], path.supported_locales
48
+
49
+ path = GetText::LocalePath.new("nodomain", "#{testdir}/locale")
50
+ assert_equal [], path.supported_locales
51
+ end
52
+
53
+ def test_env_GETTEXT_PATH
54
+ topdir = File.join(File.dirname(File.expand_path(__FILE__)), "../samples")
55
+ path1 = File.join(topdir, "locale")
56
+ path2 = File.join(topdir, "cgi", "locale")
57
+
58
+ GetText::LocalePath.memoize_clear
59
+ ENV["GETTEXT_PATH"] = path1
60
+ default_path_rules = GetText::LocalePath.default_path_rules
61
+ assert(Regexp.compile(path1) =~ default_path_rules[0])
62
+
63
+ GetText::LocalePath.memoize_clear
64
+ ENV["GETTEXT_PATH"] = "#{path1},#{path2}"
65
+ default_path_rules = GetText::LocalePath.default_path_rules
66
+ assert(Regexp.compile(path1) =~ default_path_rules[0])
67
+ assert(Regexp.compile(path2) =~ default_path_rules[1])
68
+ end
69
+
70
+ def test_default_path_rules
71
+ GetText::LocalePath.memoize_clear
72
+ $LOAD_PATH.unshift("./lib")
73
+ default_path_rules = GetText::LocalePath.default_path_rules
74
+ assert_equal($LOAD_PATH[0], "./lib")
75
+ end
76
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'testlib/helper.rb'
4
+ require 'gettext'
5
+ require 'gettext/tools/rgettext.rb'
6
+ require 'stringio'
7
+
8
+ class TestPoGeneration < Test::Unit::TestCase
9
+ def test_extracted_comments
10
+ GetText::RGetText.run(
11
+ File.join(File.dirname(__FILE__), 'testlib/gettext.rb'),
12
+ out = StringIO.new)
13
+ res = out.string
14
+
15
+ # Use following to debug the content of the
16
+ # created file: File.open('/tmp/test.po', 'w').write(res)
17
+
18
+ assert_match '#. "Fran\u00e7ois" or (with HTML entities) "Fran&ccedil;ois".', res
19
+ assert_no_match /Ignored/, res, 'Only comments starting with TRANSLATORS should be extracted'
20
+ assert_no_match /TRANSLATORS: This is a proper name/, res, 'The prefix "TRANSLATORS:" should be skipped'
21
+ end
22
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+
3
+ require 'testlib/helper.rb'
4
+ require 'gettext/tools/parser/ruby'
5
+
6
+ # Most functionality of PoMessage is thoroughly tested together
7
+ # with the parser and po file generator. Here only tests for some special
8
+ # functionality.
9
+ class TestPoMessage < Test::Unit::TestCase
10
+
11
+ def test_context_match
12
+ tt1 = GetText::PoMessage.new(:msgctxt)
13
+ tt1.msgid = 'hello'
14
+ tt1.msgctxt = 'world'
15
+ tt2 = GetText::PoMessage.new(:normal)
16
+ tt2.msgid = 'hello'
17
+ assert_raise GetText::ParseError do
18
+ tt1.merge tt2
19
+ end
20
+ end
21
+
22
+ def test_attribute_accumulation
23
+ tt = GetText::PoMessage.new(:plural)
24
+ tt.set_current_attribute 'long'
25
+ tt.set_current_attribute ' tail'
26
+ tt.advance_to_next_attribute
27
+ tt.set_current_attribute 'long tails'
28
+ assert_equal 'long tail', tt.msgid
29
+ assert_equal 'long tails', tt.msgid_plural
30
+ end
31
+
32
+ def test_to_po_str_normal
33
+ po = GetText::PoMessage.new(:normal)
34
+ po.msgid = 'hello'
35
+ po.sources = ["file1:1", "file2:10"]
36
+ assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_po_str
37
+
38
+ po.msgctxt = 'context'
39
+ po.msgid_plural = 'hello2'
40
+ # Ignore these properties.
41
+ assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_po_str
42
+ end
43
+
44
+ def test_to_po_str_plural
45
+ po = GetText::PoMessage.new(:plural)
46
+ po.msgid = 'hello'
47
+ po.msgid_plural = 'hello2'
48
+ po.sources = ["file1:1", "file2:10"]
49
+ assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_po_str
50
+
51
+ po.msgctxt = 'context'
52
+ # Ignore this property
53
+ assert_equal "\n#: file1:1 file2:10\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_po_str
54
+ end
55
+
56
+ def test_to_po_str_msgctxt
57
+ po = GetText::PoMessage.new(:msgctxt)
58
+ po.msgctxt = 'context'
59
+ po.msgid = 'hello'
60
+ po.sources = ["file1:1", "file2:10"]
61
+ assert_equal "\n#: file1:1 file2:10\nmsgctxt \"context\"\nmsgid \"hello\"\nmsgstr \"\"\n", po.to_po_str
62
+ end
63
+
64
+ def test_to_po_str_msgctxt_plural
65
+ po = GetText::PoMessage.new(:msgctxt_plural)
66
+ po.msgctxt = 'context'
67
+ po.msgid = 'hello'
68
+ po.msgid_plural = 'hello2'
69
+ po.sources = ["file1:1", "file2:10"]
70
+ assert_equal "\n#: file1:1 file2:10\nmsgctxt \"context\"\nmsgid \"hello\"\nmsgid_plural \"hello2\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n", po.to_po_str
71
+ end
72
+
73
+ def test_to_po_str_exception
74
+ po = GetText::PoMessage.new(:normal)
75
+ po.sources = ["file1:1", "file2:10"]
76
+ assert_raise(RuntimeError){ po.to_po_str }
77
+
78
+ po.sources = nil
79
+ assert_raise(RuntimeError){ po.to_po_str }
80
+
81
+ po = GetText::PoMessage.new(:plural)
82
+ po.msgid = 'hello'
83
+ po.sources = ["file1:1", "file2:10"]
84
+ assert_raise(RuntimeError){ po.to_po_str }
85
+
86
+ po.msgid_plural = 'hello2'
87
+ po.sources = nil
88
+ assert_raise(RuntimeError){ po.to_po_str }
89
+
90
+ po = GetText::PoMessage.new(:msgctxt)
91
+ po.msgid = 'hello'
92
+ po.sources = ["file1:1", "file2:10"]
93
+ assert_raise(RuntimeError){ po.to_po_str }
94
+
95
+ po = GetText::PoMessage.new(:msgctxt_plural)
96
+ po.msgctxt = 'context'
97
+ po.msgid = 'hello'
98
+ po.sources = ["file1:1", "file2:10"]
99
+ assert_raise(RuntimeError){ po.to_po_str }
100
+ end
101
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'testlib/helper.rb'
4
+
5
+ class Foo
6
+ end
7
+
8
+ class TestGetTextBind < Test::Unit::TestCase
9
+ def setup
10
+ GetText.locale = "ja_JP.EUC-JP"
11
+ GetText::TextDomainManager.clear_all_textdomains
12
+ end
13
+
14
+ def test_bindtextdomain
15
+ domain = GetText.bindtextdomain("foo")
16
+ assert_equal domain, GetText::TextDomainManager.create_or_find_textdomain_group(Object).textdomains[0]
17
+ assert_equal domain, GetText::TextDomainManager.textdomain_pool("foo")
18
+ end
19
+
20
+ def test_textdomain
21
+ domain1 = GetText.bindtextdomain("foo")
22
+
23
+ assert_equal domain1, GetText.textdomain("foo")
24
+
25
+ assert_raise(GetText::NoboundTextDomainError) {
26
+ GetText.textdomain_to(Foo, "bar")
27
+ }
28
+ end
29
+
30
+ def test_textdomain_to
31
+ domain1 = GetText.bindtextdomain("foo")
32
+
33
+ assert_equal domain1, GetText.textdomain_to(Foo, "foo")
34
+
35
+ assert_raise(GetText::NoboundTextDomainError) {
36
+ GetText.textdomain_to(Foo, "bar")
37
+ }
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'testlib/helper.rb'
4
+ require 'thread'
5
+
6
+ class TestThread < Test::Unit::TestCase
7
+ include GetText
8
+
9
+ bindtextdomain "test1", :path => "locale"
10
+
11
+ def setup
12
+ Locale.init(:driver => :env)
13
+ @mutex = Mutex.new
14
+ end
15
+
16
+ def invoke_thread(tag, language, sleep_time)
17
+ Thread.start do
18
+ @mutex.synchronize {
19
+ Thread.current["language"] = language
20
+ GetText.current_locale = tag
21
+ }
22
+ (1..10).each do |v|
23
+ @mutex.synchronize{
24
+ assert_equal Thread.current["language"], _("language")
25
+ }
26
+ print "."
27
+ $stdout.flush
28
+ sleep sleep_time
29
+ end
30
+ end
31
+ end
32
+
33
+ def test_thread
34
+ th1 = invoke_thread("ja_JP.eucJP", "japanese", 0.4)
35
+ th2 = invoke_thread("fr", "french", 0.3)
36
+ th3 = invoke_thread("en", "language", 0.1)
37
+ th4 = invoke_thread("zh_CN", "language", 0.2) # No translation.
38
+ th1.join
39
+ th2.join
40
+ th3.join
41
+ th4.join
42
+ end
43
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: x\n"
10
+ "POT-Creation-Date: 2009-02-15 09:23+0100\n"
11
+ "PO-Revision-Date: 2009-02-15 09:23+0100\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ #: tools/files/simple_translation.rb:1
20
+ msgid "a translation"
21
+ msgstr ""
@@ -0,0 +1,2 @@
1
+ msgid "x"
2
+ msgstr "y"
@@ -0,0 +1,2 @@
1
+ msgid "a"
2
+ msgstr "b"
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ _('a translation')
@@ -0,0 +1,7 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: ruby-gettext 2.0.0\n"
4
+ "Content-Type: text/plain; charset=UTF-8\n"
5
+
6
+ msgid "x"
7
+ msgstr "x"
@@ -0,0 +1,21 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: x\n"
10
+ "POT-Creation-Date: 2009-02-15 09:22+0100\n"
11
+ "PO-Revision-Date: 2009-02-15 09:22+0100\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ #: tools/files/simple_translation.rb:1
20
+ msgid "a translation"
21
+ msgstr ""
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'testlib/helper'
4
+
5
+ require 'gettext/tools'
6
+ class TestToolsTools < Test::Unit::TestCase
7
+ def setup
8
+ FileUtils.cp_r "tools/files", "tools/test_files"
9
+ end
10
+ def teardown
11
+ FileUtils.rm_rf "tools/test_files"
12
+ end
13
+
14
+ def test_msgmerge_merges_old_and_new_po_file
15
+ GetText.msgmerge(path('simple_1.po'),path('simple_2.po'),'X',:msgmerge=>[:sort_output,:no_location])
16
+ assert_equal File.read(path('simple_1.po')), <<EOF
17
+ msgid "a"
18
+ msgstr "b"
19
+
20
+ #~ msgid "x"
21
+ #~ msgstr "y"
22
+ EOF
23
+ end
24
+
25
+ def test_msgmerge_inserts_the_new_version
26
+ old = backup('version.po')
27
+ GetText.msgmerge(old,path('version.po'),'NEW')
28
+ assert File.read(old) =~ /"Project-Id-Version: NEW\\n"/
29
+ end
30
+
31
+ def test_update_pofiles_updates_a_single_language
32
+ GetText.update_pofiles('app',[path('simple_translation.rb')],'x',:po_root=>path('.'),:lang=>'en',:msgmerge=>[:no_location])
33
+ text = <<EOF
34
+ msgid "a translation"
35
+ msgstr ""
36
+ EOF
37
+ assert_equal text, File.read(path('app.pot'))
38
+ assert_equal text, File.read(path('en/app.po'))
39
+ assert_equal '', File.read(path('de/app.po'))
40
+ end
41
+
42
+ def test_update_pofiles_updates_creates_po_folder_if_missing
43
+ GetText.update_pofiles('app',[path('simple_translation.rb')],'x',:po_root=>path('./xx'))
44
+ assert File.exist?(path('xx/app.pot'))
45
+ end
46
+
47
+ def test_create_mofiles_generates_mo_for_each_po
48
+ GetText.create_mofiles(:po_root=>path('.'),:mo_root=>path('mo'))
49
+ assert File.exist?(path('mo/en/LC_MESSAGES/app.mo'))
50
+ assert File.exist?(path('mo/de/LC_MESSAGES/app.mo'))
51
+ end
52
+ private
53
+
54
+ def backup(name)
55
+ copy = path(name+".bak")
56
+ FileUtils.cp path(name), copy
57
+ copy
58
+ end
59
+
60
+ def path(name)
61
+ File.join(File.dirname(__FILE__),'test_files',name)
62
+ end
63
+ end