Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I got 2 language version for my website, english and chinese. I am currently follow this post: viewtopic.php?f=5&t=10979 for multi-lingual sites.

I need to put member addons in this project too. Some of them are per-defined, how can I make multiple language of error message?

Code: Select all
<?php
   
   if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly
   
    ///////////EDIT BELOW THIS////////////////////////////////////////
   
    // Names of the required templates
    $t['members_tpl'] = 'members/index.php';
    $t['login_tpl'] = 'members/login.php';
    $t['lost_password_tpl'] = 'members/lost-password.php';
    $t['registration_tpl'] = 'members/register.php';
   
    // Email address used for sending the password-recovery and account-activation emails
    $t['email_from'] = 'no-reply@example.com';
       
    // Text strings used for error messages and emails
    // login
    $t['prompt_username'] = 'Please enter your username';
    $t['prompt_password'] = 'Please enter your password';
    $t['invalid_credentials'] = 'Invalid username or password';
    $t['account_locked'] = 'Account locked';
    $t['account_disabled'] = 'Account disabled';

    // forgot_password
    $t['submit_error'] = 'Please enter your email address';
    $t['no_such_user'] = 'No such user exists';
    $t['reset_password_email_subject'] = 'Password reset requested';
    $t['reset_password_email_msg_0'] = 'A request was received to reset your password for the following site and username';
    $t['user_name'] = 'Username';
    $t['reset_password_email_msg_1'] = 'To confirm that the request was made by you please visit the following address, otherwise just ignore this email.';
    $t['email_failed'] = 'E-Mail could not be sent.';

    // reset_password
    $t['invalid_key'] = 'Invalid key';
    $t['new_password_email_subject'] = 'Your new password';
    $t['new_password_email_msg_0'] = 'Your password has been reset for the following site and username';
    $t['new_password'] = 'New Password';
    $t['new_password_email_msg_1'] = 'Once logged in you can change your password.';

    // registration
    $t['activation_email_subject'] = 'New Account Confirmation';
    $t['activation_email_msg_0'] = 'Please click the following link to activate your account:';
    $t['activation_email_msg_1'] = 'Thanks,';
    $t['activation_email_msg_2'] = 'Website Name';


And If I set the inputs as required='1', the error message will be "Required field cannot be left empty". How can I switch that too?
It will require some tweaking.

First edit your kfunctions.php file that brings in all addons and make the 'multi-lang' addon the very first addon to be included - i.e. move the following line to make it the very first 'require_once' statements there
Code: Select all
require_once( K_COUCH_DIR.'addons/multi-lang/multi-lang.php' );

This will ensure that the addon would have already figured out the current language to use before any other addon gets activated. This way, the addons to follow can know the current language and change act accordingly (in our case. we'll make the 'members' addon to use the selected language).

Next remove the existing 'members/config.php' file and use the following instead -
Code: Select all
<?php

   if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly

    ///////////EDIT BELOW THIS////////////////////////////////////////
    // Names of the required templates
    $t['members_tpl'] = 'members/index.php';
    $t['login_tpl'] = 'members/login.php';
    $t['lost_password_tpl'] = 'members/lost-password.php';
    $t['registration_tpl'] = 'members/register.php';

    // Email address used for sending the password-recovery and account-activation emails
    $t['email_from'] = 'no-reply@example.com';

    // Text strings used for error messages and emails
    global $MultiLang;
    if( $MultiLang ){ $lc = $MultiLang->lc; }

    if( $lc=='cn' ){ /* Put Chinese strings here */
        // login
        $t['prompt_username'] = 'Please enter your username';
        $t['prompt_password'] = 'Please enter your password';
        $t['invalid_credentials'] = 'Invalid username or password';
        $t['account_locked'] = 'Account locked';
        $t['account_disabled'] = 'Account disabled';

        // forgot_password
        $t['submit_error'] = 'Please enter your email address';
        $t['no_such_user'] = 'No such user exists';
        $t['reset_password_email_subject'] = 'Password reset requested';
        $t['reset_password_email_msg_0'] = 'A request was received to reset your password for the following site and username';
        $t['user_name'] = 'Username';
        $t['reset_password_email_msg_1'] = 'To confirm that the request was made by you please visit the following address, otherwise just ignore this email.';
        $t['email_failed'] = 'E-Mail could not be sent.';

        // reset_password
        $t['invalid_key'] = 'Invalid key';
        $t['new_password_email_subject'] = 'Your new password';
        $t['new_password_email_msg_0'] = 'Your password has been reset for the following site and username';
        $t['new_password'] = 'New Password';
        $t['new_password_email_msg_1'] = 'Once logged in you can change your password.';

        // registration
        $t['activation_email_subject'] = 'New Account Confirmation';
        $t['activation_email_msg_0'] = 'Please click the following link to activate your account:';
        $t['activation_email_msg_1'] = 'Thanks,';
        $t['activation_email_msg_2'] = 'Website Name';
    }
    else{ /* default to English */
        // login
        $t['prompt_username'] = 'Please enter your username';
        $t['prompt_password'] = 'Please enter your password';
        $t['invalid_credentials'] = 'Invalid username or password';
        $t['account_locked'] = 'Account locked';
        $t['account_disabled'] = 'Account disabled';

        // forgot_password
        $t['submit_error'] = 'Please enter your email address';
        $t['no_such_user'] = 'No such user exists';
        $t['reset_password_email_subject'] = 'Password reset requested';
        $t['reset_password_email_msg_0'] = 'A request was received to reset your password for the following site and username';
        $t['user_name'] = 'Username';
        $t['reset_password_email_msg_1'] = 'To confirm that the request was made by you please visit the following address, otherwise just ignore this email.';
        $t['email_failed'] = 'E-Mail could not be sent.';

        // reset_password
        $t['invalid_key'] = 'Invalid key';
        $t['new_password_email_subject'] = 'Your new password';
        $t['new_password_email_msg_0'] = 'Your password has been reset for the following site and username';
        $t['new_password'] = 'New Password';
        $t['new_password_email_msg_1'] = 'Once logged in you can change your password.';

        // registration
        $t['activation_email_subject'] = 'New Account Confirmation';
        $t['activation_email_msg_0'] = 'Please click the following link to activate your account:';
        $t['activation_email_msg_1'] = 'Thanks,';
        $t['activation_email_msg_2'] = 'Website Name';
    }


Make sure to reset all the default values in "Names of the required templates" section above to those used by you.

The new config has two sets of messages - one for Chinese and the other for English (the two languages you said you were using. If there are more, use the code above to add more sets).

I don't know Chinese so I have left the messages in the Chinese section untouched. Please edit them to use the Chinese language instead.

And that should now make the members module use messages in accordance to the selected language.

As for your other query
And If I set the inputs as required='1', the error message will be "Required field cannot be left empty". How can I switch that too?
I think you can use the 'validator_msg' parameter with the field (<cms:input>) to set the error message -
http://docs.couchcms.com/tags-reference ... idator_msg

Hope it helps.
Awesome mod. :D
3 posts Page 1 of 1