mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-25 00:28:20 -05:00
localize initial options, set analytics prefs every time
This commit is contained in:
parent
64019e6fd8
commit
19cb492116
3 changed files with 39 additions and 30 deletions
|
@ -98,11 +98,24 @@ function indexHideSplash () {
|
|||
}
|
||||
}
|
||||
|
||||
// set analytics prefs for all initial options, whether set in this session
|
||||
// or before
|
||||
function indexSetAnalyticsPrefs () {
|
||||
var prefs = InitialOptions.getCurrentVals();
|
||||
if (!prefs) return;
|
||||
Object.keys(prefs).map(function (key) {
|
||||
OS.setAnalyticsPref(key, prefs[key]);
|
||||
});
|
||||
}
|
||||
|
||||
function indexLoadStart () {
|
||||
indexHideSplash();
|
||||
showLogo();
|
||||
gn('gettings').className = 'gettings show';
|
||||
gn('startcode').className = 'startcode show';
|
||||
|
||||
indexSetAnalyticsPrefs();
|
||||
|
||||
document.ontouchmove = function (e) {
|
||||
e.preventDefault();
|
||||
};
|
||||
|
@ -174,9 +187,7 @@ function indexSetPlace (e) {
|
|||
}
|
||||
// Send one-time analytics event about usage
|
||||
OS.analyticsEvent('lobby', 'scratchjr_usage', usageText);
|
||||
InitialOptions.setValue('place', usageText);
|
||||
// we use 'place_preference' for this particular Firebase pref
|
||||
OS.setAnalyticsPref('place_preference', usageText);
|
||||
InitialOptions.setValue('place_preference', usageText);
|
||||
ScratchAudio.sndFX('tap.wav');
|
||||
indexHidePlaceQuestion();
|
||||
indexAskRemainingQuestions();
|
||||
|
@ -217,13 +228,13 @@ function indexShowQuestion (key) {
|
|||
indexHideSplash();
|
||||
hideLogo();
|
||||
var optionType = InitialOptions.optionTypeForKey(key);
|
||||
if (optionType === 'place') {
|
||||
if (optionType === 'place_preference') {
|
||||
indexAskPlace();
|
||||
} else { // custom question
|
||||
var options = InitialOptions.optionsForKey(key);
|
||||
// if we could not find any options, choose 'n/a'
|
||||
if (!options || !options.length) {
|
||||
indexSelectOption(key, 'n/a');
|
||||
indexSelectOption(key, 'none');
|
||||
return;
|
||||
}
|
||||
// if there's only one option, don't bother asking, just choose it!
|
||||
|
@ -232,7 +243,7 @@ function indexShowQuestion (key) {
|
|||
return;
|
||||
}
|
||||
// if we got here, there is more than one option...
|
||||
var instructionText = InitialOptions.instructionForKey(key);
|
||||
var instructionText = Localization.localizeOptional(InitialOptions.instructionForKey(key));
|
||||
var instructionElem = document.getElementById('optionsInstruction');
|
||||
instructionElem.appendChild(document.createTextNode(instructionText));
|
||||
gn('optionsInstruction').className = 'optionsInstruction show';
|
||||
|
@ -256,7 +267,8 @@ function indexShowQuestion (key) {
|
|||
break;
|
||||
case 'text':
|
||||
default:
|
||||
optionElem.appendChild(document.createTextNode(option));
|
||||
var translatedOption = Localization.localizeOptional(option);
|
||||
optionElem.appendChild(document.createTextNode(translatedOption));
|
||||
break;
|
||||
}
|
||||
optionNum = optionNum + 1;
|
||||
|
@ -268,7 +280,6 @@ function indexShowQuestion (key) {
|
|||
// store user selection, and show next question
|
||||
function indexSelectOption (key, val) {
|
||||
InitialOptions.setValue(key, val);
|
||||
OS.setAnalyticsPref(key, val);
|
||||
ScratchAudio.sndFX('tap.wav');
|
||||
|
||||
// clear out old options instruction
|
||||
|
|
|
@ -79,15 +79,7 @@ export default class InitialOptions {
|
|||
if (!settingsSection) return;
|
||||
settingsSection.forEach(function (question) {
|
||||
// question is like {key: OPTION_NAME, options: [...]}
|
||||
if (question.firstTime && !question.everyTime) {
|
||||
InitialOptions.initKeyFromCookie(question.key);
|
||||
}
|
||||
});
|
||||
settingsSection.forEach(function (question) {
|
||||
// question is like {key: OPTION_NAME, options: [...]}
|
||||
if (question.everyTime) {
|
||||
InitialOptions.initKeyFromCookie(question.key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -147,19 +139,6 @@ export default class InitialOptions {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets array of keys of all questions that still need to be answered
|
||||
* in this app session
|
||||
*/
|
||||
// static unansweredQuestions () {
|
||||
// if (!settingsSection || !settingsSection.length) return [];
|
||||
// return settingsSection.filter(function (question) {
|
||||
// return !InitialOptions.isAnswered(question);
|
||||
// }).map(function (question) {
|
||||
// return question.key;
|
||||
// });
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets next question that needs to be asked
|
||||
*/
|
||||
|
@ -172,6 +151,13 @@ export default class InitialOptions {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object of current values
|
||||
*/
|
||||
static getCurrentVals () {
|
||||
return currentVals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an options value in both cookie, and local object.
|
||||
* @param {string} key indicates which options question this value is for
|
||||
|
|
|
@ -112,6 +112,18 @@ export default class Localization {
|
|||
return 'String missing: ' + key;
|
||||
}
|
||||
|
||||
// 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
|
||||
static localizeOptional (keyOrRawText, formatting) {
|
||||
var message;
|
||||
if (keyOrRawText in localizationMessages) {
|
||||
message = new window.IntlMessageFormat(localizationMessages[keyOrRawText], currentLocale);
|
||||
return message.format(formatting);
|
||||
}
|
||||
return keyOrRawText;
|
||||
}
|
||||
|
||||
// For sample projects, some fields (sprite names, text on stage, and text in say blocks)
|
||||
// may have a special prefix to indicate that it should be replaced with a localized value.
|
||||
// E.g., we might have some text on the stage that says "Touch me" in English. This gets translated.
|
||||
|
|
Loading…
Reference in a new issue