首页 > 解决方案 > 我想了解主题开发中的翻译功能

问题描述

我很困惑在主题开发中使用翻译功能,特别是使用默认值。

  1. 在customizer.php 中

       $wp_customize->add_setting('section_title', array(
                    'default' => 'TESTIMONIALS',
                    'transport' => 'postMessage',
                    'sanitize_callback' => 'sanitize_text_field',
                    ));
    
                $wp_customize->add_control('section_title',array(
                    'type' => 'text',
                    'label' => __('Title','theme-food'),
                    'section' => 'main_section',
                    'setting' => 'section_title',
                    ));    
    

    在这行 'default' => 'TESTIMONIALS' 中,我将使用哪个函数?__ , _e 或任何其他。

  2. 当我回显时在 main.php 文件中 ---------- echo esc_html(get_theme_mod('section_title', __('TESTIMONIALS', 'theme-food'));

'TESTIMONIALS' 是 'section_title' 的默认值,那么在默认值之前使用哪个函数是正确的?__ , _e 或任何其他。

标签: phpwordpressfunctionthemestranslation

解决方案


默认情况下,您不需要使用翻译功能。如果你愿意,你也可以翻译它们。的值default应该是string. 您将了解如何在下面提到的这些链接中使字符串可翻译,并且您将对 WordPress 翻译有一个清晰的认识。

的值default最初并不存储在数据库中。

重要链接:

https://developer.wordpress.org/reference/functions/__/

https://codex.wordpress.org/I18n_for_WordPress_Developers


推荐阅读