How to save a translation of a plugin in “CodeStyling Localization”?

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 :))

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x