WordPress(含WooCommerce)翻译异常求助:部分文本仍为英文
Let's break down why your partial translation issue is happening and how to fix it—since switching to the parent theme works, the problem is almost certainly tied to how your child theme handles translations or inherits the parent theme's setup. Here are actionable steps to resolve this:
1. Ensure Your Child Theme Loads Parent Theme Translations
Child themes don’t automatically inherit parent theme translation files by default. You need to explicitly load them in your child theme’s functions.php file. Add this code (replace parent-theme-slug with your actual parent theme’s slug, e.g., storefront for the default WooCommerce theme):
add_action( 'after_setup_theme', 'child_theme_load_parent_translations' ); function child_theme_load_parent_translations() { // Load parent theme's translation domain load_theme_textdomain( 'parent-theme-slug', get_template_directory() . '/languages' ); }
This ensures your child theme pulls in all translated strings from the parent theme’s language files, including those integrated with WooCommerce.
2. Check for Hardcoded English Text in Your Child Theme
If you’ve customized templates in your child theme, some strings might be hardcoded (written directly as English instead of using WordPress translation functions). For example, instead of:
<button>Add to Cart</button>
It should use:
<button><?php _e( 'Add to Cart', 'child-theme-slug' ); ?></button>
Search all files in your child theme directory for untranslated strings. Wrap any you find in __() (for returning text) or _e() (for echoing text) functions, then update your child theme’s .po/.mo translation files to include these new strings.
3. Verify WooCommerce Translation File Loading
Child themes can sometimes interfere with how WooCommerce loads its translations. First, make sure your child theme isn’t overriding the load_plugin_textdomain hook for WooCommerce. Then, copy the WooCommerce translation files (e.g., woocommerce-xx_XX.mo and woocommerce-xx_XX.po, where xx_XX is your locale) into your child theme’s languages/woocommerce directory. This ensures the child theme uses the correct WooCommerce translations alongside the parent theme’s.
4. Clear All Caches
Translation issues often stick around due to cached content. Clear:
- Your WordPress caching plugin’s cache (if using tools like WP Rocket or W3 Total Cache)
- Your browser’s local cache
- Any CDN cache you have enabled
After clearing, reload your site to check if the untranslated strings update.
5. Check Parent Theme’s WooCommerce Template Overrides
If your parent theme overrides default WooCommerce templates (stored in parent-theme/woocommerce/), your child theme might inherit these templates. Make sure any template files you’ve copied to your child theme (in child-theme/woocommerce/) use translation functions correctly, and that your child theme’s language files include translations for custom strings in those templates.
内容的提问来源于stack exchange,提问作者Rallyholic

