Class: Translatomatic::ResourceFile::HTML

Inherits:
XML
  • Object
show all
Defined in:
lib/translatomatic/resource_file/html.rb

Overview

HTML resource file

Direct Known Subclasses

Markdown

Instance Attribute Summary

Attributes inherited from Base

#locale, #path, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XML

#set

Methods inherited from Base

#create_variable, enabled?, #format, #get, #initialize, is_key_value?, #sentences, #set, supports_variable_interpolation?, #to_s, #type, #variable_regex

Constructor Details

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

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



6
7
8
# File 'lib/translatomatic/resource_file/html.rb', line 6

def self.extensions
  %w{html htm shtml}
end

Instance Method Details

#locale_path(locale) ⇒ Pathname

Create a path for the current resource file with a given locale

Parameters:

  • locale (String)

    The target locale

Returns:

  • (Pathname)

    The path of this resource file modified for the given locale



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/translatomatic/resource_file/html.rb', line 11

def locale_path(locale)
  extlist = extension_list
  if extlist.length >= 2 && loc_idx = find_locale(extlist)
    # part of the extension is the locale
    # replace that part with the new locale
    extlist[loc_idx] = locale.to_s
    new_extension = extlist.join(".")
    return strip_extensions.sub_ext("." + new_extension)
  else
    # add locale extension
    ext = path.extname
    # TODO: need configurable order for locale & ext here?
    #path.sub_ext("#{ext}." + locale.to_s)
    path.sub_ext("." + locale.to_s + ext)
  end
end

#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



29
30
31
32
33
34
# File 'lib/translatomatic/resource_file/html.rb', line 29

def save(target = path, options = {})
  if @doc
    add_created_by unless options[:no_created_by]
    target.write(@doc.to_html)
  end
end