Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • tk/lib/tk/msgcat.rb

Class/Module Index [+]

Quicksearch

TkMsgCat

class TkMsgCatalog

Attributes

msgcat_ext[RW]

Public Class Methods

[](*args) click to toggle source
Alias for: translate
callback(namespace, locale, src_str, *args) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 58
def self.callback(namespace, locale, src_str, *args)
  src_str = sprintf(src_str, *args) unless args.empty?
  cmd_tbl = TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip]
  cmd = cmd_tbl[namespace]
  cmd = cmd_tbl['::'] unless cmd  # use global scope as interp default
  return src_str unless cmd       # no cmd -> return src-str (default action)
  begin
    cmd.call(locale, src_str)
  rescue SystemExit
    exit(0)
  rescue Interrupt
    exit!(1)
  rescue Exception => e
    begin
      msg = _toUTF8(e.class.inspect) + ': ' +
            _toUTF8(e.message) + "\n" +
            "\n---< backtrace of Ruby side >-----\n" +
            _toUTF8(e.backtrace.join("\n")) +
            "\n---< backtrace of Tk side >-------"
      if TkCore::WITH_ENCODING
        msg.force_encoding('utf-8')
      else
        msg.instance_variable_set(:@encoding, 'utf-8')
      end
    rescue Exception
      msg = e.class.inspect + ': ' + e.message + "\n" +
            "\n---< backtrace of Ruby side >-----\n" +
            e.backtrace.join("\n") +
            "\n---< backtrace of Tk side >-------"
    end
    fail(e, msg)
  end
end
            
def_unknown_proc(cmd=Proc.new) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 291
def self.def_unknown_proc(cmd=Proc.new)
  TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip]['::'] = cmd
end
            
load(dir) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 234
def self.load(dir)
  self.load_rb(dir)
end
            
load_rb(dir) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 198
def self.load_rb(dir)
  count = 0
  preferences().each{|loc|
    file = File.join(dir, loc + self::MSGCAT_EXT)
    if File.readable?(file)
      count += 1
      if TkCore::WITH_ENCODING
        eval(IO.read(file, :encoding=>"ASCII-8BIT"))
      else
        eval(IO.read(file))
      end
    end
  }
  count
end
            
load_tk(dir) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 194
def self.load_tk(dir)
  number(tk_call('::msgcat::mcload', dir))
end
            
locale() click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 173
def self.locale
  tk_call('::msgcat::mclocale')
end
            
locale=(locale) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 180
def self.locale=(locale)
  tk_call('::msgcat::mclocale', locale)
end
            
maxlen(*src_strings) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 166
def self.maxlen(*src_strings)
  tk_call('::msgcat::mcmax', *src_strings).to_i
end
            
mc(*args) click to toggle source
Alias for: translate
new(namespace = nil) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 92
def initialize(namespace = nil)
  if namespace.kind_of?(TkNamespace)
    @namespace = namespace
  elsif namespace == nil
    @namespace = TkNamespace.new('::')  # global namespace
  else
    @namespace = TkNamespace.new(namespace)
  end
  @path = @namespace.path

  @msgcat_ext = '.msg'
end
            
package_name() click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 27
def self.package_name
  PACKAGE_NAME
end
            
preferences() click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 187
def self.preferences
  tk_split_simplelist(tk_call('::msgcat::mcpreferences'))
end
            
set_translation(locale, src_str, trans_str=None, enc='utf-8') click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 239
def self.set_translation(locale, src_str, trans_str=None, enc='utf-8')
  if trans_str && trans_str != None
    trans_str = Tk.UTF8_String(_toUTF8(trans_str, enc))
    Tk.UTF8_String(ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}} {#{trans_str}}"))
  else
    Tk.UTF8_String(ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}}"))
  end
end
            
set_translation_list(locale, trans_list, enc='utf-8') click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 260
def self.set_translation_list(locale, trans_list, enc='utf-8')
  # trans_list ::= [ [src, trans], [src, trans], ... ]
  list = []
  trans_list.each{|src, trans|
    if trans && trans != None
      list << _get_eval_string(src, true)
      list << Tk.UTF8_String(_toUTF8(trans, enc))
    else
      list << _get_eval_string(src, true) << ''
    end
  }
  #number(tk_call_without_enc('::msgcat::mcmset', locale, list))
  number(ip_eval_without_enc("::msgcat::mcmset {#{locale}} {#{_get_eval_string(list)}}"))
end
            
translate(*args) click to toggle source

*args ::= form, arg, arg, …

 
               # File tk/lib/tk/msgcat.rb, line 146
def self.translate(*args)
  dst = args.collect{|src|
    tk_call_without_enc('::msgcat::mc', _get_eval_string(src, true))
  }
  Tk.UTF8_String(sprintf(*dst))
end
            
Also aliased as: mc, []

Public Instance Methods

[](*args) click to toggle source
Alias for: translate
def_unknown_proc(cmd=Proc.new) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 294
def def_unknown_proc(cmd=Proc.new)
  TkMsgCatalog::UNKNOWN_CBTBL[TkCore::INTERP.__getip][@namespace.path] = cmd
end
            
load(dir) click to toggle source
Alias for: load_rb
load_rb(dir) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 218
def load_rb(dir)
  count = 0
  preferences().each{|loc|
    file = File.join(dir, loc + @msgcat_ext)
    if File.readable?(file)
      count += 1
      if TkCore::WITH_ENCODING
        @namespace.eval(IO.read(file, :encoding=>"ASCII-8BIT"))
      else
        @namespace.eval(IO.read(file))
      end
    end
  }
  count
end
            
Also aliased as: load
load_tk(dir) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 214
def load_tk(dir)
  number(@namespace.eval{tk_call('::msgcat::mcload', dir)})
end
            
locale() click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 176
def locale
  @namespace.eval{tk_call('::msgcat::mclocale')}
end
            
locale=(locale) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 183
def locale=(locale)
  @namespace.eval{tk_call('::msgcat::mclocale', locale)}
end
            
maxlen(*src_strings) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 169
def maxlen(*src_strings)
  @namespace.eval{tk_call('::msgcat::mcmax', *src_strings).to_i}
end
            
mc(*args) click to toggle source
Alias for: translate
method_missing(id, *args) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 106
  def method_missing(id, *args)
    # locale(src, trans) ==> set_translation(locale, src, trans)
    loc = id.id2name
    case args.length
    when 0 # set locale
      self.locale=(loc)

    when 1 # src only, or trans_list
      if args[0].kind_of?(Array)
        # trans_list
        #list = args[0].collect{|src, trans|
        #  [ Tk::UTF8_String.new(src), Tk::UTF8_String.new(trans) ]
        #}
        self.set_translation_list(loc, args[0])
      else
        # src
        #self.set_translation(loc, Tk::UTF8_String.new(args[0]))
        self.set_translation(loc, args[0])
      end

    when 2 # src and trans, or, trans_list and enc
      if args[0].kind_of?(Array)
        # trans_list
        self.set_translation_list(loc, *args)
      else
        #self.set_translation(loc, args[0], Tk::UTF8_String.new(args[1]))
        self.set_translation(loc, *args)
      end

    when 3 # src and trans and enc
      self.set_translation(loc, *args)

    else
      super(id, *args)
#      fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at

    end
  end
            
preferences() click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 190
def preferences
  tk_split_simplelist(@namespace.eval{tk_call('::msgcat::mcpreferences')})
end
            
set_translation(locale, src_str, trans_str=None, enc='utf-8') click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 247
def set_translation(locale, src_str, trans_str=None, enc='utf-8')
  if trans_str && trans_str != None
    trans_str = Tk.UTF8_String(_toUTF8(trans_str, enc))
    Tk.UTF8_String(@namespace.eval{
                     ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}} {#{trans_str}}")
                   })
  else
    Tk.UTF8_String(@namespace.eval{
                     ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}}")
                   })
  end
end
            
set_translation_list(locale, trans_list, enc='utf-8') click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 274
def set_translation_list(locale, trans_list, enc='utf-8')
  # trans_list ::= [ [src, trans], [src, trans], ... ]
  list = []
  trans_list.each{|src, trans|
    if trans && trans != None
      list << _get_eval_string(src, true)
      list << Tk.UTF8_String(_toUTF8(trans, enc))
    else
      list << _get_eval_string(src, true) << ''
    end
  }
  number(@namespace.eval{
           #tk_call_without_enc('::msgcat::mcmset', locale, list)
           ip_eval_without_enc("::msgcat::mcmset {#{locale}} {#{_get_eval_string(list)}}")
         })
end
            
translate(*args) click to toggle source
 
               # File tk/lib/tk/msgcat.rb, line 156
def translate(*args)
  dst = args.collect{|src|
    @namespace.eval{tk_call_without_enc('::msgcat::mc',
                                        _get_eval_string(src, true))}
  }
  Tk.UTF8_String(sprintf(*dst))
end
            
Also aliased as: mc, []

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.