mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
Basic dialog intl support for level dialogs, Issue #42
This commit is contained in:
parent
2837315c7d
commit
2617357460
21 changed files with 1716 additions and 1388 deletions
62
src/js/intl/index.js
Normal file
62
src/js/intl/index.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
var _ = require('underscore');
|
||||
var constants = require('../util/constants');
|
||||
var util = require('../util');
|
||||
|
||||
var strings = require('../intl/strings').strings;
|
||||
|
||||
var str = exports.str = function(key, params) {
|
||||
// this function takes a key like "error-branch-delete"
|
||||
// and parameters like {branchName: 'bugFix', num: 3}.
|
||||
//
|
||||
// it sticks those into a translation string like:
|
||||
// 'en': 'You can not delete the branch {branchName} because' +
|
||||
// 'you are currently on that branch! This is error number + {num}'
|
||||
//
|
||||
// to produce:
|
||||
//
|
||||
// 'You can not delete the branch bugFix because you are currently on that branch!
|
||||
// This is error number 3'
|
||||
|
||||
var locale = util.getLocale();
|
||||
if (!strings[key]) {
|
||||
console.warn('NO INTL support for key ' + key);
|
||||
return 'NO INTL support for key ' + key;
|
||||
}
|
||||
|
||||
if (!strings[key][locale]) {
|
||||
if (key !== 'error-untranslated') {
|
||||
return str('error-untranslated');
|
||||
}
|
||||
return 'No translation for that key ' + key;
|
||||
}
|
||||
|
||||
// TODO - interpolation
|
||||
return strings[key][locale];
|
||||
};
|
||||
|
||||
var getStartDialog = exports.getStartDialog = function(level) {
|
||||
if (!level || !level.startDialog) {
|
||||
throw new Error('start dialog doesnt exist in that blob');
|
||||
}
|
||||
if (!level.startDialog.en) {
|
||||
console.warn('WARNING!! This dialog does not have intl support: ', level);
|
||||
}
|
||||
var locale = util.getLocale();
|
||||
if (level.startDialog[locale]) {
|
||||
return level.startDialog[locale];
|
||||
}
|
||||
|
||||
// we need to return english but add their locale error
|
||||
var startCopy = _.clone(level.startDialog.en || level.startDialog);
|
||||
var errorAlert = {
|
||||
type: 'ModalAlert',
|
||||
options: {
|
||||
markdown: str('error-untranslated')
|
||||
}
|
||||
};
|
||||
|
||||
startCopy.childViews.unshift(errorAlert);
|
||||
return startCopy;
|
||||
};
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue