WordPress tanslation .po file - wordpress

I translate one row in a code and still any result.
This row I need translate
This is I put into the .po file
Can you tell me what I'm doing wrong?
I need translate the custom button "Poptávka" on this page usb-4-logo.com/en/

For strings to be translatable you need to use any of WordPress translation functions around the string:
For example:
This string <-- this will not be translatable
<?php __e('This string','your-namespace'); ?> <-- this will be translatable.
You have quite a few methods for making content translatable: __(), _e() and others. Read more in the documentation about translation: https://codex.wordpress.org/L10n

Related

Translatable strings from child theme not included in translation files

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.

Why strings don't appear in "String translation" of WPML?

I have in my php files string like this:
<?php
__('My string A', 'a_theme');
_e('My string B', 'a_theme');
?>
and there are not appearing in "String translation" .
I have also bought and installed this theme: http://preview.ait-themes.com/index.php?bartype=desktop&theme=touroperator and strings from that theme aren't also appearing in "Strings translation" of WPML.
This is one example of string which was already in theme when I installed it:
<input type="text" id="dir-searchinput-location" class="dir-searchinput-select" placeholder="{__ 'Destination'}">
Is there some extra configuration which I need to do or something else?
Thanks for help
To get strings to appear in String Translation, you first need to go to Theme and plugins localization. Scroll down to the Strings in the theme section and then click the Scan the theme for strings button. WPML will then detect any unregistered or newly added strings that are properly formatted for localization.
If it works, you'll see your theme a-theme listed in the Domain column and the number of detected strings in the Count column. Clicking the View strings that need translation button will take you to String Translation. If any of the strings aren't properly formatted for localization, the count won't be updated.
If you update existing strings or add new ones, you'll need to rescan before WPML adds them to String Translation.
The formatting in your first example looks OK and WPML should detect the strings, but in the second example, you haven't declared a domain. Without a domain, WPML won't pick up the string.
The correct format is
__('Your string', 'yourDomain')
or
_e('Your string', 'yourDomain')
In this case, the domain should be the name of your theme, 'a_theme'.
Those strings are cached somehow. So, if you added new one (the right way) and it still doesn't appear in String translation go to "Theme and plugin localization" and hit "Scan the theme for strings" button. This will re-index strings and your newly added one should appear (worked for me).
I have same problem, my theme is "bookyourtravel", and plugin "WPML string translation",did not translate these texts:
<?php _e('Accommodations', 'bookyourtravel'); ?>
<?php _e('Tour', 'bookyourtravel'); ?>
<?php _e('Accommodation', 'bookyourtravel'); ?>
No translated!!!
My solution was:
In WPML go to "localization of themes and plugins", check in
Translated by WPML, then clic en Save.
Now in, "Translated string", clic in button: save the settings and rescan strings.
If you use Cache, then Clear all cache in pages.
ready, this worked!!!!!!!
source : https://wpml.org/forums/topic/using-gettext-for-hard-coded-strings-what-else/

Wordpress gettext bilingual language switching for a theme

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]

How do I target a SPECIFIC template with is_page_template() in Wordpress 3+

I'm running Wordpress 3.2 and I need a conditional to test for a certain template. My template is a file called special_offer.php. The name of the template is "Special Offer". I've tried both of the following:
is_page_template('special_offer.php');
is_page_template('Special Offer');
Neither of these work! The documentation clearly says that the parameter should be a string with the name of the file so I'm not sure what's wrong. I know the function is at least partially working because if I don't include a parameter, it returns true for any pages using templates (as expected).
AHA!
I solved this by adding wp_reset_query() just before the conditional.
I had already read warnings about many WP conditionals not working inside the loop. However, my conditional is NOT inside a loop. Turns out, it won't work even AFTER the loop, which is where mine was. So you you need to reset the query before you call it.
It's worth double checking which file is being used according to the WordPress template hierarchy [image].
Try adding this magic constant to the template file you think is being called:
<?php echo(__FILE__); ?>
If you don't see a path and filename a different file is being used (refer to the template hierarchy diagram in the link above) or check which templates are available:
<?php print_r( get_page_templates() ); ?>
(^ looks like this has to be called from the admin interface e.g. in a plugin)
Also, the documentation seems to state that is_page_template() won't work in the Loop without calling another function first.

Drupal: Translation template extractor works but the string cannot be found

I'm using Translation template extractor to extract transable strings I've added to my page.tpl.php page in my zen theme files.
I've correctly exporeted zen.pot file and overwritten the previous one. The string 'random text' contained in the t('random text') function in the template is correctly added to the file.
I've refreshed cache, refreshed the tab and run cron again.
However when I search for it in the translation interface I cannot find it and therefore I cannot translate it.
thanks
The solution was to switch the language of the page containing the string at least once to save the string.
Export a .po-file, edit it with (e.g with Poedit) save the file and import it into Drupal.

Resources