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

translation - Get Text Domain For Transalation

programmeradmin0浏览0评论

Is there a function which can be used to get the themes text-domain?

For example, if i want to provide this code to users without them needing to swap out the text-domain, can this be done, rather than this :

register_sidebar(
        array(
            'name'          => __( 'Widget Area', 'twentynineteen' ),
            'id'            => 'widget-id',
        ));

Use something like this so they don't need to change the text-domain to match the theme they are using :

 register_sidebar(
        array(
            'name'          => __( 'Widget Area', get_text_domain() ),
            'id'            => 'widget-id',
        ));

Is there a function which can be used to get the themes text-domain?

For example, if i want to provide this code to users without them needing to swap out the text-domain, can this be done, rather than this :

register_sidebar(
        array(
            'name'          => __( 'Widget Area', 'twentynineteen' ),
            'id'            => 'widget-id',
        ));

Use something like this so they don't need to change the text-domain to match the theme they are using :

 register_sidebar(
        array(
            'name'          => __( 'Widget Area', get_text_domain() ),
            'id'            => 'widget-id',
        ));
Share Improve this question edited Oct 15, 2020 at 10:07 Brad Dalton asked Oct 15, 2020 at 5:48 Brad DaltonBrad Dalton 6,9652 gold badges36 silver badges47 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

No, there isn't. The text domain needs to be hard coded, otherwise it can't be read by localization tools which parse the code without executing it.

See this note from the Internationalization documentation

The text domain should be passed as a string to the localization functions instead of a variable. It allows parsing tools to differentiate between text domains. Example of what not to do:

__( 'Translate me.' , $text_domain );

The string itself also cannot be a variable or function for the same reason.

发布评论

评论列表(0)

  1. 暂无评论