Class: I18n::Migrations::Backends::CrowdTranslateClient

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/migrations/backends/crowd_translate_client.rb

Instance Method Summary collapse

Constructor Details

#initializeCrowdTranslateClient

Returns a new instance of CrowdTranslateClient.



8
9
10
11
12
13
14
15
16
17
# File 'lib/i18n/migrations/backends/crowd_translate_client.rb', line 8

def initialize
  token = ENV['CROWD_TRANSLATE_API_TOKEN']
  raise("You must define CROWD_TRANSLATE_API_TOKEN in order to talk to Crowd Translate") unless token.present?

  server = ENV['CROWD_TRANSLATE_SERVER'] || 'https://crowd-translate.herokuapp.com'
  @faraday = Faraday.new(
    url: "#{server}/api/v1",
    headers: { 'X-CrowdTranslateApiToken' => token },
  )
end

Instance Method Details

#get_locale_file(locale_code) ⇒ Object



19
20
21
# File 'lib/i18n/migrations/backends/crowd_translate_client.rb', line 19

def get_locale_file(locale_code)
  get("locales/#{locale_code}.yml")
end

#get_migration_versionsObject



23
24
25
# File 'lib/i18n/migrations/backends/crowd_translate_client.rb', line 23

def get_migration_versions
  JSON.parse(get('migrations.json'))
end

#put_locale(locale_code, name:, yaml_file:, yaml_metadata_file:) ⇒ Object



31
32
33
34
# File 'lib/i18n/migrations/backends/crowd_translate_client.rb', line 31

def put_locale(locale_code, name:, yaml_file:, yaml_metadata_file:)
  put("locales/#{locale_code}",
      locale: { name: name, yaml_file: yaml_file, yaml_metadata_file:  })
end

#put_migration(version:, ruby_file:) ⇒ Object



27
28
29
# File 'lib/i18n/migrations/backends/crowd_translate_client.rb', line 27

def put_migration(version:, ruby_file:)
  put("migrations/#{version}.json", migration: { ruby_file: ruby_file })
end