mirror of
https://github.com/scratchfoundation/scratchjr.git
synced 2024-11-25 08:38:30 -05:00
Make Localization.includeLocales async
This commit is contained in:
parent
0c65882bd0
commit
d062dbf4ac
1 changed files with 7 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
import Cookie from './Cookie';
|
import Cookie from './Cookie';
|
||||||
import Intl from 'intl';
|
import Intl from 'intl';
|
||||||
|
import IO from '../iPad/IO';
|
||||||
window.Intl = Intl;
|
window.Intl = Intl;
|
||||||
|
|
||||||
require('intl/locale-data/jsonp/en.js');
|
require('intl/locale-data/jsonp/en.js');
|
||||||
|
@ -52,7 +53,7 @@ export default class Localization {
|
||||||
|
|
||||||
// Include locale support files and load the messages
|
// Include locale support files and load the messages
|
||||||
// Call this when the app is initialized
|
// Call this when the app is initialized
|
||||||
static includeLocales () {
|
static includeLocales (whenDone) {
|
||||||
var localizationCookie = Cookie.get('localization');
|
var localizationCookie = Cookie.get('localization');
|
||||||
|
|
||||||
if (localizationCookie === null) {
|
if (localizationCookie === null) {
|
||||||
|
@ -62,11 +63,11 @@ export default class Localization {
|
||||||
}
|
}
|
||||||
var topLevel = currentLocale.split('-')[0];
|
var topLevel = currentLocale.split('-')[0];
|
||||||
|
|
||||||
// Get messages synchronously
|
// Get messages
|
||||||
var xhr = new XMLHttpRequest();
|
IO.requestFromServer(root + 'localizations/' + topLevel + '.json', (result) => {
|
||||||
xhr.open('GET', root + 'localizations/' + topLevel + '.json', false);
|
localizationMessages = JSON.parse(result);
|
||||||
xhr.send(null);
|
whenDone();
|
||||||
localizationMessages = JSON.parse(xhr.responseText);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate a particular message given the message key and info
|
// Translate a particular message given the message key and info
|
||||||
|
|
Loading…
Reference in a new issue