plugins - Internationalization autocomplete JS variable

I'm working in a plugin (My first plugin) that uses autocomplete (Via JQuery UI) via an array and I'm wonderin

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

And 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;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745542305a4632182.html

相关推荐

  • plugins - Internationalization autocomplete JS variable

    I'm working in a plugin (My first plugin) that uses autocomplete (Via JQuery UI) via an array and I'm wonderin

    22小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信