Load textdomain from global languages directory

I am creating translations for my plugin. To fetch .mo files from my-plugin/languages directory , I use the function //Load translation function load_plugin_textdomain() { load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); } add_action( 'plugins_loaded', 'load_plugin_textdomain' ); How can i set the location to wp-content/languages Setting the location to ABSPATH.'/wp-content/languages' doesn't work.
Category: Web

Two text domains in one plugin

From start: A = main plugin(the library), B = child plugin I develop a plugin B that will depend on another plugin A in order to work properly. I do this because I'm one of the persons who don't like code duplication. So I have a plugin with the library required for other plugins A and another plugin that will do only what it should but only if plugin A is activated. Everything is working well, but... I also need …
Category: Web

Translations only load from `wp-content/languages/plugins` but not from the plugin's languages folder

I translated my plugin and put all the files (my-plugin-de_DE_formal.po, my-plugin-de_DE_formal.mo, my-plugin.pot) in the wp-content/plugins/my-plugin/languages folder. My plugins header says: … Text Domain: my-plugin Domain Path: /languages … Inside my code I loaded the textdomain like that: function mp__load_textdomain() { load_plugin_textdomain( 'my-plugin', false, 'my-plugin/languages' ); } add_action( 'init', 'mp__load_textdomain' ); I also check the return value of load_plugin_textdomain and it says true. But all my translations will not show up. But if I move the .po and .mo files to …
Category: Web

How to get menu strings, categories and tags into po file for translation

I'm prepping my theme for translation. I've added the following line to my functions.php, and added the text domain within my theme files. <?php /*** LOAD THEME TEXTDOMAIN ***/ load_theme_textdomain( 'mytheme', get_template_directory() . '/languages' ); $locale = get_locale(); $locale_file = get_template_directory() . "/languages/$locale.php"; if ( is_readable( $locale_file ) ) { require_once( $locale_file ); } ?> I've used poedit to generate my po files. It is finding some of the strings that are labeled with the text domain, but it's not …
Category: Web

How to override languages files in wp-content/languages/themes with child theme

I want to create a child theme for TwentyFifteen theme, which will customize a lot of things, including translation. When I install WordPress in my language (Farsi), it includes TwentyFifteen language files in wp-content/languages/themes So when I create a languages folder in my child theme and add customized language files to it and add load_theme_textdomain( 'twentyfifteen', get_stylesheet_directory() . '/languages' ) to my child theme's functions.php my customized language files do not load and instead the files in wp-content/languages/themes load. What …
Category: Web

Problem in Internationalizing a plugin built for network level usage

Context: I have created a plugin that is enabled only at the network level and it handles certain synchronizations between the child sites. As it is a network level plugin, it has its menu added to the network dashboard instead of the admin dashboards of child sites. Problem: I have implemented internationalization in the plugin following strict practices from the WordPress codex. For some reason, the load_plugin_textdomain function cannot load the .mo files I have generated. I have verified the …
Category: Web

How to load translation in JavaScript?

I am struggling to load translation in JavaScript for my simple plugin. Translation works for PHP, but not in JS. What seems to be the problem, how can I debug this? I have loaded text domain in my plugin method and this works ok. My text domain is instantsearch, locale for my language is hr load_plugin_textdomain('instantsearch', FALSE, basename( dirname( __FILE__ ) ) . '/languages/'); // returns true var_dump(__('No results', 'instantsearch')); // This shows correct translation for my language I have …
Category: Web

Plugin translations not installed but... strings are translated!

I've had for a long time a site with the famous Recent Tweets Widget. The plugin came as part of a theme, and back in the day, it included translation .po and .mo files for French language. I didn't pay attention to this before. But recently I have found that the strings indicating the tweet's age (x days/months ago, etc.) are translated into Spanish, main language of the site. I have confirmed that the translated strings are not in the …
Category: Web

load_plugin_text_domain() never works

This code never works: function i18n_load_plugin_textdomain() { $path = '[DIR]/wp-content/plugins/my-plugin/languages/my-plugin-de_DE.mo'; load_plugin_textdomain( 'my-plugin', false, $path); } add_action('plugins_loaded', 'i18n_load_plugin_textdomain'); I also tried 'init' instead of 'plugins_loaded' hook. I tested $path with this different values (strings!) - no one worked. load_plugin_textdomain() returned always false. $path = '[URL]/wp-content/plugins/my-plugin/languages/my-plugin-de_DE.mo'; $path = '[DIR]\wp-content\plugins\my-plugin/languages/my-plugin-de_DE.mo'; $path = 'languages/my-plugin-de_DE.mo'; $path = '/languages/my-plugin-de_DE.mo'; $path = '/languages/'; $path = '/languages'; $path = 'languages'; $path = '/'; $path = ''; But this works: function i18n_load_textdomain() { $mofile = '[DIR]/wp-content/plugins/my-plugin/languages/my-plugin-de_DE.mo'; load_textdomain( 'my-plugin', $mofile); …
Category: Web

Filter in Custom post type to find the parent post

function fws_admin_posts_filter( $query ) { global $pagenow; if ( is_admin() && $pagenow == 'edit.php' && !empty($_GET['my_parent_pages'])) { $query->query_vars['post_parent'] = $_GET['my_parent_pages']; } } add_filter( 'parse_query', 'fws_admin_posts_filter' ); function admin_page_filter_parentpages() { global $wpdb; if (isset($_GET['post_type']) && $_GET['post_type'] == 'books') { $sql = "SELECT ID, post_title FROM ".$wpdb->posts." WHERE post_type = 'books' AND post_parent = 0 AND post_status = 'publish' ORDER BY post_title"; $parent_pages = $wpdb->get_results($sql, OBJECT_K); $select = ' <select name="my_parent_pages"> <option value="">Parent Pages</option>'; $current = isset($_GET['my_parent_pages']) ? $_GET['my_parent_pages'] : ''; foreach …
Category: Web

WordPress filter load_textdomain_mofile not working inside a child theme's functions.php but works form inside a plugin

Function in a plugin is behaving differently than function in the functions.php inside a child theme. I have a custom simple plain plugin with nothing but the following code in it and it works perfectly. It translates wpamelia plugin correctly with all strings as expected. add_filter( 'load_textdomain_mofile', 'load_custom_plugin_translation_file', 2, 2 ); function load_custom_plugin_translation_file( $mofile, $domain ) { if ( 'wpamelia' === $domain ) { $mofile = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . '/amelia-translate/de_DE/wpamelia-de_DE.mo'; } return $mofile; …
Category: Web

How to reload wordpress textdomains at runtime

I'm currently using this to reload my theme and plugin textdomain in order to send e-mails (admin move, in admin language) in the user language. add_filter("theme_locale", array($this, "theme_locale"), 9999, 2); add_filter("plugin_locale", array($this, "plugin_locale"), 9999, 2); $this->load_textdomains(); remove_filter("theme_locale", array($this, "theme_locale"), 9999, 2); remove_filter("plugin_locale", array($this, "plugin_locale"), 9999, 2); public function load_textdomains() { if (function_exists("WC")) { WC()->load_plugin_textdomain(); } if (class_exists("My_Plugin_Class")) { My_Plugin_Class::load_plugin_textdomain(); } load_my_theme_textdomain(); } And the theme/plugin functions works like this: function load_my_theme_textdomain(){ unload_textdomain('my-theme-textdomain'); load_theme_textdomain('my-theme-textdomain', get_template_directory() . '/i18n/'); } And thats okay, …
Category: Web

Should I change text-domain of TGM library inside theme?

I created a theme and I want to publish it in wordpress.org. I used TGM library to check to require plugins. but the Theme-check get bellow warning: Warning: More than one text-domain is being used in this theme. This means the theme will not be compatible with WordPress.org language packs. Should I change text-domain of TGM library? Or like the Envato, it's not necessary to change text-domain of TGM?
Category: Web

Translation ready code format for taxonomy

https://codex.wordpress.org/Function_Reference/register_taxonomy i have these doubts _x( 'Categories', 'taxonomy general name' ) does it make taxonomy general name a text domain? wont it resulting in multiple translation? __( 'All Categories' ),__( 'Edit Category' )etc does not seems to have any text domain, is it required?
Category: Web

Multiple text-domains per single plugin - admin and frontend

There is a plugin: In admin area it has about 300 various strings added via __('', 'my-textdomain'). Most of these are form labels, titles, etc. On "frontend" (which end user sees), there just 15 strings added via the same __('', 'my-textdomain') method Most website editors will want to translate "frontend" part. Admin area part is technical and most editors will understand english version. Is it worth having two plugin textdomains - one for admin area strings and another one for …
Category: Web

How to debug load_textdomain?

I'm really stumpted here. I've got this code to load my textdomains for the english version of the site I'm working on. The following code is in the Functions.php theme file. if(ICL_LANGUAGE_CODE == 'en'){ $textdomainLoad = load_textdomain( SHIROI_THEME_DOMAIN, get_template_directory().'/lang/en_US.mo' ); load_textdomain( "site", get_template_directory().'/lang/en_US.mo' ); echo '<!--textdomainloadednohook '.$textdomainLoad.'-->'; } This usually works. But on this website, it doesnt. I checked, and my textdomain is correct. The echo underneath echoes at the beginning of the page, meaning the file is OK and …
Category: Web

Is a text-domain necessary for a child theme

Sorry for the noob question. Is a text-domain necessary for a child theme? I am building a simple child theme with no text-domain declared. So, when I use strings which are to be translated, should I use the parent theme text-domain (yes parent theme has text-domain loaded and also has .mo/.po files). For example adding this line in my child theme template <?php __('Some String', 'parent-text-domain');> Will be above string be translated? Thanks in advance
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.