WordPress.org

Ready to get started?Download WordPress

Forums

OptionTree
Option Tree and WPML (7 posts)

  1. federicom985
    Member
    Posted 1 year ago #

    Hello, I have problem in translating with WPML strings insterted in Option tree. WPML cannot see them. How to solve?

    http://wordpress.org/extend/plugins/option-tree/

  2. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    I need more information, I'm not familiar with your issue.

  3. kraterdesign
    Member
    Posted 1 year ago #

    I just happened to have recently modified a theme to make its admin options compatible with WPML, so maybe I can shed some light on this...

    The OptionTree code that saves input would for example need an extra line of code, right after calling update_option( $id, $value);

    if (function_exists('icl_register_string')) icl_register_string('OptionTree', $id, $value));

    and right after calling delete_option( $id );

    if (function_exists('icl_unregister_string')) icl_unregister_string('OptionTree', $id);

    That would make WPML (if installed) 'see' the strings OptionTree manipulates in the DB and allow them to be translated via the WPML String Translation plugin.

    The same goes for any other places/methods where OptionTree saves/manipulates user-inputted strings which someone might want to be able to translate (even URLs, as you might want to show a different URL linking to something, depending on the language the site is displayed in).

    Then to display the translated strings, you would use

    echo icl_t('OptionTree', $id, get_option($id));

    and a few extra lines of code in OptionTree to make icl_t() also work when WPML is not installed:

    if(!function_exists('icl_t')){
    	function icl_t($c, $n, $str){return $str;}
    }

    Voila, everything inputted can be translated by WPML users and those without won't notice anything different.

    See for more info: http://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/

  4. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    @kraterdesign Which 'update_option' are you referring to in the core of OptionTree? I'm currently trying to make OT compatible with WPML but since I'v never used the plugin I've got a steep learning curve if I want to get it finished this weekend.

  5. kraterdesign
    Member
    Posted 1 year ago #

    I modified a theme's admin panel code, not OT. That panel stored each entry as separate options btw (horrible, I know), so I wasn't speaking of any specific update_option in OptionTree's code.

    Looking at the latest version though, I'd say in ot-functions-admin.php, either right after all four of the calls like update_option( 'option_tree', .... ), OR perhaps better yet, inside the function ot_after_theme_options_save().

    You could use a function like this for recursively registering strings from the $options array you retrieve there:

    function icl_register_string_recursively( $context, $name, $value ) {
        $value = maybe_unserialize( $value );
        if ( is_array( $value ) ) {
            foreach ( $value as $k => $v )
                icl_register_string_deep( $context, $k, $v );
        } else {
            icl_register_string( $context, $name, $value );
        }
    }

    and pass the $options array like:

    if ( function_exists('icl_register_string') ) {
        icl_register_string_deep('OptionTree', null, $options);
    }

    Add the dummy icl_t function (see previous post) in case WPML is not installed/active and you could then modify ot_get_option() to always pass the value through icl_t() with the 'OptionTree' context, before returning it.

    You'll also need to UNREGISTER (with WPML) previously registered strings that have been deleted as OT options. So before you're doing update_option( 'option_tree_settings', ...), you need to array_diff the old array of settings against the new array and recursively unregister all deleted settings.

    Hope this helps.

    PS. would really appreciate if you could spare the time to take a look at my other OptionTree comments.

    Bugs (some with fixes):
    http://wordpress.org/support/topic/issues-with-i18n-l10n-incl-fixes
    http://wordpress.org/support/topic/font-family-boxes-not-showing-selected-fix
    http://wordpress.org/support/topic/function-call-with-too-few-arguments

    Feature requests:
    http://wordpress.org/support/topic/request-for-implementation-of-new-media-uploader-wp-35
    http://wordpress.org/support/topic/feature-request-multiple-select-and-tagbox-like-input
    http://wordpress.org/support/topic/feature-request-option-to-move-optionspanel-theme-options-to-main-menu (filter for 'parent_slug')

  6. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    @kraterdesign Do you have skype? I'd like to pick your brain if you have 10-15 minutes to chat? My handle is valendesigns

  7. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    OK, I ran into some an pretty big issue with arrays and since I need to push a version to fix some regression issues from 2.0.13 I'll have to hold off on adding this until 2.0.15 and I get a chance to test it more.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic