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

时间:2013-05-21 12:05:56

标签: javascript jquery localization jquery-chosen

当您在selected.js中的多个选择框中键入不可用选项时,它将生成输出'无结果匹配'查询“'。有没有办法改变输出语言? See the text on the bottom.

4 个答案:

答案 0 :(得分:10)

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

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

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

答案 1 :(得分:5)

您可以为其设置默认消息 -

// 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支持。

答案 2 :(得分:1)

如果你查看source code of chosen.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已更改,上述内容无效

答案 3 :(得分:0)

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

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