class ArcadiaLocalization

Constants

KEY_CACHE_VERSION
PARAM_SIG
STANDARD_LOCALE

Attributes

lc_lang[R]

Public Class Methods

new() click to toggle source
# File lib/a-core.rb, line 2695
def initialize
  @standard_locale=Arcadia.conf("locale.standard").nil? ? STANDARD_LOCALE : Arcadia.conf("locale.standard")
  @locale=Arcadia.conf("locale").nil? ? STANDARD_LOCALE : Arcadia.conf("locale")
  lc_lang_standard_file="conf/LC/#{Arcadia.conf('locale.standard')}.LANG"
  lc_lang_locale_file="conf/LC/#{Arcadia.conf('locale')}.LANG"
  need_cache_update = false
  if @standard_locale == @locale || !File.exist?(lc_lang_locale_file)
    @lc_lang = properties_file2hash(lc_lang_standard_file) if File.exist?(lc_lang_standard_file)
  else
    lc_lang_cache_file=File.join(Arcadia.local_dir, "#{Arcadia.conf('locale')}.LC_LANG_CACHE")
    if File.exist?(lc_lang_cache_file)
      @lc_lang = properties_file2hash(lc_lang_cache_file)
      if @lc_lang[KEY_CACHE_VERSION] != Arcadia.version
        # is to update
        need_cache_update = true
      end
    else
      need_cache_update = true
    end
    if need_cache_update
      @lc_lang = properties_file2hash(lc_lang_standard_file)
      @lc_lang.each_pair{|key,value| @lc_lang[key] = "#{@locale}:#{value}"}
      if File.exist?(lc_lang_locale_file)
        lc_lang_locale = properties_file2hash(lc_lang_locale_file)
      else
        lc_lang_locale = {}
      end
      lc_lang_locale.each{|k,v| @lc_lang[k]=v}
      @lc_lang[KEY_CACHE_VERSION]=Arcadia.version
      hash2properties_file(@lc_lang, lc_lang_cache_file)
    end
  end
end

Public Instance Methods

text(_key, _params = nil) click to toggle source
# File lib/a-core.rb, line 2729
def text(_key, _params = nil)
  ret = @lc_lang.nil?||@lc_lang[_key].nil? ? "?" : @lc_lang[_key]
  if !_params.nil?
    _params.each_with_index{|param, i| ret = ret.gsub("#{PARAM_SIG}#{i}", param.to_s) }
  end
  ret
end