jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/382113 )
Change subject: Make bin/apertium-xhtml a generic mt testing utility
......................................................................
Make bin/apertium-xhtml a generic mt testing utility
Moved it to bin/mt and accepts MT service name. Helps testing
mt services easily.
Change-Id: Ic214822132e339208b2e7c158510c7d8779ed18f
---
D bin/apertium-xhtml
A bin/mt
2 files changed, 64 insertions(+), 55 deletions(-)
Approvals:
jenkins-bot: Verified
Nikerabbit: Looks good to me, approved
diff --git a/bin/apertium-xhtml b/bin/apertium-xhtml
deleted file mode 100755
index 61cde1a..0000000
--- a/bin/apertium-xhtml
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env node
-var sourceLang, targetLang, sourceHtml, script, args, config, cxConfig,
- fs = require( 'fs' ),
- yaml = require( 'js-yaml' ),
- Apertium = require( __dirname + '/../lib/mt/Apertium.js' );
-
-config = yaml.load( fs.readFileSync( 'config.yaml' ) );
-if ( !config ) {
- console.error( 'Failed to load config' );
- process.exit( 1 );
-}
-cxConfig = config.services && Array.isArray( config.services ) &&
- config.services.filter( function ( item ) {
- return item && item.name === 'cxserver';
- } )[ 0 ];
-if ( !cxConfig ) {
- console.error( 'Cannot find cxserver config' );
- process.exit( 1 );
-}
-
-script = process.argv[ 1 ];
-args = process.argv.slice( 2 );
-if ( args.length !== 2 ) {
- process.stderr.write(
- 'Usage: node ' + script + ' <sourceLang> <targetLang> <
xhtmlSource\n\n' +
- 'xhtml must be wrapped in a block element such as <p>...</p> or
<div>..</div>.\n' +
- 'Example:\n\techo "<p>A <b>red</b> box.</p>" | node ' + script
+ ' en es\n\n'
- );
- process.exit( 1 );
-}
-
-sourceLang = args[ 0 ];
-targetLang = args[ 1 ];
-
-sourceHtml = [];
-
-process.stdin.on( 'data', function ( data ) {
- sourceHtml.push( data );
-} );
-process.stdin.on( 'end', function () {
- new Apertium( cxConfig ).translate(
- sourceLang,
- targetLang,
- sourceHtml.join( '' )
- ).then( function ( targetHtml ) {
- process.stdout.write( targetHtml + '\n' );
- } ).catch( function ( error ) {
- if ( error.stack ) {
- console.error( 'error', error.stack );
- } else {
- console.error( 'error', error );
- }
- process.exit( 2 );
- } );
-} );
diff --git a/bin/mt b/bin/mt
new file mode 100755
index 0000000..4796cf5
--- /dev/null
+++ b/bin/mt
@@ -0,0 +1,64 @@
+#!/usr/bin/env node
+const fs = require( 'fs' ),
+ yaml = require( 'js-yaml' ),
+ MTClients = require( __dirname + '/../lib/mt/' );
+
+const config = yaml.load( fs.readFileSync( 'config.yaml' ) );
+if ( !config ) {
+ console.error( 'Failed to load config' );
+ process.exit( 1 );
+}
+const cxConfig = config.services && Array.isArray( config.services ) &&
+ config.services.filter( function ( item ) {
+ return item && item.name === 'cxserver';
+ } )[ 0 ];
+if ( !cxConfig ) {
+ console.error( 'Cannot find cxserver config' );
+ process.exit( 1 );
+}
+
+function showHelpAndExit() {
+ const script = process.argv[ 1 ];
+ process.stderr.write(
+ 'Usage: node ' + script + ' <sourceLang> <targetLang> <
xhtmlSource\n\n' +
+ 'Example:\n\techo "<p>A <b>red</b> box.</p>" | node ' + script
+ ' Apertium en es\n\n'
+ );
+ process.exit( 1 );
+}
+
+const args = process.argv.slice( 2 );
+if ( args.length !== 3 ) {
+ showHelpAndExit();
+}
+
+const mtService = args[ 0 ];
+const sourceLang = args[ 1 ];
+const targetLang = args[ 2 ];
+
+let sourceHtml = fs.readFileSync( '/dev/stdin', 'utf8' );
+
+if ( sourceHtml.trim() === '' ) {
+ showHelpAndExit();
+}
+
+if ( !MTClients[ mtService ] ) {
+ console.error( `Cannot find MT service: ${mtService}` );
+ process.exit( 1 );
+}
+
+let mt = new MTClients[ mtService ]( cxConfig );
+
+return mt.translate(
+ sourceLang,
+ targetLang,
+ sourceHtml
+).then( ( targetHtml ) => {
+ process.stdout.write( targetHtml + '\n' );
+} ).catch( ( error ) => {
+ if ( error.stack ) {
+ console.error( 'error', error.stack );
+ } else {
+ console.error( 'error', error );
+ }
+ process.exit( 2 );
+} );
--
To view, visit https://gerrit.wikimedia.org/r/382113
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic214822132e339208b2e7c158510c7d8779ed18f
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits