Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#17266 closed feature request (worksforme)

Custom languages files support

Reported by: dreadlox's profile DreadLox Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords:
Focuses: Cc:



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 file, wordpess should first look for it in wp-content/languages directory.

Change History (2)

#1 @anmari
13 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 :

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); 
			return $mofile;
add_filter ('load_textdomain_mofile','amr_load_custom_text',10,2 );
Last edited 13 years ago by anmari (previous) (diff)

#2 @ocean90
13 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.