Skip to content

Commit

Permalink
fix: translations
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Feb 17, 2024
1 parent 111fe5e commit 45e4b36
Showing 1 changed file with 24 additions and 63 deletions.
87 changes: 24 additions & 63 deletions lib/package/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default class {
return result( isTranslated ? 200 : 500, status );
}

// XXX
async update () {
await this.#initTranslationMemory();

Expand Down Expand Up @@ -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:
Expand All @@ -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 );
}
}

Expand Down Expand Up @@ -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 }
Expand All @@ -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,
] );
}
Expand Down

0 comments on commit 45e4b36

Please sign in to comment.