Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hi I was translating one of my plugins in "CodeStyling Localization". when I update my plugin my translation erased. Is there anyway to find it ? And How can I backup my translation (I don't want to waste my time next time :))

share|improve this question
    
If you don't have a backup of your translation, yes, unfortunately you lost it. And if you don't have any, use this plugin (BackWpUp) or similar together with DropBox. –  brasofilo May 17 '12 at 22:11
add comment

1 Answer

up vote 5 down vote accepted

You should move the po- and mo-file with the translation of your plugin outside your plugin's directory. Whenever you update your plugin, your plugin files are replaced causing any file that is not part of the default plugin package to be deleted. (If you are translating your own plugin, you could as well add the translation files directly to your plugin repository.)

How to move custom translation files outside of the plugin's directory? In your plugin code, add a method like this to the init hook:

public function load_plugin_textdomain()
{
    $domain = 'my-plugin';
    $locale = apply_filters('plugin_locale', get_locale(), $domain);

    load_textdomain($domain, WP_LANG_DIR.'/my-plugin/'.$domain.'-'.$locale.'.mo');
    load_plugin_textdomain($domain, FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
}

The code above first looks for a translation file in WP_LANG_DIR, to be found in wp-content/languages/ by default. Putting your custom translation files in there is safe for upgrades.

Also, by using the the approriate hook and functions to load the translations for your plugin, you allow users to hook into the language loading process for your plugin, giving them much flexibility to load language file(s) from anywhere they want.

I've written a more in-depth article about this on my blog.

share|improve this answer
    
Thanks a lot dear Geert . I translate other plugins with poedit and I upload them manually and I have no problems yet . Is it for some of the plugins ? –  mahdiar May 17 '12 at 9:21
    
All I can say is that if you put your own translation files for a plugin in that plugin's directory, you lose them when upgrading the plugin. –  Geert May 17 '12 at 11:30
    
Wonderful code, Geert, much appreciated! ps: the article too –  brasofilo May 17 '12 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.