Class: I18n::Migrations::Backends::CrowdTranslateBackend

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCrowdTranslateBackend

Returns a new instance of CrowdTranslateBackend.



9
10
11
# File 'lib/i18n/migrations/backends/crowd_translate_backend.rb', line 9

def initialize
  @client = CrowdTranslateClient.new
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/i18n/migrations/backends/crowd_translate_backend.rb', line 7

def client
  @client
end

Instance Method Details

#pull(locale) ⇒ Object



13
14
15
16
# File 'lib/i18n/migrations/backends/crowd_translate_backend.rb', line 13

def pull(locale)
  pull_from_crowd_translate(locale)
  locale.migrate!
end

#pull_from_crowd_translate(locale) ⇒ Object



29
30
31
32
33
# File 'lib/i18n/migrations/backends/crowd_translate_backend.rb', line 29

def pull_from_crowd_translate(locale)
  data = @client.get_locale_file(locale.name)
  locale.write_raw_data("#{locale.name}.yml", data)
  locale.write_remote_version(YAML::load(data)[locale.name])
end

#push(locale, force = false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/i18n/migrations/backends/crowd_translate_backend.rb', line 18

def push(locale, force = false)
  raise "CrowdTranslate does not support -f flag yet" if force

  # do this just once
  unless @migrations_synced
    @client.sync_migrations(locale.migrations)
    @migrations_synced = true
  end
  pull(locale)
end