lib/gettext/runtime/locale_path.rb in gettext-2.1.0 vs lib/gettext/runtime/locale_path.rb in gettext-2.2.0
- old
+ new
@@ -1,9 +1,11 @@
+# encoding: utf-8
+
=begin
locale_path.rb - GetText::LocalePath
- Copyright (C) 2001-2009 Masao Mutoh
+ Copyright (C) 2001-2010 Masao Mutoh
You may redistribute it and/or modify it under the same
license terms as Ruby or LGPL.
=end
@@ -15,16 +17,16 @@
# Treats locale-path for mo-files.
class LocalePath
include Locale::Util::Memoizable
# The default locale paths.
- CONFIG_PREFIX = Config::CONFIG['prefix'].gsub(/\/local/, "")
+ CONFIG_PREFIX = RbConfig::CONFIG['prefix'].gsub(/\/local/, "")
DEFAULT_RULES = [
"./locale/%{lang}/LC_MESSAGES/%{name}.mo",
"./locale/%{lang}/%{name}.mo",
- "#{Config::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
- "#{Config::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
+ "#{RbConfig::CONFIG['datadir']}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
+ "#{RbConfig::CONFIG['datadir'].gsub(/\/local/, "")}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
"#{CONFIG_PREFIX}/share/locale/%{lang}/LC_MESSAGES/%{name}.mo",
"#{CONFIG_PREFIX}/local/share/locale/%{lang}/LC_MESSAGES/%{name}.mo"
].uniq
class << self
@@ -35,37 +37,33 @@
# ('locale' => "ja_JP", 'name' => "textdomain")
# * Returns: the new DEFAULT_LOCALE_PATHS
def add_default_rule(path)
DEFAULT_RULES.unshift(path)
end
-
- # Returns path rules as an Array.
- # (e.g.) ["/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo", ...]
- def default_path_rules
+
+ # Returns path rules as an Array.
+ # (e.g.) ["/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo", ...]
+ def default_path_rules
default_path_rules = []
if ENV["GETTEXT_PATH"]
- ENV["GETTEXT_PATH"].split(/,/).each {|i|
- default_path_rules = ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
+ ENV["GETTEXT_PATH"].split(/,/).each {|i|
+ default_path_rules += ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
}
end
-
default_path_rules += DEFAULT_RULES
-
- load_path = $LOAD_PATH
- if defined? ::Gem
- load_path += Gem.all_load_paths
- end
+
+ load_path = $LOAD_PATH.dup
load_path.map!{|v| v.match(/(.*?)(\/lib)*?$/); $1}
load_path.each {|path|
default_path_rules += [
- "#{path}/data/locale/%{lang}/LC_MESSAGES/%{name}.mo",
- "#{path}/data/locale/%{lang}/%{name}.mo",
+ "#{path}/data/locale/%{lang}/LC_MESSAGES/%{name}.mo",
+ "#{path}/data/locale/%{lang}/%{name}.mo",
"#{path}/locale/%{lang}/%{name}.mo"]
}
# paths existed only.
- default_path_rules = default_path_rules.select{|path|
+ default_path_rules = default_path_rules.select{|path|
Dir.glob(path % {:lang => "*", :name => "*"}).size > 0}.uniq
default_path_rules
end
memoize_dup :default_path_rules
end
@@ -75,11 +73,11 @@
# Creates a new GetText::TextDomain.
# * name: the textdomain name.
# * topdir: the locale path ("%{topdir}/%{lang}/LC_MESSAGES/%{name}.mo") or nil.
def initialize(name, topdir = nil)
@name = name
-
+
if topdir
path_rules = ["#{topdir}/%{lang}/LC_MESSAGES/%{name}.mo", "#{topdir}/%{lang}/%{name}.mo"]
else
path_rules = self.class.default_path_rules
end
@@ -87,11 +85,11 @@
@locale_paths = {}
path_rules.each do |rule|
this_path_rules = rule % {:lang => "([^\/]+)", :name => name}
Dir.glob(rule %{:lang => "*", :name => name}).each do |path|
if /#{this_path_rules}/ =~ path
- @locale_paths[$1] = path unless @locale_paths[$1]
+ @locale_paths[$1] = path.untaint unless @locale_paths[$1]
end
end
end
@supported_locales = @locale_paths.keys.sort
end
@@ -115,8 +113,8 @@
end
end
nil
end
memoize :current_path
-
+
end
end