Globalization Pipeline client
This is a JavaScript SDK for the
Globalization Pipeline
Bluemix service. The Globalization Pipeline service makes it easy for you to provide your global customers
with Bluemix applications translated into the languages in which they work.
The SDK currently supports Node.js.
Node.js
The remainder of this document explains how to use the Globalization service
with the Node.js client.
For a working Bluemix application sample,
see gp-nodejs-sample.
![npm version](https://badge.fury.io/js/g11n-pipeline.svg)
Quickstart - Bluemix
Add g11n-pipeline
to your project, as well as cfenv
.
npm install --save g11n-pipeline cfenv
Load the gaas client object as follows (using cfenv ).
var appEnv = require('cfenv').getAppEnv();
var gpClient = require('g11n-pipeline').getClient({
appEnv: appEnv
});
Using
To fetch the strings for a bundle named "hello", first create a bundle accessor:
var mybundle = gpClient.bundle('hello');
Then, call the getStrings
function with a callback:
mybundle.getStrings({ languageId: 'es'}, function (err, result) {
if (err) {
// handle err..
console.error(err);
} else {
var myStrings = result.resourceStrings;
console.dir(myStrings);
}
});
This code snippet will output the translated strings such as the following:
{
hello: '¡Hola!',
goodbye: '¡Adiós!',
…
}
Testing
See TESTING.md
API convention
APIs take a callback and use this general pattern:
gpClient.function( { /*params*/ } , function callback(err, ...))
- params: an object containing input parameters, if needed.
err
: if truthy, indicates an error has occured....
: other parameters (optional)
These APIs may be promisified easily using a library such as Q
's
nfcall:
return Q.ninvoke(bundle, "delete", {});
return Q.ninvoke(gpClient, "getBundleList", {});
Also, note that there are aliases from the swagger doc function names
to the convenience name. For example, bundle.uploadResourceStrings
can be
used in place of bundle.uploadStrings
.
All language identifiers are IETF BCP47 codes.
API reference
Author: Steven R. Loomis
- g11n-pipeline
- static
- inner
- ~Client
- ~Bundle
- new Bundle(gp, props)
- .getInfoFields
- .delete(opts, cb)
- .create(body, cb)
- .getInfo(opts, cb)
- .getStrings(opts, cb)
- .getEntryInfo(opts, cb)
- .uploadStrings(opts, cb)
- .update(opts, cb)
- .updateStrings(opts, cb)
- .updateEntryInfo(opts, cb)
- ~getClient(params) ⇒
Client
g11n-pipeline.serviceRegex
a Regex for matching the service.
Usage: var credentials = require('cfEnv')
.getAppEnv().getServiceCreds(gp.serviceRegex);
Kind: static property of g11n-pipeline
Properties
g11n-pipeline.exampleCredentials
Example credentials
Kind: static property of g11n-pipeline
Properties
g11n-pipeline~Client
Kind: inner class of g11n-pipeline
client.ping
Do we have access to the server?
Kind: instance property of Client
Param | Type | Description |
---|
args | object | (ignored) |
cb | callback | |
client.getBundleList(opts, cb)
Get a list of the bundles.
Note: This function may be deprecated soon, but won't be removed.
Kind: instance method of Client
Param | Type | Description |
---|
opts | Object | |
opts.serviceInstance | String | optional service instance |
cb | bundleListCallback | callback: (err, array-of-ids) |
client.supportedTranslations(args, cb)
This function returns a map from source language(s) to target language(s).
Kind: instance method of Client
Param | Type | Description |
---|
args | object | |
cb | supportedTranslationsCallback | (err, map-of-languages) |
client.getServiceInfo(args, cb)
Get information about this service
Kind: instance method of Client
Param | Type |
---|
args | object |
cb | basicCallback |
client.createUser(args, cb)
Create a user
Note: This function may be deprecated soon, but won't be removed.
Kind: instance method of Client
Param | Type | Description |
---|
args | object | |
args.type | string | User type (ADMINISTRATOR, TRANSLATOR, or READER) |
args.displayName | string | Optional display name for the user. This can be any string. |
args.comment | string | Optional comment |
args.bundles | Array | set of accessible bundle ids or ['*'] to mean “all bundles” |
args.metadata | Object | optional key/value pairs for user metadata |
args.externalId | string | optional external user ID for your application’s use |
cb | basicCallback | |
client.deleteUser(args, cb)
Delete a user.
Note: This function may be deprecated soon, but won't be removed.
Kind: instance method of Client
Param | Type | Description |
---|
args | object | TBD |
args.userId | string | user ID to be deleted. |
cb | basicCallback | |
client.bundle(opts) ⇒ Bundle
Create a bundle access object.
This doesn’t create the bundle itself, just a handle object.
Call create() on the bundle to create it.
Kind: instance method of Client
Param | Type | Description |
---|
opts | Object | String (id) or map {id: bundleId, serviceInstance: serviceInstanceId} |
g11n-pipeline~Bundle
Kind: inner class of g11n-pipeline
- ~Bundle
- new Bundle(gp, props)
- .getInfoFields
- .delete(opts, cb)
- .create(body, cb)
- .getInfo(opts, cb)
- .getStrings(opts, cb)
- .getEntryInfo(opts, cb)
- .uploadStrings(opts, cb)
- .update(opts, cb)
- .updateStrings(opts, cb)
- .updateEntryInfo(opts, cb)
new Bundle(gp, props)
Param | Type | Description |
---|
gp | Client | parent g11n-pipeline client object |
props | Object | properties to inherit |
bundle.getInfoFields
List of fields usable with Bundle.getInfo()
Kind: instance property of Bundle
bundle.delete(opts, cb)
Delete this bundle.
Kind: instance method of Bundle
Param | Type |
---|
opts | Object |
cb | basicCallback |
bundle.create(body, cb)
Create this bundle.
Kind: instance method of Bundle
Param | Type | Description |
---|
body | Object | - |
body.sourceLanguage | string | bcp47 id of source language such as 'en' |
body.targetLanguages | Array | optional array of target languages |
body.metadata | Object | optional metadata for the bundle |
body.partner | string | optional ID of partner assigned to translate this bundle |
cb | basicCallback | |
bundle.getInfo(opts, cb)
Get bundle info
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | Options object |
opts.fields | String | Comma separated list of fields |
opts.translationStatusMetricsByLanguage | Boolean | Optional field (false by default) |
opts.reviewStatusMetricsByLanguage | Boolean | Optional field (false by default) |
opts.partnerStatusMetricsByLanguage | Boolean | Optional field (false by default) |
cb | basicCallback | callback (err, { updatedBy, updatedAt, sourceLanguage, targetLanguages, readOnly, metadata, partner} ) |
bundle.getStrings(opts, cb)
Fetch one entry's strings
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | options |
opts.languageId | String | language to fetch |
opts.resourceKey | String | resource to fetch |
cb | basicCallback | callback (err, { resourceStrings: { strings … } }) |
bundle.getEntryInfo(opts, cb)
Fetch one entry's info
Note: This function may be deprecated soon, but won't be removed.
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | options |
opts.languageId | String | language to fetch |
opts.resourceKey | String | resource to fetch |
cb | basicCallback | callback (err, { resourceEntry: { updatedBy, updatedAt, value, sourceValue, reviewed, translationStatus, metadata, partnerStatus } } ) |
bundle.uploadStrings(opts, cb)
Upload resource strings, replacing all current contents for the language
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | options |
opts.languageId | String | language to update |
opts.strings | Object.<string, string> | strings to update |
cb | basicCallback | |
bundle.update(opts, cb)
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | options |
opts.targetLanguages | array | optional: list of target languages to update |
opts.readOnly | boolean | optional: set this bundle to be readonly or not |
opts.metadata | object | optional: metadata to update |
opts.partner | string | optional: partner id to update |
cb | basicCallback | callback |
bundle.updateStrings(opts, cb)
Update some strings in a language.
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | options |
opts.strings | Object.<string, string> | strings to update. |
opts.resync | Boolean | optional: If true, resynchronize strings in the target language and resubmit previously-failing translation operations |
cb | basicCallback | |
bundle.updateEntryInfo(opts, cb)
Note: This function may be deprecated soon, but won't be removed.
Kind: instance method of Bundle
Param | Type | Description |
---|
opts | Object | options |
opts.value | string | string value to update |
opts.reviewed | boolean | optional boolean indicating if value was reviewed |
opts.metadata | object | optional metadata to update |
opts.partnerStatus | string | translation status maintained by partner |
cb | basicCallback | |
g11n-pipeline~getClient(params) ⇒ Client
Construct a g11n-pipeline client.
params.credentials is required unless params.appEnv is supplied.
Kind: inner method of g11n-pipeline
Param | Type | Description |
---|
params | Object | configuration params |
params.appEnv | Object | pass the result of cfEnv.getAppEnv(). Ignored if params.credentials is supplied. |
params.credentials | Object.<string, string> | Bound credentials as from the CF service broker (overrides appEnv) |
params.credentials.url | string | service URL. (should end in '/translate') |
params.credentials.userId | string | service API key. |
params.credentials.password | string | service API key. |
params.credentials.instanceId | string | instance ID |
docs autogenerated via jsdoc2md
Support
You can post questions about using this service in the developerWorks Answers site
using the tag "[globalization-pipeline](https://developer.ibm.com/answers/topics/globalization-pipeline
/)".
LICENSE
Apache 2.0. See LICENSE.txt
Copyright IBM Corp. 2015