Class: LocoStrings::XCStringsDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/loco_strings/decoders/xcstrings_decoder.rb

Overview

The XCStringsDecoder class is responsible for decoding the XCStrings file format.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ XCStringsDecoder

Returns a new instance of XCStringsDecoder.



10
11
12
13
14
15
16
# File 'lib/loco_strings/decoders/xcstrings_decoder.rb', line 10

def initialize(file_path)
  @file_path = file_path
  @strings = {}
  @translations = {}
  @languages = []
  @language = nil
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



8
9
10
# File 'lib/loco_strings/decoders/xcstrings_decoder.rb', line 8

def language
  @language
end

#languagesObject (readonly)

Returns the value of attribute languages.



8
9
10
# File 'lib/loco_strings/decoders/xcstrings_decoder.rb', line 8

def languages
  @languages
end

#stringsObject (readonly)

Returns the value of attribute strings.



8
9
10
# File 'lib/loco_strings/decoders/xcstrings_decoder.rb', line 8

def strings
  @strings
end

#translationsObject (readonly)

Returns the value of attribute translations.



8
9
10
# File 'lib/loco_strings/decoders/xcstrings_decoder.rb', line 8

def translations
  @translations
end

Instance Method Details

#decodeObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/loco_strings/decoders/xcstrings_decoder.rb', line 18

def decode
  return @strings unless File.exist?(@file_path)

  file = File.read(@file_path)
  json = JSON.parse(file)
  extract_languages(json)
  @language = json["sourceLanguage"]
  decode_strings(json)
  @strings
end