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
-
.create(path, options = {}) ⇒ Object
Create a new resource file.
-
.find(path, options = {}) ⇒ Array<Translatomatic::ResourceFile>
Find all resource files under the given directory.
-
.load(path, options = {}) ⇒ Translatomatic::ResourceFile::Base
Load a resource file.
-
.types ⇒ Array<Class>
Find all configured resource file classes.
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, = {}) klass = types_for_path(path).first return nil unless klass file = klass.new file.path = path file.locale = build_locale([:locale]) file end |
.find(path, options = {}) ⇒ Array<Translatomatic::ResourceFile>
Find all resource files under the given directory. Follows symlinks.
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, = {}) files = [] include_dot_directories = [: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.
14 15 16 17 18 19 20 21 |
# File 'lib/translatomatic/resource_file.rb', line 14 def load(path, = {}) 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, ) end nil end |