Forums  ›  General  ›  General discussions
 

How does {0} work in language keys

 

Yes, but the _t function only supports 3 arguments. So 0, 1, and 2 only.

 OK, that is probably fine for most things.

 

I definitely need to add an entry on Nginx; especially the rewrites as Nginx handles rewrites completely different.

The Nginx section is already in there. It is empty. I had set you as the owner of that item so you should be able to edit the current entry.

I will be moving the docs to a actual wiki when i find the time to complete it. I just don't have time to add the features i want to the doc module. So i am just going to use mediawiki. It's almost ready to go.

{0} is $site['url'] and {1} is $site['title'].  You are basically using the 0, 1, 2, 3 to equate to the position of the parameters as they are listed in the _t() call.

Yes, but the _t function only supports 3 arguments. So 0, 1, and 2 only.

I had basically stepped away from any Dolphin (and now Cheetah) development work for a few years.  As I pull things back into focus, maybe I should add to the tutorials or maybe in the Cheetah Docs.  I added a section to the Cheetah Docs the other day because I am working on a Cheetah site and the owner was unsure of the actions; how they applied.  So I decided to add it to the Cheetah Docs for others.  It was based on Nathan's write up.  I definitely need to add an entry on Nginx; especially the rewrites as Nginx handles rewrites completely different.

As I work to understand I look at code.  In the forgot.php there is this code snippet:

if ($mail_ret)

        $action_result = _t( "_MEMBER_RECOGNIZED_MAIL_SENT", $site['url'], $site['title'] );

    else

The language key for this is:

'_MEMBER_RECOGNIZED_MAIL_SENT' => 'You have been recognized as a {1} member and your account details have just been sent to you. Once you receive the letter from us, <a href="{0}member.php">log-in here</a>.'

{0} is $site['url'] and {1} is $site['title'].  You are basically using the 0, 1, 2, 3 to equate to the position of the parameters as they are listed in the _t() call.

 

OK, I think I am gaining some ground on this.  I see this: 

function showBlockEcho( $sCaption, $sContent )

    {

        echo DesignBoxContent( _t($sCaption), $sContent, 1 );

    }

 

So the language key is passed to the $sCaption variable and $sCaption is passed to _t().

 
Yes. _t handles translating of all language keys.

In your example above you could change _t($sCaption) to _t($sCaption, $sNickname) to pass a nick name to the _t function. Then edit your language key and add a {0} where you want the nickname to appear.


I will have to look into it, but i don't think the template key for language keys which is <ch_text:_key> is able to parse extra parameters. So i don't think it can be used within templates. But i could be wrong, i just have not fully investigated it.

OK, I think I am gaining some ground on this.  I see this: 

function showBlockEcho( $sCaption, $sContent )

    {

        echo DesignBoxContent( _t($sCaption), $sContent, 1 );

    }

 

So the language key is passed to the $sCaption variable and $sCaption is passed to _t().

I am a little bit confused.  On the Profile Comments block the only place I find _profile_comments is in the install sql file:

('profile', '1140px', 'Comments on member profile', '_profile_comments', 0, 0, 'Cmts', '', 1, 71.9, 'non,memb', 0, 0),

I don't see it being run through the _t().  So how is that handled?  Does the _t() also handle translations?

 

The {0} replacement is handled in the language key function _t

In code the language key is translated using the _t function. Example. echo _t('_my_key');

The {0}, {1} and {2} are replaced with optional perams that can be passed in that function.  Example echo _t('_my_key', $sParam1, $sParam2, $sParam3);

In language keys how does the {0} replacement work?  Can this be used in the header of blocks where we have such things as Video Albums so that I can have Jim's Video Albums?