Skip to content

Commit

Permalink
Translation - Introduce a public API for merging a locale with default
Browse files Browse the repository at this point in the history
…fix #5256 (#5263)
  • Loading branch information
andrewtelnov committed Feb 26, 2024
1 parent a5d12aa commit 8a8a1e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,8 @@ export class Translation extends Base implements ITranslationLocales {
this.setVisibleLocales([]);
this.reset();
}
public reset(): void {
public reset(alwaysReset: boolean = true): void {
if(!alwaysReset && !!this.root) return;
var rootObj = !!this.filteredPage ? this.filteredPage : this.survey;
var rootName = !!this.filteredPage ? rootObj["name"] : "survey";
this.root = new TranslationGroup(rootName, rootObj, this);
Expand Down Expand Up @@ -1253,6 +1254,7 @@ export class Translation extends Base implements ITranslationLocales {
});
}
public mergeLocaleWithDefault() {
this.reset(false);
if (!this.hasLocale(this.defaultLocale)) return;
this.root.mergeLocaleWithDefault(this.defaultLocale);
this.setVisibleLocales([]);
Expand Down
38 changes: 38 additions & 0 deletions packages/survey-creator-core/tests/tabs/translation-v1.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,44 @@ test("Merging a locale with default", () => {
expect(translation.canMergeLocaleWithDefault).toBeTruthy();
surveyLocalization.defaultLocale = "en";
});
test("Merging a locale with default - no reset", () => {
surveyLocalization.defaultLocale = "de";
const survey: SurveyModel = new SurveyModel({
locale: "de",
elements: [
{
type: "text",
name: "question1",
title: {
de: "title de",
fr: "title fr"
}
},
{
type: "text",
name: "question2",
title: {
default: "title default",
de: "title de",
fr: "title fr"
}
},
{
type: "text",
name: "question3",
title: {
default: "title default",
fr: "title fr"
}
}
]
});
const translation: Translation = new Translation(survey);
translation.mergeLocaleWithDefault();
expect(translation.locales).toHaveLength(2);
expect(translation.canMergeLocaleWithDefault).toBeFalsy();
surveyLocalization.defaultLocale = "en";
});
test("Custom localizable property in question", () => {
Serializer.addProperty("question", {
name: "customProp",
Expand Down

0 comments on commit 8a8a1e4

Please sign in to comment.