函数文档

list_translation_updates()

💡 云策文档标注

概述

list_translation_updates() 函数用于显示 WordPress 翻译更新表单,检查是否有可用的语言更新,并根据当前区域设置输出相应内容。

关键要点

  • 函数调用 wp_get_translation_updates() 获取翻译更新列表,若无更新且非英语区域,则显示“Translations are all up to date”消息。
  • 当有更新时,生成一个表单,包含非ce字段和提交按钮,用于升级翻译。
  • 函数涉及多个核心函数如 get_locale()、wp_nonce_field() 和 esc_url(),确保安全性和本地化处理。

代码示例

function list_translation_updates() {
    $updates = wp_get_translation_updates();
    if ( ! $updates ) {
        if ( 'en_US' !== get_locale() ) {
            echo '' . __( 'Translations' ) . '';
            echo '' . __( 'Your translations are all up to date.' ) . '';
        }
        return;
    }

    $form_action = 'update-core.php?action=do-translation-upgrade';
    ?>
    <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
        <?php wp_nonce_field( 'upgrade-translations' ); ?>
        <p><input type="submit" class="button" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
    </form>
    <?php
}

注意事项

  • 此函数自 WordPress 3.7.0 版本引入,主要用于核心更新界面。
  • 使用时需确保相关 Hook 和函数如 wp_get_translation_updates() 正常工作,以正确检测翻译更新。

📄 原文内容

Display the update translations form.

Source

function list_translation_updates() {
$updates = wp_get_translation_updates();
if ( ! $updates ) {
if ( 'en_US' !== get_locale() ) {
echo '<h2>' . __( 'Translations' ) . '</h2>';
echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
}
return;
}

$form_action = 'update-core.php?action=do-translation-upgrade';
?>
<h2></h2>
<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
<p></p>

<p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
</form>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/update-core.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/update-core.php#L815">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/update-core.php#L815-L834">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/esc_attr_e/">esc_attr_e()</a><code>wp-includes/l10n.php

Displays translated text that has been escaped for safe use in an attribute.

get_locale()wp-includes/l10n.php

Retrieves the current locale.

wp_nonce_field()wp-includes/functions.php

Retrieves or display nonce hidden field for forms.

wp_get_translation_updates()wp-includes/update.php

Retrieves a list of all language updates available.

__()wp-includes/l10n.php

Retrieves the translation of $text.

_e()wp-includes/l10n.php

Displays translated text.

esc_url()wp-includes/formatting.php

Checks and cleans a URL.

Show 3 moreShow less

Changelog

Version Description
3.7.0 Introduced.