gettext 2.1.0 → 2.2.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 (148) hide show
  1. data/README.rdoc +10 -6
  2. data/Rakefile +15 -66
  3. data/data/locale/bg/LC_MESSAGES/rgettext.mo +0 -0
  4. data/data/locale/bs/LC_MESSAGES/rgettext.mo +0 -0
  5. data/data/locale/ca/LC_MESSAGES/rgettext.mo +0 -0
  6. data/data/locale/cs/LC_MESSAGES/rgettext.mo +0 -0
  7. data/data/locale/de/LC_MESSAGES/rgettext.mo +0 -0
  8. data/data/locale/el/LC_MESSAGES/rgettext.mo +0 -0
  9. data/data/locale/eo/LC_MESSAGES/rgettext.mo +0 -0
  10. data/data/locale/es/LC_MESSAGES/rgettext.mo +0 -0
  11. data/data/locale/et/LC_MESSAGES/rgettext.mo +0 -0
  12. data/data/locale/fr/LC_MESSAGES/rgettext.mo +0 -0
  13. data/data/locale/hr/LC_MESSAGES/rgettext.mo +0 -0
  14. data/data/locale/hu/LC_MESSAGES/rgettext.mo +0 -0
  15. data/data/locale/it/LC_MESSAGES/rgettext.mo +0 -0
  16. data/data/locale/ja/LC_MESSAGES/rgettext.mo +0 -0
  17. data/data/locale/ko/LC_MESSAGES/rgettext.mo +0 -0
  18. data/data/locale/lv/LC_MESSAGES/rgettext.mo +0 -0
  19. data/data/locale/nb/LC_MESSAGES/rgettext.mo +0 -0
  20. data/data/locale/nl/LC_MESSAGES/rgettext.mo +0 -0
  21. data/data/locale/pt_BR/LC_MESSAGES/rgettext.mo +0 -0
  22. data/data/locale/ru/LC_MESSAGES/rgettext.mo +0 -0
  23. data/data/locale/sr/LC_MESSAGES/rgettext.mo +0 -0
  24. data/data/locale/sv/LC_MESSAGES/rgettext.mo +0 -0
  25. data/data/locale/uk/LC_MESSAGES/rgettext.mo +0 -0
  26. data/data/locale/vi/LC_MESSAGES/rgettext.mo +0 -0
  27. data/data/locale/zh/LC_MESSAGES/rgettext.mo +0 -0
  28. data/data/locale/zh_TW/LC_MESSAGES/rgettext.mo +0 -0
  29. data/doc/text/news.md +30 -0
  30. data/gettext.gemspec +26 -34
  31. data/lib/gettext.rb +26 -24
  32. data/lib/gettext/cgi.rb +2 -0
  33. data/lib/gettext/core_ext/iconv.rb +7 -7
  34. data/lib/gettext/core_ext/string.rb +8 -6
  35. data/lib/gettext/parser/erb.rb +2 -0
  36. data/lib/gettext/parser/glade.rb +2 -0
  37. data/lib/gettext/parser/ruby.rb +12 -12
  38. data/lib/gettext/runtime/class_info.rb +5 -3
  39. data/lib/gettext/runtime/locale_path.rb +20 -22
  40. data/lib/gettext/runtime/mofile.rb +45 -18
  41. data/lib/gettext/runtime/textdomain.rb +6 -4
  42. data/lib/gettext/runtime/textdomain_group.rb +3 -1
  43. data/lib/gettext/runtime/textdomain_manager.rb +29 -26
  44. data/lib/gettext/tools.rb +15 -13
  45. data/lib/gettext/tools/parser/erb.rb +5 -3
  46. data/lib/gettext/tools/parser/glade.rb +16 -14
  47. data/lib/gettext/tools/parser/ruby.rb +16 -16
  48. data/lib/gettext/tools/pomessage.rb +9 -7
  49. data/lib/gettext/tools/poparser.rb +38 -36
  50. data/lib/gettext/tools/rgettext.rb +38 -13
  51. data/lib/gettext/tools/rmsgfmt.rb +7 -5
  52. data/lib/gettext/tools/rmsgmerge.rb +116 -114
  53. data/lib/gettext/utils.rb +2 -0
  54. data/lib/gettext/version.rb +3 -3
  55. data/po/bg/rgettext.po +17 -12
  56. data/po/bs/rgettext.po +16 -12
  57. data/po/ca/rgettext.po +17 -12
  58. data/po/cs/rgettext.po +16 -12
  59. data/po/de/rgettext.po +17 -12
  60. data/po/el/rgettext.po +17 -12
  61. data/po/eo/rgettext.po +17 -12
  62. data/po/es/rgettext.po +17 -12
  63. data/po/et/rgettext.po +17 -12
  64. data/po/fr/rgettext.po +17 -12
  65. data/po/hr/rgettext.po +19 -15
  66. data/po/hu/rgettext.po +17 -12
  67. data/po/it/rgettext.po +16 -12
  68. data/po/ja/rgettext.po +21 -15
  69. data/po/ko/rgettext.po +16 -12
  70. data/po/lv/rgettext.po +17 -12
  71. data/po/nb/rgettext.po +17 -12
  72. data/po/nl/rgettext.po +16 -12
  73. data/po/pt_BR/rgettext.po +17 -12
  74. data/po/rgettext.pot +16 -12
  75. data/po/ru/rgettext.po +17 -12
  76. data/po/sr/rgettext.po +17 -12
  77. data/po/sv/rgettext.po +16 -12
  78. data/po/{ua → uk}/rgettext.po +17 -12
  79. data/po/vi/rgettext.po +17 -12
  80. data/po/zh/rgettext.po +17 -12
  81. data/po/zh_TW/rgettext.po +17 -12
  82. data/samples/cgi/hellolib.rb +1 -1
  83. data/samples/cgi/http.rb +5 -5
  84. data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/helloerb1.mo +0 -0
  85. data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/helloerb2.mo +0 -0
  86. data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/hellolib.mo +0 -0
  87. data/samples/cgi/locale/{ua → uk}/LC_MESSAGES/main.mo +0 -0
  88. data/samples/cgi/po/{ua → uk}/helloerb1.po +0 -0
  89. data/samples/cgi/po/{ua → uk}/helloerb2.po +0 -0
  90. data/samples/cgi/po/{ua → uk}/hellolib.po +0 -0
  91. data/samples/cgi/po/{ua → uk}/main.po +0 -0
  92. data/samples/hello.rb +1 -1
  93. data/samples/hello_gtk2.rb +1 -1
  94. data/samples/hello_noop.rb +1 -1
  95. data/samples/locale/{ua → uk}/LC_MESSAGES/hello.mo +0 -0
  96. data/samples/locale/{ua → uk}/LC_MESSAGES/hello2.mo +0 -0
  97. data/samples/locale/{ua → uk}/LC_MESSAGES/hello_glade2.mo +0 -0
  98. data/samples/locale/{ua → uk}/LC_MESSAGES/hello_gtk.mo +0 -0
  99. data/samples/locale/{ua → uk}/LC_MESSAGES/hello_noop.mo +0 -0
  100. data/samples/locale/{ua → uk}/LC_MESSAGES/hello_plural.mo +0 -0
  101. data/samples/locale/{ua → uk}/LC_MESSAGES/hello_tk.mo +0 -0
  102. data/samples/makemo.rb +2 -0
  103. data/samples/po/test.rb +2 -0
  104. data/samples/po/{ua → uk}/hello.po +0 -0
  105. data/samples/po/{ua → uk}/hello2.po +0 -0
  106. data/samples/po/{ua → uk}/hello_glade2.po +0 -0
  107. data/samples/po/{ua → uk}/hello_gtk.po +0 -0
  108. data/samples/po/{ua → uk}/hello_noop.po +0 -0
  109. data/samples/po/{ua → uk}/hello_plural.po +0 -0
  110. data/samples/po/{ua → uk}/hello_tk.po +0 -0
  111. data/test/Rakefile +1 -1
  112. data/test/test_class_info.rb +5 -0
  113. data/test/test_gettext.rb +12 -1
  114. data/test/test_locale_path.rb +29 -3
  115. data/test/test_parser.rb +61 -59
  116. data/test/test_po_generation.rb +3 -1
  117. data/test/test_pomessage.rb +4 -2
  118. data/test/test_string.rb +2 -0
  119. data/test/test_textdomain_bind.rb +2 -0
  120. data/test/test_textdomain_multi.rb +2 -0
  121. data/test/test_textdomain_toplevel.rb +2 -0
  122. data/test/test_thread.rb +4 -2
  123. data/test/testlib/N_.rb +5 -3
  124. data/test/testlib/gettext.rb +4 -2
  125. data/test/testlib/helper.rb +2 -0
  126. data/test/testlib/multi_textdomain.rb +2 -0
  127. data/test/testlib/ngettext.rb +10 -8
  128. data/test/testlib/npgettext.rb +9 -7
  129. data/test/testlib/nsgettext.rb +4 -2
  130. data/test/testlib/pgettext.rb +4 -2
  131. data/test/testlib/sgettext.rb +4 -2
  132. data/test/testlib/simple.rb +2 -0
  133. data/test/tools/files/simple_translation.rb +3 -1
  134. data/test/tools/test_tools.rb +3 -1
  135. metadata +772 -737
  136. data/ChangeLog +0 -78
  137. data/ChangeLog-1 +0 -2016
  138. data/NEWS-1 +0 -414
  139. data/benchmark/1.93.0.txt +0 -8
  140. data/benchmark/2.0.0.txt +0 -8
  141. data/benchmark/2.0.4.txt +0 -11
  142. data/benchmark/2.1.0.txt +0 -11
  143. data/benchmark/benchmark.rb +0 -68
  144. data/benchmark/test.rb +0 -28
  145. data/data/locale/ua/LC_MESSAGES/rgettext.mo +0 -0
  146. data/replace.rb +0 -8
  147. data/samples/cgi/po/bg/#main.po# +0 -84
  148. data/test.rb +0 -33
data/lib/gettext/cgi.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  =begin
2
4
  gettext/cgi.rb - GetText for CGI
3
5
 
@@ -18,12 +18,12 @@ begin
18
18
  require 'iconv.so'
19
19
  rescue LoadError
20
20
  # Pseudo Iconv class
21
- #
21
+ #
22
22
  # ==== For Matz Ruby:
23
- # If you don't have iconv but Ruby/GLib2, this library uses Ruby/GLib2's
23
+ # If you don't have iconv but Ruby/GLib2, this library uses Ruby/GLib2's
24
24
  # iconv functions.
25
25
  #
26
- # Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
26
+ # Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
27
27
  # You can get binaries for Win32(One-Click Ruby Installer).
28
28
  # <URL: http://ruby-gnome2.sourceforge.jp/>
29
29
  # ==== For JRuby:
@@ -47,16 +47,16 @@ rescue LoadError
47
47
  else
48
48
  begin
49
49
  require 'glib2'
50
-
50
+
51
51
  def self.check_glib_version?(major, minor, micro) # :nodoc:
52
52
  (GLib::BINDING_VERSION[0] > major ||
53
- (GLib::BINDING_VERSION[0] == major &&
53
+ (GLib::BINDING_VERSION[0] == major &&
54
54
  GLib::BINDING_VERSION[1] > minor) ||
55
- (GLib::BINDING_VERSION[0] == major &&
55
+ (GLib::BINDING_VERSION[0] == major &&
56
56
  GLib::BINDING_VERSION[1] == minor &&
57
57
  GLib::BINDING_VERSION[2] >= micro))
58
58
  end
59
-
59
+
60
60
  if check_glib_version?(0, 11, 0)
61
61
  # This is a function equivalent of Iconv.iconv.
62
62
  # * to: encoding name for destination
@@ -1,19 +1,21 @@
1
+ # encoding: utf-8
2
+
1
3
  =begin
2
4
  string.rb - Extension for String.
3
5
 
4
6
  Copyright (C) 2005-2009 Masao Mutoh
5
-
7
+
6
8
  You may redistribute it and/or modify it under the same
7
9
  license terms as Ruby or LGPL.
8
10
  =end
9
11
 
10
12
  # Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError.
11
13
  #
12
- # String#% method which accept "named argument". The translator can know
14
+ # String#% method which accept "named argument". The translator can know
13
15
  # the meaning of the msgids using "named argument" instead of %s/%d style.
14
16
  class String
15
17
 
16
- unless instance_methods.find {|m| m.to_s == 'bytesize'}
18
+ unless instance_methods.find {|m| m.to_s == 'bytesize'}
17
19
  # For older ruby (such as ruby-1.8.5)
18
20
  alias :bytesize :size
19
21
  end
@@ -30,9 +32,9 @@ class String
30
32
  # %(arg)
31
33
  # %(hash)
32
34
  #
33
- # Format - Uses str as a format specification, and returns the result of applying it to arg.
34
- # If the format specification contains more than one substitution, then arg must be
35
- # an Array containing the values to be substituted. See Kernel::sprintf for details of the
35
+ # Format - Uses str as a format specification, and returns the result of applying it to arg.
36
+ # If the format specification contains more than one substitution, then arg must be
37
+ # an Array containing the values to be substituted. See Kernel::sprintf for details of the
36
38
  # format string. This is the default behavior of the String class.
37
39
  # * arg: an Array or other class except Hash.
38
40
  # * Returns: formatted String
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  warn "DEPRECATED: Use 'gettext/tools/parser/erb' instead."
2
4
 
3
5
  require 'gettext/tools/parser/erb'
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  warn "DEPRECATED: Use 'gettext/tools/parser/glade' instead."
2
4
 
3
5
  require 'gettext/tools/parser/glade'
@@ -5,7 +5,7 @@
5
5
  Copyright (C) 2003-2005 Masao Mutoh
6
6
  Copyright (C) 2005 speakillof
7
7
  Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
8
-
8
+
9
9
  You may redistribute it and/or modify it under the same
10
10
  license terms as Ruby.
11
11
 
@@ -22,13 +22,13 @@ class RubyLexX < RubyLex # :nodoc: all
22
22
  s = get_readed
23
23
  if RubyToken::TkSTRING === tk
24
24
  def tk.value
25
- @value
25
+ @value
26
26
  end
27
-
27
+
28
28
  def tk.value=(s)
29
29
  @value = s
30
30
  end
31
-
31
+
32
32
  if @here_header
33
33
  s = s.sub(/\A.*?\n/, '').sub(/^.*\n\Z/, '')
34
34
  else
@@ -38,10 +38,10 @@ class RubyLexX < RubyLex # :nodoc: all
38
38
  # Do nothing.
39
39
  end
40
40
  end
41
-
41
+
42
42
  tk.value = s
43
43
  end
44
-
44
+
45
45
  if $DEBUG
46
46
  if tk.is_a? TkSTRING
47
47
  $stderr.puts("#{tk}: #{tk.value}")
@@ -51,7 +51,7 @@ class RubyLexX < RubyLex # :nodoc: all
51
51
  $stderr.puts(tk)
52
52
  end
53
53
  end
54
-
54
+
55
55
  yield tk
56
56
  end
57
57
  return nil
@@ -62,7 +62,7 @@ end
62
62
  module GetText
63
63
  module RubyParser
64
64
  extend self
65
-
65
+
66
66
  unless defined? ID
67
67
  ID = ['gettext', '_', 'N_', 'sgettext', 's_']
68
68
  PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
@@ -154,7 +154,7 @@ module GetText
154
154
  def target?(file) # :nodoc:
155
155
  true # always true, as default parser.
156
156
  end
157
- end
157
+ end
158
158
  end
159
159
 
160
160
 
@@ -164,9 +164,9 @@ if __FILE__ == $0
164
164
  ARGV.each do |file|
165
165
  pp GetText::RubyParser.parse(file)
166
166
  end
167
-
168
- #rl = RubyLexX.new; rl.set_input(ARGF)
167
+
168
+ #rl = RubyLexX.new; rl.set_input(ARGF)
169
169
  #rl.parse do |tk|
170
170
  #p tk
171
- #end
171
+ #end
172
172
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'locale/util/memoizable'
2
4
 
3
5
  module GetText
@@ -12,7 +14,7 @@ module GetText
12
14
  # klass should kind of the class, not object.
13
15
  def normalize_class(klass)
14
16
  ret = (klass.kind_of? Module) ? klass : klass.class
15
- if ret.name =~ /^\#<|^$/ or ret == GetText
17
+ if ret.name =~ /^\#<|^$/ or ret == GetText or ret.name.nil?
16
18
  ret = Object
17
19
  end
18
20
  ret
@@ -47,13 +49,13 @@ module GetText
47
49
  end
48
50
 
49
51
  if all_classes.size > 0
50
- (ret & all_classes).uniq
52
+ (ret & all_classes).uniq
51
53
  else
52
54
  ret.uniq
53
55
  end
54
56
  end
55
57
 
56
- # Returns the classes which related to klass
58
+ # Returns the classes which related to klass
57
59
  # (klass's ancestors, included modules and nested modules)
58
60
  def related_classes(klass, all_classes = [])
59
61
  ret = related_classes_internal(klass, all_classes)
@@ -1,7 +1,9 @@
1
+ # encoding: utf-8
2
+
1
3
  =begin
2
4
  locale_path.rb - GetText::LocalePath
3
5
 
4
- Copyright (C) 2001-2009 Masao Mutoh
6
+ Copyright (C) 2001-2010 Masao Mutoh
5
7
 
6
8
  You may redistribute it and/or modify it under the same
7
9
  license terms as Ruby or LGPL.
@@ -17,12 +19,12 @@ module GetText
17
19
  include Locale::Util::Memoizable
18
20
 
19
21
  # The default locale paths.
20
- CONFIG_PREFIX = Config::CONFIG['prefix'].gsub(/\/local/, "")
22
+ CONFIG_PREFIX = RbConfig::CONFIG['prefix'].gsub(/\/local/, "")
21
23
  DEFAULT_RULES = [
22
24
  "./locale/%{lang}/LC_MESSAGES/%{name}.mo",
23
25
  "./locale/%{lang}/%{name}.mo",
24
- "#{Config::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
25
- "#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
26
+ "#{RbConfig::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
27
+ "#{RbConfig::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
26
28
  "#{CONFIG_PREFIX}/share/locale/%{lang}/LC_MESSAGES/%{name}.mo",
27
29
  "#{CONFIG_PREFIX}/local/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
28
30
  ].uniq
@@ -37,33 +39,29 @@ module GetText
37
39
  def add_default_rule(path)
38
40
  DEFAULT_RULES.unshift(path)
39
41
  end
40
-
41
- # Returns path rules as an Array.
42
- # (e.g.) ["/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo", ...]
43
- def default_path_rules
42
+
43
+ # Returns path rules as an Array.
44
+ # (e.g.) ["/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo", ...]
45
+ def default_path_rules
44
46
  default_path_rules = []
45
47
 
46
48
  if ENV["GETTEXT_PATH"]
47
- ENV["GETTEXT_PATH"].split(/,/).each {|i|
48
- default_path_rules = ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
49
+ ENV["GETTEXT_PATH"].split(/,/).each {|i|
50
+ default_path_rules += ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
49
51
  }
50
52
  end
51
-
52
53
  default_path_rules += DEFAULT_RULES
53
-
54
- load_path = $LOAD_PATH
55
- if defined? ::Gem
56
- load_path += Gem.all_load_paths
57
- end
54
+
55
+ load_path = $LOAD_PATH.dup
58
56
  load_path.map!{|v| v.match(/(.*?)(\/lib)*?$/); $1}
59
57
  load_path.each {|path|
60
58
  default_path_rules += [
61
- "#{path}/data/locale/%{lang}/LC_MESSAGES/%{name}.mo",
62
- "#{path}/data/locale/%{lang}/%{name}.mo",
59
+ "#{path}/data/locale/%{lang}/LC_MESSAGES/%{name}.mo",
60
+ "#{path}/data/locale/%{lang}/%{name}.mo",
63
61
  "#{path}/locale/%{lang}/%{name}.mo"]
64
62
  }
65
63
  # paths existed only.
66
- default_path_rules = default_path_rules.select{|path|
64
+ default_path_rules = default_path_rules.select{|path|
67
65
  Dir.glob(path % {:lang => "*", :name => "*"}).size > 0}.uniq
68
66
  default_path_rules
69
67
  end
@@ -77,7 +75,7 @@ module GetText
77
75
  # * topdir: the locale path ("%{topdir}/%{lang}/LC_MESSAGES/%{name}.mo") or nil.
78
76
  def initialize(name, topdir = nil)
79
77
  @name = name
80
-
78
+
81
79
  if topdir
82
80
  path_rules = ["#{topdir}/%{lang}/LC_MESSAGES/%{name}.mo", "#{topdir}/%{lang}/%{name}.mo"]
83
81
  else
@@ -89,7 +87,7 @@ module GetText
89
87
  this_path_rules = rule % {:lang => "([^\/]+)", :name => name}
90
88
  Dir.glob(rule %{:lang => "*", :name => name}).each do |path|
91
89
  if /#{this_path_rules}/ =~ path
92
- @locale_paths[$1] = path unless @locale_paths[$1]
90
+ @locale_paths[$1] = path.untaint unless @locale_paths[$1]
93
91
  end
94
92
  end
95
93
  end
@@ -117,6 +115,6 @@ module GetText
117
115
  nil
118
116
  end
119
117
  memoize :current_path
120
-
118
+
121
119
  end
122
120
  end
@@ -1,6 +1,9 @@
1
+ # encoding: utf-8
2
+
1
3
  =begin
2
4
  mofile.rb - A simple class for operating GNU MO file.
3
5
 
6
+ Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
7
  Copyright (C) 2003-2009 Masao Mutoh
5
8
  Copyright (C) 2002 Masahiro Sakai, Masao Mutoh
6
9
  Copyright (C) 2001 Masahiro Sakai
@@ -14,11 +17,10 @@
14
17
 
15
18
  =end
16
19
 
17
- require 'gettext/core_ext/iconv'
18
20
  require 'stringio'
19
21
 
20
22
  module GetText
21
- class MOFile < Hash
23
+ class MOFile < Hash
22
24
  class InvalidFormat < RuntimeError; end;
23
25
 
24
26
  attr_reader :filename
@@ -31,7 +33,7 @@ module GetText
31
33
  :hash_table_size,
32
34
  :hash_table_offset)
33
35
 
34
- # The following are only used in .mo files
36
+ # The following are only used in .mo files
35
37
  # with minor revision >= 1.
36
38
  class HeaderRev1 < Header
37
39
  attr_accessor :n_sysdep_segments,
@@ -43,6 +45,10 @@ module GetText
43
45
 
44
46
  MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde"
45
47
  MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95"
48
+ if "".respond_to?(:force_encoding)
49
+ MAGIC_BIG_ENDIAN.force_encoding("ASCII-8BIT")
50
+ MAGIC_LITTLE_ENDIAN.force_encoding("ASCII-8BIT")
51
+ end
46
52
 
47
53
  def self.open(arg = nil, output_charset = nil)
48
54
  result = self.new(output_charset)
@@ -145,17 +151,8 @@ module GetText
145
151
  @plural = "0" unless @plural
146
152
  end
147
153
  else
148
- if @output_charset
149
- begin
150
- str = Iconv.conv(@output_charset, @charset, str) if @charset
151
- rescue Iconv::Failure
152
- if $DEBUG
153
- warn "@charset = ", @charset
154
- warn"@output_charset = ", @output_charset
155
- warn "msgid = ", original_strings[i]
156
- warn "msgstr = ", str
157
- end
158
- end
154
+ if @charset and @output_charset
155
+ str = convert_encoding(str, original_strings[i])
159
156
  end
160
157
  end
161
158
  self[original_strings[i]] = str.freeze
@@ -186,7 +183,7 @@ module GetText
186
183
  # From gettext-0.12.1/gettext-runtime/intl/hash-string.h
187
184
  # Defines the so called `hashpjw' function by P.J. Weinberger
188
185
  # [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
189
- # 1986, 1987 Bell Telephone Laboratories, Inc.]
186
+ # 1986, 1987 Bell Telephone Laboratories, Inc.]
190
187
  def hash_string(str)
191
188
  hval = 0
192
189
  i = 0
@@ -208,7 +205,7 @@ module GetText
208
205
  header_size = 4 * 7
209
206
  table_size = 4 * 2 * size
210
207
 
211
- hash_table_size = next_prime((size * 4) / 3)
208
+ hash_table_size = next_prime((size * 4) / 3)
212
209
  hash_table_size = 3 if hash_table_size <= 2
213
210
  header = Header.new(
214
211
  MAGIC_LITTLE_ENDIAN, # magic
@@ -302,8 +299,38 @@ module GetText
302
299
 
303
300
  attr_accessor :little_endian, :path, :last_modified
304
301
  attr_reader :charset, :nplurals, :plural
305
- end
306
302
 
303
+ private
304
+ if "".respond_to?(:encode)
305
+ def convert_encoding(string, original_string)
306
+ begin
307
+ string.encode(@output_charset, @charset)
308
+ rescue EncodingError
309
+ if $DEBUG
310
+ warn "@charset = ", @charset
311
+ warn "@output_charset = ", @output_charset
312
+ warn "msgid = ", original_string
313
+ warn "msgstr = ", string
314
+ end
315
+ string
316
+ end
317
+ end
318
+ else
319
+ require 'gettext/core_ext/iconv'
320
+ def convert_encoding(string, original_string)
321
+ begin
322
+ Iconv.conv(@output_charset, @charset, string)
323
+ rescue Iconv::Failure
324
+ if $DEBUG
325
+ warn "@charset = ", @charset
326
+ warn "@output_charset = ", @output_charset
327
+ warn "msgid = ", original_string
328
+ warn "msgstr = ", str
329
+ end
330
+ end
331
+ end
332
+ end
333
+ end
307
334
  end
308
335
 
309
336
  # Test
@@ -313,7 +340,7 @@ if $0 == __FILE__
313
340
  STDERR.puts("mo.rb [filename.mo ...]")
314
341
  exit
315
342
  end
316
-
343
+
317
344
  ARGV.each{ |item|
318
345
  mo = GetText::MOFile.open(item)
319
346
  puts "------------------------------------------------------------------"
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  =begin
2
4
  textdomain.rb - GetText::Textdomain
3
5
 
@@ -60,7 +62,7 @@ module GetText
60
62
  @locale_path = LocalePath.new(@name, topdir)
61
63
  @mofiles = {}
62
64
  end
63
-
65
+
64
66
  # Translates the translated string.
65
67
  # * lang: Locale::Tag::Simple's subclass.
66
68
  # * msgid: the original message.
@@ -77,7 +79,7 @@ module GetText
77
79
  unless mofile
78
80
  mofile = load_mo(lang)
79
81
  end
80
-
82
+
81
83
  if (! mofile) or (mofile ==:empty)
82
84
  return nil
83
85
  end
@@ -89,7 +91,7 @@ module GetText
89
91
  # Check "aaa\000bbb" and show warning but return the singluar part.
90
92
  ret = nil
91
93
  msgid_single = msgid.split("\000")[0]
92
- mofile.each{|key, val|
94
+ mofile.each{|key, val|
93
95
  if key =~ /^#{Regexp.quote(msgid_single)}\000/
94
96
  # Usually, this is not caused to make po-files from rgettext.
95
97
  warn %Q[Warning: n_("#{msgid_single}", "#{msgid.split("\000")[1]}") and n_("#{key.gsub(/\000/, '", "')}") are duplicated.]
@@ -100,7 +102,7 @@ module GetText
100
102
  ret
101
103
  else
102
104
  ret = nil
103
- mofile.each{|key, val|
105
+ mofile.each{|key, val|
104
106
  if key =~ /^#{Regexp.quote(msgid)}\000/
105
107
  ret = val.split("\000")[0]
106
108
  break