Class: Translatomatic::ResourceFile::HTML

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

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

#initialize, #set

Methods inherited from Base

#format, #get, #initialize, #sentences, #set, #to_s, #valid?

Methods included from Util

#locale, #log, #string

Constructor Details

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

Class Method Details

.extensionsArray<String>

Returns File extensions supported by this resource file.

Returns:

  • (Array<String>)

    File extensions supported by this resource file



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

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)

    for the path

Returns:

  • (Pathname)

    The path of this resource file modified for the given locale



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

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



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

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