Class: GetText::LocalePath

### Home Classes Methods

### In Files

- lib/gettext/locale_path.rb

### Parent

Object

### Methods

- ::add_default_rule
- ::default_path_rules
- ::new
- #current_path

### Included Modules

- Locale::Util::Memoizable

### Class/Module Index

Quicksearch

- GetText
- GetText::ClassInfo
- GetText::ErbParser
- GetText::GladeParser
- GetText::LocalePath
- GetText::MO
- GetText::MO::HeaderRev1
- GetText::MO::InvalidFormat
- GetText::NoboundTextDomainError
- GetText::PO
- GetText::PO::NonExistentEntryError
- GetText::POEntry
- GetText::POEntry::InvalidTypeError
- GetText::POEntry::NoMsgctxtError
- GetText::POEntry::NoMsgidError
- GetText::POEntry::NoMsgidPluralError
- GetText::POEntryForRubyParser
- GetText::POParser
- GetText::ParseError
- GetText::RubyParser
- GetText::TextDomain
- GetText::TextDomainGroup
- GetText::TextDomainManager
- GetText::Tools
- GetText::Tools::MsgInit
- GetText::Tools::MsgInit::ArgumentError
- GetText::Tools::MsgInit::Error
- GetText::Tools::MsgInit::ValidationError
- GetText::Tools::MsgMerge
- GetText::Tools::Task
- GetText::Tools::XGetText

No matching classes.

# GetText::LocalePath

Treats locale-path for mo-files.

### Constants

CONFIG_PREFIX

  The default locale paths.

DEFAULT_RULES

### Attributes

locale_paths[R]
supported_locales[R]

### Public Class Methods

add_default_rule(path) click to toggle source

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/locale_path.rb, line 37
    def add_default_rule(path)
      DEFAULT_RULES.unshift(path)
    end

default_path_rules() click to toggle source

Returns path rules as an Array. (e.g.) ["/usr/share/locale/%{lang}/LC_MESSAGES/%{name}.mo", ...]

    # File lib/gettext/locale_path.rb, line 43
    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"]
        }
      end
      default_path_rules += DEFAULT_RULES

      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}/locale/%{lang}/LC_MESSAGES/%{name}.mo",
          "#{path}/locale/%{lang}/%{name}.mo",
        ]
      }
      # paths existed only.
      default_path_rules = default_path_rules.select{|path|
        Dir.glob(path % {:lang => "*", :name => "*"}).size > 0}.uniq
      default_path_rules
    end

new(name, topdir = nil) click to toggle source

Creates a new GetText::TextDomain.

- name: the textdomain name.

- topdir: the locale path ("%{topdir}/%{lang}/LC_MESSAGES/%{name}.mo") or nil.

    # File lib/gettext/locale_path.rb, line 76
    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

      @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.untaint unless @locale_paths[$1]
          end
        end
      end
      @supported_locales = @locale_paths.keys.sort
    end

### Public Instance Methods

current_path(lang) click to toggle source

Gets the current path.

- lang: a Locale::Tag.

    # File lib/gettext/locale_path.rb, line 99
    def current_path(lang)
      lang_candidates = lang.to_posix.candidates

      lang_candidates.each do |tag|
        path = @locale_paths[tag.to_s]
        warn "GetText::TextDomain#load_mo: mo-file is #{path}" if $DEBUG
        return path if path
      end

      if $DEBUG
        warn "MO file is not found in"
        @locale_paths.each do |path|
          warn "  #{path[1]}"
        end
      end
      nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.