Update to v1.3.0 #10

Merged
merged 1 commit into from Dec 7, 2016
Jump to file or symbol
Failed to load files and symbols.
+7 −11
Diff settings

Always

Just for now

View
16 app.js
@@ -4,7 +4,7 @@
*/
/*
- * Copyright IBM Corp. 2015
+ * Copyright IBM Corp. 2015,2016

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor

OK, it's been a while.

@srl295

srl295 Dec 7, 2016

Contributor

OK, it's been a while.

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ var mybundle = gpClient.bundle(bundleName);
// Example: /
app.get('/', function (req, res) {
// For the root page, load the list of supported langs
- mybundle.getInfo({}, function (err, projInfo) {
+ mybundle.getInfo(function (err, projInfo) {

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor

in v1.3.0, where the {} options are ignored or optional, they may be omitted.

@srl295

srl295 Dec 7, 2016

Contributor

in v1.3.0, where the {} options are ignored or optional, they may be omitted.

if(err) {
// console.error(err);
res.write(err.toString());
@@ -49,12 +49,8 @@ app.get('/', function (req, res) {
res.write('<h1>Welcome to the Globalization Pipeline Node.js sample!</h1>');
res.write('<h2> Pick a language code:</h2>');
res.write('<ul>');
- // add the source (probably english)
- addLang(projInfo.sourceLanguage);
- // add all of the targets
- if( projInfo.targetLanguages) {
- projInfo.targetLanguages.forEach( addLang );
- }
+ projInfo.languages() // --> Array: [ 'en', 'de', … ]

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor
  • projInfo is now a Bundle object here
  • the new languages() function returns both the source AND target languages, in a single convenient array!
@srl295

srl295 Dec 7, 2016

Contributor
  • projInfo is now a Bundle object here
  • the new languages() function returns both the source AND target languages, in a single convenient array!

This comment has been minimized.

@steveatkin

steveatkin Dec 7, 2016

This seems like a good change.

@steveatkin

steveatkin Dec 7, 2016

This seems like a good change.

+ .forEach( addLang );
res.write('</ul>');
res.end();
}
@@ -65,12 +61,12 @@ app.get('/', function (req, res) {
app.get(/^\/(\w+)\/hello/, function (req, res) {
var lang = req.params[0];
// Just get this string
- mybundle.getEntryInfo({ resourceKey: 'hello', languageId: lang}, function (err, data) {
+ mybundle.entry({ resourceKey: 'hello', languageId: lang})
+ .getInfo(function (err, entry) {

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor

the ResourceEntry object supports getInfo() which returns another ResourceEntry object, but populated with the data

@srl295

srl295 Dec 7, 2016

Contributor

the ResourceEntry object supports getInfo() which returns another ResourceEntry object, but populated with the data

This comment has been minimized.

@steveatkin

steveatkin Dec 7, 2016

I am not sure I understand. Do you mean it will have the target translation data and the source as well?

@steveatkin

steveatkin Dec 7, 2016

I am not sure I understand. Do you mean it will have the target translation data and the source as well?

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor

mybundle.entry({ resourceKey: 'hello', languageId: lang})
.getInfo(function (err, theEntry) { …} )

theEntry contains the translation data for languageId lang

@srl295

srl295 Dec 7, 2016

Contributor

mybundle.entry({ resourceKey: 'hello', languageId: lang})
.getInfo(function (err, theEntry) { …} )

theEntry contains the translation data for languageId lang

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor

Or put another way:

var anEntry = mybundle.entry({ resourceKey: 'hello', languageId: lang});

anEntry is now a ResourceEntry object It does not have any translation data in it. But you can call .getInfo

anEntry.getInfo(function (err, entryWithInfo) { … } );

… Now, entryWithInfo has the full information for the entry - the value, the updatedAt (mod time), etc. Also, entryWithInfo is itself a ResourceEntry object, so you could make further calls.

@srl295

srl295 Dec 7, 2016

Contributor

Or put another way:

var anEntry = mybundle.entry({ resourceKey: 'hello', languageId: lang});

anEntry is now a ResourceEntry object It does not have any translation data in it. But you can call .getInfo

anEntry.getInfo(function (err, entryWithInfo) { … } );

… Now, entryWithInfo has the full information for the entry - the value, the updatedAt (mod time), etc. Also, entryWithInfo is itself a ResourceEntry object, so you could make further calls.

if(err) {
console.error(err);
res.end('Sorry, an error occured.');
} else {
- var entry = data.resourceEntry;
if(entry.translationStatus === 'failed') {
res.end(lang + ':\n\n** failed: retry the translation from the dashboard');
} else if(entry.translationStatus === 'inProgress') {
View
@@ -12,7 +12,7 @@
"dependencies": {
"cfenv": "^1.0.3",
"express": "^4.14.0",
- "g11n-pipeline": "^1.2.0",
+ "g11n-pipeline": "^1.3.0",

This comment has been minimized.

@srl295

srl295 Dec 7, 2016

Contributor

All you need to do… is 1.3.0 - and you're through!

@srl295

srl295 Dec 7, 2016

Contributor

All you need to do… is 1.3.0 - and you're through!

"optional": "^0.1.3"
}
}