Background of the issue:
Hi there, I'm new to using WPML and I had a question about the String Translations and how best to setup language files for the theme. Typically I would setup a pot file with wp cli and generate the po/mo files with poedit. However WPML has an option for adding these within the CMS, and then it generates a MO file under /wp-content/languages/wpml/ and there's also the option for exporting a pot/po file from the found string translations under "Theme and plugins localization".
Symptoms:
Questions:
My question is what is better for performance? Using the WPML generated .mo file for theme translations or generating the pot/po file with WPML and then generating a mo file with poedit and adding that to the theme? Or copying the mo file from the /wp-content/languages/ folder to the themes language folder so it loads directly from there? Whats the order of loading, does it check the theme/plugin folder first for a language folder, then check in the /wp-content/language/wpml/ folder? Is there a database call between those?
If loading directly from the theme is better for performance, can the WPML generated mo file be moved to the theme for that use? If so, is there a particular formatting or change I need to make to it to accomplish this?
If it's the same or actually better performance to load the WPML generate mo file, whats the point of the pot/po export options? To have the files as a template for the theme?
Under "Theme and plugins localization" there's an option for "Automatically load the theme's .mo file using 'load_textdomain'". Which mo file is this refering to, the one generated by WPML or the one located in the theme? I saw this thread (https://wpml.org/forums/topic/automatically-load-the-themes-mo-file-using-load_textdomain/) and they mention if you have this checked, it load first from the languages folder, then do a database call. Does this mean the themes language folder, or the language folder under /wp-content/? Is there a database call to load the generated WPML mo file?
Also with that option, if it's refering to the themes mo (not the wpml generated) file, if I'm already running "load_theme_textdomain" in my theme under the action "after_setup_theme", is it still necessary to tick that option?
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Hello,
When creating your theme or plugin you will provide the .pot and .po files.
WPML will use the available .pot and .po to create .mo files and those .mo files are saved inside /wp-content/languages/wpml.
Those are machine language files which are identical copies of the .po files and they are there to enhance the site's performance, as the system can load .mo files faster.
Thanks for clarifying. As I understand it, you can use the "Strings in the themes" option under "Theme and plugins localization" to generate a list of strings for the "String Translation" table. You can then go into that table, add your translations and on save WPML will generate a .mo file from the translations. This is without a .pot or .po setup in the theme.
My question is, is it better for performance to have the .pot, .po and .mo setup in the theme or does the auto generated .mo file from WPML work just as well?
I had a few other questions in my original ticket if you wouldn't mind scanning through again please, but the above one is the main question as setting up the .mo/string translations via the CMS is more efficient than setting up via Poedit.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Using WPML > Theme & Plugin Localization to scan for strings from themes and plugins is not always the best solution, as it will register all the strings found in the theme and plugin you might end up with filling the string tables with strings that do not need a translation.
At WPML > String Translation you will find an option to "Register strings while page is rendered". This is more effective and will only register those strings that actually need a translation. This option will be enabled by default in the upcoming version of WPML 4.7.
The WPML > String Translation table will also read any .pot and .po files and save any default translations coming from theme or plugins.
This is how WPML String Translation always used to work, we only added afterward the option to create our own custom .mo-files for enhancing the performance.
If you create a theme or plugin, I would always suggest to ship it with .po file, if possible.
WPML will simply check for the textdomain of the theme and plugin and then check for available language files and also for GetText Calls.
I can sadly not provide more details about your questions as these are developer topics and not really support related. If you take a look into the code of WPML you might find the questions for your answers.