How to add your own language files

This How-to doc explains how to add language files to TheCartPress. TheCartPress provides a full range of translations, but perhaps, you’d like to add your own version of one of the existing language files.

To add a language file we’ll need to create a new plugin. In the next example you can see how to xcreate a plugin to add your own spanish translation. The mo files must be stored in languages folder, inside the new plugin:

Plugin Name: My own language
Plugin URI: http://...
Description: my own language
Version: 1.0
Author: author
Author URI: http://...
License: GPL
Parent: thecartpress

define( 'TCP_SPANISH_FOLDER', dirname( __FILE__ ) . '/languages/' );

class TCPSpanishSetup {
	function load_textdomain_mofile( $moFile, $domain ) {
		if ( 'tcp' == substr( $domain, 0, 3 ) ) {
			$wplang = get_option( 'WPLANG', WPLANG );
			$is_spanish = 'es_' == substr( $wplang, 0, 3 );
			if ( $is_spanish ) {
				$new_mofile = TCP_SPANISH_FOLDER . $domain . '-' . $wplang . '.mo';
				if ( is_readable( $new_mofile ) ) return $new_mofile;
		return $moFile;

	function __construct() {
		add_filter( 'load_textdomain_mofile', array( $this, 'load_textdomain_mofile' ), 10, 2 );

new TCPSpanishSetup();

The Steps to create a new plugin would be:

1. Relating to the example, you will need to create a new folder called “TCP_SPANISH_FOLDER” (rename if you want matching what it says in the plugin code) in your wp-content/plugins/ folder.

2. In this folder you create a .php file named something like tcp-spanish.class.php

3. Also, in this folder create a folder called “languages” and copy the new .po and .mo file in there.

4. Go to your backend and activate the new plugin.