I would like to know where the file with Woocommerce system messages and text (for ex. - Add to cart, Product Description etc...)?
I think woocommerce should have a language file, where I can change whatever I want, right?
Thanks
Yes, woocommerce, theme and core file provide .po .mo files, that you can modify with poedit (for example).
They are located in the folder, wp-content/plugins/woocommerce/languages/
Every translatable strings can be spot in php files with the functions __('Add to cart', 'woocommerce'); or _e('Add to cart', 'woocommerce');
You can edit them or create your own language file with poedit. New language must have the language "slug" at its end, i.e: woocommerce-fr_FR.mo (po files remains woocommerce.po).
When editing or creating these files, you need to put them in the folder wp-content/languages/plugins/woocommerce/. If you leave them in the main woocommerce languages folder they will be delete and replace by new one when you update the plugin.
You will find better explanation in the internationalization handbook here
if you want override the language of a plugin or theme, put it in
/wp-content/languages/plugins/ or /wp-content/languages/themes/
Related
So I think that I have all the configuration for translation set, but my translatable strings are not loaded to .po or .pot.
In functions.php:
function opportune_child_setup() {
load_child_theme_textdomain( 'opportune', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'opportune_child_setup' );
In style.css:
/*
[...]
Text Domain: opportune
*/
Translatable string (example):
<label for="custom_field"><?php _e( "Company Tax ID", 'opportune' ) ?></label>
Translation files directory:
themes/opportune-child/languages/opportune.pot
themes/opportune-child/languages/pt_PT.mo
themes/opportune-child/languages/pt_PT.po
The .po and .mo files were created with Poedit based on opportune.pot in the parent theme (which is located in equivalent directory:)
themes/opportune/languages/opportune.pot
I've even hardcoded in my wp-config.php (although already set in WP Admin):
define('WP_LANG', 'pt_PT');
What I do to see if the string has been loaded to either .po or .pot is: I go to a page with translatable strings, make hard refresh (deleting cache), download .po and .pot and then search for the string. None of the strings have ever been loaded.
I've used Loco Translate plugin, I think with the right configurations, and still no result.
What am I missing? Thank you so much!
Firstly, child themes should not use the same text domain as the parent theme.
If you're only using strings from the parent theme, then just translate the parent. But if you're adding new strings into your own PHP files, then use a separate text domain.
So if "Company Tax ID" is a string you've added and it isn't in the parent, ensure it's in a text domain matching the child theme folder, i.e. "opportune-child".
Secondly, strings aren't automatically "loaded into po files" as you say. You create your .pot file by extracting strings from your PHP files. Then you base your .po files from that. Read about WordPress internationalization to understand this process.
Don't create files "based on opportune.pot" because the parent theme is a separate entity. You only need to extract and load strings you've defined for your child. Let the parent take care of itself.
There is a guide for translating child themes here:
https://localise.biz/wordpress/plugin/child-themes
Full disclosure: I am the author.
I'm building a multilingual site with WP using Woocommerce.
The client asked me to change the Sale Flash text, after some research i found this code
add_filter('woocommerce_sale_flash', 'avia_change_sale_content', 10, 3);
function avia_change_sale_content($content, $post, $product){
$content = '<span class="onsale">'.__( 'Sale custom text!', 'woocommerce' ).'</span>';
return $content;
}
It works just fine, but it also changes the german and spanish text - replacing it with the english one.
I checked at the WPML strings (hoping to translate it through that system), but couldn't find it there.
Does anyone know what filter i would have to set to create custom flash sale text in english, spanish and german
Thanks
You are replacing the text correctly, however the issue is that the new string is not found in the language files provided by WooCommerce. The plugin will load a domain called "woocommerce" which is then used to locate strings and their translations if necessary. You are passing the text into __() (more info on __()', '_e(), _x(), _n()), but because your text is new, it isn't found in the dictionary provided by WooCommerce so it defaults to English.
// the __() function can't find 'Sale custom text' in the 'woocommerce' text domain,
// so it does not translate.
__( 'Sale custom text!', 'woocommerce' )
To have this text translate, you will need to load your own language files and text domain and pass the text through __() using your custom domain.
The short version of how to do this:
Use a custom text domain
// load text from 'my_text_domain'
__( 'Sale custom text!', 'my_text_domain' )
Download and install PoEdit to create *.po language files. It has options to scan PHP files for translations entries and will add them to your dictionary. There are tutorials on this on the Internet.
Create one translation file per language that you want to support
Create a folder called languages under your theme directory (this should be a Child Theme so that updates don't overwrite your work), or plugin directory if you are doing your customizations that way.
Update your functions.php (or other plugin, etc) to load your custom text domain. Make sure to use the appropriate path, this assumes it's in the theme.
function load_textdomain_my_text_domain() {
$language_dir = get_template_directory() . '/languages/';
load_plugin_textdomain( 'my_text_domain', false, $language_dir );
}
add_action( 'plugins_loaded', 'load_textdomain_my_text_domain' );
An example of doing this in a plugin using one I wrote:
Spanish language files create by PoEdit under the /languages directory.
Loading the language files under a custom text domain.
Text being passed through __() using the custom text domain.
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
When using gettext in Wordpress to create a bilingual theme, do we have to create one .php file for every page twice (English, French)? For example, header.php, header-fr.php, sidebar.php, sidebar-fr.php, taxonomy-types.php, taxonomy-types-fr.php, etc. Sidebar-fr.php would then use _e('Text to translate', 'domain'). Is there a way to simply keep one copy of all php files and to switch the locale?
Thank you.
Create languages folder inside the theme directory, that's where you save language files, e.g. ar.po (for Arabic).
When writing strings in the code use the following (I usually use English text as the default text, so I won't need to create extra language file, and for each other language create files):
<?php echo __('This is a test','my_theme_name'); ?>
<?php _e('This is a test','my_theme_name'); ?>
in functions.php in the theme folder add the following code to load the language file (please note my_theme_name as given above):
add_action( 'after_setup_theme', 'my_theme_setup' );
function my_theme_setup(){
load_theme_textdomain('my_theme_name', get_template_directory() . '/languages');
}
This way you create only one file(header.php, index.php, etc), where strings are easy to translate.
[Note: this answer assumes that you have knowledge in how to create gettext translation files]
I've googled around quite a lot, but can't seem to find where I should be saving the code for the widget I've created. It's a bit baffling.
So, can anyone tell me where I should save my widget?
Thanks,
John.
You need to put your widget code in either the functions.php file of your current theme, or within a plugin. In order to put it in a plugin, create a new folder in the plugins folder and create a .php file with the name of the folder you created within that folder. In that file, use this code to start your plugin:
<?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
*/
?>
Obviously, change the values to something useful for your plugin. You can then paste your widget code into this file and it should be ready to use.
Sources:
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Plugin_API
As far as I know, widget (ie plugins) go in your wp-content/plugins folder eg. wp-content/plugins/YOUR WIDGET/
Is that what you need?
You can save your code in the file of wp-content\themes\YOUR-THEME-NAME\functions.php.