最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Make dynamic string translatable

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论