WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#17266 closed feature request (worksforme)

Custom languages files support

Reported by: DreadLox Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords:
Focuses: Cc:

Description

Hello,

Sometimes, themes/plugins translations do no use the words I would like for some specific texts. When it occurs, it could be nice to be able to create my own custom language file to use instead of the plugin's and that do not get overwritten when upgrading the plugin.

In practical, when looking for a my-plug.xx_xx.mo file, wordpess should first look for it in wp-content/languages directory.

Change History (2)

comment:1 anmari3 years ago

This functionality could also be added as a simple plugin or function using the load_textdomain_mofile filter.

WP code will call:

$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );

The filter could check for mofile in languages folder first, and if not there, then use normal path.

I wrote something like that for my own plugin and wrote the general concept up : http://icalevents.com/3445-an-accent-for-your-website/.

Just coded and tested - seems to do the trick

if (!function_exists('amr_load_custom_text') ) { // for filter
	function amr_load_custom_text( $mofile, $domain='' ) {
	//only do for the plugins/themes you want
	if (!in_array($domain, array('amr-ical-events-list', 'amr-events')))
        return $mofile;
 
    $pathinfo = pathinfo($mofile);
	$custom_mofile = WP_CONTENT_DIR."/languages/" . $pathinfo["basename"];
	if (file_exists($custom_mofile)) 			
			return ($custom_mofile); 
	else  
			return $mofile;
    }
}
add_filter ('load_textdomain_mofile','amr_load_custom_text',10,2 );
Last edited 3 years ago by anmari (previous) (diff)

comment:2 ocean903 years ago

  • Keywords 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

As already mentioned by anmari, you can hook into load_textdomain_mofile.

Note: See TracTickets for help on using tickets.