Replacing Dojo/Dijit NLS strings

醉酒当歌 提交于 2019-12-11 14:06:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!