Package: gp-python-client-sid
gp-python-clientgp-python-clientis the official Python client forIBM Globalization Pipeline.IBM Globalization Pipeline is a DevOps integrated application translation management service that you can use to rapidly translate and release cloud and mobile applications to your global customers. Access IBM Globalization Pipeline capabilities through its dashboard, RESTful API, or integrate it seamlessly into your application's Delivery Pipeline.This package expands on thegettext module(avaliable as part of the Python standard library) and provides functionality for Python applications to use the Globalization Pipeline service.Getting startedTo get started, you should familiarize yourself with the service itself. A
good place to begin is by reading theQuick Start Guideand the officialGetting Started with IBM Globalizationdocumentation.The documentation explains how to find the service on IBM Cloud; authentication mechanisms supported; create a new service instance; create a new bundle; access the translated messages.DemoThisdemo Bluemix appuses the Globalization Pipeline with the Python client to display a short welcome message that is translated in several languages. The source code for the demo app can be found in thedemo dir.InstallationTo installgp-python-client, simply run:$pipinstallgp-python-clientOr if you're oldschool, run:$easy_installgp-python-clientAPIThe API documentation for the package can be foundhere. If the link is broken, you cangenerate the documentationyourself.ExamplesExample 1 - Bluemix app:This sample code will allow you to get started using the Globalization Pipeline service in your Bluemix app. The example assumes the Bluemix app has been connected to a Globalization Pipeline service instance and has a bundle namedmyBundle, and that the bundle contains a source string with keygreet.>>>fromgpclientimportGPClient,GPServiceAccount,GPTranslations>>>importlocale>>>>>>acc=GPServiceAccount()>>>client=GPClient(acc)>>>>>>languages=[locale.getdefaultlocale()[0]]# languages=['fr_CA']>>>>>>t=client.translation(bundleId='myBundle',languages=languages)>>>_=t.gettext# create alias for method>>>>>>print_('greet')# 'greet' key's French translated value will be usedBonjour>>>Example 2 - Non-Bluemix app:This sample code will allow you to get started using the Globalization Pipeline service in a standalone Python app that is not hosted on Bluemix. The example assumes a Globalization Pipeline service instance exists with a bundle namedmyBundle, and that the bundle contains a source string with keyexit.You will need theservice instance credentials.>>>fromgpclientimportGPClient,GPServiceAccount,GPTranslations>>>importlocale>>>>>>acc=GPServiceAccount(url=url,instanceId=instId,userId=userId,password=passwd)# Using Globalization Pipeline authentication# Using IAM# acc = GPServiceAccount(url=url, instanceId=instanceId,#                                apiKey=apiKey)>>>client=GPClient(acc)>>>>>>languages=[locale.getdefaultlocale()[0]]# languages=['es-mx']>>>>>>t=client.translation(bundleId='myBundle',languages=languages)>>>_=t.gettext# create alias for method>>>>>>print_('exit')# 'exit' key's Spanish translated value will be usedAdiós>>>You can also provide the service credentials through a JSON file as shown in the snippet below>>>fromgpclientimportGPClient,GPServiceAccount>>>>>>acc=GPServiceAccount(credentialsJson="./local_credentials.json")>>>client=GPClient(acc)Obtaining language/locale codesThis package requires that valid (BCP47 compliant) language/locale codes be provided when asked; for example, when callingGPClient.translation()(seeExamples). From these codes, the language, region, and script subtags will be extracted.Some example codes are:zh-Hanspt-BRjaen_USThere are several ways to get the code for the working locale. One way
is to use thelocale module(avaliable as part of the Python standard library).>>>importlocale>>>myLocale=locale.getdefaultlocale()>>>printmyLocale('en_US','UTF-8')>>>code=myLocale[0]>>>printcodeen_USFor the above example, the language code isen_US- whereenis the language subtag, andUSis the region subtag.Running TestsRefer totest/README.md.Generating documentationDocumentation can be generated usingSphinx.You must first install it:$pipinstallsphinxThen, to auto generate the documentation, run:$cd$BASEDIR/docs
$makeclean
$makehtmlTo navigate the documentation, open$BASEDIR/docs/_build/html/index.html.Creating distribution packageFirst updateCHANGES.txtandsetup.pyif necessary (e.g. update version number), then create the preferreddistribution package.Wheel distribution(Recommended)$pipinstallwheel
$pythonsetup.pybdist_wheelSource distribution$pythonsetup.pysdistNote: Source distribution contains tests as well.Build distribution$pythonsetup.pybdistThe new distribution files should be located under$BASEDIR/dist/.CommunityView or file GitHubIssuesConnect with the open source community ondeveloperWorks OpenContributingSeeCONTRIBUTING.md.LicenseApache 2.0. SeeLICENSE.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 athttp://www.apache.org/licenses/LICENSE-2.0Unless 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.