Table of Contents


Whether you are developing an app or just using Ruby to script some tasks, transifex-interface-ruby is a library that can help when it comes to send content to Transifex.

This is a neat piece of code that wrappers Transifex's API and offers an easy interphase to create projects, sent and pull files directly from your ruby code. Below you can see a list of the main functionalities it has.


Installation

Add this line to your application's Gemfile:

gem 'transifex-interface-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install transifex-interface-ruby


Usage

Initialization

To initialize the gem, you will have to create an initializer like follow:

Transifex.configure do |c| 
c.client_login = 'your_client_login'
c.client_secret = 'your_secret'
end

Then restart the server.

If you don't do this you will end up with the following error:

#<Transifex::TransifexError: Authorization Required>

Formats

It represents all the formats available on Transifex:

Transifex::Formats.fetch

Languages

It represents all the languages available on Transifex:

FETCH

You can fetch all the languages:

Transifex::Languages.fetch

Or specify a language:

Transifex::Languages.fetch('en')

Projects (to fetch all projects and create a new one)

FETCH

To fetch all the projects owned by the account specified in the initializer:

Transifex::Projects.fetch

CREATE

To create a new project, you can proceed as following:

For a private project

private_project_params = {:slug => "private_project", :name => "Private Project", :description => "description", :source_language_code => "en", :private => true} Transifex::Projects.create(private_project_params)

For a public project

public_project_params = {:slug => "public_project", :name => "Public Project", :description => "description", :source_language_code => "en", :repository_url => "http://example.com"} Transifex::Projects.create(public_project_params) ​```

The complete list of the allowed parameters is located in the Transifex documentation.

Project (symbolize an existing project)

INSTANTIATION

transifex_project = Transifex::Project.new('project_slug')

or

transifex_project = Transifex::Projects.create(params)

FETCH

You can fetch the project informations from Transifex:

transifex_project_informations = transifex_project.fetch

with more details:

transifex_project_informations = transifex_project.fetch_with_details

UPDATE

You can update the project: (see documentation for available fields

transifex_project.update({:description => "new description"})

DESTROY

You can destroy a project:

transifex_project.delete

Project Languages ( to fetch all languages of a project and create a new one)

INSTANTIATION

project_languages = transifex_project.languages

FETCH

You can retrieve informations about all the languages of a project:

project_languages.fetch

CREATE

You can create a new language for a project:

params = {:language_code => "el", :coordinators => ['username']} project_languages.create(params)

Project Language (Symbolize a single language of a project)

INSTANTIATION

project_language = transifex_project.language('en')

FETCH

You can retrieve informations for a project's specified language:

project_language.fetch

with details:

project_language.fetch_with_details

UPDATE

You can update the information of a project's specified language:

params = {:coordinators => ['username1', 'username2'], :translators => ['username'], :reviewers => ['username']} project_language.update(params) ​```

DELETE

You can delete a project's specified language:

project_language.delete

Project language management

You have access to the different teams of a language: coordinators, reviewers and translators.

INSTANTIATION:

project_language_coordinators_team = project_language.coordinators project_language_reviewers_team = project_language.reviewers project_language_translators_team = project_language.translators

FETCH

project_language_xxx_team.fetch

UPDATE

project_language_xxx_team.update(['username1', 'username2'])

Resources ( to fetch all resources of a project and create a new one)

First, instantiate a project (see project/instantiation)

FETCH

You can fetch all the resources of projects:

transifex_project.resources.fetch

CREATE

You can create a new resource for the specified project:

Without a file (you have to send the content as a string)

params = {:slug => "project_slug", :name => "Project created with content as a string", :i18n_type => "TXT", :content => "test"} transifex_project.resources.create(params)

With a file: (YAML currently supported)

params = {:slug => "project_slug", :name => "Project created with a file", :i18n_type => "YAML", :content => 'path/to/your/file.yml'} options = {:trad_from_file => true} transifex_project.resources.create(params, options)

Resource (Symbolize a single resource of a project)

INSTANTIATION

You can instantiate a resource as follow:

project_resource = transifex_project.resource("resource_slug")

FETCH

You can retrieve information of the specified resource:

project_resource.fetch

with more details:

project_resource.fetch_with_details

UPDATE

You can update a resource: (see the documentation for allowed fields)

project_resource.update({name: "new_name", categories: ["cat1", "cat2"]})

DELETE

You can delete the specified resource:

project_resource.delete

Resource Content ( Source language content)

You can manage the resource's source language

FETCH

You can retrieve the source language content:

As a hash: (content is encoded as a string)


Continue Reading

Did this answer your question?