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

View file

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

View file

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

View file

@ -112,6 +112,16 @@ export default class Localization {
return 'String missing: ' + key; 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; // 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, // if key not found, assume it's just a raw text string without a translation,
// and return that // and return that