I have a very strict directory structure I must adhere to within mu-plugins, but I would like POEdit to be able to help me generate translation files for specific code within this structure, while ignoring a bunch of others.
At the moment, POEdit is having difficulty locating valid code. I have purchased the Pro version, but I think my structure is too customized to be able to benefit from the automated features of Pro. I have also tried using the blank WordPress .pot file located at https://github.com/fxbenard/Blank-WordPress-Pot as a starting point, but I’m still getting similar results.
Here is my structure:
- mu-plugins
- vendor [don't translate]
- languages [.mo, .po and .pot files should go here]
- client [translate some of these]
- Custom_Class
- Custom_Class.php [the file that is automatically loaded by _loader.php]
- Custom_Class_2
- Custom_Class_2.php [file that is automatically loaded by _loader.php]
- includes
- Included_File_1.php [files included by Custom_Class_2.php]
- react_app [all these files should be EXCLUDED, especially node_modules/*]
- _loader.php [contains the WordPress plugin headers, and includes all the other php files within the other folders]
_loader.php
has the following:
define( 'MY_TEXTDOMAIN', 'MY_TEXTDOMAIN' );
function load_mu_plugin_textdomain(){
load_plugin_textdomain( MY_TEXTDOMAIN, false, plugin_dit_path( __FILE__ ) );
}
add_action( 'plugins-loaded', 'load_mu_plugin_textdomain' );
note: there are typos in the above code that are addressed in my answer below. Leaving this here for a record of the problem.
I’m using the define()
exclusively for IDE code completion. As you can see, the string is the same as the constant, so POEdit shouldn’t have a problem finding things like __( 'my string', MY_TEXTDOMAIN );
I realize there are a number of non-standard approaches from a POEdit perspective, but I feel I should be able to manually customize my .pot file to handle this. Here’s my .pot file as it stands:
# WordPress Blank Pot
# Copyright (C) 2014 ...
# This file is distributed under the GNU General Public License v2 or later.
msgid ""
msgstr ""
"Project-Id-Version: MY_PROJECT\n"
"POT-Creation-Date: 2012-10-05 10:50+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Your Name <you@example.com>\n"
"Language-Team: Your Team <translations@example.com>\n"
"Report-Msgid-Bugs-To: Translator Name <translations@example.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Textdomain-Support: yes"
"X-Generator: Poedit 1.6.4\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;esc_html_e;esc_html_x:1,2c;esc_html__;esc_attr_e;esc_attr_x:1,2c;esc_attr__;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2;_n_noop:1,2;__ngettext:1,2;__ngettext_noop:1,2;_c,_nc:4c,1,2;\n"
"X-Poedit-Basepath: ../client/\n"
"X-Poedit-SearchPath-0: .\n"
"X-Poedit-Language: English\n"
"X-Poedit-Country: UNITED STATES\n"
"X-Poedit-Bookmarks: \n"