mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 00:40:07 +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 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(
|
||||
CasperUtils.getUrl(),
|
||||
|
@ -18,16 +31,6 @@ casper.start(
|
|||
|
||||
Object.keys(langLocaleMap).forEach(function(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) {
|
||||
debug_LocaleActions_changeLocaleFromHeader(lang);
|
||||
return debug_LocaleStore_getLocale();
|
||||
|
|
|
@ -7,6 +7,11 @@ var ActionTypes = AppConstants.ActionTypes;
|
|||
|
||||
describe('LocaleStore', function() {
|
||||
|
||||
it('has default locale', function() {
|
||||
expect(LocaleStore.getLocale())
|
||||
.toEqual(LocaleStore.getDefaultLocale());
|
||||
});
|
||||
|
||||
it('changes locales', function() {
|
||||
expect(LocaleStore.getLocale()).toEqual('en_US');
|
||||
LocaleActions.changeLocale('ja_JP');
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
var _ = require('underscore');
|
||||
var Backbone = require('backbone');
|
||||
|
||||
var constants = require('../util/constants');
|
||||
var util = require('../util');
|
||||
var intl = require('../intl');
|
||||
var GlobalState = require('../util/globalState');
|
||||
var LocaleStore = require('../stores/LocaleStore');
|
||||
var LocaleActions = require('../actions/LocaleActions');
|
||||
|
||||
|
@ -31,7 +29,6 @@ var init = function() {
|
|||
* - handling window.focus and zoom events
|
||||
**/
|
||||
var Sandbox = require('../sandbox/').Sandbox;
|
||||
var Level = require('../level').Level;
|
||||
var EventBaton = require('../util/eventBaton').EventBaton;
|
||||
var LevelArbiter = require('../level/arbiter').LevelArbiter;
|
||||
var LevelDropdownView = require('../views/levelDropdownView').LevelDropdownView;
|
||||
|
@ -45,7 +42,6 @@ var init = function() {
|
|||
});
|
||||
|
||||
LocaleStore.subscribe(intlRefresh);
|
||||
events.on('localeChanged', intlRefresh);
|
||||
events.on('vcsModeChange', vcsModeRefresh);
|
||||
|
||||
initRootEvents(eventBaton);
|
||||
|
@ -221,8 +217,7 @@ var initDemo = function(sandbox) {
|
|||
}
|
||||
|
||||
if (params.locale !== undefined && params.locale.length) {
|
||||
GlobalState.locale = params.locale;
|
||||
events.trigger('localeChanged');
|
||||
LocaleActions.changeLocale(params.locale);
|
||||
} else {
|
||||
tryLocaleDetect();
|
||||
}
|
||||
|
@ -255,8 +250,6 @@ function tryLocaleDetect() {
|
|||
|
||||
function changeLocaleFromHeaders(langString) {
|
||||
LocaleActions.changeLocaleFromHeader(langString);
|
||||
GlobalState.locale = LocaleStore.getLocale();
|
||||
events.trigger('localeChanged');
|
||||
}
|
||||
|
||||
if (require('../util').isBrowser()) {
|
||||
|
@ -292,8 +285,6 @@ function CommandUI() {
|
|||
});
|
||||
}
|
||||
|
||||
exports.changeLocaleFromHeaders = changeLocaleFromHeaders;
|
||||
|
||||
exports.getEvents = function() {
|
||||
return events;
|
||||
};
|
||||
|
|
|
@ -1,44 +1,14 @@
|
|||
var _ = require('underscore');
|
||||
var constants = require('../util/constants');
|
||||
var util = require('../util');
|
||||
var GlobalState = require('../util/globalState');
|
||||
var LocaleStore = require('../stores/LocaleStore');
|
||||
|
||||
var _ = require('underscore');
|
||||
var strings = require('../intl/strings').strings;
|
||||
|
||||
var getDefaultLocale = exports.getDefaultLocale = function() {
|
||||
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 getDefaultLocale = LocaleStore.getDefaultLocale;
|
||||
|
||||
var fallbackMap = {
|
||||
'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
|
||||
// things like "{branchName} does not exist".
|
||||
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!
|
||||
// This is error number 3'
|
||||
|
||||
var locale = getLocale();
|
||||
var locale = LocaleStore.getLocale();
|
||||
if (!strings[key]) {
|
||||
console.warn('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) {
|
||||
|
@ -106,8 +76,7 @@ exports.todo = function(str) {
|
|||
};
|
||||
|
||||
exports.getDialog = function(obj) {
|
||||
var defaultLocale = getDefaultLocale();
|
||||
return getIntlKey(obj, 'dialog') || obj.dialog[defaultLocale];
|
||||
return getIntlKey(obj, 'dialog') || obj.dialog[getDefaultLocale()];
|
||||
};
|
||||
|
||||
exports.getHint = function(level) {
|
||||
|
|
|
@ -10,6 +10,7 @@ var Errors = require('../util/errors');
|
|||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
var Level = require('../level').Level;
|
||||
var LocaleStore = require('../stores/LocaleStore');
|
||||
|
||||
var Command = require('../models/commandModel').Command;
|
||||
var GitShim = require('../git/gitShim').GitShim;
|
||||
|
@ -44,7 +45,7 @@ var LevelBuilder = Level.extend({
|
|||
options = options || {};
|
||||
options.level = {};
|
||||
|
||||
var locale = intl.getLocale();
|
||||
var locale = LocaleStore.getLocale();
|
||||
options.level.startDialog = {};
|
||||
options.level.startDialog[locale] = {
|
||||
childViews: intl.getDialog(require('../dialogs/levelBuilder'))
|
||||
|
|
|
@ -8,6 +8,8 @@ var intl = require('../intl');
|
|||
var Commands = require('../commands');
|
||||
var Errors = require('../util/errors');
|
||||
var CommandProcessError = Errors.CommandProcessError;
|
||||
var LocaleStore = require('../stores/LocaleStore');
|
||||
var LocaleActions = require('../actions/LocaleActions');
|
||||
var GitError = Errors.GitError;
|
||||
var Warning = Errors.Warning;
|
||||
var CommandResult = Errors.CommandResult;
|
||||
|
@ -24,13 +26,14 @@ var instantCommands = [
|
|||
});
|
||||
}],
|
||||
[/^(locale|locale reset)$/, function(bits) {
|
||||
GlobalState.locale = intl.getDefaultLocale();
|
||||
var Main = require('../app').getEvents().trigger('localeChanged');
|
||||
LocaleActions.changeLocale(
|
||||
LocaleStore.getDefaultLocale()
|
||||
);
|
||||
|
||||
throw new CommandResult({
|
||||
msg: intl.str(
|
||||
'locale-reset-command',
|
||||
{ locale: intl.getDefaultLocale() }
|
||||
{ locale: LocaleStore.getDefaultLocale() }
|
||||
)
|
||||
});
|
||||
}],
|
||||
|
@ -48,9 +51,7 @@ var instantCommands = [
|
|||
});
|
||||
}],
|
||||
[/^locale (\w+)$/, function(bits) {
|
||||
GlobalState.locale = bits[1];
|
||||
|
||||
var Main = require('../app').getEvents().trigger('localeChanged');
|
||||
LocaleActions.changeLocale(bits[1]);
|
||||
throw new CommandResult({
|
||||
msg: intl.str(
|
||||
'locale-command',
|
||||
|
|
|
@ -8,6 +8,7 @@ var assign = require('object-assign');
|
|||
|
||||
var ActionTypes = AppConstants.ActionTypes;
|
||||
var CHANGE_EVENT = 'change';
|
||||
var DEFAULT_LOCALE = 'en_US';
|
||||
|
||||
// resolve the messy mapping between browser language
|
||||
// and our supported locales
|
||||
|
@ -48,9 +49,13 @@ function _getLocaleFromHeader(langString) {
|
|||
return desiredLocale;
|
||||
}
|
||||
|
||||
var _locale = 'en_US';
|
||||
var _locale = DEFAULT_LOCALE;
|
||||
var LocaleStore = assign({}, EventEmitter.prototype, {
|
||||
|
||||
getDefaultLocale: function() {
|
||||
return DEFAULT_LOCALE;
|
||||
},
|
||||
|
||||
getLangLocaleMap: function() {
|
||||
return assign({}, langLocaleMap);
|
||||
},
|
||||
|
|
|
@ -2,6 +2,7 @@ var _ = require('underscore');
|
|||
var Q = require('q');
|
||||
// horrible hack to get localStorage Backbone plugin
|
||||
var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.Backbone;
|
||||
var LocaleStore = require('../stores/LocaleStore');
|
||||
|
||||
var util = require('../util');
|
||||
var intl = require('../intl');
|
||||
|
@ -71,7 +72,7 @@ var LevelDropdownView = ContainedBase.extend({
|
|||
this.render();
|
||||
|
||||
Main.getEvents().on('resetMapSolved', this.render, this);
|
||||
Main.getEvents().on('localeChanged', this.render, this);
|
||||
LocaleStore.subscribe(this.render.bind(this));
|
||||
|
||||
if (!options.wait) {
|
||||
this.show();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue