如何更改selected.js中警报的语言?

当您在selected.js中的多个选择框中键入不可用选项时,它将生成输出’无结果匹配’ 查询 “’。 有没有办法改变输出语言? 请参阅底部的文字。

您可以为它设置默认消息 –

// jQuery version: https://github.com/harvesthq/chosen/blob/master/example.jquery.html $(".chzn-select").chosen({no_results_text: "Translated No results matched"}); // Prototype version: https://github.com/harvesthq/chosen/blob/master/example.proto.html new Chosen($$(".chzn-select")[element_index],{no_results_text: "Translated No results matched"}); 

除此之外,似乎没有任何i18n支持。

您可以更改3条消息。 单选,多选和无结果文本。

 $('#ID').chosen({ no_results_text: "Sem resultados para", placeholder_text_single: "Selecione uma opção", placeholder_text_multiple: "Selecione as opções" }); 

在这种情况下,它已被翻译成葡萄牙语。

如果您查看selected.js的源代码,您会发现:

 AbstractChosen.default_multiple_text = "Select Some Options"; AbstractChosen.default_single_text = "Select an Option"; AbstractChosen.default_no_result_text = "No results match"; 

AbstractChosen正在使用全局命名空间,所以你可以简单地说:

 AbstractChosen.default_no_result_text = 'My default text'; 

并且一定要在初始化任何组件之前设置default_no_result_text

您可以稍后在特定组件上覆盖此值:(假设您使用的是jQuery):

config.js

 AbstractChosen.default_no_result_text = 'default no result text:' 

app.js

 $(select).chosen({ no_result_text: 'specific no result text for this component' }); 

API已更改,上述内容无效

如果您将该行代码放在任何地方,浏览器控制台会说:

无法全局覆盖默认文本。 您必须为每个selected()调用指定它们。