Skip to content

Commit

Permalink
fix: Save developer note changes to g.xlf
Browse files Browse the repository at this point in the history
  • Loading branch information
jwikman committed Feb 24, 2024
1 parent f8f07dc commit 65a67d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions extension/src/Xliff/XLIFFDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class Xliff implements XliffDocumentInterface {
public buildNum?: string;
public requestId?: string;
public header?: HeaderInterface;
public _isModified = false;

constructor(
datatype: string,
Expand Down
18 changes: 18 additions & 0 deletions extension/src/XliffFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export async function _refreshXlfFilesFromGXlf({
languageFunctionsSettings.searchReplaceBeforeSaveXliff
);
}
if (gXliff._isModified) {
gXliff.toFileSync(gXliff._path, undefined, true, []);
}

return refreshResult;
}
Expand Down Expand Up @@ -303,9 +306,13 @@ export function refreshSelectedXlfFileFromGXlf(
if (threeLetterAbbreviationLanguageCode) {
targetFoundInComments = addTranslationIfFound(
langTransUnit,
gTransUnit,
threeLetterAbbreviationLanguageCode,
transUnitsToRemoveCommentsInCode
);
if (targetFoundInComments) {
gXliff._isModified = true;
}
}
if (
!targetFoundInComments &&
Expand Down Expand Up @@ -348,9 +355,13 @@ export function refreshSelectedXlfFileFromGXlf(
if (threeLetterAbbreviationLanguageCode) {
targetFoundInComments = addTranslationIfFound(
newTransUnit,
gTransUnit,
threeLetterAbbreviationLanguageCode,
transUnitsToRemoveCommentsInCode
);
if (targetFoundInComments) {
gXliff._isModified = true;
}
}
if (!targetFoundInComments) {
newTransUnit.targets.push(
Expand Down Expand Up @@ -422,6 +433,7 @@ export function refreshSelectedXlfFileFromGXlf(

function addTranslationIfFound(
langTransUnit: TransUnit,
gTransUnit: TransUnit,
threeLetterAbbreviationLanguageCode: string,
transUnitsToRemoveCommentsInCode: Map<TransUnit, string>
): boolean {
Expand All @@ -439,6 +451,12 @@ export function refreshSelectedXlfFileFromGXlf(
.developerNote()
.textContent.replace(matchResult[0], "");
transUnitsToRemoveCommentsInCode.set(langTransUnit, matchResult[0]);
if (
gTransUnit.developerNote().textContent !==
langTransUnit.developerNote().textContent
) {
gTransUnit.developerNote().textContent = langTransUnit.developerNote().textContent;
}
}
return true;
}
Expand Down

0 comments on commit 65a67d9

Please sign in to comment.