transifex-api-es6
A promise-based Transifex API client for node, written in es6. Promises are thenable using the q library.
The motivation behind this API is that there are no modern, promise-based JS API for Transifex out there that I could find. If found those that exist being difficult to overview or understand, so I started building on a new one.
Installation
npm install [--save] [--save-dev] transifex-api-es6
Usage
var TransifexApi = ; var api = user: 'username' password: 'password' projectName: 'my-project' resourceName: 'customer-area' // optional; // Get resource translationapi; // Get translation stringsapi
API Reference
- TransifexApi
- new TransifexApi(opts)
- .setResourceName(resourceName)
- .getProject() ⇒
Object
- .getProjectLanguages() ⇒
Object
- .getResources() ⇒
array
- .getResource(resourceName) ⇒
Object
- .createResource(resource) ⇒
Object
- .deleteResource(resourceName) ⇒
Object
- .getResourceTranslation(langCode, resourceName) ⇒
string
- .getTranslationStrings(langCode, resourceName) ⇒
string
new TransifexApi(opts)
Param | Type | Description |
---|---|---|
opts | Object |
An object with required projectName , user and password fields. Optionally takes a resourceName which is stored as the default resource. |
transifexApi.setResourceName(resourceName)
Sets the default resource slug
Param | Type | Description |
---|---|---|
resourceName | string |
A resource slug |
Object
transifexApi.getProject() ⇒ Returns information about the project
Returns: Object
- A project instance (wrapped in a promise)
Object
transifexApi.getProjectLanguages() ⇒ Returns an list of languages that belong to the project
Returns: Object
- A list of languages (wrapped in a promise)
array
transifexApi.getResources() ⇒ Returns a list of resources in the project
Returns: array
- A list of the project's resources (wrapped in a promise)
Object
transifexApi.getResource(resourceName) ⇒ Returns a resource
Param | Type | Description |
---|---|---|
resourceName | string |
(Optional) The slug of the requested resource. |
Returns: Object
- A resource as JSON (wrapped in a promise)
Object
transifexApi.createResource(resource) ⇒ Creates a new resources in the project
Param | Type | Description |
---|---|---|
resource | Object |
Dictionary with info about the resource |
Object
transifexApi.deleteResource(resourceName) ⇒ Deletes a resource
Param | Type | Description |
---|---|---|
resourceName | string |
(Optional) The slug of the resource |
string
transifexApi.getResourceTranslation(langCode, resourceName) ⇒ Returns a translation of a given (or default) resource in a given language as .po contents.
Param | Type | Description |
---|---|---|
langCode | string |
A language code, e.g. en_US |
resourceName | string |
(Optional) A resource slug |
Returns: string
- A PO file as a string (wrapped in a promise)
string
transifexApi.getTranslationStrings(langCode, resourceName) ⇒ Returns a set of translated strings of a given (or default) resource in a given language.
Param | Type | Description |
---|---|---|
langCode | string |
A language code, e.g. en_US |
resourceName | string |
(Optional) A resource slug |
Returns: string
- A list of translation strings as JSON objects
(wrapped in a promise)
Contributing
This project is in early development. Issues and pull requests are more than welcome!