1
# $Id: locale.rb,v 1.5 2010/06/29 12:08:35 chabannf Exp $
4
# CONTACT : zonecheck@nic.fr
5
# AUTHOR : Stephane D'Alu <sdalu@nic.fr>
7
# CREATED : 2003/08/29 14:10:22
8
# REVISION : $Revision: 1.5 $
9
# DATE : $Date: 2010/06/29 12:08:35 $
11
# CONTRIBUTORS: (see also CREDITS file)
15
# COPYRIGHT : AFNIC (c) 2003
17
# This file is part of ZoneCheck.
19
# ZoneCheck is free software; you can redistribute it and/or modify it
20
# under the terms of the GNU General Public License as published by
21
# the Free Software Foundation; either version 3 of the License, or
22
# (at your option) any later version.
24
# ZoneCheck is distributed in the hope that it will be useful, but
25
# WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
# General Public License for more details.
29
# You should have received a copy of the GNU General Public License
30
# along with ZoneCheck; if not, write to the Free Software Foundation,
31
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35
LANGRegex = /^(\w+?)(?:_(\w+))?(?:\.([\w\-]+))?$/
39
# (and raise exception is the parameter is suspicious)
40
# The settings are based on: LanguageCode_CountryCode.Encoding
42
def self.normlang(lng)
43
unless md = LANGRegex.match(lng)
44
raise ArgumentError, "Suspicious language selection: #{lng}"
47
lang += '_' + md[2].upcase if md[2]
48
lang += '.' + md[3].downcase if md[3]
53
# Split lang between Language, Country, Encoding
55
def self.splitlang(lng)
56
unless md = LANGRegex.match(lng)
57
raise ArgumentError, "Suspicious language selection: #{lng}"
59
[ md[1], md[2], md[3] ]
76
ln, ct, en = ZoneCheck::Locale::splitlang(ZoneCheck::Locale::normlang(lng))
78
evlist << 'lang' if (@language != ln) || (@country != ct)
79
evlist << 'encoding' if (@encoding != en)
80
@lang, @language, @country, @encoding = lng, ln, ct, en
81
$dbg.msg(DBG::LOCALE) { "locale set to #{lng}" }
86
attr_reader :lang, :language, :country, :encoding
89
ln, ct, en = ZoneCheck::Locale::splitlang(ZoneCheck::Locale::normlang(lng))
90
if($supported_languages.include?(ln.downcase))
92
evlist << 'lang' if (@language != ln) || (@country != ct)
93
evlist << 'encoding' if (@encoding != en)
94
@lang, @language, @country, @encoding = lng, ln, ct, en
95
$dbg.msg(DBG::LOCALE) { "locale set to #{lng}" }
98
$dbg.msg(DBG::LOCALE) { "The given language (#{lng}) is not supported by ZoneCheck. " +
99
"Here is a list of supported languages: " +
100
$supported_languages.join(", ") }
104
def watch(event, action)
105
(@actions[event] ||= []) << action
110
@actions[ev].each { |a| a.call } if @actions.has_key?(ev) }
b'\\ No newline at end of file'