简体   繁体   English

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

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

When you type in an unavailable option in the multiple select box in chosen.js, it will generate the output 'No results match " query "'. 当您在selected.js中的多选框中键入不可用选项时,它将生成输出'无结果匹配' 查询 “'。 Is there a way to change the output language? 有没有办法改变输出语言? 请参阅底部的文字。

You're able to change 3 messages. 您可以更改3条消息。 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. 在这种情况下,它已被翻译成葡萄牙语。

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. 除此之外,似乎没有任何i18n支持。

If you look in the source code of chosen.js you will find these: 如果你查看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 is using the global namespace so think you can simply say: AbstractChosen正在使用全局命名空间,所以你可以简单地说:

 AbstractChosen.default_no_result_text = 'My default text'; 

And be sure to set the default_no_result_text before initializing any components. 并且一定要在初始化任何组件之前设置default_no_result_text

You can later on overwrite this value on specific components: (Assuming you are using jQuery): 您可以稍后在特定组件上覆盖此值:(假设您使用的是jQuery):

config.js config.js

 AbstractChosen.default_no_result_text = 'default no result text:' 

app.js app.js

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

The API is changed and the above wont work API已更改,上述内容无效

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. 您必须为每个selected()调用指定它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM