New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

g11n-pipeline

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

g11n-pipeline

JavaScript (Node.js, etc) client for Bluemix Globalization Pipeline

  • 1.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Globalization Pipeline Client for JavaScript

This is the 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. This SDK currently supports Node.js.

npm version

Sample

For a working Bluemix application sample, see gp-nodejs-sample.

Quickstart - Bluemix

Add g11n-pipeline to your project, as well as cfenv and optional.

npm install --save g11n-pipeline cfenv optional

Load the client object as follows (using cfenv ). You can store a copy of the credentials in local-credentials.json for local operation.

var optional = require('optional');
var appEnv = require('cfenv').getAppEnv();
var gpClient = require('g11n-pipeline').getClient(
  optional('./local-credentials.json')   // if it exists, use local-credentials.json
    || {appEnv: appEnv}                  // otherwise, the 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!',
        …
    }

Async

Note that all calls that take a callback are asynchronous. For example, the following code:

var bundle = client.bundle('someBundle');
bundle.create({…}, function(){…});
bundle.uploadStrings({…}, function(){…});

…will fail, because the bundle someBundle hasn’t been created by the time the uploadStrings call is made. Instead, make the uploadStrings call within a callback:

var bundle = client.bundle('someBundle');
bundle.create({…}, function(){
    …
    bundle.uploadStrings({…}, function(){…});
});

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

g11n-pipeline

Author: Steven R. Loomis

g11n-pipeline.serviceRegex

a Regex for matching the service. Usage: var credentials = require('cfEnv') .getAppEnv().getServiceCreds(gp.serviceRegex); (except that it needs to match by label)

Kind: static property of g11n-pipeline
Properties

Name
serviceRegex

g11n-pipeline.exampleCredentials

Example credentials

Kind: static property of g11n-pipeline
Properties

Name
exampleCredentials

g11n-pipeline~Client

Kind: inner class of g11n-pipeline

client.ping

Do we have access to the server?

Kind: instance property of Client

ParamTypeDescription
argsobject(ignored)
cbcallback

client.supportedTranslations(args, cb)

This function returns a map from source language(s) to target language(s). Example: { en: ['de', 'ja']} (English translates to German and Japanese.)

Kind: instance method of Client

ParamTypeDescription
argsobject
cbsupportedTranslationsCallback(err, map-of-languages)

client.getServiceInfo(args, cb)

Get information about this service

Kind: instance method of Client

ParamType
argsobject
cbbasicCallback

client.createUser(args, cb)

Create a user

Kind: instance method of Client

ParamTypeDescription
argsobject
args.typestringUser type (ADMINISTRATOR, TRANSLATOR, or READER)
args.displayNamestringOptional display name for the user. This can be any string.
args.commentstringOptional comment
args.bundlesArrayset of accessible bundle ids or ['*'] to mean “all bundles”
args.metadataObjectoptional key/value pairs for user metadata
args.externalIdstringoptional external user ID for your application’s use
cbbasicCallbackpassed a new User object

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

ParamTypeDescription
optsObjectString (id) or map {id: bundleId, serviceInstance: serviceInstanceId}

client.user(id) ⇒ User

Create a user access object. This doesn’t create the user itself, nor query the server, but is just a handle object. Use createUser() to create a user.

Kind: instance method of Client

ParamTypeDescription
idObjectString (id) or map {id: bundleId, serviceInstance: serviceInstanceId}

client.users(opts, cb)

List users. Callback is called with an array of user access objects.

Kind: instance method of Client

ParamTypeDescription
optsObjectignored
cblistUsersCallback

client.bundles(opts, cb)

List bundles. Callback is called with an map of bundle access objects.

Kind: instance method of Client

ParamTypeDescription
optsObjectignored
cblistBundlesCallbackgiven a map of Bundle objects

g11n-pipeline~Bundle

Kind: inner class of g11n-pipeline

new Bundle(gp, props)
ParamTypeDescription
gpClientparent g11n-pipeline client object
propsObjectproperties 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

ParamType
optsObject
cbbasicCallback

bundle.create(body, cb)

Create this bundle with the specified params. Note that on failure, such as an illegal language being specified, the bundle is not created.

Kind: instance method of Bundle

ParamTypeDescription
bodyObject
body.sourceLanguagestringbcp47 id of source language such as 'en'
body.targetLanguagesArrayoptional array of target languages
body.metadataObjectoptional metadata for the bundle
body.partnerstringoptional ID of partner assigned to translate this bundle
cbbasicCallback

bundle.getInfo(opts, cb)

Get bundle info

Kind: instance method of Bundle

ParamTypeDescription
optsObjectOptions object
opts.fieldsStringComma separated list of fields
opts.translationStatusMetricsByLanguageBooleanOptional field (false by default)
opts.reviewStatusMetricsByLanguageBooleanOptional field (false by default)
opts.partnerStatusMetricsByLanguageBooleanOptional field (false by default)
cbbasicCallbackcallback (err, { updatedBy, updatedAt, sourceLanguage, targetLanguages, readOnly, metadata, partner} )

bundle.getStrings(opts, cb)

Fetch one language's strings

Kind: instance method of Bundle

ParamTypeDescription
optsObjectoptions
opts.languageIdStringlanguage to fetch
cbbasicCallbackcallback (err, { resourceStrings: { strings … } })

bundle.entry(opts)

Create an entry object. Doesn't fetch data,

Kind: instance method of Bundle
See: ResourceEntry~getInfo

ParamTypeDescription
optsObjectoptions
opts.languageIdStringlanguage
opts.resourceKeyStringresource key

bundle.uploadStrings(opts, cb)

Upload resource strings, replacing all current contents for the language

Kind: instance method of Bundle

ParamTypeDescription
optsObjectoptions
opts.languageIdStringlanguage to update
opts.stringsObject.<string, string>strings to update
cbbasicCallback

bundle.update(opts, cb)

Kind: instance method of Bundle

ParamTypeDescription
optsObjectoptions
opts.targetLanguagesarrayoptional: list of target languages to update
opts.readOnlybooleanoptional: set this bundle to be readonly or not
opts.metadataobjectoptional: metadata to update
opts.partnerstringoptional: partner id to update
cbbasicCallbackcallback

bundle.updateStrings(opts, cb)

Update some strings in a language.

Kind: instance method of Bundle

ParamTypeDescription
optsObjectoptions
opts.stringsObject.<string, string>strings to update.
opts.resyncBooleanoptional: If true, resynchronize strings in the target language and resubmit previously-failing translation operations
cbbasicCallback

g11n-pipeline~User

Kind: inner class of g11n-pipeline
Properties

NameTypeDescription
idStringthe userid
updatedByStringgives information about which user updated this user last
updatedAtDatethe date when the item was updated
typeStringADMINISTRATOR
displayNameStringoptional human friendly name
metadataObject.<string, string>optional user-defined data
serviceManagedBooleanif true, the GP service is managing this user
passwordStringuser password
commentStringoptional user comment
externalIdStringoptional User ID used by another system associated with this user
bundlesArray.<string>list of bundles managed by this user

new User(gp, props)
ParamTypeDescription
gpClientparent g11n-pipeline client object
propsObjectproperties to inherit

user.update(opts, cb)

Update this user. All fields of opts are optional. For strings, falsy = no change, empty string '' = deletion.

Kind: instance method of User

ParamTypeDescription
optsobjectoptions
opts.displayNamestringUser's display name - falsy = no change, empty string '' = deletion.
opts.commentstringoptional comment - falsy = no change, empty string '' = deletion.
opts.bundlesArray.<string>Accessible bundle IDs.
opts.metadataobject.<string, string>User defined user metadata containg key/value pairs. Data will be merged in. Pass in "{}" to erase all metadata.
opts.externalIdstringUser ID used by another system associated with this user - falsy = no change, empty string '' = deletion.
cbbasicCallbackcallback with success or failure

user.delete(cb)

Delete this user. Note that the service managed user (the initial users created by the service) may not be deleted.

Kind: instance method of User

ParamTypeDescription
cbbasicCallbackcallback with success or failure

user.getInfo(opts, cb)

Fetch user info. The callback is given a new User instance, with all properties filled in.

Kind: instance method of User

ParamTypeDescription
optsObjectoptional, ignored
cbgetUserCallback

g11n-pipeline~ResourceEntry

ResourceEntry Creating this object does not modify any data.

Kind: inner class of g11n-pipeline
See: Bundle~entries
Properties

NameTypeDescription
resourceKeyStringkey for the resource

new ResourceEntry(bundle, props)
ParamTypeDescription
bundleBundleparent Bundle object
propsObjectproperties to inherit

resourceEntry.getInfo(opts, cb)

Load this entry's information. Callback is given another ResourceEntry but one with all current data filled in.

Kind: instance method of ResourceEntry

ParamTypeDescription
optsObjectoptions (currently ignored)
cbbasicCallbackcallback (err, ResourceEntry)

resourceEntry.update()

Update this resource entry's fields.

Kind: instance method of ResourceEntry

ParamTypeDescription
opts.valuestringstring value to update
opts.reviewedbooleanoptional boolean indicating if value was reviewed
opts.metadataobjectoptional metadata to update
opts.partnerStatusstringtranslation status maintained by partner

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

ParamTypeDescription
paramsObjectconfiguration params
params.appEnvObjectpass the result of cfEnv.getAppEnv(). Ignored if params.credentials is supplied.
params.credentialsObject.<string, string>Bound credentials as from the CF service broker (overrides appEnv)
params.credentials.urlstringservice URL. (should end in '/translate')
params.credentials.userIdstringservice API key.
params.credentials.passwordstringservice API key.
params.credentials.instanceIdstringinstance ID

g11n-pipeline~listUsersCallback : function

Called when listusers completes

Kind: inner typedef of g11n-pipeline
See: User

ParamTypeDescription
errobjecterror , or null
usersObject.<string, User>user list

g11n-pipeline~basicCallback : function

Basic Callback

Kind: inner typedef of g11n-pipeline

ParamTypeDescription
errobjecterror , or null
dataObjectReturned data

docs autogenerated via jsdoc2md

Support

You can post questions about using this service to StackOverflow using the tag "globalization-pipeline".

LICENSE

Apache 2.0. See LICENSE.txt

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Keywords

FAQs

Package last updated on 14 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc