How to change the language for alerts in chosen.js?

你说的曾经没有我的故事 提交于 2019-12-08 17:20:44

问题


When you type in an unavailable option in the multiple select box in chosen.js, it will generate the output 'No results match "query"'. Is there a way to change the output language?


回答1:


You can set default message for it -

// 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"});

Except this, there doesn't seem to be any i18n support.




回答2:


You're able to change 3 messages. Single selection, Multiple selection and no results text.

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

In this case it has been translated to Portuguese.




回答3:


If you look in the source code of chosen.js you will find these:

AbstractChosen.default_multiple_text = "Select Some Options";

AbstractChosen.default_single_text = "Select an Option";

AbstractChosen.default_no_result_text = "No results match";

AbstractChosen is using the global namespace so think you can simply say:

AbstractChosen.default_no_result_text = 'My default text';

And be sure to set the default_no_result_text before initializing any components.

You can later on overwrite this value on specific components: (Assuming you are using 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'
});

The API is changed and the above wont work




回答4:


If you place that line of code in any place, browser console will say:

No way to override default texts globally. You have to specify them for every chosen() call.



来源:https://stackoverflow.com/questions/16669592/how-to-change-the-language-for-alerts-in-chosen-js

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