Class: LocoStrings::XCStringsEncoder
- Inherits:
-
Object
- Object
- LocoStrings::XCStringsEncoder
- Defined in:
- lib/loco_strings/encoders/xcstrings_encoder.rb
Overview
The XCStringsEncoder class is responsible for encoding the LocoStrings data to the XCStrings format.
Instance Attribute Summary collapse
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#languages ⇒ Object
readonly
Returns the value of attribute languages.
-
#strings ⇒ Object
readonly
Returns the value of attribute strings.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(strings, translations, languages, language) ⇒ XCStringsEncoder
constructor
A new instance of XCStringsEncoder.
Constructor Details
#initialize(strings, translations, languages, language) ⇒ XCStringsEncoder
Returns a new instance of XCStringsEncoder.
10 11 12 13 14 15 |
# File 'lib/loco_strings/encoders/xcstrings_encoder.rb', line 10 def initialize(strings, translations, languages, language) @strings = strings @translations = translations @languages = languages @language = language end |
Instance Attribute Details
#language ⇒ Object (readonly)
Returns the value of attribute language.
8 9 10 |
# File 'lib/loco_strings/encoders/xcstrings_encoder.rb', line 8 def language @language end |
#languages ⇒ Object (readonly)
Returns the value of attribute languages.
8 9 10 |
# File 'lib/loco_strings/encoders/xcstrings_encoder.rb', line 8 def languages @languages end |
#strings ⇒ Object (readonly)
Returns the value of attribute strings.
8 9 10 |
# File 'lib/loco_strings/encoders/xcstrings_encoder.rb', line 8 def strings @strings end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
8 9 10 |
# File 'lib/loco_strings/encoders/xcstrings_encoder.rb', line 8 def translations @translations end |
Instance Method Details
#encode ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/loco_strings/encoders/xcstrings_encoder.rb', line 17 def encode raise Error, "The base language is not defined" if @language.nil? json = { "sourceLanguage" => @language, "strings" => {}, "version" => "1.0" } generate_keys.each do |key| json["strings"][key] = encode_key(key) end JSON.pretty_generate(json, { space_before: " " }) end |