问题
I wish to override a NLS file (dijit/form/validate.js) file with a new one, or replace some of the NLS string mappings. I want this file to be picked up by the standard Dijits.
I do not wish to delete the file in the standard Dojo library. Can I specify a path in djConfig to search directories for NLS files in order so my new file is picked up instead of the the original? If so, how do I do this?
Alternatively how can I mix in a new definition of a string i.e
replace:
missingMessage: "This value is required.",
with:
missingMessage: "My string is here.",
回答1:
If you want to do literally what you request and pick an alternate file for the dijit/form/nls/validate
i18n modules, you can use the map property to remap the module IDs (1.8+):
var dojoConfig = {
map: { dijit: {
'dijit/form/nls/validate': 'my/form/nls/validate',
'dijit/form/nls/en/validate': 'my/form/nls/en/validate',
// ... etc
} }
};
However, the standard and recommended method for overriding the messages on a validation widget are to just set the message properties using your own values:
define([
'dijit/form/ValidationTextBox',
'dojo/i18n!my/form/validate'
], function (ValidationTextBox, myI18n) {
var instance = new ValidationTextBox({ missingMessage: myI18n.missingMessage });
// ...
});
来源:https://stackoverflow.com/questions/17342386/replacing-dojo-dijit-nls-strings