### Update Portable Object (.po) File with WP-CLI Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Command to update an existing .po file, typically after new strings have been added to the source code. This synchronizes the .po file with the latest .pot template. ```shell wp i18n update-po path/to/lang-dir/text-domain-locale.po ``` -------------------------------- ### Generate Machine Object (.mo) File with WP-CLI Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Command to compile a .po file into a binary .mo file. The .mo file is the actual file WordPress uses to load translations, offering optimized performance for string lookups. ```shell wp i18n make-mo path/to/lang-dir/text-domain-locale.po path/to/lang-dir/text-domain-locale.mo ``` -------------------------------- ### Enqueue JavaScript with WordPress i18n Dependency Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Shows how to enqueue a JavaScript file in WordPress using `wp_enqueue_script`, ensuring the `wp-i18n` dependency is included. This is crucial for enabling client-side translation capabilities. ```php wp_enqueue_script('script-name', Plugin::get_url('/path/to/your/script-name.js'), ['wp-i18n']); ``` -------------------------------- ### Translate Strings in PHP Files using WordPress Functions Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Demonstrates how to use WordPress's `__()` function for simple string translation and `sprintf()` for complex, formatted strings within PHP files. Requires a defined text domain for proper localization. ```php // Simple translation __('some text', 'text-domain'); // Complex translation with sprintf sprintf( __('some %s', 'text-domain'), __('text', 'text-domain') ); ``` -------------------------------- ### Generate Portable Object Template (.pot) File with WP-CLI Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Command to create a .pot file, which serves as a template for translations. It scans PHP, Blade-PHP, and JavaScript files for translatable strings. The `--domain` argument specifies the text domain, and the output path is provided. Use `--merge` to combine with an existing .pot file. ```shell wp i18n make-pot . path/to/lang-dir/text-domain-locale.pot --domain=text-domain ``` -------------------------------- ### Set JavaScript Translation Source for WordPress Scripts Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Illustrates how to use `wp_set_script_translations` to link a JavaScript file with its translation domain and the directory containing its language files. This function ensures the correct translation strings are loaded for the script. ```php wp_set_script_translations('script-name', 'text-domain', WP_PLUGIN_DIR . 'plugin-dir-name/path/to/your/lang-dir'); ``` -------------------------------- ### Load Plugin Text Domain for WordPress Internationalization Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Details how to load a plugin's text domain using `load_plugin_textdomain` within the plugin's initialization method. This function makes the plugin's strings translatable and specifies the path to its language files. Unlike `wp_set_script_translations`, `load_plugin_textdomain` uses `WP_PLUGIN_DIR` under the hood. ```php load_plugin_textdomain('text-domain', false, 'plugin-dir-name/path/to/lang-dir'); ``` -------------------------------- ### Translate Strings in JavaScript Files using wp.i18n Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Explains how to import and use the `__` and `sprintf` functions from `wp.i18n` in JavaScript files for client-side string translation. This requires the script to be enqueued with the `wp-i18n` dependency and translations set via `wp_set_script_translations`. ```javascript const { __, sprintf } = wp.i18n; // Simple translation __('some text', 'text-domain'); // Complex translation with sprintf sprintf( __('some %s', 'text-domain'), __('text', 'text-domain') ); ``` -------------------------------- ### Generate JSON Translation Files for JavaScript with WP-CLI Source: https://github.com/globalpayments/globalpayments-woocommerce/blob/master/languages/README.md Command to extract JavaScript-specific translation strings from .po files and save them into separate .json files. This optimizes client-side translation loading by providing only necessary strings. All JavaScript strings are removed from the .po file after this command runs. ```shell wp i18n make-json path/to/lang-dir/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.