Class: Danger::DangerTransifex

Inherits:
Plugin
  • Object
show all
Defined in:
lib/transifex/plugin.rb

Overview

Plugin to push Transifex translations

Examples:

Pushes your source language translations


transifex.push_source(path/to/your.strings)

See Also:

  • Bogren/danger-transifex

Instance Method Summary collapse

Instance Method Details

#configure(project_name, resource_name) ⇒ Object

Configure the Transifex client with your project name and resource. The resource is a single source of translations.



15
16
17
18
19
20
21
22
23
24
# File 'lib/transifex/plugin.rb', line 15

def configure(project_name, resource_name)
  require 'transifex'
  Transifex.configure do |c|
    c. = ENV['TRANSIFEX_API']
    c.client_secret = ENV['TRANSIFEX_API_TOKEN']
  end

  @project = Transifex::Project.new(project_name)
  @resource = @project.resource(resource_name)
end

#push_source(type, source) ⇒ Object

Push the source language file to transifex, please note the source is the only allowed resource to use with this method.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/transifex/plugin.rb', line 28

def push_source(type, source)
  unless @resource.nil?
    begin
      message("Translations changed - pushing changes to Transifex")
      @resource.content.update({:i18n_type => type, :content => source})
      message("Translations updated \u{2705}")
    rescue
      warn("Updating translations failed \u{274C}")
    end
  end
end