Sha256: 4f3e649ccf2f80b572fcaa9c3893ba8adfbf39208fe5cc617d27426f0e04ec41

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.

$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
require 'qwik/catalog-factory'
require 'qwik/gettext'

module Qwik
  class Action
    include GetText

    def init_gettext
      init_catalog(@memory.catalog, @req.accept_language)
    end

    def init_catalog(catalog_factory, langs)
      langs.each {|lang|
	catalog = catalog_factory.get_catalog(lang)
        if catalog
          set_catalog(catalog)	# GetText::set_catalog
          return
        end
      }
    end
  end
end

if $0 == __FILE__
  require 'qwik/test-common'
  $test = true
end

if defined?($test) && $test
  class TestCommonGettext < Test::Unit::TestCase
    include TestSession

    def test_init_catalog
      res = session

      accept_languages = ['en']
      @action.init_catalog(@memory.catalog, accept_languages)
      ok_eq('hello', @action._('hello'))

      accept_languages = ['ja']
      @action.init_catalog(@memory.catalog, accept_languages)
      ok_eq('こんにちは', @action._('hello'))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qwikdoc-0.0.1 vendor/qwik/common-gettext.rb