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.
Related
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.
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
I'm at an early stage of learning Wordpress (and shortcode), so bear with me:
To me, shortcodes seem like a swiss army knife of not having to use page-specific templates for everything. I like to build as many pages in the wysiwyg as possible, but often I would need some (reusable) php stuff for displaying stuff in a certain way.
Having googled a lot, it seems to me the way to do shortcodes is like:
function caption_shortcode( $atts, $content = null ) {
return '<span class="caption">' . $content . '</span>';
}
My question is, is it possible to put the html in a separate template-ish file? It seems wrong and verbose to put all this markup here, escape quotes, et.c. Like a template-file for a shortcode, to which the shortcode can pass some Data Transfer Object (or simply just some scoped variables). So: display in template-file, logic for finding data (to pass to said template-file) in shortcode-function (wherever it may be defined, functions.php, separate plugin, or something).
You can set-up views(php files) and then include partial views into those ones. Wordpress allows templates to be includes within other templates to ensure code reuse and its easily modifiable by child themes. You can use this function to include those
get_template_part( $slug );
However, in your case, the short code function needs to return the value to the caller function. So, this setup will not work.
For code that effects FUNCTIONALITY, put your code in a plugin.
For APPEARANCE, put your code in your theme's template files or funtions.php file.
Many beggining WP developers lump all their code into the theme's functions.php file, this is often the wrong place for it (if that code might ever get exported to another theme, for instance). Only put code specific to a specific theme in a theme's functions.php .
To get Wordpress to recognize your plugin, create a php file and start the file like this:
<?php
/*
Plugin Name: My Caption Shortcode Plugin
Description: A really cool plugin
*/
function caption_shortcode( $atts, $content = null ) {
return '<span class="caption">' . $content . '</span>';
}
?>
Put this file in your plugins directory (usually, you should create a sub directory for each plugin). Plugins are usually held in /wp-content/plugins/ . Then you can activate or deactive the code as a plugin, when you go to the plugins tab in the admin menu.
Of course, this plugin won't do anything as is. Remember that plugin functionality should be hooked into Wordpress via action hooks, filters, and shortcodes. For a shortcode for instance, you'd use the function add_shortcode somewhere to let Wordpress know your function is a shortcode.
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.
I've built a view using the views module in Drupal to display a grid of thumbnail images (field_image) that are linked to a full size image for use with Lightbox.
I've got that part working but I also display caption text beneath the thumbnail image. I want to append this caption text to the A tag like: ...
I looked at overriding the views-view-field.tpl.php template but this is no HTML in this template it just prints $output;
I'm assuming that some PHP function somewhere in the views module is generating the actual HTML code for the link but I don't know where and how to override it in my theme.
Any help would be appreciated.
The $output for views-view-field.tpl.php is generated by default in the views field handler itself. You can set aside the $output variable, and use the template variables mentioned in the comments at the start of the file to build your own output.
I install the devel module, then using dpm($row) (etc) to see what values are available. All fields your View is pulling are available in the template. This includes fields for which you check on the "Exclude" option.
In building your link, I suggest you use the Drupal API functions, that way the link will be properly modified by other Drupal functions.
l(t('Link Title'), url/path, array(
'attributes' => array(
'title' => t('My Image Caption'),
),
));