Blame view
node_modules/g11n-pipeline/template-README.md
5.63 KB
f7563de62
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
Globalization Pipeline Client for JavaScript ============================================ This is the JavaScript SDK for the [Globalization Pipeline](https://github.com/IBM-Bluemix/gp-common#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](http://nodejs.org). [](https://badge.fury.io/js/g11n-pipeline) [](https://travis-ci.org/IBM-Bluemix/gp-js-client) [](https://coveralls.io/github/IBM-Bluemix/gp-js-client) [](https://scan.coverity.com/projects/ibm-bluemix-gp-js-client) ## Sample For a working Bluemix application sample, see [gp-nodejs-sample](https://github.com/IBM-Bluemix/gp-nodejs-sample). ## Quickstart * You should familiarize yourself with the service itself. A good place to begin is by reading the [Quick Start Guide](https://github.com/IBM-Bluemix/gp-common#quick-start-guide) and the official [Getting Started with IBM Globalization ](https://www.ng.bluemix.net/docs/services/GlobalizationPipeline/index.html) documentation. The documentation explains how to find the service on Bluemix, create a new service instance, create a new bundle, and access the translated messages. * Next, 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](https://www.npmjs.com/package/cfenv) ). ```javascript 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 ); ``` * For local testing, create a `local-credentials.json` file with the credentials as given in the bound service: { "credentials": { "url": "https://…", "userId": "…", "password": "……", "instanceId": "………" } } ## Using To fetch the strings for a bundle named "hello", first create a bundle accessor: ```javascript var mybundle = gpClient.bundle('hello'); ``` Then, call the `getStrings` function with a callback: ```javascript 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: ```javascript { hello: '¡Hola!', goodbye: '¡Adiós!', … } ``` ### Async Note that all calls that take a callback are asynchronous. For example, the following code: ```javascript var bundle = client.bundle('someBundle'); bundle.create({…}, function(…){…}); bundle.uploadStrings({…}, function(…){…}); ``` …will fail, because the bundle `someBundle` hasn’t been `create`d by the time the `uploadStrings` call is made. Instead, make the `uploadStrings` call within a callback: ```javascript var bundle = client.bundle('someBundle'); bundle.create({…}, function(…){ … bundle.uploadStrings({…}, function(…){…}); }); ``` ## Testing See [TESTING.md](TESTING.md) API convention == APIs take a callback and use this general pattern: ```javascript gpClient.function( { /*opts*/ } , function callback(err, ...)) ``` * opts: an object containing input parameters, if needed. * `err`: if truthy, indicates an error has occured. * `...`: other parameters (optional) Sometimes the `opts` object is optional. If this is the case, the API doc will indicate it with this notation: `[opts]` For example, `bundle.getInfo(cb)` and `bundle.getInfo({}, cb)` are equivalent. These APIs may be promisified easily using a library such as `Q`'s [nfcall](http://documentup.com/kriskowal/q/#adapting-node): ```javascript 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](http://tools.ietf.org/html/bcp47) codes. API reference === {{>main}} *docs autogenerated via [jsdoc2md](https://github.com/jsdoc2md/jsdoc-to-markdown)* Community === * View or file GitHub [Issues](https://github.com/IBM-Bluemix/gp-js-client/issues) * Connect with the open source community on [developerWorks Open](https://developer.ibm.com/open/ibm-bluemix-globalization-pipeline/node-js-sdk/) Contributing === See [CONTRIBUTING.md](CONTRIBUTING.md). License === Apache 2.0. See [LICENSE.txt](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. |