gpt4 book ai didi

php - "double underscore"和 "underscore x"有什么区别?

转载 作者:可可西里 更新时间:2023-11-01 00:42:42 28 4
gpt4 key购买 nike

在 PHP 中,特别是在 Wordpress 中,__('string')_x('string') 有什么区别?

我正在阅读 Wordpress 文档并感到困惑。以下混淆的好例子来自 Wordpress doc 上的示例代码对于 register_post_type():

$labels = array(
'name' => _x( 'Books', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Book', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Books', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Book', 'your-plugin-textdomain' ),
'new_item' => __( 'New Book', 'your-plugin-textdomain' ),
'edit_item' => __( 'Edit Book', 'your-plugin-textdomain' ),
'view_item' => __( 'View Book', 'your-plugin-textdomain' ),
'all_items' => __( 'All Books', 'your-plugin-textdomain' ),
'search_items' => __( 'Search Books', 'your-plugin-textdomain' ),
'parent_item_colon' => __( 'Parent Books:', 'your-plugin-textdomain' ),
'not_found' => __( 'No books found.', 'your-plugin-textdomain' ),
'not_found_in_trash' => __( 'No books found in Trash.', 'your-plugin-textdomain' )
);

最佳答案

在WordPress中,_x()__()都是翻译函数。 _x() 允许您为翻译指定上下文:

<?php _x( $text, $context, $domain ); ?>

__() 不会:

<?php __( $text, $domain ); ?>

上下文选项在直译可能无法产生预期结果的各种情况下很有用。

Since the string 'Read' on its own could have one of several different meanings in English, context is given so that translators know that they should be supplying a short term that means "Books I have read."

一些其他示例可能是:“日期”、“类型”、“正确”、“叶子”等。

来源:WordPress Codex

关于php - "double underscore"和 "underscore x"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30113638/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com