From 45e4b3698eea049f8a3b255b655c23a3b219f720 Mon Sep 17 00:00:00 2001 From: zdm Date: Sat, 17 Feb 2024 12:51:01 +0200 Subject: [PATCH] fix: translations --- lib/package/localization.js | 87 ++++++++++--------------------------- 1 file changed, 24 insertions(+), 63 deletions(-) diff --git a/lib/package/localization.js b/lib/package/localization.js index 4e9353a1..4d1996f8 100644 --- a/lib/package/localization.js +++ b/lib/package/localization.js @@ -76,7 +76,6 @@ export default class { return result( isTranslated ? 200 : 500, status ); } - // XXX async update () { await this.#initTranslationMemory(); @@ -156,7 +155,6 @@ 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: @@ -180,17 +178,14 @@ ${ 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 ); } } @@ -267,45 +262,15 @@ ${ res.data } // XXX async #resolveConflict ( poFile, message, translatedMessage ) { - var messageHash, translatedMessageHash; - - if ( !message.pluralId ) { - messageHash = JSON.stringify( message.singleFormTranslation ); - translatedMessageHash = JSON.stringify( translatedMessage.translations[ message.singleFormIndex ] ); + if ( message.pluralId ) { + if ( JSON.stringify( message.translations ) === JSON.stringify( translatedMessage.translations ) ) return; } else { - messageHash = JSON.stringify( message.translations ); - translatedMessageHash = JSON.stringify( translatedMessage.translations ); - } - - if ( message.pluralId && translatedMessage.msgid_plural && message.pluralId !== translatedMessage.msgid_plural ) { - console.error( `Plural form conflict found: - -[en] message: -${ message.id } - -[en] Old plural form: -${ translatedMessage.msgid_plural } - -Mew plural form: -${ message.pluralId } - -Please, check thet plural forms for this message are the same in all your sources. -` ); - - const answer = await utils.confirm( "Do you want to commit new plural form?", [ "no", "yes" ] ); - - if ( answer === "no" ) { - process.exit( 1 ); - } - else { - this.#storeMessage( poFile.language, message ); - } + if ( message.singleFormTranslation === translatedMessage.translations[ message.singleFormIndex ] ) return; } - // translation memory conflict - if ( messageHash !== translatedMessageHash ) { - console.log( `Translation memory conflict found: + // XXX + console.log( `Translation memory conflict found: [en] message: ${ message.id } @@ -320,39 +285,35 @@ ${ JSON.stringify( translatedMessage.translations, null, 4 ) } ${ JSON.stringify( message.translations, null, 4 ) } ` ); - const answer = await utils.confirm( "What translations do you want to use?", [ "exit", "new", "old" ] ); - - if ( answer === "exit" ) { - process.exit( 1 ); - } - else if ( answer === "new" ) { - if ( !message.pluralId ) { - translatedMessage.translations[ message.singleFormIndex ] = message.singleFormTranslation; - } - else { - translatedMessage.translations = message.translations; - } + const answer = await utils.confirm( "What translations do you want to use?", [ "exit", "new", "old" ] ); - this.#storeMessage( poFile.language, { - "id": translatedMessage.msgid, - "pluralId": translatedMessage.msgid_plural, - "translations": translatedMessage.translations, - } ); + if ( answer === "exit" ) { + process.exit( 1 ); + } + else if ( answer === "new" ) { + if ( !message.pluralId ) { + translatedMessage.translations[ message.singleFormIndex ] = message.singleFormTranslation; } else { - message.setTranslations( translatedMessage.translations ); + translatedMessage.translations = message.translations; } + + this.#storeMessage( poFile.language, { + "id": translatedMessage.msgid, + "translations": translatedMessage.translations, + } ); + } + else { + message.setTranslations( translatedMessage.translations ); } } - // XXX - #storeMessage ( language, { id, pluralId, translations } ) { + #storeMessage ( language, { id, translations } ) { this.#dbh.do( SQL.updateTranslations, [ // language, id, - pluralId || "", translations, ] ); }