#!/usr/bin/env ruby =begin hello.cgi - Sample script for CGI 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) 2005 Masao Mutoh You may redistribute it and/or modify it under the same license terms as Ruby. =end $:.insert(0, "../../lib") # gettext/cgi support CGI. begin require 'rubygems' rescue LoadError end require 'gettext/cgi' include GetText set_cgi(CGI.new) print "Content-type:text/html; charset=UTF-8\n\n" # Configure GetText first. set_output_charset("UTF-8") bindtextdomain("main", "locale") langs = ["en"] + Dir.glob("locale/*").collect{|item| File.basename(item)} langs.sort! urls = [ ["helloerb1.cgi", N_("an ERB/CGI sample (UTF-8).")], ["helloerb1.cgi?other=true", N_("an ERB/CGI sample (UTF-8). This sample uses the same container as sample 1 but has a different rhtml file.")], ["helloerb2.cgi", N_("an ERB/CGI sample (Auto-Detect charset).")] ] # # CGI part # puts %Q[ ] puts _("Sample script for CGI/ERB and gettext") puts "

" puts _("Ruby-GetText CGI sample scripts") puts "

" puts "

" + _("Supported Locales:") + "[#{langs.join(", ")}]

" puts "

" + _("Auto-Detect a locale from the WWW browser") + "

" puts "
    " urls.each do |url, desc| puts "
  1. #{url}
    " + _(desc) + "
  2. " end puts "
" puts "

" + _('Set locale as a "lang" parameter') + "

" langs.each do |lang| puts "

[#{lang}]

" puts "
    " urls.each do |url, desc| if /\?other/ =~ url url += "&lang=" + lang else url += "?lang=" + lang end puts "
  1. #{CGI.escapeHTML(url)}
    " + _(desc) + "
  2. " end puts "
" end puts "

" + _('Set "lang" to cookie.') + "

" puts "

" + _('Click one of the link below, and then click "Auto-Detect a locale from the WWW browser" samples.') + "

" puts "
    " langs.each do |lang| url = "cookie.cgi?lang=" + lang puts "
  1. #{CGI.escapeHTML(url)} [#{lang}]
  2. " end puts "
" puts "

" + _("Source codes") + "

" puts "
    " Dir.glob("*cgi\0*rb\0*rhtml)").sort.each do |src| unless /http.rb|makemo.rb/ =~ src puts %Q[
  1. #{src}
  2. ] end end puts %Q[

]