Translate WordPress plugin header - php

How can I translate WordPress plug-in header?
I have translate all strings in my plug-in using:
__() and _e() functions
.po files
Text Domain
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:
Download the zip from https://github.com/wp-mirrors/wp-i18n-tools.
Extract its content into the wp-includes folder.
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
Then you take this resulting .pot file as source for PoEdit.
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.

Related

How to translate custom plugin by creating .po and .mo file

Basically my requirement is to translate my custom plugin in dutch language for WPML. So when I change the language from english to dutch, It has to automatically change all the text of my plugin in admin panel. I am creating .po file from poedit software. It generates two files .po and .mo file. I put them in the plugin folder;
../wp-content/plugins/cleaner/languages/nl_NL.po
../wp-content/plugins/cleaner/languages/nl_NL.mo
Now I put this code in root file of the plugin.
add_action('init', 'cleaner_load_textdomain');
function cleaner_load_textdomain() {
load_plugin_textdomain(
'cleaner'
, false
, basename(dirname(__FILE__)) . '/languages'
);
}
But it is not doing anything. Any suggetions. Thanks in advance.

WordPress independent functions.php

I have a fresh WordPress and bbPress installed on an internal server.
While I was setting up bbPress I wanted to test the functionalities like creating a forum, topic, etc. When doing these stuff in the back-end (dashboard) there didn't seem to be any problems but when I did it from the front-end I kept getting
ERROR: Are you sure you wanted to do that?
I searched for a solution and found this.
add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 );
function my_bbp_verify_nonce_request_url( $requested_url )
{
return 'http://localhost:8888' . $_SERVER['REQUEST_URI'];
}
I simply changed the hard-coded URL to what our internal server is set up to and it fixed the problem.
Now my question: is it possible for me to add this solution to a functions.php that is independent of the theme being used? I asked this because I have 2 concerns:
The current theme might get updated and will overwrite the file
I'm aware that the solution to this is simply create a child theme but my second concern prevents me from doing this.
The WordPress administrator might change themes and so both the functions.php file on the main theme and the child theme will stop working
How could I add the solution above so that I don't have to worry about the theme being updated and/or replaced with a new theme in the future? I don't want to keep adding this solution every time the administrator decides to change themes.
If you can't put it in a theme, put it in a Plugin. If you're worried that the plugin will get de-activated make it a Must Use Plugin.
It's dead simple to create a plugin. Create a file plugin-name.php and place it in a directory wp-content/plugins/plugin-name/. That file should contain the following code:
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
add_filter( 'bbp_verify_nonce_request_url', 'my_bbp_verify_nonce_request_url', 999, 1 );
function my_bbp_verify_nonce_request_url( $requested_url )
{
return 'http://localhost:8888' . $_SERVER['REQUEST_URI'];
}
If you want it to be a must use plugin, put it in wp-content/mu-plugins/ instead of wp-content/plugins.

WPML String translation for Custom theme not working

I am developing a custom wordpress theme and the client requirement is that the site should be on two languages (i.e English and Chinese).
I am facing using translating theme options. I have installed all the plugins required like CMS, String translation and Translation Management but yet the translation is not working.
I have created the XML file as well and stored it on the theme root folder.
After all, this the error is displayed as:
[theme_switched: 0] shineway_footer_partnertwo: http://yelkolab.com/projects/shineway/wp-content/uploads/2015/10/e.png
string not registered
I have using following code snippet to display theme option values on site:
<?php echo stripslashes(get_option('shineway_footer_partnertwo'));?>
You need to use _e instead of echo:
<?php _e( stripslashes(get_option('shineway_footer_partnertwo')), 'your-text-domain' ); ?>
Afterwards rescan your theme with String Translation and add the translation.

Woocommerce Multilingual issue, How to add and edit string.

I am working on an multilingual e-Shop using Woocommerce. I downloaded the woocommerce .po and .mo, they work fine.
However, I added some custom content into some .php files.
And there are some string that I want to translate.
E.g. I found the code in "templates/content-product.php" and the code is at line 64:
I get into the .po file.
And added:
#: templates/content-product.php:64
msgid "View Product"
msgstr "查看產品"
But it doesn't work.
How to check the exact line of code to make it works?
You should copy template files into your theme's WooCommerce folder. And then if you modify strings, use the gettext() functions with a custom text domain.
For example:
_e( 'Some sample text', 'my-text-domain' );
Then you will be able to generate mo/po files for the 'my-text-domain'.
Developer's Handbook on internationalizing plugins
Codex: i18n for WordPress Developers

How to convert a Shortcode into a Plugin

1. Shortcode (working)
I have made a Shortcode which display the current weatherinformations from yahoo. There was 3 Files (simple-pie.inc, simple-pie-yahoo.inc and yahooweather.php) and I grabed the content of these files and pasted it inside my function.php – works good!
This looks so and got more then 16.000 Lines of Code:
// Add Shortcode for weather
function get_rohrau_wetter() {
content of simple-pie.inc
content of simple-pie-yahoo.inc
content of yahooweather.php -> return "weather-html"
}
add_shortcode( 'rohrauwetter', 'get_rohrau_wetter' );
2. Plugin (no clue where to start)
All I want to do is making a Plugin out of my working shortcode to get that "wall-of-code" out of my function.php and of course for better reuseability. Also I think so it will be possible to turn the simple-pie cache to "on" for faster processing…
My Question is: How do I convert my Shortcode into an Plugin?
A good place to start would the plugin handbook: https://developer.wordpress.org/plugins/the-basics/header-requirements/
But the cheap and nasty way to place it into a plugin, create a directory for your plugin, create a index.php (realistically it can be any name) file. Add this in
<?php
/*
Plugin Name: WordPress.org Plugin
Plugin URI: https://developer.wordpress.org/plugins/the-basics/
Description: Basic WordPress Plugin Header Comment
Version: 20160911
Author: WordPress.org
Author URI: https://developer.wordpress.org/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wporg
Domain Path: /languages
*/
Then underneath it add in your above functions. Obviously Change out the text to suit yourself so that you can identify the plugin. Then upload it too your plugins directory.
As I said, this is the cheap and nasty way to set it up. I would advise to have a look at the plugin handbook I linked to above. Also Using OOP plugin development is advised, a good starting point is Tom McFarlin tutorial on tutsplus: https://code.tutsplus.com/series/object-oriented-programming-in-wordpress--cms-699 .. and after that well worth looking at https://github.com/DevinVinson/WordPress-Plugin-Boilerplate and https://wppb.me/ hope that all helps.

Categories