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/base.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,
lib/translatomatic/resource_file/key_value_support.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, options = {}) ⇒ Object

Create a new resource file



24
25
26
27
28
29
30
31
# File 'lib/translatomatic/resource_file.rb', line 24

def create(path, options = {})
  klass = types_for_path(path).first
  return nil unless klass
  file = klass.new
  file.path = path
  file.locale = build_locale(options[:locale])
  file
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:



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

def find(path, options = {})
  files = []
  include_dot_directories = options[:include_dot_directories]
  path = Pathname.new(path) unless path.is_a?(Pathname)
  path.find do |file|
    puts "loading #{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, options = {}) ⇒ Translatomatic::ResourceFile::Base

Load a resource file. If options 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

Returns:



14
15
16
17
18
19
20
21
# File 'lib/translatomatic/resource_file.rb', line 14

def load(path, options = {})
  path = path.is_a?(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, options)
  end
  nil
end

.typesArray<Class>

Find all configured resource file classes

Returns:

  • (Array<Class>)

    Available resource file classes



54
55
56
57
58
# File 'lib/translatomatic/resource_file.rb', line 54

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