There is an easy way to get around this problem. Store all frontend messages as options of your theme. Let's define an option 'messages':
add_option('messages',array());
Now we must populate this option. Let's define the defaults:
$theme_messages_defaults = array (
'read-more' => __('Read more','tekko'),
'next-page' => __('Next page','tekko'),
... and so on ...
)
Now, we have to transfer the defaults to the option. We want to do this only at first install, when the translation files have been updated or when the user switches languages. When this test passes run this function:
function run_only_at_install_or_new_version {
global $theme_messages_defaults;
var $messages = array();
foreach ($theme_messages_defaults as $message_key => $message_val) {
$messages[$message_key] = $theme_messages_defaults[$message_val];
}
update_option('messages',$messages);
}
Given that the option is an array, we need a slightly different get_option
function:
function mytheme_get_message_option ($message_key) {
$messages = get_option('messages');
$message = $messages[$message_key];
return $message;
}
In your templates replace all your echo statements like this:
mytheme_get_message_option('read-more');
Don't forget you won't need the textdomain on the frontend anymore, so add a condition in your function file:
if (is_admin()) load_theme_textdomain ('mytheme', 'path/to/languages');
Now you have all your messages in one place and are preventing unnecessary translation actions. Actually you have even more possibilities. You can add the messages to your option pages and have your clients change the texts without having to change templates. Hey, if you use mods in stead of options, you can even add them to the theme customizer. Beware that you would have to add an extra condition to run_only_at_install_or_new_version
to prevent overriding client messages when the theme is updated.
Note: The above is adapted from a more complex setup I use myself, so there may be some typos. If you're at this stage debugging it shouldn't be a problem.