Permalink
Browse files

running code cleaner, adding magic comments

  • Loading branch information...
1 parent 9ed5652 commit 11b8c1525ba9f00afb1942f7ebf34bec12f7558b @masone masone committed with Masao Mutoh Jul 12, 2010
Showing with 444 additions and 358 deletions.
  1. +2 −2 gettext.gemspec
  2. +25 −23 lib/gettext.rb
  3. +2 −0 lib/gettext/cgi.rb
  4. +7 −7 lib/gettext/core_ext/iconv.rb
  5. +8 −6 lib/gettext/core_ext/string.rb
  6. +2 −0 lib/gettext/parser/erb.rb
  7. +2 −0 lib/gettext/parser/glade.rb
  8. +12 −12 lib/gettext/parser/ruby.rb
  9. +4 −2 lib/gettext/runtime/class_info.rb
  10. +13 −11 lib/gettext/runtime/locale_path.rb
  11. +7 −5 lib/gettext/runtime/mofile.rb
  12. +6 −4 lib/gettext/runtime/textdomain.rb
  13. +3 −1 lib/gettext/runtime/textdomain_group.rb
  14. +28 −26 lib/gettext/runtime/textdomain_manager.rb
  15. +15 −13 lib/gettext/tools.rb
  16. +5 −3 lib/gettext/tools/parser/erb.rb
  17. +16 −14 lib/gettext/tools/parser/glade.rb
  18. +16 −16 lib/gettext/tools/parser/ruby.rb
  19. +8 −6 lib/gettext/tools/pomessage.rb
  20. +38 −36 lib/gettext/tools/poparser.rb
  21. +7 −7 lib/gettext/tools/rgettext.rb
  22. +7 −5 lib/gettext/tools/rmsgfmt.rb
  23. +116 −114 lib/gettext/tools/rmsgmerge.rb
  24. +2 −0 lib/gettext/utils.rb
  25. +1 −1 lib/gettext/version.rb
  26. +1 −1 samples/cgi/hellolib.rb
  27. +5 −5 samples/cgi/http.rb
  28. +1 −1 samples/hello.rb
  29. +1 −1 samples/hello_gtk2.rb
  30. +1 −1 samples/hello_noop.rb
  31. +2 −0 samples/makemo.rb
  32. +2 −0 samples/po/test.rb
  33. +2 −0 test/test_class_info.rb
  34. +3 −1 test/test_locale_path.rb
  35. +3 −1 test/test_parser.rb
  36. +3 −1 test/test_po_generation.rb
  37. +4 −2 test/test_pomessage.rb
  38. +2 −0 test/test_string.rb
  39. +2 −0 test/test_textdomain_bind.rb
  40. +2 −0 test/test_textdomain_multi.rb
  41. +2 −0 test/test_textdomain_toplevel.rb
  42. +4 −2 test/test_thread.rb
  43. +5 −3 test/testlib/N_.rb
  44. +4 −2 test/testlib/gettext.rb
  45. +2 −0 test/testlib/helper.rb
  46. +2 −0 test/testlib/multi_textdomain.rb
  47. +10 −8 test/testlib/ngettext.rb
  48. +9 −7 test/testlib/npgettext.rb
  49. +4 −2 test/testlib/nsgettext.rb
  50. +4 −2 test/testlib/pgettext.rb
  51. +4 −2 test/testlib/sgettext.rb
  52. +2 −0 test/testlib/simple.rb
  53. +3 −1 test/tools/files/simple_translation.rb
  54. +3 −1 test/tools/test_tools.rb
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
=begin
gettext.rb - GetText module
@@ -14,7 +16,7 @@
if Object.constants.include? "Gem"
begin
begin
- gem 'locale', '>=2.0.5'
+ gem 'locale', '>=2.0.5'
rescue Gem::LoadError
end
rescue NoMethodError
@@ -47,14 +49,14 @@ def self.included(mod) #:nodoc:
# bindtextdomain(domainname, options = {})
#
- # Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to
+ # Bind a textdomain(%{path}/%{locale}/LC_MESSAGES/%{domainname}.mo) to
# your program.
- # Normally, the texdomain scope becomes the class/module(and parent
+ # Normally, the texdomain scope becomes the class/module(and parent
# classes/included modules).
#
# * domainname: the textdomain name.
# * options: options as an Hash.
- # * :path - the path to the mo-files. When the value is nil, it will search default paths such as
+ # * :path - the path to the mo-files. When the value is nil, it will search default paths such as
# /usr/share/locale, /usr/local/share/locale)
# * :output_charset - The output charset. Same with GetText.set_output_charset. Usually, L10n
# library doesn't use this option. Application may use this once.
@@ -68,7 +70,7 @@ def bindtextdomain(domainname, *options)
# * klass: the target ruby class.
# * domainname: the textdomain name.
# * options: options as an Hash. See GetText.bindtextdomain.
- def bindtextdomain_to(klass, domainname, *options)
+ def bindtextdomain_to(klass, domainname, *options)
if options[0].kind_of? Hash
opts = options[0]
else
@@ -83,17 +85,17 @@ def bindtextdomain_to(klass, domainname, *options)
TextDomainManager.bind_to(klass, domainname, opts)
end
- # Binds a existed textdomain to your program.
+ # Binds a existed textdomain to your program.
# This is the same function with GetText.bindtextdomain but simpler(and faster) than bindtextdomain.
- # Note that you need to call GetText.bindtextdomain first. If the domainname hasn't bound yet,
+ # Note that you need to call GetText.bindtextdomain first. If the domainname hasn't bound yet,
# raises GetText::NoboundTextDomainError.
# * domainname: a textdomain name.
# * Returns: the GetText::TextDomainManager.
def textdomain(domainname) #:nodoc:
textdomain_to(self, domainname)
end
- # Includes GetText module and bind an exsited textdomain to a class.
+ # Includes GetText module and bind an exsited textdomain to a class.
# See textdomain for more detail.
# * klass: the target ruby class.
# * domainname: the textdomain name.
@@ -109,13 +111,13 @@ def textdomain_to(klass, domainname) #:nodoc:
# _(msgid)
#
# Translates msgid and return the message.
- # This doesn't make a copy of the message.
+ # This doesn't make a copy of the message.
#
- # You need to use String#dup if you want to modify the return value
- # with destructive functions.
+ # You need to use String#dup if you want to modify the return value
+ # with destructive functions.
#
# (e.g.1) _("Hello ").dup << "world"
- #
+ #
# But e.g.1 should be rewrite to:
#
# (e.g.2) _("Hello %{val}") % {:val => "world"}
@@ -132,12 +134,12 @@ def gettext(msgid)
# sgettext(msgid, div = '|')
# s_(msgid, div = '|')
#
- # Translates msgid, but if there are no localized text,
+ # Translates msgid, but if there are no localized text,
# it returns a last part of msgid separeted "div".
#
# * msgid: the message id.
# * separator: separator or nil for no seperation.
- # * Returns: the localized text by msgid. If there are no localized text,
+ # * Returns: the localized text by msgid. If there are no localized text,
# it returns a last part of the msgid separeted by "seperator".
# <tt>Movie|Location -> Location</tt>
# See: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151
@@ -155,7 +157,7 @@ def sgettext(msgid, seperator = "|")
#
# * msgctxt: the message context.
# * msgid: the message id.
- # * Returns: the localized text by msgid. If there are no localized text,
+ # * Returns: the localized text by msgid. If there are no localized text,
# it returns msgid.
# See: http://www.gnu.org/software/autoconf/manual/gettext/Contexts.html
def pgettext(msgctxt, msgid)
@@ -168,7 +170,7 @@ def pgettext(msgctxt, msgid)
# n_(msgid, msgid_plural, n)
# n_(msgids, n) # msgids = [msgid, msgid_plural]
#
- # The ngettext is similar to the gettext function as it finds the message catalogs in the same way.
+ # The ngettext is similar to the gettext function as it finds the message catalogs in the same way.
# But it takes two extra arguments for plural form.
#
# * msgid: the singular form.
@@ -187,7 +189,7 @@ def ngettext(msgid, msgid_plural, n = nil)
# ns_(msgids, n, div = "|") # msgids = [msgid, msgid_plural]
#
# The nsgettext is similar to the ngettext.
- # But if there are no localized text,
+ # But if there are no localized text,
# it returns a last part of msgid separeted "div".
#
# * msgid: the singular form with "div". (e.g. "Special|An apple")
@@ -227,15 +229,15 @@ def npgettext(msgctxt, msgids, arg2 = nil, arg3 = nil)
opt1 = arg3
opt2 = nil
end
-
+
msgstr = TextDomainManager.translate_plural_message(self, msgid_ctxt, msgid_plural, opt1, opt2)
if msgstr == msgid_ctxt
msgid
else
msgstr
end
end
-
+
# makes dynamic translation messages readable for the gettext parser.
# <tt>_(fruit)</tt> cannot be understood by the gettext parser. To help the parser find all your translations,
# you can add <tt>fruit = N_("Apple")</tt> which does not translate, but tells the parser: "Apple" needs translation.
@@ -245,15 +247,15 @@ def N_(msgid)
msgid
end
- # This is same function as N_ but for ngettext.
+ # This is same function as N_ but for ngettext.
# * msgid: the message id.
# * msgid_plural: the plural message id.
# * Returns: msgid.
def Nn_(msgid, msgid_plural)
[msgid, msgid_plural]
end
- # Sets charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", ...
+ # Sets charset(String) such as "euc-jp", "sjis", "CP932", "utf-8", ...
# You shouldn't use this in your own Libraries.
# * charset: an output_charset
# * Returns: self
@@ -277,9 +279,9 @@ def set_locale(lang)
Locale.current = lang
end
- # Set the locale to the current thread.
+ # Set the locale to the current thread.
# Note that if #set_locale is set, this value is ignored.
- # If you need, set_locale(nil); set_current_locale(lang)
+ # If you need, set_locale(nil); set_current_locale(lang)
def set_current_locale(lang)
Locale.current = lang
end
View
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
=begin
gettext/cgi.rb - GetText for CGI
@@ -18,12 +18,12 @@
require 'iconv.so'
rescue LoadError
# Pseudo Iconv class
- #
+ #
# ==== For Matz Ruby:
- # If you don't have iconv but Ruby/GLib2, this library uses Ruby/GLib2's
+ # If you don't have iconv but Ruby/GLib2, this library uses Ruby/GLib2's
# iconv functions.
#
- # Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
+ # Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
# You can get binaries for Win32(One-Click Ruby Installer).
# <URL: http://ruby-gnome2.sourceforge.jp/>
# ==== For JRuby:
@@ -47,16 +47,16 @@ def self.conv(to, from, str)
else
begin
require 'glib2'
-
+
def self.check_glib_version?(major, minor, micro) # :nodoc:
(GLib::BINDING_VERSION[0] > major ||
- (GLib::BINDING_VERSION[0] == major &&
+ (GLib::BINDING_VERSION[0] == major &&
GLib::BINDING_VERSION[1] > minor) ||
- (GLib::BINDING_VERSION[0] == major &&
+ (GLib::BINDING_VERSION[0] == major &&
GLib::BINDING_VERSION[1] == minor &&
GLib::BINDING_VERSION[2] >= micro))
end
-
+
if check_glib_version?(0, 11, 0)
# This is a function equivalent of Iconv.iconv.
# * to: encoding name for destination
@@ -1,19 +1,21 @@
+# encoding: utf-8
+
=begin
string.rb - Extension for String.
Copyright (C) 2005-2009 Masao Mutoh
-
+
You may redistribute it and/or modify it under the same
license terms as Ruby or LGPL.
=end
# Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError.
#
-# String#% method which accept "named argument". The translator can know
+# String#% method which accept "named argument". The translator can know
# the meaning of the msgids using "named argument" instead of %s/%d style.
class String
- unless instance_methods.find {|m| m.to_s == 'bytesize'}
+ unless instance_methods.find {|m| m.to_s == 'bytesize'}
# For older ruby (such as ruby-1.8.5)
alias :bytesize :size
end
@@ -30,9 +32,9 @@ class String
# %(arg)
# %(hash)
#
- # Format - Uses str as a format specification, and returns the result of applying it to arg.
- # If the format specification contains more than one substitution, then arg must be
- # an Array containing the values to be substituted. See Kernel::sprintf for details of the
+ # Format - Uses str as a format specification, and returns the result of applying it to arg.
+ # If the format specification contains more than one substitution, then arg must be
+ # an Array containing the values to be substituted. See Kernel::sprintf for details of the
# format string. This is the default behavior of the String class.
# * arg: an Array or other class except Hash.
# * Returns: formatted String
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
warn "DEPRECATED: Use 'gettext/tools/parser/erb' instead."
require 'gettext/tools/parser/erb'
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
warn "DEPRECATED: Use 'gettext/tools/parser/glade' instead."
require 'gettext/tools/parser/glade'
View
@@ -5,7 +5,7 @@
Copyright (C) 2003-2005 Masao Mutoh
Copyright (C) 2005 speakillof
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
-
+
You may redistribute it and/or modify it under the same
license terms as Ruby.
@@ -22,13 +22,13 @@ def parse
s = get_readed
if RubyToken::TkSTRING === tk
def tk.value
- @value
+ @value
end
-
+
def tk.value=(s)
@value = s
end
-
+
if @here_header
s = s.sub(/\A.*?\n/, '').sub(/^.*\n\Z/, '')
else
@@ -38,10 +38,10 @@ def tk.value=(s)
# Do nothing.
end
end
-
+
tk.value = s
end
-
+
if $DEBUG
if tk.is_a? TkSTRING
$stderr.puts("#{tk}: #{tk.value}")
@@ -51,7 +51,7 @@ def tk.value=(s)
$stderr.puts(tk)
end
end
-
+
yield tk
end
return nil
@@ -62,7 +62,7 @@ def tk.value=(s)
module GetText
module RubyParser
extend self
-
+
unless defined? ID
ID = ['gettext', '_', 'N_', 'sgettext', 's_']
PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
@@ -154,7 +154,7 @@ def parse_lines(file_name, lines, targets) # :nodoc:
def target?(file) # :nodoc:
true # always true, as default parser.
end
- end
+ end
end
@@ -164,9 +164,9 @@ def target?(file) # :nodoc:
ARGV.each do |file|
pp GetText::RubyParser.parse(file)
end
-
- #rl = RubyLexX.new; rl.set_input(ARGF)
+
+ #rl = RubyLexX.new; rl.set_input(ARGF)
#rl.parse do |tk|
#p tk
- #end
+ #end
end
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
require 'locale/util/memoizable'
module GetText
@@ -47,13 +49,13 @@ def related_classes_internal(klass, all_classes = [], analyzed_classes = [] )
end
if all_classes.size > 0
- (ret & all_classes).uniq
+ (ret & all_classes).uniq
else
ret.uniq
end
end
- # Returns the classes which related to klass
+ # Returns the classes which related to klass
# (klass's ancestors, included modules and nested modules)
def related_classes(klass, all_classes = [])
ret = related_classes_internal(klass, all_classes)
Oops, something went wrong.

0 comments on commit 11b8c15

Please sign in to comment.