简体   繁体   中英

Translate WordPress plugin header

How can I translate WordPress plug-in header?

I have translate all strings in my plug-in using:

  1. __() and _e() functions

  2. .po files

  3. Text Domain

  4. WordPress function to load language file

     load_plugin_textdomain('mnbaa-seo', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 

I want to translate this section

<?php
/*
Plugin Name: Mnbaa SEO
Plugin URI: http://www.mnbaa.com
Description: WP blugin fom make SEO and Social SEO.
Author: Mnbaa CO
Author URI: http://www.mnbaa.com
Version: 1.0
Text Domian:mnbaa-seo
Domain Path: /languages/
*/
?>

You have to use WordPress' i18n tools to get the plugin's description translatable. i18n tools' makepot.php lets you auto-generate a .pot file, which then can be used to create the .mo/.po pair (with the free PoEdit for example).

The easiest way would be:

  1. Download the zip from https://github.com/wp-mirrors/wp-i18n-tools .
  2. Extract its content into the wp-includes folder.
  3. Command line one-liner from within WP root: $ php wp-includes/makepot.php wp-plugin wp-content/plugins/MYPLUGIN/ wp-content/plugins/MYPLUGIN/MYLANGFOLDER/MYPLUGIN.pot
  4. Then you take this resulting .pot file as source for PoEdit.
  5. Finally ensure to name the .mo/.po like your plugin plus language code, for example: MYPLUGIN-de_DE.mo/MYPLUGIN-de_DE.po.

More (but not quite up-to-date) info can be found at WPO: https://codex.wordpress.org/I18n_for_WordPress_Developers#Translating_Plugins_and_Themes

I wonder if maybe PoEdit Pro can do that without us calling on the command line... Maybe someone who knows can drop a comment below.

Add somewhere inside your plugin code a dummy translation for the description and plugin name:

$dummy_name = __( 'Mnbaa SEO', 'mnbaa-seo' );
$dummy_desc = __( 'WP blugin fom make SEO and Social SEO.', 'mnbaa-seo' );

Then re-generate the .po / .mo pair.

I use only /languages for Domain Path , no trailing slash.
Check this answer for I18n support by plugins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM