Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Tobias Schutter

    (@tschutter)

    We use the standard function “load_plugin_textdomain( ‘cpac’, …. )” for all our translations. You should be able to overwrite the textdomain with your own translations.

    Thread Starter Tikweb Management

    (@kasperta)

    Well, the translation file shipping with the plugin do take precedence. I can just delete it,
    but with each plugin update you will “overrule” my translation.

    Maybe this is default behavior in WordPress, but none of my other plugins ships with .mo files, so for all other plugins it doesn’t matter.

    So could you just delete the .mo files from the plugin?

    Plugin Author Tobias Schutter

    (@tschutter)

    The mo files contain all translations, we have to ship them with the plugin.

    If you have any improvements for the translation you can help us by translating them at Transifex. We update all our translations from there for each release. You can contribute here.

    Cheers, Tobias

    Thread Starter Tikweb Management

    (@kasperta)

    You need to ship .po files, you do not need to ship .mo files.

    My translations are not always the same as everybody else wants them, so i prefer to translate myself with each release.

    Plugin Author Tobias Schutter

    (@tschutter)

    Without the .mo files none of the translation will work. They are the binary ones getting loaded by WordPress.

    The .po files only contains the raw translation strings, which are only used by translators. If you’d like to use these, they are either available on Transifex or in the plugin languages folder.

    Overwriting any plugin language is easy. Just place your own .mo file in this folder: /wp-content/languages/plugins/cpac-da_DK.mo’. That’s it! Works for all plugins.

    If you rather have your admin columns language file in a theme. Place your .mo file inside the “/languages” folder in your theme and place this code in the functions.php:

    function cpac_load_cpac_translation_from_theme( $mofile, $domain ) {
        if ( 'cpac' === $domain ) {
        	$mofile = get_template_directory() . '/languages/' . $domain . '-' . get_locale() . '.mo';
        }
        return $mofile;
    }
    add_filter('load_textdomain_mofile', 'cpac_load_cpac_translation_from_theme', 10, 2 );

    Thread Starter Tikweb Management

    (@kasperta)

    I am aware of how the translations work – as i wrote in the beginning of this thread i have my own translation in /wp-content/languages/plugins/cpac-da_DK.mo

    The problem is that my own translation is overruled by the .mo file shipping with the plugin, so on each update of the plugin my translation do not get loaded, because the plugin ships with compiled .mo files, instead of .po files the user can compile.

    I can't figure out the priority of load_plugin_textdomain, but on my site it works like this:
    1. /wp-content/plugins/codepress-admin-columns/languages/cpac-da_DK.mo
    2. /wp-content/languages/plugins/cpac-da_DK.mo

    Meaning WordPress will only load number 2. if it does not find number 1.

    Plugin Author Tobias Schutter

    (@tschutter)

    It seems placing the .mo file in the “plugins/languages” is not enough after all ?? But you can disable the first check by using ‘load_textdomain_mofile’.
    Try this:

    function cpac_load_cpac_translation_from_theme( $mofile, $domain ) {
    	return 'cpac' === $domain && strpos( strrev( $mofile ), strrev( 'codepress-admin-columns/languages/cpac-da_DK.mo' ) ) === 0 ? false : $mofile;
    }
    add_filter( 'load_textdomain_mofile', 'cpac_load_cpac_translation_from_theme', 10, 2 );

    Plugin Author Tobias Schutter

    (@tschutter)

    Here is a small function I came up with to give all files in the “/plugin/languages/” folder presendence over their original translations. You could use this for other projects aswell.

    function cpac_load_custom_plugin_translations_first( $mofile ) {
    	$moplugin = WP_LANG_DIR . '/plugins/' . basename( $mofile );
    	if ( false !== strpos( $mofile, '/wp-content/plugins/' ) && file_exists( $moplugin ) ) {
    		$mofile = $moplugin;
    	}
    	return $mofile;
    }
    add_filter( 'load_textdomain_mofile', 'cpac_load_custom_plugin_translations_first' );
    Thread Starter Tikweb Management

    (@kasperta)

    Very nice solution, i will try to use that function – thanks ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Translation not loaded’ is closed to new replies.