localize sample name in storyStarter mode

This commit is contained in:
Yueyu 2021-07-31 09:27:18 +08:00
parent fa6bf47b35
commit 5c0d80f048
4 changed files with 18 additions and 7 deletions

View file

@ -355,7 +355,7 @@ export default class ScratchJr {
if (ScratchJr.isEditable() && editmode == 'storyStarter' && storyStarted && !Project.error) {
OS.analyticsEvent('samples', 'story_starter_edited', Project.metadata.name);
// Localize sample project names
var sampleName = Localization.localize('SAMPLE_' + Project.metadata.name);
var sampleName = Localization.localizeSampleName(Project.metadata.name);
// Get the new project name
IO.uniqueProjectName({
name: sampleName

View file

@ -339,7 +339,7 @@ export default class UI {
if (ScratchJr.isEditable() && ScratchJr.editmode == 'storyStarter' && !Project.error && ScratchJr.changed) {
OS.analyticsEvent('samples', 'story_starter_edited', Project.metadata.name);
// Get the new project name
var sampleName = Localization.localize('SAMPLE_' + Project.metadata.name);
var sampleName = Localization.localizeSampleName(Project.metadata.name);
IO.uniqueProjectName({
name: sampleName
}, function (jsonData) {
@ -423,7 +423,11 @@ export default class UI {
}
if (ScratchJr.isEditable()) {
(document.forms.projectname.myproject).value = Project.metadata.name;
var name = Project.metadata.name;
if (ScratchJr.editmode == 'storyStarter') {
name = Localization.localizeSampleName(name);
}
(document.forms.projectname.myproject).value = name;
} else {
gn('pname').textContent = Project.metadata.name;
}

View file

@ -52,10 +52,7 @@ export default class Samples {
var name = mt.childNodes[1];
// Localize sample project names
var sampleName = data.name;
sampleName = Localization.localize('SAMPLE_' + sampleName);
name.textContent = sampleName;
name.textContent = Localization.localizeSampleName(data.name);
var cnv = mt.childNodes[0].childNodes[1];
Samples.insertThumbnail(cnv, data.thumbnail);
mt.onclick = function (evt) {

View file

@ -112,6 +112,16 @@ export default class Localization {
return 'String missing: ' + key;
}
static localizeSampleName (key) {
var name = Localization.localizeOptional('SAMPLE_' + key);
// If the localized name is still started with 'SAMPLE_',
// it is not a preset name.
if (name.startsWith('SAMPLE_')) {
return key;
}
return name;
}
// Translate a particular message given the message key and info;
// if key not found, assume it's just a raw text string without a translation,
// and return that