Sha256: 17ec3f06d8f3d33809a7126e66cf06b77256ff73592f8bd75603034805bc8c08

Contents?: true

Size: 1.17 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
qwik2md-2.0.1 vendor/qwik/lib/qwik/common-gettext.rb
qwik2md-2.0.0 vendor/qwik/lib/qwik/common-gettext.rb
qwik2md-1.0.2 vendor/qwik/lib/qwik/common-gettext.rb
qwik2md-1.0.1 vendor/qwik/lib/qwik/common-gettext.rb
qwik2md-1.0.0 vendor/qwik/lib/qwik/common-gettext.rb
qwik2md-0.1.0 vendor/qwik/lib/qwik/common-gettext.rb