WPML String translation for Custom theme not working - php

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.

Related

I can not translate the theme created for WordPress?

I need to translate my wordpress theme.
I did:
load_theme_textdomain( 'text_domain', get_template_directory().'/language' );
in to function.php.
through the functions__("string","text_domain") and poedit I have generated files po and mo , but nothing translation.
what is the problem?
i have
also tried with _e() esc_html_e() esc_html__() nothing.The problem is that I'm working in local?

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

Translate WordPress plugin header

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.

Dynamic content using .PO file

I have a Wordpress site that has support for other languages using the gettext system.
I am curious if I can call content dynamically, let's say from function the_content():
printf( __( '%s', 'my-theme' ), the_content() );
I'm guessing this is only possible if I provide the entire string in a .po file, which would obviously be in-efficient, not to mention that content would always be changing.
But I CAN do this, correct?
Since the_content() should be the content of a Post or a Page, you can install WordPress plugin like qTranslate, zTranslate or equiv. to provide multi-language contents.
Translation via .po file is only recommend for static contents, like menu items, static links, etc.

Include wordpress theme in a custom php page

I need to include a custom PHP page in Wordpress.
So what I need to do is just to show this custom php page using the Wordpress theme installed on that Wordpress.
Does not mind which theme is up, the custom php page will have to be shown under any theme is installed in that moment.
How do I do it in Wordpress?
I am new to Wordpress development.
Thanks
Creating a custom php page that will be able to be viewed in any theme (and have the theme applied) would be considerably difficult.
Each wordpress page calls specific theme functions of that particular theme, as well as referencing files of that theme to generate header, footer, css files, javascript files, etc.. Your custom page would need to plan for all of these contingencies, for each possible theme used.
Here's a alternative solution: inject PHP code directly into a standard wordpress page via this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/
Meaning: you make a normal wordpress page, but are able to add php to it. When this page is rendered, the proper page template is used, and all the theme references are taken care of for you.
You could do this easily with a page template. WordPress allows you to create page templates which can be assigned to a page via the 'Page Attributes' panel within the page editor. These templates are php files inside your theme directory which begin with some code like (see this page in The Codex for more info):
<?php
/*
Template name: Custom PHP Page
*/
?>
<?php // begin custom PHP page ?>
Typically a template is a variation on the regular theme files (such as page.php) and would call the get_header() and get_footer() functions and have an instance of the loop. However if you simply want to use a custom PHP page, then all you need to do is create the file you want inside the current theme directory and add the above code at the very top of the file.
To output the custom PHP page on your site, you would need to add a new page via the admin area and then assign your new page template to this page.
Alternatively, if you want to include a custom PHP page inside an existing theme file, you use the code:
<?php include(TEMPLATEPATH . '/includes/file.php'); ?>
in this case your custom PHP file would be located inside a directory called 'includes' within your current theme directory.
Tim.
It's not that difficult. Here's what you need:
Once you include the main wordpress blog header, the entire armamentarium of wordpress functions is available to you, which allows you to get the active theme's directory. Once you get that, just include the header and the footer of the theme.
// If title is not displayed before loading the header, Wordpress displays "Page not found" as the title
echo "<head>
<title>Your page title</title>
</head>";
// Include the Main Wordpress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
//Now, you need to get the active theme's folder, and get a relative path to that folder
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path;
//Once you have the path, include the header and footer, adding your custom php code in between.
// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";
// Your custom PHP code STARTS here
// Add anything you want to display to the user
echo "
<h2>
Your form has been submitted
</h2>";
// END of custom code
?>
<?php
}
// Now end with the theme's footer
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";
?>
Was very helpfull (even if dated of 2011-13)
Also, as a thank you, i'm sharing the version i made
it's usefull if your wordpress folder is not located at ROOT
PasBin Link - wordpress custom php page
just change the value of $wplocalpath in :
// Wordpress path (if wordpress is not located at ROOT
// $wplocalpath="/Wordpress1";

Categories