Skip to content

Commit

Permalink
running code cleaner, adding magic comments
Browse files Browse the repository at this point in the history
  • Loading branch information
masone authored and Masao Mutoh committed Aug 5, 2010
1 parent 9ed5652 commit 11b8c15
Show file tree
Hide file tree
Showing 54 changed files with 444 additions and 358 deletions.
4 changes: 2 additions & 2 deletions gettext.gemspec

Large diffs are not rendered by default.

48 changes: 25 additions & 23 deletions lib/gettext.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

=begin =begin
gettext.rb - GetText module gettext.rb - GetText module
Expand All @@ -14,7 +16,7 @@
if Object.constants.include? "Gem" if Object.constants.include? "Gem"
begin begin
begin begin
gem 'locale', '>=2.0.5' gem 'locale', '>=2.0.5'
rescue Gem::LoadError rescue Gem::LoadError
end end
rescue NoMethodError rescue NoMethodError
Expand Down Expand Up @@ -47,14 +49,14 @@ def self.included(mod) #:nodoc:


# bindtextdomain(domainname, options = {}) # 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. # 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). # classes/included modules).
# #
# * domainname: the textdomain name. # * domainname: the textdomain name.
# * options: options as an Hash. # * 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) # /usr/share/locale, /usr/local/share/locale)
# * :output_charset - The output charset. Same with GetText.set_output_charset. Usually, L10n # * :output_charset - The output charset. Same with GetText.set_output_charset. Usually, L10n
# library doesn't use this option. Application may use this once. # library doesn't use this option. Application may use this once.
Expand All @@ -68,7 +70,7 @@ def bindtextdomain(domainname, *options)
# * klass: the target ruby class. # * klass: the target ruby class.
# * domainname: the textdomain name. # * domainname: the textdomain name.
# * options: options as an Hash. See GetText.bindtextdomain. # * 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 if options[0].kind_of? Hash
opts = options[0] opts = options[0]
else else
Expand All @@ -83,17 +85,17 @@ def bindtextdomain_to(klass, domainname, *options)
TextDomainManager.bind_to(klass, domainname, opts) TextDomainManager.bind_to(klass, domainname, opts)
end 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. # 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. # raises GetText::NoboundTextDomainError.
# * domainname: a textdomain name. # * domainname: a textdomain name.
# * Returns: the GetText::TextDomainManager. # * Returns: the GetText::TextDomainManager.
def textdomain(domainname) #:nodoc: def textdomain(domainname) #:nodoc:
textdomain_to(self, domainname) textdomain_to(self, domainname)
end 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. # See textdomain for more detail.
# * klass: the target ruby class. # * klass: the target ruby class.
# * domainname: the textdomain name. # * domainname: the textdomain name.
Expand All @@ -109,13 +111,13 @@ def textdomain_to(klass, domainname) #:nodoc:
# _(msgid) # _(msgid)
# #
# Translates msgid and return the message. # 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 # You need to use String#dup if you want to modify the return value
# with destructive functions. # with destructive functions.
# #
# (e.g.1) _("Hello ").dup << "world" # (e.g.1) _("Hello ").dup << "world"
# #
# But e.g.1 should be rewrite to: # But e.g.1 should be rewrite to:
# #
# (e.g.2) _("Hello %{val}") % {:val => "world"} # (e.g.2) _("Hello %{val}") % {:val => "world"}
Expand All @@ -132,12 +134,12 @@ def gettext(msgid)
# sgettext(msgid, div = '|') # sgettext(msgid, div = '|')
# s_(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". # it returns a last part of msgid separeted "div".
# #
# * msgid: the message id. # * msgid: the message id.
# * separator: separator or nil for no seperation. # * 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". # it returns a last part of the msgid separeted by "seperator".
# <tt>Movie|Location -> Location</tt> # <tt>Movie|Location -> Location</tt>
# See: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151 # See: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC151
Expand All @@ -155,7 +157,7 @@ def sgettext(msgid, seperator = "|")
# #
# * msgctxt: the message context. # * msgctxt: the message context.
# * msgid: the message id. # * 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. # it returns msgid.
# See: http://www.gnu.org/software/autoconf/manual/gettext/Contexts.html # See: http://www.gnu.org/software/autoconf/manual/gettext/Contexts.html
def pgettext(msgctxt, msgid) def pgettext(msgctxt, msgid)
Expand All @@ -168,7 +170,7 @@ def pgettext(msgctxt, msgid)
# n_(msgid, msgid_plural, n) # n_(msgid, msgid_plural, n)
# n_(msgids, n) # msgids = [msgid, msgid_plural] # 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. # But it takes two extra arguments for plural form.
# #
# * msgid: the singular form. # * msgid: the singular form.
Expand All @@ -187,7 +189,7 @@ def ngettext(msgid, msgid_plural, n = nil)
# ns_(msgids, n, div = "|") # msgids = [msgid, msgid_plural] # ns_(msgids, n, div = "|") # msgids = [msgid, msgid_plural]
# #
# The nsgettext is similar to the ngettext. # 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". # it returns a last part of msgid separeted "div".
# #
# * msgid: the singular form with "div". (e.g. "Special|An apple") # * msgid: the singular form with "div". (e.g. "Special|An apple")
Expand Down Expand Up @@ -227,15 +229,15 @@ def npgettext(msgctxt, msgids, arg2 = nil, arg3 = nil)
opt1 = arg3 opt1 = arg3
opt2 = nil opt2 = nil
end end

msgstr = TextDomainManager.translate_plural_message(self, msgid_ctxt, msgid_plural, opt1, opt2) msgstr = TextDomainManager.translate_plural_message(self, msgid_ctxt, msgid_plural, opt1, opt2)
if msgstr == msgid_ctxt if msgstr == msgid_ctxt
msgid msgid
else else
msgstr msgstr
end end
end end

# makes dynamic translation messages readable for the gettext parser. # 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, # <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. # you can add <tt>fruit = N_("Apple")</tt> which does not translate, but tells the parser: "Apple" needs translation.
Expand All @@ -245,15 +247,15 @@ def N_(msgid)
msgid msgid
end end


# This is same function as N_ but for ngettext. # This is same function as N_ but for ngettext.
# * msgid: the message id. # * msgid: the message id.
# * msgid_plural: the plural message id. # * msgid_plural: the plural message id.
# * Returns: msgid. # * Returns: msgid.
def Nn_(msgid, msgid_plural) def Nn_(msgid, msgid_plural)
[msgid, msgid_plural] [msgid, msgid_plural]
end 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. # You shouldn't use this in your own Libraries.
# * charset: an output_charset # * charset: an output_charset
# * Returns: self # * Returns: self
Expand All @@ -277,9 +279,9 @@ def set_locale(lang)
Locale.current = lang Locale.current = lang
end 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. # 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) def set_current_locale(lang)
Locale.current = lang Locale.current = lang
end end
Expand Down
2 changes: 2 additions & 0 deletions lib/gettext/cgi.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

=begin =begin
gettext/cgi.rb - GetText for CGI gettext/cgi.rb - GetText for CGI
Expand Down
14 changes: 7 additions & 7 deletions lib/gettext/core_ext/iconv.rb
Expand Up @@ -18,12 +18,12 @@
require 'iconv.so' require 'iconv.so'
rescue LoadError rescue LoadError
# Pseudo Iconv class # Pseudo Iconv class
# #
# ==== For Matz Ruby: # ==== 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. # 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). # You can get binaries for Win32(One-Click Ruby Installer).
# <URL: http://ruby-gnome2.sourceforge.jp/> # <URL: http://ruby-gnome2.sourceforge.jp/>
# ==== For JRuby: # ==== For JRuby:
Expand All @@ -47,16 +47,16 @@ def self.conv(to, from, str)
else else
begin begin
require 'glib2' require 'glib2'

def self.check_glib_version?(major, minor, micro) # :nodoc: 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[0] == major &&
GLib::BINDING_VERSION[1] > minor) || GLib::BINDING_VERSION[1] > minor) ||
(GLib::BINDING_VERSION[0] == major && (GLib::BINDING_VERSION[0] == major &&
GLib::BINDING_VERSION[1] == minor && GLib::BINDING_VERSION[1] == minor &&
GLib::BINDING_VERSION[2] >= micro)) GLib::BINDING_VERSION[2] >= micro))
end end

if check_glib_version?(0, 11, 0) if check_glib_version?(0, 11, 0)
# This is a function equivalent of Iconv.iconv. # This is a function equivalent of Iconv.iconv.
# * to: encoding name for destination # * to: encoding name for destination
Expand Down
14 changes: 8 additions & 6 deletions lib/gettext/core_ext/string.rb
@@ -1,19 +1,21 @@
# encoding: utf-8

=begin =begin
string.rb - Extension for String. string.rb - Extension for String.
Copyright (C) 2005-2009 Masao Mutoh Copyright (C) 2005-2009 Masao Mutoh
You may redistribute it and/or modify it under the same You may redistribute it and/or modify it under the same
license terms as Ruby or LGPL. license terms as Ruby or LGPL.
=end =end


# Extension for String class. This feature is included in Ruby 1.9 or later but not occur TypeError. # 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. # the meaning of the msgids using "named argument" instead of %s/%d style.
class String 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) # For older ruby (such as ruby-1.8.5)
alias :bytesize :size alias :bytesize :size
end end
Expand All @@ -30,9 +32,9 @@ class String
# %(arg) # %(arg)
# %(hash) # %(hash)
# #
# Format - Uses str as a format specification, and returns the result of applying it to arg. # 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 # 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 # 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. # format string. This is the default behavior of the String class.
# * arg: an Array or other class except Hash. # * arg: an Array or other class except Hash.
# * Returns: formatted String # * Returns: formatted String
Expand Down
2 changes: 2 additions & 0 deletions lib/gettext/parser/erb.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

warn "DEPRECATED: Use 'gettext/tools/parser/erb' instead." warn "DEPRECATED: Use 'gettext/tools/parser/erb' instead."


require 'gettext/tools/parser/erb' require 'gettext/tools/parser/erb'
2 changes: 2 additions & 0 deletions lib/gettext/parser/glade.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

warn "DEPRECATED: Use 'gettext/tools/parser/glade' instead." warn "DEPRECATED: Use 'gettext/tools/parser/glade' instead."


require 'gettext/tools/parser/glade' require 'gettext/tools/parser/glade'
24 changes: 12 additions & 12 deletions lib/gettext/parser/ruby.rb
Expand Up @@ -5,7 +5,7 @@
Copyright (C) 2003-2005 Masao Mutoh Copyright (C) 2003-2005 Masao Mutoh
Copyright (C) 2005 speakillof Copyright (C) 2005 speakillof
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
You may redistribute it and/or modify it under the same You may redistribute it and/or modify it under the same
license terms as Ruby. license terms as Ruby.
Expand All @@ -22,13 +22,13 @@ def parse
s = get_readed s = get_readed
if RubyToken::TkSTRING === tk if RubyToken::TkSTRING === tk
def tk.value def tk.value
@value @value
end end

def tk.value=(s) def tk.value=(s)
@value = s @value = s
end end

if @here_header if @here_header
s = s.sub(/\A.*?\n/, '').sub(/^.*\n\Z/, '') s = s.sub(/\A.*?\n/, '').sub(/^.*\n\Z/, '')
else else
Expand All @@ -38,10 +38,10 @@ def tk.value=(s)
# Do nothing. # Do nothing.
end end
end end

tk.value = s tk.value = s
end end

if $DEBUG if $DEBUG
if tk.is_a? TkSTRING if tk.is_a? TkSTRING
$stderr.puts("#{tk}: #{tk.value}") $stderr.puts("#{tk}: #{tk.value}")
Expand All @@ -51,7 +51,7 @@ def tk.value=(s)
$stderr.puts(tk) $stderr.puts(tk)
end end
end end

yield tk yield tk
end end
return nil return nil
Expand All @@ -62,7 +62,7 @@ def tk.value=(s)
module GetText module GetText
module RubyParser module RubyParser
extend self extend self

unless defined? ID unless defined? ID
ID = ['gettext', '_', 'N_', 'sgettext', 's_'] ID = ['gettext', '_', 'N_', 'sgettext', 's_']
PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext'] PLURAL_ID = ['ngettext', 'n_', 'Nn_', 'ns_', 'nsgettext']
Expand Down Expand Up @@ -154,7 +154,7 @@ def parse_lines(file_name, lines, targets) # :nodoc:
def target?(file) # :nodoc: def target?(file) # :nodoc:
true # always true, as default parser. true # always true, as default parser.
end end
end end
end end




Expand All @@ -164,9 +164,9 @@ def target?(file) # :nodoc:
ARGV.each do |file| ARGV.each do |file|
pp GetText::RubyParser.parse(file) pp GetText::RubyParser.parse(file)
end end

#rl = RubyLexX.new; rl.set_input(ARGF) #rl = RubyLexX.new; rl.set_input(ARGF)
#rl.parse do |tk| #rl.parse do |tk|
#p tk #p tk
#end #end
end end
6 changes: 4 additions & 2 deletions lib/gettext/runtime/class_info.rb
@@ -1,3 +1,5 @@
# encoding: utf-8

require 'locale/util/memoizable' require 'locale/util/memoizable'


module GetText module GetText
Expand Down Expand Up @@ -47,13 +49,13 @@ def related_classes_internal(klass, all_classes = [], analyzed_classes = [] )
end end


if all_classes.size > 0 if all_classes.size > 0
(ret & all_classes).uniq (ret & all_classes).uniq
else else
ret.uniq ret.uniq
end end
end end


# Returns the classes which related to klass # Returns the classes which related to klass
# (klass's ancestors, included modules and nested modules) # (klass's ancestors, included modules and nested modules)
def related_classes(klass, all_classes = []) def related_classes(klass, all_classes = [])
ret = related_classes_internal(klass, all_classes) ret = related_classes_internal(klass, all_classes)
Expand Down

0 comments on commit 11b8c15

Please sign in to comment.