Module: Translatomatic::ResourceFile

Extended by:
Util
Defined in:
lib/translatomatic/resource_file.rb,
lib/translatomatic/resource_file/po.rb,
lib/translatomatic/resource_file/csv.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/subtitle.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, CSV, HTML, Markdown, PO, Plist, Properties, RESW, Subtitle, Text, XCodeStrings, XML, YAML

Class Method Summary collapse

Class Method Details

.create(path, locale = nil) ⇒ Object

Create a new resource file



26
27
28
29
# File 'lib/translatomatic/resource_file.rb', line 26

def self.create(path, locale = nil)
  klass = const_get(klass_name)
  klass.new
end

.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:



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

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
# File 'lib/translatomatic/resource_file.rb', line 16

def self.load(path, locale = nil)
  path = path.kind_of?(Pathname) ? path : Pathname.new(path)
  types_for_path(path).each do |klass|
    log.debug(t("file.loading", file: path, name: klass.name.demodulize))
    return klass.new(path, locale: locale)
  end
  nil
end

.typesArray<Class>

Find all configured resource file classes

Returns:

  • (Array<Class>)

    Available resource file classes



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

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