mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 08:50:06 +02:00
[Flux] Locale data flow converted to Flux
This commit is contained in:
parent
b4a6ac3784
commit
1afd48bb39
8 changed files with 45 additions and 69 deletions
|
@ -1,9 +1,22 @@
|
||||||
//var LocaleStore = require('../../js/stores/LocaleStore');
|
|
||||||
var CasperUtils = require('./casperUtils').CasperUtils;
|
var CasperUtils = require('./casperUtils').CasperUtils;
|
||||||
|
|
||||||
var intl = require('../../js/intl/index.js');
|
var langLocaleMap = {
|
||||||
|
en: 'en_US',
|
||||||
|
zh: 'zh_CN',
|
||||||
|
ja: 'ja',
|
||||||
|
ko: 'ko',
|
||||||
|
es: 'es_AR',
|
||||||
|
fr: 'fr_FR',
|
||||||
|
de: 'de_DE',
|
||||||
|
pt: 'pt_BR'
|
||||||
|
};
|
||||||
|
|
||||||
var langLocaleMap = intl.langLocaleMap;
|
/*
|
||||||
|
var headerLocaleMap = {
|
||||||
|
'zh-CN': 'zh_CN',
|
||||||
|
'zh-TW': 'zh_TW',
|
||||||
|
'pt-BR': 'pt_BR'
|
||||||
|
};*/
|
||||||
|
|
||||||
casper.start(
|
casper.start(
|
||||||
CasperUtils.getUrl(),
|
CasperUtils.getUrl(),
|
||||||
|
@ -18,16 +31,6 @@ casper.start(
|
||||||
|
|
||||||
Object.keys(langLocaleMap).forEach(function(lang) {
|
Object.keys(langLocaleMap).forEach(function(lang) {
|
||||||
var locale = langLocaleMap[lang];
|
var locale = langLocaleMap[lang];
|
||||||
this.test.assertEvalEquals(function(lang) {
|
|
||||||
debug_App_changeLocaleFromHeaders(lang);
|
|
||||||
return debug_Intl_getLocale();
|
|
||||||
},
|
|
||||||
locale,
|
|
||||||
'Testing changing the locale from ' + lang +
|
|
||||||
' to ' + locale,
|
|
||||||
{ lang: lang }
|
|
||||||
);
|
|
||||||
|
|
||||||
this.test.assertEvalEquals(function(lang) {
|
this.test.assertEvalEquals(function(lang) {
|
||||||
debug_LocaleActions_changeLocaleFromHeader(lang);
|
debug_LocaleActions_changeLocaleFromHeader(lang);
|
||||||
return debug_LocaleStore_getLocale();
|
return debug_LocaleStore_getLocale();
|
||||||
|
|
|
@ -7,6 +7,11 @@ var ActionTypes = AppConstants.ActionTypes;
|
||||||
|
|
||||||
describe('LocaleStore', function() {
|
describe('LocaleStore', function() {
|
||||||
|
|
||||||
|
it('has default locale', function() {
|
||||||
|
expect(LocaleStore.getLocale())
|
||||||
|
.toEqual(LocaleStore.getDefaultLocale());
|
||||||
|
});
|
||||||
|
|
||||||
it('changes locales', function() {
|
it('changes locales', function() {
|
||||||
expect(LocaleStore.getLocale()).toEqual('en_US');
|
expect(LocaleStore.getLocale()).toEqual('en_US');
|
||||||
LocaleActions.changeLocale('ja_JP');
|
LocaleActions.changeLocale('ja_JP');
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
|
|
||||||
var constants = require('../util/constants');
|
|
||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
var intl = require('../intl');
|
var intl = require('../intl');
|
||||||
var GlobalState = require('../util/globalState');
|
|
||||||
var LocaleStore = require('../stores/LocaleStore');
|
var LocaleStore = require('../stores/LocaleStore');
|
||||||
var LocaleActions = require('../actions/LocaleActions');
|
var LocaleActions = require('../actions/LocaleActions');
|
||||||
|
|
||||||
|
@ -31,7 +29,6 @@ var init = function() {
|
||||||
* - handling window.focus and zoom events
|
* - handling window.focus and zoom events
|
||||||
**/
|
**/
|
||||||
var Sandbox = require('../sandbox/').Sandbox;
|
var Sandbox = require('../sandbox/').Sandbox;
|
||||||
var Level = require('../level').Level;
|
|
||||||
var EventBaton = require('../util/eventBaton').EventBaton;
|
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||||
var LevelArbiter = require('../level/arbiter').LevelArbiter;
|
var LevelArbiter = require('../level/arbiter').LevelArbiter;
|
||||||
var LevelDropdownView = require('../views/levelDropdownView').LevelDropdownView;
|
var LevelDropdownView = require('../views/levelDropdownView').LevelDropdownView;
|
||||||
|
@ -45,7 +42,6 @@ var init = function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
LocaleStore.subscribe(intlRefresh);
|
LocaleStore.subscribe(intlRefresh);
|
||||||
events.on('localeChanged', intlRefresh);
|
|
||||||
events.on('vcsModeChange', vcsModeRefresh);
|
events.on('vcsModeChange', vcsModeRefresh);
|
||||||
|
|
||||||
initRootEvents(eventBaton);
|
initRootEvents(eventBaton);
|
||||||
|
@ -221,8 +217,7 @@ var initDemo = function(sandbox) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.locale !== undefined && params.locale.length) {
|
if (params.locale !== undefined && params.locale.length) {
|
||||||
GlobalState.locale = params.locale;
|
LocaleActions.changeLocale(params.locale);
|
||||||
events.trigger('localeChanged');
|
|
||||||
} else {
|
} else {
|
||||||
tryLocaleDetect();
|
tryLocaleDetect();
|
||||||
}
|
}
|
||||||
|
@ -255,8 +250,6 @@ function tryLocaleDetect() {
|
||||||
|
|
||||||
function changeLocaleFromHeaders(langString) {
|
function changeLocaleFromHeaders(langString) {
|
||||||
LocaleActions.changeLocaleFromHeader(langString);
|
LocaleActions.changeLocaleFromHeader(langString);
|
||||||
GlobalState.locale = LocaleStore.getLocale();
|
|
||||||
events.trigger('localeChanged');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require('../util').isBrowser()) {
|
if (require('../util').isBrowser()) {
|
||||||
|
@ -292,8 +285,6 @@ function CommandUI() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.changeLocaleFromHeaders = changeLocaleFromHeaders;
|
|
||||||
|
|
||||||
exports.getEvents = function() {
|
exports.getEvents = function() {
|
||||||
return events;
|
return events;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,44 +1,14 @@
|
||||||
var _ = require('underscore');
|
var LocaleStore = require('../stores/LocaleStore');
|
||||||
var constants = require('../util/constants');
|
|
||||||
var util = require('../util');
|
|
||||||
var GlobalState = require('../util/globalState');
|
|
||||||
|
|
||||||
|
var _ = require('underscore');
|
||||||
var strings = require('../intl/strings').strings;
|
var strings = require('../intl/strings').strings;
|
||||||
|
|
||||||
var getDefaultLocale = exports.getDefaultLocale = function() {
|
var getDefaultLocale = LocaleStore.getDefaultLocale;
|
||||||
return 'en_US';
|
|
||||||
};
|
|
||||||
|
|
||||||
var headerLocaleMap = exports.headerLocaleMap = {
|
|
||||||
'zh-CN': 'zh_CN',
|
|
||||||
'zh-TW': 'zh_TW',
|
|
||||||
'pt-BR': 'pt_BR',
|
|
||||||
};
|
|
||||||
|
|
||||||
// resolve the messy mapping between browser language
|
|
||||||
// and our supported locales
|
|
||||||
var langLocaleMap = exports.langLocaleMap = {
|
|
||||||
en: 'en_US',
|
|
||||||
zh: 'zh_CN',
|
|
||||||
ja: 'ja',
|
|
||||||
ko: 'ko',
|
|
||||||
es: 'es_AR',
|
|
||||||
fr: 'fr_FR',
|
|
||||||
de: 'de_DE',
|
|
||||||
pt: 'pt_BR'
|
|
||||||
};
|
|
||||||
|
|
||||||
var fallbackMap = {
|
var fallbackMap = {
|
||||||
'zh_TW': 'zh_CN'
|
'zh_TW': 'zh_CN'
|
||||||
};
|
};
|
||||||
|
|
||||||
var getLocale = exports.getLocale = function() {
|
|
||||||
if (GlobalState.locale) {
|
|
||||||
return GlobalState.locale;
|
|
||||||
}
|
|
||||||
return getDefaultLocale();
|
|
||||||
};
|
|
||||||
|
|
||||||
// lets change underscores template settings so it interpolates
|
// lets change underscores template settings so it interpolates
|
||||||
// things like "{branchName} does not exist".
|
// things like "{branchName} does not exist".
|
||||||
var templateSettings = _.clone(_.templateSettings);
|
var templateSettings = _.clone(_.templateSettings);
|
||||||
|
@ -61,7 +31,7 @@ var str = exports.str = function(key, params) {
|
||||||
// 'You can not delete the branch bugFix because you are currently on that branch!
|
// 'You can not delete the branch bugFix because you are currently on that branch!
|
||||||
// This is error number 3'
|
// This is error number 3'
|
||||||
|
|
||||||
var locale = getLocale();
|
var locale = LocaleStore.getLocale();
|
||||||
if (!strings[key]) {
|
if (!strings[key]) {
|
||||||
console.warn('NO INTL support for key ' + key);
|
console.warn('NO INTL support for key ' + key);
|
||||||
return 'NO INTL support for key ' + key;
|
return 'NO INTL support for key ' + key;
|
||||||
|
@ -98,7 +68,7 @@ var getIntlKey = exports.getIntlKey = function(obj, key) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj[key][getLocale()];
|
return obj[key][LocaleStore.getLocale()];
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.todo = function(str) {
|
exports.todo = function(str) {
|
||||||
|
@ -106,8 +76,7 @@ exports.todo = function(str) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getDialog = function(obj) {
|
exports.getDialog = function(obj) {
|
||||||
var defaultLocale = getDefaultLocale();
|
return getIntlKey(obj, 'dialog') || obj.dialog[getDefaultLocale()];
|
||||||
return getIntlKey(obj, 'dialog') || obj.dialog[defaultLocale];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getHint = function(level) {
|
exports.getHint = function(level) {
|
||||||
|
|
|
@ -10,6 +10,7 @@ var Errors = require('../util/errors');
|
||||||
var Visualization = require('../visuals/visualization').Visualization;
|
var Visualization = require('../visuals/visualization').Visualization;
|
||||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||||
var Level = require('../level').Level;
|
var Level = require('../level').Level;
|
||||||
|
var LocaleStore = require('../stores/LocaleStore');
|
||||||
|
|
||||||
var Command = require('../models/commandModel').Command;
|
var Command = require('../models/commandModel').Command;
|
||||||
var GitShim = require('../git/gitShim').GitShim;
|
var GitShim = require('../git/gitShim').GitShim;
|
||||||
|
@ -44,7 +45,7 @@ var LevelBuilder = Level.extend({
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.level = {};
|
options.level = {};
|
||||||
|
|
||||||
var locale = intl.getLocale();
|
var locale = LocaleStore.getLocale();
|
||||||
options.level.startDialog = {};
|
options.level.startDialog = {};
|
||||||
options.level.startDialog[locale] = {
|
options.level.startDialog[locale] = {
|
||||||
childViews: intl.getDialog(require('../dialogs/levelBuilder'))
|
childViews: intl.getDialog(require('../dialogs/levelBuilder'))
|
||||||
|
|
|
@ -8,6 +8,8 @@ var intl = require('../intl');
|
||||||
var Commands = require('../commands');
|
var Commands = require('../commands');
|
||||||
var Errors = require('../util/errors');
|
var Errors = require('../util/errors');
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
var CommandProcessError = Errors.CommandProcessError;
|
||||||
|
var LocaleStore = require('../stores/LocaleStore');
|
||||||
|
var LocaleActions = require('../actions/LocaleActions');
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
var Warning = Errors.Warning;
|
var Warning = Errors.Warning;
|
||||||
var CommandResult = Errors.CommandResult;
|
var CommandResult = Errors.CommandResult;
|
||||||
|
@ -24,13 +26,14 @@ var instantCommands = [
|
||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
[/^(locale|locale reset)$/, function(bits) {
|
[/^(locale|locale reset)$/, function(bits) {
|
||||||
GlobalState.locale = intl.getDefaultLocale();
|
LocaleActions.changeLocale(
|
||||||
var Main = require('../app').getEvents().trigger('localeChanged');
|
LocaleStore.getDefaultLocale()
|
||||||
|
);
|
||||||
|
|
||||||
throw new CommandResult({
|
throw new CommandResult({
|
||||||
msg: intl.str(
|
msg: intl.str(
|
||||||
'locale-reset-command',
|
'locale-reset-command',
|
||||||
{ locale: intl.getDefaultLocale() }
|
{ locale: LocaleStore.getDefaultLocale() }
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
|
@ -48,9 +51,7 @@ var instantCommands = [
|
||||||
});
|
});
|
||||||
}],
|
}],
|
||||||
[/^locale (\w+)$/, function(bits) {
|
[/^locale (\w+)$/, function(bits) {
|
||||||
GlobalState.locale = bits[1];
|
LocaleActions.changeLocale(bits[1]);
|
||||||
|
|
||||||
var Main = require('../app').getEvents().trigger('localeChanged');
|
|
||||||
throw new CommandResult({
|
throw new CommandResult({
|
||||||
msg: intl.str(
|
msg: intl.str(
|
||||||
'locale-command',
|
'locale-command',
|
||||||
|
|
|
@ -8,6 +8,7 @@ var assign = require('object-assign');
|
||||||
|
|
||||||
var ActionTypes = AppConstants.ActionTypes;
|
var ActionTypes = AppConstants.ActionTypes;
|
||||||
var CHANGE_EVENT = 'change';
|
var CHANGE_EVENT = 'change';
|
||||||
|
var DEFAULT_LOCALE = 'en_US';
|
||||||
|
|
||||||
// resolve the messy mapping between browser language
|
// resolve the messy mapping between browser language
|
||||||
// and our supported locales
|
// and our supported locales
|
||||||
|
@ -48,9 +49,13 @@ function _getLocaleFromHeader(langString) {
|
||||||
return desiredLocale;
|
return desiredLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _locale = 'en_US';
|
var _locale = DEFAULT_LOCALE;
|
||||||
var LocaleStore = assign({}, EventEmitter.prototype, {
|
var LocaleStore = assign({}, EventEmitter.prototype, {
|
||||||
|
|
||||||
|
getDefaultLocale: function() {
|
||||||
|
return DEFAULT_LOCALE;
|
||||||
|
},
|
||||||
|
|
||||||
getLangLocaleMap: function() {
|
getLangLocaleMap: function() {
|
||||||
return assign({}, langLocaleMap);
|
return assign({}, langLocaleMap);
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@ var _ = require('underscore');
|
||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
// horrible hack to get localStorage Backbone plugin
|
// horrible hack to get localStorage Backbone plugin
|
||||||
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
|
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
|
||||||
|
var LocaleStore = require('../stores/LocaleStore');
|
||||||
|
|
||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
var intl = require('../intl');
|
var intl = require('../intl');
|
||||||
|
@ -71,7 +72,7 @@ var LevelDropdownView = ContainedBase.extend({
|
||||||
this.render();
|
this.render();
|
||||||
|
|
||||||
Main.getEvents().on('resetMapSolved', this.render, this);
|
Main.getEvents().on('resetMapSolved', this.render, this);
|
||||||
Main.getEvents().on('localeChanged', this.render, this);
|
LocaleStore.subscribe(this.render.bind(this));
|
||||||
|
|
||||||
if (!options.wait) {
|
if (!options.wait) {
|
||||||
this.show();
|
this.show();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue