Class: Translatomatic::ResourceFile::Subtitle

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/resource_file/subtitle.rb

Overview

Subtitle resource file. requires ‘titlekit’ gem

Instance Attribute Summary

Attributes inherited from Base

#locale, #options, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create_variable, #get, #get_context, #initialize, key_value?, #locale_path, preferred_locale_separator, #properties, #properties=, #sentences, supports_variable_interpolation?, #to_s, #type, #variable_regex

Methods included from PathUtils

#detect_path_locale, #modify_path_locale

Constructor Details

This class inherits a constructor from Translatomatic::ResourceFile::Base

Class Method Details

.enabled?boolean

Returns True if this resource format is enabled.

Returns:

  • (boolean)

    True if this resource format is enabled



12
13
14
15
16
17
18
19
# File 'lib/translatomatic/resource_file/subtitle.rb', line 12

def self.enabled?
  @enabled ||= begin
    require 'titlekit'
    true
  rescue LoadError
    false
  end
end

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



7
8
9
# File 'lib/translatomatic/resource_file/subtitle.rb', line 7

def self.extensions
  %w[srt ass ssa]
end

Instance Method Details

#save(target = path, options = {}) ⇒ void

This method returns an undefined value.

Save the resource file.

Parameters:

  • target (Pathname) (defaults to: path)

    The destination path

  • options (Hash<Symbol, Object>) (defaults to: {})

    Output format options



33
34
35
36
# File 'lib/translatomatic/resource_file/subtitle.rb', line 33

def save(target = path, options = {})
  add_created_by unless options[:no_created_by] || created_by?
  export(target)
end

#set(key, value) ⇒ String

Set a property

Parameters:

  • key (String)

    The name of the property

  • value (String)

    The new value of the property

Returns:

  • (String)

    The new value of the property



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

def set(key, value)
  super(key, value)

  if @subtitle_map.include?(key)
    @subtitle_map[key][:lines] = value.to_s
  else
    add_subtitle(lines: value) unless value.blank?
  end
end