diff --git a/lib/package/localization.js b/lib/package/localization.js index b3a1ceef..29bc2248 100644 --- a/lib/package/localization.js +++ b/lib/package/localization.js @@ -18,31 +18,28 @@ if ( process.env.GCLOUD_TRANSLATION_API_KEY ) { const SQL = { "schema": sql` -CREATE TABLE IF NOT EXISTS translation ( +CREATE TABLE IF NOT EXISTS message ( language text NOT NULL, - msgid text NOT NULL, - msgid_plural text NOT NULL, + id text NOT NULL, translations json NOT NULL, - PRIMARY KEY ( language, msgid ) + PRIMARY KEY ( language, id ) ); `, "updateTranslations": sql` -INSERT INTO translation +INSERT INTO message ( language, - msgid, msgid_plural, translations ) VALUES ( ?, ?, ?, ? ) -ON CONFLICT ( language, msgid ) DO UPDATE SET - msgid_plural = EXCLUDED.msgid_plural, +ON CONFLICT ( language, id ) DO UPDATE SET translations = EXCLUDED.translations `.prepare(), - "getTranslations": sql`SELECT * FROM translation WHERE language = ? AND msgid = ?`.prepare(), + "getTranslatedMessage": sql`SELECT * FROM message WHERE language = ? AND id = ?`.prepare(), }; export default class { @@ -159,6 +156,7 @@ export default class { for ( const message of Object.values( poFile.messages ) ) { if ( message.isDisabled ) continue; + // XXX // delete invalid translation if ( message.id === message.singleFormTranslation ) { console.warn( `Failed translation removed: @@ -174,7 +172,7 @@ ${ message.singleFormTranslation } message.setTranslations( null ); } - const translatedMessage = this.#dbh.selectRow( SQL.getTranslations, [ + const translatedMessage = this.#dbh.selectRow( SQL.getTranslatedMessage, [ // poFile.language, @@ -182,29 +180,36 @@ ${ message.singleFormTranslation } ] ).data; // message is fully translated + // XXX if ( message.isTranslated && !message.isFuzzy ) { if ( translatedMessage ) { - await this.#resolveConflict( poFile, message, translatedMessage ); + + // await this.#resolveConflict( poFile, message, translatedMessage ); } // store to the translatuin memory else { - this.#storeMessage( poFile.language, message ); + + // this.#storeMessage( poFile.language, message ); } } // message is not translated else { + // XXX // get message from the translation memory if ( translatedMessage ) { - message.isFuzzy = false; - message.setTranslations( translatedMessage.translations ); + + // message.isFuzzy = false; + // message.setTranslations( translatedMessage.translations ); } + // XXX // pre-translate single form else if ( cloudTranslationApi && !message.isSingleFormTranslated ) { - await this.#preTranslate( poFile, message ); + + // await this.#preTranslate( poFile, message ); } } } @@ -231,6 +236,7 @@ ${ message.singleFormTranslation } this.#dbh.exec( SQL.schema ); } + // XXX async #preTranslate ( poFile, message ) { const res = await cloudTranslationApi.translate( poFile.language, message.id ); @@ -264,6 +270,7 @@ ${ res.data } } } + // XXX async #resolveConflict ( poFile, message, translatedMessage ) { var messageHash, translatedMessageHash; @@ -343,6 +350,7 @@ ${ JSON.stringify( message.translations, null, 4 ) } } } + // XXX #storeMessage ( language, { id, pluralId, translations } ) { this.#dbh.do( SQL.updateTranslations, [