Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Derek Herman

    (@valendesigns)

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

    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: https://wpml.org/documentation/support/translation-for-texts-by-other-plugins-and-themes/

    Plugin Author Derek Herman

    (@valendesigns)

    @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.

    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):
    https://www.ads-software.com/support/topic/issues-with-i18n-l10n-incl-fixes
    https://www.ads-software.com/support/topic/font-family-boxes-not-showing-selected-fix
    https://www.ads-software.com/support/topic/function-call-with-too-few-arguments

    Feature requests:
    https://www.ads-software.com/support/topic/request-for-implementation-of-new-media-uploader-wp-35
    https://www.ads-software.com/support/topic/feature-request-multiple-select-and-tagbox-like-input
    https://www.ads-software.com/support/topic/feature-request-option-to-move-optionspanel-theme-options-to-main-menu (filter for ‘parent_slug’)

    Plugin Author Derek Herman

    (@valendesigns)

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

    Plugin Author Derek Herman

    (@valendesigns)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Option Tree and WPML’ is closed to new replies.