当我使用阿拉伯语时,“我的帐户”页面中的“地址”选项卡未以网站语言显示,而应该已经翻译了。
它的占位符“屏幕截图中突出显示的空白区域”仍然有效,并按预期导航到正确的页面。
我正在使用最新的 WordPress 5.5 和 WooCommerce 4.4.1,如果我切换到英语并且之前使用阿拉伯语 AFAIK,它可以正常工作。
出于测试目的,我使用 TranslatePress 插件为字符串插入阿拉伯语翻译,它仅在使用插件时有效。
我还尝试使用开发人员控制台进行调试并尝试使用以下代码无济于事,甚至在使用默认主题时也存在该问题。
1- 负责显示菜单标签的代码:wp-content\plugins\woocommerce emplates\myaccount 航海.php
<nav class="woocommerce-MyAccount-navigation">
<ul>
<?php foreach ( wc_get_account_menu_items() as $endpoint => $label ) : ?>
<li class="<?php echo wc_get_account_menu_item_classes( $endpoint ); ?>">
<a href="<?php echo esc_url( wc_get_account_endpoint_url( $endpoint ) ); ?>"><?php echo esc_html( $label ); ?></a>
</li>
<?php endforeach; ?>
</ul>
</nav>
<?php do_action( 'woocommerce_after_account_navigation' ); ?>
2- 显示的项目代码,如果我将“地址”更改为其他内容,则会显示:wp-content\plugins\woocommerce\includes\wc-account-functions.php
$items = array(
'dashboard' => __( 'Dashboard', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'edit-address' => _n( 'Addresses', 'Address', (int) wc_shipping_enabled(), 'woocommerce' ),
'payment-methods' => __( 'Payment methods', 'woocommerce' ),
'edit-account' => __( 'Account details', 'woocommerce' ),
'customer-logout' => __( 'Logout', 'woocommerce' ),
);
3- 翻译字符串:wp-content\languages\plugins\woocommerce-ar.po
#: includes/class-wc-query.php:126
#: includes/admin/settings/class-wc-settings-advanced.php:284
#: includes/wc-account-functions.php:102
msgid "Addresses"
msgid_plural "Address"
msgstr[0] "العناوين"
msgstr[1] ""
msgstr[2] ""
msgstr[3] ""
msgstr[4] ""
msgstr[5] ""
根据 github 问题反馈和插件目录上的 woocommerce 支持论坛更新阿拉伯语翻译 PO 和 MO 文件,使用 Loco Translate 解决了这个问题。
https://github.com/woocommerce/woocommerce/issues/27428 和 https://wordpress.org/support/topic/updating-translations-after-updates/
我的解决方案是使用 javascript 代码
let addressLink=document.querySelector('.woocommerce-MyAccount-navigation-link--edit-address a')
if (addressLink!=null) {
if(addressLink.innerText==""){
addressLink.innerText="العنوان"
}}