Translate WordPress plugin header

﹥>﹥吖頭↗ 提交于 2021-02-07 19:50:25

问题


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/
*/
?>

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/25739544/translate-wordpress-plugin-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!