Translate plugin and wordpress and the same time - wordpress

I have seen many questions and answers but none that fit the bill. So here is my issue.
I have a plugin that I have localized which works fine on it's own when you add
define('WPLANG', 'my-plugin-name-de_DE');
to the wp-config file. But then when someone try's to translate the rest of the wp site it will not show the languange.
What am I missing here? I even tried naming the files I added the the wp-content folder to be the same name as my plugin... for example my-plugin-name-de_DE.po and .mo and no luck.

ANSWER
Ok so in wordpress 4.0 you can now select your language from the settings /general page.
My plugin was localized using the code
function plugin_action_init()
{
// Localization
load_plugin_textdomain('my-plugin-name', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
// Add actions
add_action('init', 'plugin_action_init');
Example of a string that would get translated.
_e('Simple text example', 'my-plugin-name');
SO all that needed to be done to get my plugin's and wordpress's translation to work at the same time was to upload the wp language that I want to the wp-content/languages folder. Making sure the file name was simply de_DE.mo and de_DE.po
Such a simple mistake :)

Related

How to make custom Wordpress plugin aware of .po and .mo files?

I am trying to add a translation to a plugin I wrote from scratch but after experimenting a while I'm not sure how to make Wordpress aware that there's a translation available for my plugin.
I'm not sure what else to try so I thought that someone more experienced could point out things I might need to change.
What I did so far:
Added either _e() or __() to the sentences I want to be translated in my plugin files.
Used Loco Translate plugin to generate a .pot file.
Opened .pot file in Poedit, (it displayed a list of all the strings I wanted to translate) translated plugin and generated .po and .mo files from it.
Moved .pot, .po and .mo to my-plugin/languages/.
Renamed files to my-plugin-pt.po and my-plugin-pt.mo.
Changed Wordpress site language to translated language. Language changed everywhere else but the plugin still renders in english.
Not really sure what to do next.
I've created a method that runs load_plugin_textdomain() while following these instructions from Wordpress and have added it as an action to my-plugin __construct():
my-plugin.php
public function __construct() {
// Other filters and actions...
add_action( 'plugins_loaded', array( $this, 'translation_init' ) );
} // __construct
function translation_init() {
load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
The language code at the end of the .po and .mo files was incorrect.
Changed from -pt.po to -pt_PT.po (did the same for .mo file) and it started working perfectly.
There's a list of the available language codes for Wordpress which I should have had a look before naming the files in the first place.

Half of the po/mo file strings are working, Wordpress Localization

I'd like to change theme (Flatsome) language on admin control panel site. One of the page UX Builder that i can...but the customizer page (..>appereance>customize)
does not change.
I made the localization:
define('THEME_PATH', get_template_directory());
load_theme_textdomain( 'flatsome', THEME_PATH . '/languages' );
$locale = get_locale();
$locale_file = THEME_PATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) ) require_once( $locale_file );
I've change all the string like I want with __() and _e()
Then I scanned the project, locally (with POedit) and created the POT and PO files.
I did my translation. After finished, I transfered the PO and MO files to FTP. Like I said, half of them has changed. I tried so many things now I think totally stuck.
Yes, I solved the problem. If anyone come across this kind of problem. After WP updated 3.7, the main folder for themes is under wp-content/languages/themes/
And also if you are translating plugin it is wp-content/languages/plugins/
if your theme mo file doesn't work or half of them is working then take your po mo files to these directories, but this time make theme {text-domain}-{locale}.mo and {text-domain}-{locale}.po

Trouble Translating a WordPress theme

I've created an Arabic website and I am using the zippy theme from MageeWP the things is that I am trying to translate some strings in the theme, but I don't seem to get it working well.
In the theme functions file, there is a specification for the folder location for .PO and .MO files
I created a file ar.mo and put it there, but it still not working, can anybody guide to a clue?
I checked in wp_config.php and indeed the WPLAND is set to ar
I also used the CodeStyling plugin to make the translation, and it didn't work, although the plugin does not problem a .po or .mo files for ONLY ar.
Additionally
the source code of the zippy theme is here: http://themes.svn.wordpress.org/zippy/1.0.9/
Looks like the theme is doing it wrong (simplified code):
define( 'ZIPPY_THEME_BASE_URL', get_template_directory_uri() );
$lang = ZIPPY_THEME_BASE_URL. '/lang';
load_theme_textdomain( 'zippy', $lang );
It's passing an URL and it should be a path, change the load_theme_textdomain line to:
load_theme_textdomain( 'zippy', get_template_directory() . '/lang');
I had a look at the Zippy theme. There are a template called en_US.po inside the lang folder. I had a look at that as well.
If you don't have poedit installed, download poedit now and install it on your computer. Now, make a copy of en_US.po and rename it ar.po. Open ar.po with poedit. Now you can do all your translations in this template. When you're done, just click save in poedit. Poedit will automatically create a ar.mo template when your ar.po is saved.
Note, this is just a quick way of doing it, as there are already a language file available that isn't yet translated.
Hope this helps

Changes on archive-product.php doesn't work

I'm trying to customize the standard woocommerce theme and so far that has worked well. I copied all template files from /plugins/woocommerce/templates to /mytheme/woocommerce and customized the files.
But when i'm change something in archive-product.php nothing happens? I even tried to customize this in the core files (/plugins/woocommerce/templates/archive-product.php) but i doesn't work.
I want to change the class of the h1 heading: <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>.
So i looked up all woocommerce template files, the class page-title occurs only in this one file (to prevent editing the wrong file).
Edit:
In detail, i want to customize the theme used in this path: http://example.com/product-category/mycategory
I tried all the above solutions, to no avail. No matter what I did, the archive-product.php was not being used at all. Instead, most woocommerce pages were using page.php from my theme.
The solution for me was to add theme support... Which, it's been a while since I used woocommerce, so I completely forgot about that. But after adding the following line to my functions.php file, archive-product.php is now being used (/mytheme/woocommerce/archive-product.php) and I can update it, as I should be able to.
add_theme_support('woocommerce');
Seems this is STILL an issue in Woocommerce. For anyone landing here, the following solution was working for me as of version 2.1.6.
Apparently the problem is due to the function woocommerce_content() outputting the wrong page for archive content.
I used the following to get around it:
replace woocommerce_content() in woocommerce.php with:
if ( is_singular( 'product' ) ) {
woocommerce_content();
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
woocommerce_get_template( 'archive-product.php' );
}
Credit: found the solution here
Here's how I fixed mine:
Delete woocommerce.php in your theme folder.
Copy TEMPLATE folder in woocommerce plugin dir, paste it in your THEME folder, and rename it to woocommerce.
Open the folder you just renamed, go to shop folder, and edit wrapper-start.php and wrapper-end.php.
If you use the woocommerce.php method you cannot customize archive-product. You must use the hooks method
http://docs.woothemes.com/document/third-party-custom-theme-compatibility/
Please note: when creating woocommerce.php in your theme’s folder, you won’t be able to override the woocommerce/archive-product.php custom template as woocommerce.php has the priority over archive-product.php. This is intended to prevent display issues.
For others searching here, doublecheck the path. It is for example not /mytheme/woocommerce/templates/archive-product.php but only /mytheme/woocommerce/archive-product.php. I didn't have to apply #Talk nerdy to me's patch or any other to make it work.
you need to edit the file "taxonomy-product_cat.php" and add a conditional is_product_category( 'mycategory' ).
open your theme folder and add a new subfolder named "woocommerce" to it.
copy the files "archive-product.php" and "taxonomy-product_cat.php" from /plugins/woocommerce/templates to the woocommerce subfolder in your theme.
rename "archive-product.php" to "archive-mycategory.php" (or whatever you like, this will be the template file to the category).
open "taxonomy-product_cat.php" and wrap the wc_get_template( 'archive-product.php' ); with:
if (is_product_category( 'mycategory' )){
wc_get_template( 'archive-mycategory.php' );
} else {
wc_get_template( 'archive-product.php' );
}

WordPress Plugin Localization

I've just built my first plugin for WordPress, and even if it's not a great "code poetry" it works as it should. It's a plugin that transform the default wp gallery using the GalleryView 3.0 jQuery plugin (http://spaceforaname.com/galleryview).
The only thing I'm not able to do is localization.
Localization for this plugin in means translating the admin interface, where someone can configure the jQuery plugin options to change the aspect of the resulting gallery.
I've tried to follow the millions of tutorials present on the web, read a lot of posts about this issue on forums and followed the guidelinees of codex... but still with no luck.
this is what I've done:
every text line is inside a gettext function ( __ and _e )
using poedit I created the .po and .mo file scanning the plugin directory (everything went ok), then i added translations on that file.
I named the .po file like that NAME-OF-THE-PLUGIN-it_IT.po (the .mo file was generated with the same name)
I've put the translations files inside the plugin folder/languages (name of the folder is the same of the plugin and of the translations files)
then I've tried to add the load_plugin_textdomain function inside the main plugin file. I've tried because there's no way to get it working.
The only thing on which I'm not sure is the fact that the plugin I've created is not under a class+constructor functions... just because I'm still not so good in coding.
But I've put the load_plugin_textdomain inside an init add_action, like this:
add_action('init', 'gw_load_translation_file');
function gw_load_translation_file() {
// relative path to WP_PLUGIN_DIR where the translation files will sit:
$plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );
load_plugin_textdomain( 'gallery-view-for-wordpress', false, $plugin_path );
}
the lines above are not inside a logic, they are just in the main plugin file, like that.
this is an example of my use of gettext functions:
<h3><?php _e('Panel Options','gallery-view-for-wordpress') ?></h3>
What did I not understand?
My mistake was on language files path declaration.
this fixed:
$plugin_path = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
this was wrong:
$plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );
I was answered on Wordpress Stack Exchange
Contrary to my previous statement, I've succeeded using this filename: gallery-view-for-wp-it_IT.mo
Strange, though - themes use just it_IT.mo.

Resources