gettext 2.0.4 → 2.1.0

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 (109) hide show
  1. data/COPYING +9 -8
  2. data/ChangeLog +21 -0
  3. data/README.rdoc +7 -13
  4. data/Rakefile +7 -5
  5. data/benchmark/1.93.0.txt +8 -0
  6. data/benchmark/2.0.0.txt +8 -0
  7. data/benchmark/2.0.4.txt +11 -0
  8. data/benchmark/2.1.0.txt +11 -0
  9. data/benchmark/benchmark.rb +68 -0
  10. data/benchmark/test.rb +28 -0
  11. data/bin/rgettext +1 -2
  12. data/bin/rmsgfmt +1 -3
  13. data/bin/rmsgmerge +0 -2
  14. data/data/locale/bg/LC_MESSAGES/rgettext.mo +0 -0
  15. data/data/locale/bs/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
  17. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  18. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  20. data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  22. data/data/locale/et/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  24. data/data/locale/hr/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/hu/LC_MESSAGES/rgettext.mo +0 -0
  26. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  28. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  29. data/data/locale/lv/LC_MESSAGES/rgettext.mo +0 -0
  30. data/data/locale/nb/LC_MESSAGES/rgettext.mo +0 -0
  31. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  32. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  33. data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
  34. data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
  35. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  36. data/data/locale/ua/LC_MESSAGES/rgettext.mo +0 -0
  37. data/data/locale/vi/LC_MESSAGES/rgettext.mo +0 -0
  38. data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
  39. data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
  40. data/lib/gettext.rb +4 -6
  41. data/lib/gettext/cgi.rb +1 -3
  42. data/lib/gettext/core_ext/iconv.rb +2 -4
  43. data/lib/gettext/core_ext/string.rb +3 -3
  44. data/lib/gettext/parser/erb.rb +2 -53
  45. data/lib/gettext/parser/glade.rb +2 -99
  46. data/lib/gettext/parser/ruby.rb +7 -5
  47. data/lib/gettext/{class_info.rb → runtime/class_info.rb} +2 -1
  48. data/lib/gettext/{locale_path.rb → runtime/locale_path.rb} +1 -2
  49. data/lib/gettext/{mofile.rb → runtime/mofile.rb} +0 -0
  50. data/lib/gettext/{textdomain.rb → runtime/textdomain.rb} +3 -5
  51. data/lib/gettext/{textdomain_group.rb → runtime/textdomain_group.rb} +1 -1
  52. data/lib/gettext/{textdomain_manager.rb → runtime/textdomain_manager.rb} +11 -5
  53. data/lib/gettext/tools.rb +2 -2
  54. data/lib/gettext/tools/parser/erb.rb +52 -0
  55. data/lib/gettext/tools/parser/glade.rb +98 -0
  56. data/lib/gettext/tools/parser/ruby.rb +226 -0
  57. data/lib/gettext/tools/pomessage.rb +197 -0
  58. data/lib/gettext/{poparser.rb → tools/poparser.rb} +128 -122
  59. data/lib/gettext/tools/rgettext.rb +47 -92
  60. data/lib/gettext/tools/rmsgfmt.rb +2 -2
  61. data/lib/gettext/tools/rmsgmerge.rb +2 -2
  62. data/lib/gettext/utils.rb +1 -1
  63. data/lib/gettext/version.rb +2 -2
  64. data/po/bg/rgettext.po +68 -64
  65. data/po/bs/rgettext.po +69 -65
  66. data/po/ca/rgettext.po +67 -64
  67. data/po/cs/rgettext.po +73 -70
  68. data/po/de/rgettext.po +69 -65
  69. data/po/el/rgettext.po +67 -64
  70. data/po/eo/rgettext.po +67 -63
  71. data/po/es/rgettext.po +67 -63
  72. data/po/et/rgettext.po +66 -63
  73. data/po/fr/rgettext.po +69 -66
  74. data/po/hr/rgettext.po +77 -73
  75. data/po/hu/rgettext.po +68 -65
  76. data/po/it/rgettext.po +69 -65
  77. data/po/ja/rgettext.po +69 -65
  78. data/po/ko/rgettext.po +73 -70
  79. data/po/lv/rgettext.po +68 -65
  80. data/po/nb/rgettext.po +68 -65
  81. data/po/nl/rgettext.po +74 -70
  82. data/po/pt_BR/rgettext.po +69 -66
  83. data/po/rgettext.pot +52 -48
  84. data/po/ru/rgettext.po +69 -66
  85. data/po/sr/rgettext.po +68 -64
  86. data/po/sv/rgettext.po +59 -55
  87. data/po/ua/rgettext.po +69 -66
  88. data/po/vi/rgettext.po +67 -63
  89. data/po/zh/rgettext.po +65 -62
  90. data/po/zh_TW/rgettext.po +65 -62
  91. data/replace.rb +8 -0
  92. data/samples/cgi/hellolib.rb +1 -3
  93. data/samples/cgi/http.rb +2 -4
  94. data/samples/cgi/locale/bg/LC_MESSAGES/main.mo +0 -0
  95. data/samples/cgi/po/bg/#main.po# +84 -0
  96. data/samples/cgi/po/bg/main.po +1 -1
  97. data/samples/hello.rb +1 -1
  98. data/src/poparser.ry +2 -1
  99. data/test.rb +33 -0
  100. data/test/test_class_info.rb +1 -1
  101. data/test/test_gettext.rb +1 -0
  102. data/test/test_parser.rb +120 -75
  103. data/test/test_po_generation.rb +20 -0
  104. data/test/test_pomessage.rb +99 -0
  105. data/test/test_string.rb +8 -0
  106. data/test/testlib/gettext.rb +17 -0
  107. data/test/testlib/ngettext.rb +6 -1
  108. data/test/testlib/pgettext.rb +5 -0
  109. metadata +726 -985
@@ -4,7 +4,7 @@
4
4
  Copyright (C) 2005-2009 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
7
+ license terms as Ruby or LGPL.
8
8
  =end
9
9
 
10
10
  # Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError.
@@ -22,8 +22,8 @@ class String
22
22
 
23
23
  PERCENT_MATCH_RE = Regexp.union(
24
24
  /%%/,
25
- /%\{(\w+)\}/,
26
- /%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/
25
+ /%\{(.+?)\}/,
26
+ /%<(.+?)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/
27
27
  )
28
28
 
29
29
  # call-seq:
@@ -1,54 +1,3 @@
1
- =begin
2
- parser/erb.rb - parser for ERB
1
+ warn "DEPRECATED: Use 'gettext/tools/parser/erb' instead."
3
2
 
4
- Copyright (C) 2005 Masao Mutoh
5
-
6
- You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
8
-
9
- $Id: erb.rb,v 1.5 2007/08/01 01:39:14 mutoh Exp $
10
- =end
11
-
12
- require 'erb'
13
- require 'gettext/parser/ruby.rb'
14
-
15
- module GetText
16
- module ErbParser
17
- extend self
18
-
19
- @config = {
20
- :extnames => ['.rhtml', '.erb']
21
- }
22
-
23
- # Sets some preferences to parse ERB files.
24
- # * config: a Hash of the config. It can takes some values below:
25
- # * :extnames: An Array of target files extension. Default is [".rhtml"].
26
- def init(config)
27
- config.each{|k, v|
28
- @config[k] = v
29
- }
30
- end
31
-
32
- def parse(file, targets = []) # :nodoc:
33
- src = ERB.new(IO.readlines(file).join).src
34
- # Remove magic comment prepended by erb in Ruby 1.9.
35
- src.sub!(/\A#.*?coding[:=].*?\n/, '') if src.respond_to?(:encode)
36
- erb = src.split(/$/)
37
- RubyParser.parse_lines(file, erb, targets)
38
- end
39
-
40
- def target?(file) # :nodoc:
41
- @config[:extnames].each do |v|
42
- return true if File.extname(file) == v
43
- end
44
- false
45
- end
46
- end
47
- end
48
-
49
- if __FILE__ == $0
50
- # ex) ruby glade.rhtml foo.rhtml bar.rhtml
51
- ARGV.each do |file|
52
- p GetText::ErbParser.parse(file)
53
- end
54
- end
3
+ require 'gettext/tools/parser/erb'
@@ -1,100 +1,3 @@
1
- =begin
2
- parser/glade.rb - parser for Glade-2
1
+ warn "DEPRECATED: Use 'gettext/tools/parser/glade' instead."
3
2
 
4
- Copyright (C) 2004,2005 Masao Mutoh
5
-
6
- You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
8
-
9
- $Id: glade.rb,v 1.5 2006/06/11 15:36:20 mutoh Exp $
10
- =end
11
-
12
- require 'cgi'
13
- require 'gettext'
14
-
15
- module GetText
16
- module GladeParser
17
- extend GetText
18
- extend self
19
-
20
- bindtextdomain("rgettext")
21
-
22
- TARGET1 = /<property.*translatable="yes">(.*)/
23
- TARGET2 = /(.*)<\/property>/
24
-
25
- def parse(file, targets = []) # :nodoc:
26
- lines = IO.readlines(file)
27
- parse_lines(file, lines, targets)
28
- end
29
-
30
- #from ary of lines.
31
- def parse_lines(file, lines, targets) # :nodoc:
32
- cnt = 0
33
- target = false
34
- line_no = 0
35
- val = nil
36
-
37
- loop do
38
- line = lines.shift
39
- break unless line
40
-
41
- cnt += 1
42
- if TARGET1 =~ line
43
- line_no = cnt
44
- val = $1 + "\n"
45
- target = true
46
- if TARGET2 =~ $1
47
- val = $1
48
- add_target(val, file, line_no, targets)
49
- val = nil
50
- target = false
51
- end
52
- elsif target
53
- if TARGET2 =~ line
54
- val << $1
55
- add_target(val, file, line_no, targets)
56
- val = nil
57
- target = false
58
- else
59
- val << line
60
- end
61
- end
62
- end
63
- targets
64
- end
65
-
66
- XML_RE = /<\?xml/
67
- GLADE_RE = /glade-2.0.dtd/
68
-
69
- def target?(file) # :nodoc:
70
- data = IO.readlines(file)
71
- if XML_RE =~ data[0] and GLADE_RE =~ data[1]
72
- true
73
- else
74
- if File.extname(file) == '.glade'
75
- raise _("`%{file}' is not glade-2.0 format.") % {:file => file}
76
- end
77
- false
78
- end
79
- end
80
-
81
- def add_target(val, file, line_no, targets) # :nodoc:
82
- return unless val.size > 0
83
- assoc_data = targets.assoc(val)
84
- val = CGI.unescapeHTML(val)
85
- if assoc_data
86
- targets[targets.index(assoc_data)] = assoc_data << "#{file}:#{line_no}"
87
- else
88
- targets << [val.gsub(/\n/, '\n'), "#{file}:#{line_no}"]
89
- end
90
- targets
91
- end
92
- end
93
- end
94
-
95
- if __FILE__ == $0
96
- # ex) ruby glade.rb foo.glade bar.glade
97
- ARGV.each do |file|
98
- p GetText::GladeParser.parse(file)
99
- end
100
- end
3
+ require 'gettext/tools/parser/glade'
@@ -9,11 +9,11 @@
9
9
  You may redistribute it and/or modify it under the same
10
10
  license terms as Ruby.
11
11
 
12
- $Id: ruby.rb,v 1.13 2008/12/01 14:30:30 mutoh Exp $
13
12
  =end
14
13
 
15
14
  require 'irb/ruby-lex.rb'
16
15
  require 'stringio'
16
+ warn "DEPRECATED: Use 'gettext/tools/parser/ruby' instead."
17
17
 
18
18
  class RubyLexX < RubyLex # :nodoc: all
19
19
  # Parser#parse resemlbes RubyLex#lex
@@ -63,10 +63,12 @@ module GetText
63
63
  module RubyParser
64
64
  extend self
65
65
 
66
- ID = ['gettext', '_', 'N_', 'sgettext', 's_']
67
- PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
68
- MSGCTXT_ID = ['pgettext', 'p_']
69
- MSGCTXT_PLURAL_ID = ['npgettext', 'np_']
66
+ unless defined? ID
67
+ ID = ['gettext', '_', 'N_', 'sgettext', 's_']
68
+ PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
69
+ MSGCTXT_ID = ['pgettext', 'p_']
70
+ MSGCTXT_PLURAL_ID = ['npgettext', 'np_']
71
+ end
70
72
 
71
73
  def parse(file, targets = []) # :nodoc:
72
74
  lines = IO.readlines(file)
@@ -9,9 +9,10 @@ module GetText
9
9
  include Locale::Util::Memoizable
10
10
 
11
11
  # normalize the class name
12
+ # klass should kind of the class, not object.
12
13
  def normalize_class(klass)
13
14
  ret = (klass.kind_of? Module) ? klass : klass.class
14
- if ret.name.to_s =~ /^\#<|^$/ or ret == GetText
15
+ if ret.name =~ /^\#<|^$/ or ret == GetText
15
16
  ret = Object
16
17
  end
17
18
  ret
@@ -4,7 +4,7 @@
4
4
  Copyright (C) 2001-2009 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
7
+ license terms as Ruby or LGPL.
8
8
 
9
9
  =end
10
10
 
@@ -82,7 +82,6 @@ module GetText
82
82
  path_rules = ["#{topdir}/%{lang}/LC_MESSAGES/%{name}.mo", "#{topdir}/%{lang}/%{name}.mo"]
83
83
  else
84
84
  path_rules = self.class.default_path_rules
85
-
86
85
  end
87
86
 
88
87
  @locale_paths = {}
@@ -8,14 +8,12 @@
8
8
  Masao Mutoh <mutomasa at gmail.com>
9
9
 
10
10
  You may redistribute it and/or modify it under the same
11
- license terms as Ruby.
12
-
13
- $Id$
11
+ license terms as Ruby or LGPL.
14
12
  =end
15
13
 
16
14
  require 'gettext/core_ext/string'
17
- require 'gettext/mofile'
18
- require 'gettext/locale_path'
15
+ require 'gettext/runtime/mofile'
16
+ require 'gettext/runtime/locale_path'
19
17
 
20
18
  module GetText
21
19
  # GetText::TextDomain class manages mo-files of a textdomain.
@@ -4,7 +4,7 @@
4
4
  Copyright (C) 2009 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
7
+ license terms as Ruby or LGPL.
8
8
 
9
9
  =end
10
10
 
@@ -4,13 +4,13 @@
4
4
  Copyright (C) 2009 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
7
+ license terms as Ruby or LGPL.
8
8
 
9
9
  =end
10
10
 
11
- require 'gettext/class_info'
12
- require 'gettext/textdomain'
13
- require 'gettext/textdomain_group'
11
+ require 'gettext/runtime/class_info'
12
+ require 'gettext/runtime/textdomain'
13
+ require 'gettext/runtime/textdomain_group'
14
14
 
15
15
  module GetText
16
16
 
@@ -67,7 +67,6 @@ module GetText
67
67
 
68
68
  charset = options[:output_charset] || self.output_charset
69
69
  textdomain = create_or_find_textdomain(domainname,options[:path],charset)
70
-
71
70
  target_klass = ClassInfo.normalize_class(klass)
72
71
  create_or_find_textdomain_group(target_klass).add(textdomain)
73
72
  @@gettext_classes << target_klass unless @@gettext_classes.include? target_klass
@@ -95,6 +94,7 @@ module GetText
95
94
  # * Returns: the localized text by msgid. If there are no localized text,
96
95
  # it returns a last part of msgid separeted "div".
97
96
  def translate_singluar_message(klass, msgid, div = nil)
97
+ klass = ClassInfo.normalize_class(klass)
98
98
  key = [Locale.current, klass, msgid, div].hash
99
99
  msg = @@singular_message_cache[key]
100
100
  return msg if msg and @@cached
@@ -137,6 +137,7 @@ module GetText
137
137
  # * n: a number used to determine the plural form.
138
138
  # * div: the separator. Default is "|".
139
139
  def translate_plural_message(klass, arg1, arg2, arg3 = "|", arg4 = "|")
140
+ klass = ClassInfo.normalize_class(klass)
140
141
  # parse arguments
141
142
  if arg1.kind_of?(Array)
142
143
  msgid = arg1[0]
@@ -184,6 +185,11 @@ module GetText
184
185
  @@textdomain_pool = {}
185
186
  @@textdomain_group_pool = {}
186
187
  @@gettext_classes = []
188
+ clear_caches
189
+ end
190
+
191
+ # for testing.
192
+ def clear_caches
187
193
  @@singular_message_cache = {}
188
194
  @@plural_message_cache = {}
189
195
  end
@@ -4,7 +4,7 @@
4
4
  Copyright (C) 2005-2008 Masao Mutoh
5
5
 
6
6
  You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
7
+ license terms as Ruby or LGPL.
8
8
  =end
9
9
 
10
10
  require 'rbconfig'
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  require 'gettext/tools/rgettext'
18
18
  require 'gettext/tools/rmsgfmt'
19
- require 'gettext/mofile'
19
+ require 'gettext/runtime/mofile'
20
20
  require 'fileutils'
21
21
 
22
22
  module GetText
@@ -0,0 +1,52 @@
1
+ =begin
2
+ parser/erb.rb - parser for ERB
3
+
4
+ Copyright (C) 2005-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 'erb'
11
+ require 'gettext/tools/parser/ruby'
12
+
13
+ module GetText
14
+ module ErbParser
15
+ extend self
16
+
17
+ @config = {
18
+ :extnames => ['.rhtml', '.erb']
19
+ }
20
+
21
+ # Sets some preferences to parse ERB files.
22
+ # * config: a Hash of the config. It can takes some values below:
23
+ # * :extnames: An Array of target files extension. Default is [".rhtml"].
24
+ def init(config)
25
+ config.each{|k, v|
26
+ @config[k] = v
27
+ }
28
+ end
29
+
30
+ def parse(file, targets = []) # :nodoc:
31
+ src = ERB.new(IO.readlines(file).join).src
32
+ # Remove magic comment prepended by erb in Ruby 1.9.
33
+ src.sub!(/\A#.*?coding[:=].*?\n/, '') if src.respond_to?(:encode)
34
+ erb = src.split(/$/)
35
+ RubyParser.parse_lines(file, erb, targets)
36
+ end
37
+
38
+ def target?(file) # :nodoc:
39
+ @config[:extnames].each do |v|
40
+ return true if File.extname(file) == v
41
+ end
42
+ false
43
+ end
44
+ end
45
+ end
46
+
47
+ if __FILE__ == $0
48
+ # ex) ruby glade.rhtml foo.rhtml bar.rhtml
49
+ ARGV.each do |file|
50
+ p GetText::ErbParser.parse(file)
51
+ end
52
+ end
@@ -0,0 +1,98 @@
1
+ =begin
2
+ parser/glade.rb - parser for Glade-2
3
+
4
+ Copyright (C) 2004,2005 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 'cgi'
11
+ require 'gettext'
12
+
13
+ module GetText
14
+ module GladeParser
15
+ extend GetText
16
+ extend self
17
+
18
+ bindtextdomain("rgettext")
19
+
20
+ TARGET1 = /<property.*translatable="yes">(.*)/
21
+ TARGET2 = /(.*)<\/property>/
22
+
23
+ def parse(file, targets = []) # :nodoc:
24
+ lines = IO.readlines(file)
25
+ parse_lines(file, lines, targets)
26
+ end
27
+
28
+ #from ary of lines.
29
+ def parse_lines(file, lines, targets) # :nodoc:
30
+ cnt = 0
31
+ target = false
32
+ line_no = 0
33
+ val = nil
34
+
35
+ loop do
36
+ line = lines.shift
37
+ break unless line
38
+
39
+ cnt += 1
40
+ if TARGET1 =~ line
41
+ line_no = cnt
42
+ val = $1 + "\n"
43
+ target = true
44
+ if TARGET2 =~ $1
45
+ val = $1
46
+ add_target(val, file, line_no, targets)
47
+ val = nil
48
+ target = false
49
+ end
50
+ elsif target
51
+ if TARGET2 =~ line
52
+ val << $1
53
+ add_target(val, file, line_no, targets)
54
+ val = nil
55
+ target = false
56
+ else
57
+ val << line
58
+ end
59
+ end
60
+ end
61
+ targets
62
+ end
63
+
64
+ XML_RE = /<\?xml/
65
+ GLADE_RE = /glade-2.0.dtd/
66
+
67
+ def target?(file) # :nodoc:
68
+ data = IO.readlines(file)
69
+ if XML_RE =~ data[0] and GLADE_RE =~ data[1]
70
+ true
71
+ else
72
+ if File.extname(file) == '.glade'
73
+ raise _("`%{file}' is not glade-2.0 format.") % {:file => file}
74
+ end
75
+ false
76
+ end
77
+ end
78
+
79
+ def add_target(val, file, line_no, targets) # :nodoc:
80
+ return unless val.size > 0
81
+ assoc_data = targets.assoc(val)
82
+ val = CGI.unescapeHTML(val)
83
+ if assoc_data
84
+ targets[targets.index(assoc_data)] = assoc_data << "#{file}:#{line_no}"
85
+ else
86
+ targets << [val.gsub(/\n/, '\n'), "#{file}:#{line_no}"]
87
+ end
88
+ targets
89
+ end
90
+ end
91
+ end
92
+
93
+ if __FILE__ == $0
94
+ # ex) ruby glade.rb foo.glade bar.glade
95
+ ARGV.each do |file|
96
+ p GetText::GladeParser.parse(file)
97
+ end
98
+ end