plugin development - Make dynamic string translatable

I have a plugin where people can add their own (title) somewhere, but this title is not picked up by multilingual plugin

I have a plugin where people can add their own (title) somewhere, but this title is not picked up by multilingual plugins.

Reason for that is that I'm not using the __() function of course, I'm just echoing the option value that the user has input.

For example echo esc_html( $my_title );

How can I make it translatable? Would echo esc_html__( $my_title, 'text-domain' ) work? I don't think so, I mean what would people see as the original string?

How WP would handle this?

I have a plugin where people can add their own (title) somewhere, but this title is not picked up by multilingual plugins.

Reason for that is that I'm not using the __() function of course, I'm just echoing the option value that the user has input.

For example echo esc_html( $my_title );

How can I make it translatable? Would echo esc_html__( $my_title, 'text-domain' ) work? I don't think so, I mean what would people see as the original string?

How WP would handle this?

Share Improve this question asked May 27, 2019 at 14:04 mrKC.988mrKC.988 1072 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

No, you wouldn't use the translation functions (__(), _e() etc.). Those are for creating language files and must only be used on static strings. They need to be static because the tools for generating the language files don't execute PHP, so they can't process variables. They just parse the text of the code, essentially.

If you want to support multilingual plugins then you need to build that support in manually with whatever methods those plugins require. WordPress won't help you here. So you'll need to check the developer documentation of the multilingual plugins that you want to support. Here's some documentation for adding multilingual support for custom content for WPML, for example.

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

相关推荐

  • plugin development - Make dynamic string translatable

    I have a plugin where people can add their own (title) somewhere, but this title is not picked up by multilingual plugin

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信