Class: Translatomatic::ResourceFile::XCodeStrings
- Defined in:
- lib/translatomatic/resource_file/xcode_strings.rb
Overview
XCode strings file
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.extensions ⇒ Array<String>
File extensions supported by this resource file.
Instance Method Summary collapse
-
#initialize(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base
constructor
Create a new resource file.
-
#locale_path(locale) ⇒ Pathname
Create a path for the current resource file with a given locale.
-
#save(target = path, options = {}) ⇒ void
Save the resource file.
Methods inherited from Base
#format, #get, #sentences, #set, #to_s, #valid?
Methods included from Util
Constructor Details
#initialize(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base
Create a new resource file. If locale is unspecified, attempts to determine the locale of the file automatically, and if that fails, uses the default locale.
13 14 15 16 17 |
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 13 def initialize(path, locale = nil) super(path, locale) @valid = true @properties = @path.exist? ? read(@path) : {} end |
Class Method Details
.extensions ⇒ Array<String>
Returns File extensions supported by this resource file.
8 9 10 |
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 8 def self.extensions %w{strings} end |
Instance Method Details
#locale_path(locale) ⇒ Pathname
Note:
localization files in XCode use the following file name convention: Project/locale.lproj/filename
Create a path for the current resource file with a given locale
22 23 24 25 26 27 28 29 30 |
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 22 def locale_path(locale) if path.to_s.match(/\/([-\w]+).lproj\/.+.strings$/) # xcode style filename = path.basename path.parent.parent + (locale.to_s + ".lproj") + filename else super(locale) end end |
#save(target = path, options = {}) ⇒ void
This method returns an undefined value.
Save the resource file.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/translatomatic/resource_file/xcode_strings.rb', line 33 def save(target = path, = {}) out = "" out += comment(created_by) unless [:no_created_by] properties.each do |key, value| key = escape(key) value = escape(value) out += %Q{"#{key}" = "#{value}";\n} end target.write(out) end |