umdevelopera / um-account-tabs

Adds custom tabs to user account
GNU General Public License v3.0
9 stars 2 forks source link

Translating account tabs #10

Open hazirahs opened 9 months ago

hazirahs commented 9 months ago

Hi, how do I translate the account tabs (title plus the content from shortcode) using polylang or poedit? I translated the UM profile aside from the tabs through Poedit with no problem.

umdevelopera commented 8 months ago

Hello @hazirahs

Custom account tabs cannot be translated using multilingual plugins. This is the same problem as translating custom profile tabs.

Custom tabs can only be translated using hooks and custom functions. Use hook um_account_page_default_tabs_hook for account tabs.

Example

function my_translate_account_tabs( $tabs ) {
    $lang  = pll_current_language();

    $texts = array(
        'Account' => array(
            'en' => 'Account',
            'es' => 'Cuenta',
        ),
        'Change Password' => array(
            'en' => 'Change Password',
            'es' => 'Cambiar la contraseña',
        ),
        'Custom fields' => array(
            'en' => 'Custom fields',
            'es' => 'Campos Personalizados',
        ),
        'Social fields' => array(
            'en' => 'Social fields',
            'es' => 'Campos sociales',
        ),
    );

    foreach ( $tabs as $p => $tab ) {
        foreach ( $tab as $k => $tabdata ) {
            if ( isset( $tabdata['title'] ) ) {
                $t = $tabdata['title'];
                if ( array_key_exists( $t, $texts ) ) {
                    if ( array_key_exists( $lang, $texts[ $t ] ) ) {
                        $tabs[ $p ][ $k ]['title'] = $texts[ $t ][ $lang ];
                    }
                }
            }
        }
    }
    return $tabs;
}
add_filter( 'um_account_page_default_tabs_hook', 'my_translate_account_tabs', 110, 1 );

There are many texts in UM that can not be easily translated. I want to add a tool for translating such texts to the extension for Polylang integration but this requires a lot of time because every place needs a specific hook.

metechant commented 2 weeks ago

Hello my friend, first of all thank your for your plugins. All of them are very useful. I can understand that we can cant change the tabs as we do like in pages or forms. But I have some questions that I couldnt find any solution. I have a tab called as "Kişisel Bilgiler" which is turkish and I have a form for that. In turkish language selected there is no problem. And I have english form of the form created with polylang. but when I change the title with the code above and choose english title comes in english but I cant get the english form published on frontend still the turkish form comes. Any advice or solution for this?