Object
Treats locale-path for mo-files.
The default locale paths.
Add default locale path. Usually you should use GetText.add_default_locale_path instead.
path: a new locale path. (e.g.) “/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo” (‘locale’ => “ja_JP“, ‘name’ => “textdomain”)
Returns: the new DEFAULT_LOCALE_PATHS
# File lib/gettext/runtime/locale_path.rb, line 37
37: def add_default_rule(path)
38: DEFAULT_RULES.unshift(path)
39: end
Returns path rules as an Array. (e.g.) [“/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo”, …]
# File lib/gettext/runtime/locale_path.rb, line 43
43: def default_path_rules
44: default_path_rules = []
45:
46: if ENV["GETTEXT_PATH"]
47: ENV["GETTEXT_PATH"].split(/,/).each {|i|
48: default_path_rules = ["#{i}/%{lang}/LC_MESSAGES/%{name}.mo", "#{i}/%{lang}/%{name}.mo"]
49: }
50: end
51:
52: default_path_rules += DEFAULT_RULES
53:
54: load_path = $LOAD_PATH
55: if defined? ::Gem
56: load_path += Gem.all_load_paths
57: end
58: load_path.map!{|v| v.match(/(.*?)(\/lib)*?$/); $1}
59: load_path.each {|path|
60: default_path_rules += [
61: "#{path}/data/locale/%{lang}/LC_MESSAGES/%{name}.mo",
62: "#{path}/data/locale/%{lang}/%{name}.mo",
63: "#{path}/locale/%{lang}/%{name}.mo"]
64: }
65: # paths existed only.
66: default_path_rules = default_path_rules.select{|path|
67: Dir.glob(path % {:lang => "*", :name => "*"}).size > 0}.uniq
68: default_path_rules
69: end
Creates a new GetText::TextDomain.
name: the textdomain name.
topdir: the locale path (“%{topdir}/%{lang}/LC_MESSAGES/%{name}.mo”) or nil.
# File lib/gettext/runtime/locale_path.rb, line 78
78: def initialize(name, topdir = nil)
79: @name = name
80:
81: if topdir
82: path_rules = ["#{topdir}/%{lang}/LC_MESSAGES/%{name}.mo", "#{topdir}/%{lang}/%{name}.mo"]
83: else
84: path_rules = self.class.default_path_rules
85: end
86:
87: @locale_paths = {}
88: path_rules.each do |rule|
89: this_path_rules = rule % {:lang => "([^\/]+)", :name => name}
90: Dir.glob(rule %{:lang => "*", :name => name}).each do |path|
91: if /#{this_path_rules}/ =~ path
92: @locale_paths[$1] = path unless @locale_paths[$1]
93: end
94: end
95: end
96: @supported_locales = @locale_paths.keys.sort
97: end
Gets the current path.
lang: a Locale::Tag.
# File lib/gettext/runtime/locale_path.rb, line 101
101: def current_path(lang)
102: lang_candidates = lang.to_posix.candidates
103: search_files = []
104:
105: lang_candidates.each do |tag|
106: path = @locale_paths[tag.to_s]
107: warn "GetText::TextDomain#load_mo: mo-file is #{path}" if $DEBUG
108: return path if path
109: end
110:
111: if $DEBUG
112: warn "MO file is not found in"
113: @locale_paths.each do |path|
114: warn " #{path[1]}"
115: end
116: end
117: nil
118: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.