admin管理员组文章数量:1022956
I'm working in a plugin (My first plugin) that uses autocomplete (Via JQuery UI) via an array and I'm wondering if I have to translate the array too if I want to make my plugin fully translatable.
jQuery(function(){
let supportedServices = [
'Academia', 'Airbnb', 'Amazon', 'AppStore', 'Bandcamp', 'Blogger',
];
jQuery('#service_name ').autocomplete({
source: supportedServices,
classes: {
"ui-autocomplete": "contactmefy_ui_autocomplete"
},
select: SomeFunction,
});
});
In that case, it's a good idea to use the new wp-i18n JavaScript package? Internationalization in WordPress 5.0
I'm working in a plugin (My first plugin) that uses autocomplete (Via JQuery UI) via an array and I'm wondering if I have to translate the array too if I want to make my plugin fully translatable.
jQuery(function(){
let supportedServices = [
'Academia', 'Airbnb', 'Amazon', 'AppStore', 'Bandcamp', 'Blogger',
];
jQuery('#service_name ').autocomplete({
source: supportedServices,
classes: {
"ui-autocomplete": "contactmefy_ui_autocomplete"
},
select: SomeFunction,
});
});
In that case, it's a good idea to use the new wp-i18n JavaScript package? Internationalization in WordPress 5.0
Share Improve this question asked Apr 29, 2019 at 7:49 Marco DiazMarco Diaz 133 bronze badges1 Answer
Reset to default 1And I'm wondering if I have to translate the array too if I want to make my plugin fully translatable.
It wouldn't be fully translatable if you didn't, would it? So yes, you need to make these translatable for that to be true.
In that case, it's a good idea to use the new wp-i18n JavaScript package? Internationalization in WordPress 5.0
It could be, yes. The previous way, which still works, is what wp_localize_script()
is for. For example, if you enqueue this script like this:
wp_enqueue_script( 'my-plugin', // etc. etc.
Then you can provide translatable strings like this:
wp_localize_script(
'my-plugin',
'myPlugin',
[
'supportedServices' => [
__( 'Academia', 'my-plugin' ),
__( 'Airbnb', 'my-plugin' ),
__( 'Amazon', 'my-plugin' ),
__( 'AppStore', 'my-plugin' ),
__( 'Bandcamp', 'my-plugin' ),
__( 'Blogger','my-plugin' ),
],
]
);
The supported service names would now be translatable in PHP, but you can access them in JavaScript like this:
let supportedServices = myPlugin.supportedServices;
I'm working in a plugin (My first plugin) that uses autocomplete (Via JQuery UI) via an array and I'm wondering if I have to translate the array too if I want to make my plugin fully translatable.
jQuery(function(){
let supportedServices = [
'Academia', 'Airbnb', 'Amazon', 'AppStore', 'Bandcamp', 'Blogger',
];
jQuery('#service_name ').autocomplete({
source: supportedServices,
classes: {
"ui-autocomplete": "contactmefy_ui_autocomplete"
},
select: SomeFunction,
});
});
In that case, it's a good idea to use the new wp-i18n JavaScript package? Internationalization in WordPress 5.0
I'm working in a plugin (My first plugin) that uses autocomplete (Via JQuery UI) via an array and I'm wondering if I have to translate the array too if I want to make my plugin fully translatable.
jQuery(function(){
let supportedServices = [
'Academia', 'Airbnb', 'Amazon', 'AppStore', 'Bandcamp', 'Blogger',
];
jQuery('#service_name ').autocomplete({
source: supportedServices,
classes: {
"ui-autocomplete": "contactmefy_ui_autocomplete"
},
select: SomeFunction,
});
});
In that case, it's a good idea to use the new wp-i18n JavaScript package? Internationalization in WordPress 5.0
Share Improve this question asked Apr 29, 2019 at 7:49 Marco DiazMarco Diaz 133 bronze badges1 Answer
Reset to default 1And I'm wondering if I have to translate the array too if I want to make my plugin fully translatable.
It wouldn't be fully translatable if you didn't, would it? So yes, you need to make these translatable for that to be true.
In that case, it's a good idea to use the new wp-i18n JavaScript package? Internationalization in WordPress 5.0
It could be, yes. The previous way, which still works, is what wp_localize_script()
is for. For example, if you enqueue this script like this:
wp_enqueue_script( 'my-plugin', // etc. etc.
Then you can provide translatable strings like this:
wp_localize_script(
'my-plugin',
'myPlugin',
[
'supportedServices' => [
__( 'Academia', 'my-plugin' ),
__( 'Airbnb', 'my-plugin' ),
__( 'Amazon', 'my-plugin' ),
__( 'AppStore', 'my-plugin' ),
__( 'Bandcamp', 'my-plugin' ),
__( 'Blogger','my-plugin' ),
],
]
);
The supported service names would now be translatable in PHP, but you can access them in JavaScript like this:
let supportedServices = myPlugin.supportedServices;
本文标签: pluginsInternationalization autocomplete JS variable
版权声明:本文标题:plugins - Internationalization autocomplete JS variable 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745542303a2155237.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论