• Hi,

    I could not figure out which is the best way to translate bits of text used by other plugins.

    Sadly, many plugins still use bits of text which are hard coded inside the plugin php files, so no easy way to translate them.

    What string shall I use inside those php files to have those texts translated?

    Example: I have for example smth. like

    <?php _e("Add your text","plug");?>

    and I need to translate somehow that “Add your text” bit.

    Thank you in advance

    https://wordpress.org/plugins/sublanguage/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author maximeschoeni

    (@maximeschoeni)

    Hello,

    For translating this you need to create a language file for the plugin. This process is called internationalizing plugin (or theme). First you need to install this software: poedit. There should be a .po file somewhere in the plugin folder. You can edit this file with poedit and generate a .mo file. You can find additional documentation here: https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/

    Maybe you can also contact this plugin author for help. What is actually this plugin name? And what language you need translation for?

    Thread Starter candy2012

    (@candy2012)

    Hi,

    but this po/mo story works when I have a different language defined for my whole WordPress installation, no? And I surely do not want that. I want my admin in one language (English) and than the frontend translated to say 4 languages (using your cute plugin for ex. :))

    The problem with the harcoded bits of text appears in MANY plugins actually.

    And I do not really understand HOW will your plugin act upon those po/mo files installed in a different plugin ?!?!

    Plugin Author maximeschoeni

    (@maximeschoeni)

    Ok this is what Sublanguage does as soon as possible (only on front-end):
    1. It figures out what is the wanted language by fetching language slug in url.
    2. It hooks into get_locale() to change the returning locale code (like ‘en_US’). Normally get_locale() return the admin language. But with sublanguage it return the queried language instead.
    3. When any further php file is included, by plugins, themes or core, it is parsed to translate every localized strings (__('...') things). But actually this is a builtin wordpress process.

    Thread Starter candy2012

    (@candy2012)

    Thank you v. much for the explanation!

    Understood now, quite complicated though (lots of work to do …).

    But what about “options” (WP get_option) – can we translate those too ??!

    Thanks again!

    Plugin Author maximeschoeni

    (@maximeschoeni)

    Yeah that’s true, multi-language is a lot of work, I agree!

    An interface to translate wp options (among other things) is currently in preparation and will be available in the next release of Sublanguage. For now you need to do it programmatically (see this example on github).

    Thread Starter candy2012

    (@candy2012)

    Hi,

    Thanks for the tip but I am afraid I did not really understand how to apply that code 🙁

    Say the name of my option in database table “wp_options” is “my_option_name” (found in the option_name column) and the value in the option_value column is “my_option_value”.

    How do I use that exactely ?!? I did not really understand how to adapt your code example 🙁

    The reference language will than be the language I set as default, or ?!?

    Thanks again!

    Thread Starter candy2012

    (@candy2012)

    Could you help me with the needed code I should add to functions.php?
    I do not understand where to put the option name (my_option_name) and the option value, the one that should be translated (my_option_value)

    Thank you in advance!

    Plugin Author maximeschoeni

    (@maximeschoeni)

    Is it more clear like this:

    if ( !is_admin() ) {
    
         add_filter( 'my_option_name', 'my_translate_option_field' );
    
    }
    
    function my_translate_option_field( $value ) {
    
        return apply_filters( 'sublanguage_custom_translate', $value, 'my_get_description' );
    
    }
    
    function my_custom_language_parser( $original, $language ) {
    
        if ( $language->post_content == 'fr_FR' ) {
    
            return 'my_french_option_value';
    
        } else if ( $language->post_content == 'ko_KR' ) {
    
            return 'my_korean_option_value';
    
        }
    
        return $original;
    }
    Thread Starter candy2012

    (@candy2012)

    well, I did not manage to get to work yet 🙁

    Example: I have an option_name called < > _transient_the_seo_f3_exc_pro_cat_12_1 with the option_value > a:2:{s:6:”normal”;s:120:”Modify this short text …”;s:6:”social”;s:153:”Modify the text bellow. Start by choosing a category.”;}.

    I tried adding this code to functions.php and it did not work (no translation):

    if ( !is_admin() ) {
    
         add_filter( '_transient_the_seo_f3_exc_pro_cat_12_1', 'my_translate_option_field' );
    
    }
    
    function my_translate_option_field( $value ) {
    
        return apply_filters( 'sublanguage_custom_translate', $value, 'my_get_description' );
    
    }
    
    function my_custom_language_parser( $original, $language ) {
    
        if ( $language->post_content == 'de_DE' ) {
    
            return 'a:2:{s:6:"normal";s:120:"Kurztext bitte ergänzen ...";s:6:"social";s:153:"Text ergänzen, Kategorie wählen";}';
    
        } else if ( $language->post_content == 'fe_FR' ) {
    
            return 'a:2:{s:6:"normal";s:120:"Modifier le texte  ci-dessous...";s:6:"social";s:153:"modifier le texte  ci-dessous. Commencer par modifier une categorie";}';
    
        }
    
        return $original;
    }
    Plugin Author maximeschoeni

    (@maximeschoeni)

    Maybe the following is going to work better:

    if ( !is_admin() ) {
    
         add_filter( '_transient_the_seo_f3_exc_pro_cat_12_1', 'my_translate_option_field' );
    
    }
    
    function my_translate_option_field( $value ) {
    
        return apply_filters( 'sublanguage_custom_translate', $value, 'my_get_description' );
    
    }
    
    function my_custom_language_parser( $original, $language ) {
    
        if ( $language->post_content == 'de_DE' ) {
            return array(
    		"normal" => "Kurztext bitte ergänzen ...",
    		"social" => "Text ergänzen, Kategorie wählen"
             );
        } else if ( $language->post_content == 'fe_FR' ) {
            return array(
    		"normal" => "Modifier le texte  ci-dessous...",
    		"social" => "modifier le texte  ci-dessous. Commencer par modifier une categorie"
             );
        }
    
        return $original;
    }

    If it still doesn’t work, please wait for next update of this plugin, I am preparing an interface to ease this kind of thing.

    Thread Starter candy2012

    (@candy2012)

    Hi,

    I must be doing smth. wrong, don’t know whatz.
    I think I’ll have to wait for your update …

    Thank you

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Translating bits of texts from other plugins’ is closed to new replies.