https://github.com/alexanderwallin/transifex-api-es6
A promise-based Transifex API client for node, written in es6
https://github.com/alexanderwallin/transifex-api-es6
Last synced: 6 months ago
JSON representation
A promise-based Transifex API client for node, written in es6
- Host: GitHub
- URL: https://github.com/alexanderwallin/transifex-api-es6
- Owner: alexanderwallin
- Created: 2015-11-10T18:15:38.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-09T18:47:22.000Z (about 7 years ago)
- Last Synced: 2024-04-25T14:21:23.548Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 7
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/transifex-api-es6)
[](https://david-dm.org/alexanderwallin/transifex-api-es6)
# transifex-api-es6
A promise-based Transifex API client for node, written in es6. Promises are thenable using the [q library](https://github.com/kriskowal/q).
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](#Installation)
* [Usage](#Usage)
* [API Reference](#API_Reference)
* [Contributing](#Contributing)
```bash
npm install [--save] [--save-dev] transifex-api-es6
```
```javascript
var TransifexApi = require('transifex-api-es6');
var api = new TransifexApi({
user: 'username',
password: 'password',
projectName: 'my-project',
resourceName: 'customer-area' // optional
});
// Get resource translation
api.getResourceTranslation('en')
.then((contents) => {
// contents -> PO contents as a string
}, (err) => console.error(err));
// Get translation strings
api.getTranslationStrings('en', 'my_resource')
.then((strings) => {
// strings -> Set of string objects for 'my_resource'
}, (err) => console.error(err))
```
* [TransifexApi](#TransifexApi)
* [new TransifexApi(opts)](#new_TransifexApi_new)
* [.setResourceName(resourceName)](#TransifexApi+setResourceName)
* [.getProject()](#TransifexApi+getProject) ⇒ Object
* [.getProjectLanguages()](#TransifexApi+getProjectLanguages) ⇒ Object
* [.getResources()](#TransifexApi+getResources) ⇒ array
* [.getResource(resourceName)](#TransifexApi+getResource) ⇒ Object
* [.createResource(resource)](#TransifexApi+createResource) ⇒ Object
* [.deleteResource(resourceName)](#TransifexApi+deleteResource) ⇒ Object
* [.getResourceTranslation(langCode, resourceName)](#TransifexApi+getResourceTranslation) ⇒ string
* [.getTranslationStrings(langCode, resourceName)](#TransifexApi+getTranslationStrings) ⇒ string
| 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 |
#### transifexApi.getProject() ⇒ Object
Returns information about the project
**Returns**: Object - A project instance (wrapped in a promise)
#### transifexApi.getProjectLanguages() ⇒ Object
Returns an list of languages that belong to the project
**Returns**: Object - A list of languages (wrapped in a promise)
#### transifexApi.getResources() ⇒ array
Returns a list of resources in the project
**Returns**: array - A list of the project's resources (wrapped in a promise)
#### transifexApi.getResource(resourceName) ⇒ Object
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)
#### transifexApi.createResource(resource) ⇒ Object
Creates a new resources in the project
| Param | Type | Description |
| --- | --- | --- |
| resource | Object | Dictionary with info about the resource |
**Returns**: Object - A q promise
#### transifexApi.deleteResource(resourceName) ⇒ Object
Deletes a resource
| Param | Type | Description |
| --- | --- | --- |
| resourceName | string | (Optional) The slug of the resource |
**Returns**: Object - A q promise
#### transifexApi.getResourceTranslation(langCode, resourceName) ⇒ string
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)
#### transifexApi.getTranslationStrings(langCode, resourceName) ⇒ string
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)
This project is in early development. Issues and pull requests are more than welcome!