Supposing that I have two domains in my theme named “basic” and “advance”.
Is it possible to load two different domains in my theme?
load_theme_textdomain( 'basic', TEMPLATEPATH.'/languages' );
load_theme_textdomain( 'advance', TEMPLATEPATH.'/languages' );
Note that if you put your mo-files inside your themeâs directory, the same mo-file will be loaded for every theme textdomain. That is because a theme mo-file is based solely on the locale. For example:
Given that âen_USâ is your
WPLANG
locale, the code above will loadwp-content/themes/your-theme/languages/en_US.mo
three times! Bad because having the same mo-file imported multiple times only causes superfluous work. In that case youâre better off using a single theme domain.However, if the
wp-content/themes/your-theme/languages/en_US.mo
does not exist, WordPress will have a look in the subdirectory âthemesâ of the default language directory and in that case it does take the domain into account as part of the filename. You can learn all that from a quick look at theload_theme_textdomain()
function:If you’re creating this theme or plugin for inclusion in the official plugin or theme directories on WordPress.org, then you need to use the plugin or theme’s slug as the text-domain. You cannot have multiple text domains, and the text domain cannot be anything other than the slug of the plugin or theme.
This is due to the new language pack support coming in 3.7. The language pack system will use the slug for the text domain, and won’t work with anything else there.
You certainly can.. however, you cannot use two separate language translations on a single text string.
For example, let’s consider we have this text string somewhere on our page:
Now, if we want to set that up for language localization, here is what we do:
In your case, it could be either:
Or,
But, it is not possible to translate the single string into two localizations.
Also, when using a localization name; make it something unique so that it does not clash with other plugins/themes.
Since WordPress 4, I suggest you create a simple plugin and “only” load the needed text domain. All strings in your Theme folders or templates or everywhere will be translated. Example:
Works great for custom changes in woocommerce template files or Buddypress template files in your main domain Theme!
Remember to give the mo and po files the slug, in my case above:
And the folder Languages goes in your plugin folder