File: cookie.cgi

package info (click to toggle)
ruby-locale 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 444 kB
  • ctags: 293
  • sloc: ruby: 3,203; makefile: 4
file content (62 lines) | stat: -rwxr-xr-x 1,323 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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[
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" type="text/css" href="locale.css" media="all">
  <title>Sample script for CGI and Ruby/Locale</title>
</head>
<body>

<div style="text-align:center; margin:5em;">
]

if lang.size > 0
  puts %Q!<p><div id="result">Set [#{lang}] as the cookie of your WWW browser.</div></p>!
else
  puts %Q!<p><div id="result">Clear "lang" value from your WWW browser.</div></p>!
end

puts %Q!
<p style="margin:2em;"><a href="/">Back</a></p>
</div>
<div style="text-align:right">
  <p>Copyright (C) 2008 Masao Mutoh</p>
</div>
</body>
</html>
!