Class: Bisu::Source::OneSky

Inherits:
Object
  • Object
show all
Defined in:
lib/bisu/source/one_sky.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, project_id, file_name) ⇒ OneSky

Returns a new instance of OneSky.



7
8
9
10
11
12
# File 'lib/bisu/source/one_sky.rb', line 7

def initialize(api_key, api_secret, project_id, file_name)
  @api_key    = api_key
  @api_secret = api_secret
  @project_id = project_id
  @file_name  = file_name
end

Instance Method Details

#to_i18Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bisu/source/one_sky.rb', line 14

def to_i18
  Logger.info("Downloading dictionary from OneSky...")

  path = "https://platform.api.onesky.io/1/projects/#{@project_id}/translations/multilingual"
  file = get(path, source_file_name: @file_name, file_format: "I18NEXT_MULTILINGUAL_JSON")

  hash = JSON.parse(file)

  hash.each do |lang, v|
    hash[lang] = v["translation"]
    hash[lang].each do |key, text|
      hash[lang][key] = hash[lang][key].join("\\n") if hash[lang][key].is_a? Array
      hash[lang][key] = hash[lang][key].gsub("\n", "\\n") # fixes the 'stupid newline bug'
      hash[lang][key] = hash[lang][key].gsub("\\'", "'") # fixes the 'stupid single quote bug'
    end
  end

  Logger.info("OneSky response parsed successfully!")
  Logger.info("Found #{hash.count} languages.")

  hash
end