Module: Translatomatic::ResourceFile

Extended by:
Util
Defined in:
lib/translatomatic/resource_file.rb,
lib/translatomatic/resource_file/xml.rb,
lib/translatomatic/resource_file/html.rb,
lib/translatomatic/resource_file/resw.rb,
lib/translatomatic/resource_file/text.rb,
lib/translatomatic/resource_file/yaml.rb,
lib/translatomatic/resource_file/plist.rb,
lib/translatomatic/resource_file/markdown.rb,
lib/translatomatic/resource_file/properties.rb,
lib/translatomatic/resource_file/xcode_strings.rb

Overview

Provides methods to create resource files of various types.

Defined Under Namespace

Classes: Base, HTML, Markdown, Plist, Properties, RESW, Text, XCodeStrings, XML, YAML

Class Method Summary collapse

Class Method Details

.find(path, options = {}) ⇒ Array<Translatomatic::ResourceFile>

Find all resource files under the given directory. Follows symlinks.

Parameters:

  • path (String, Pathname)

    The path to search from

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/translatomatic/resource_file.rb', line 33

def self.find(path, options = {})
  files = []
  include_dot_directories = options[:include_dot_directories]
  path = Pathname.new(path) unless path.kind_of?(Pathname)
  path.find do |file|
    if !include_dot_directories && file.basename.to_s[0] == ?.
      Find.prune
    else
      resource = load(file)
      files << resource if resource
    end
  end
  files
end

.load(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base

Load a resource file. If locale is not specified, the locale of the file will be determined from the filename, or else the current default locale will be used.

Parameters:

  • path (String)

    Path to the resource file

  • locale (String) (defaults to: nil)

    Locale of the resource file

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/translatomatic/resource_file.rb', line 16

def self.load(path, locale = nil)
  path = path.kind_of?(Pathname) ? path : Pathname.new(path)
  modules.each do |mod|
    # match on entire filename to support extensions containing locales
    if extension_match(mod, path)
      log.debug(t("resource.loading", file: path,
        name: mod.name.demodulize))
      file = mod.new(path, locale)
      return file if file.valid?
    end
  end
  nil
end

.modulesArray<Class>

Find all configured resource file classes

Returns:

  • (Array<Class>)

    Available resource file classes



50
51
52
53
54
# File 'lib/translatomatic/resource_file.rb', line 50

def self.modules
  self.constants.map { |c| self.const_get(c) }.select do |klass|
    klass.is_a?(Class) && klass != Base
  end
end