#!/usr/bin/env ruby
=begin
  cookie.cgi - Set a selected locale to the cookie of WWW Browser.

  Set UTF-8 forcely as output charset.

  Recommanded to set UTF-8 forcely because some web browser
  doesn't send HTTP_ACCEPT_CHARSET correctly.

  Copyright (C) 2008  Masao Mutoh

  You may redistribute it and/or modify it under the same
  license terms as Ruby.
=end

$:<< "../../lib"

require 'locale'
require 'cgi'

# Initialization of Locale library.
Locale.init(:driver => :cgi)
cgi = CGI.new
Locale.set_cgi(cgi)

# Get "lang" from the query string.
lang = cgi["lang"] or ""

#
# CGI part
#
print "Set-Cookie:lang=#{lang}\n"
print "Content-type:text/html; charset=UTF-8\n\n"

puts %Q[

  Sample script for CGI and Ruby/Locale

]

if lang.size > 0
  puts %Q!

Set [#{lang}] as the cookie of your WWW browser.

!
else
  puts %Q!

Clear "lang" value from your WWW browser.

!
end

puts %Q!

Back

Copyright (C) 2008 Masao Mutoh

!

