Constant based on placeholder?

Having a question about translating phpBB3? Want to discuss and collaborate with people currently translating phpBB3? Here would be the correct place to do so.
Anti-Spam Guide
Theodolite
Registered User
Posts: 42
Joined: Wed Dec 29, 2010 3:49 pm

Constant based on placeholder?

Post by Theodolite »

Hi, how to create Constant value based on the placeholder?

Code: Select all

'FOUND_SEARCH_MATCH'		=> 'Search found %d match',
What's the easiest way to do this:

Code: Select all

if (%d == 1) {
string = '%d aaaaaaaaa';
} else { 
string = '%d bbbbbbbbb';
}
?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53563
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Constant based on placeholder?

Post by Brf »

Find the spot in the PHP code where that language string is used, and choose a different language string if the number is not 1.
That is the way it works anyway:

Code: Select all

	'FOUND_SEARCH_MATCH'		=> 'Search found %d match',
	'FOUND_SEARCH_MATCHES'		=> 'Search found %d matches',

Code: Select all

		$l_search_matches = ($total_match_count == 1) ? sprintf($user->lang['FOUND_SEARCH_MATCH'], $total_match_count) : sprintf($user->lang['FOUND_SEARCH_MATCHES'], $total_match_count);
Theodolite
Registered User
Posts: 42
Joined: Wed Dec 29, 2010 3:49 pm

Re: Constant based on placeholder?

Post by Theodolite »

Thanks, but it's my fault. My problem is different and I didn't describe it properly... I mean about plural forms... I see this question was raised before here http://www.phpbb.com/community/viewtopi ... 6&t=401987
But it's an old topic. Are there any solutions to this problem? It's cruficial to my language... Without the solution to this problem forum translation looks messy and unprofessional. :?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53563
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Constant based on placeholder?

Post by Brf »

Yes. I already gave you your solution.
Put your IF statement in the PHP where it is using the language string. Have it choose a different string based on the value that will be used for the parameter, exactly like how is already being done for match(es).
Theodolite
Registered User
Posts: 42
Joined: Wed Dec 29, 2010 3:49 pm

Re: Constant based on placeholder?

Post by Theodolite »

Thanks, but it will be a very big job to find and edit all the constants in original php files. It would be much simpler to have such functionality in language php files. :?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53563
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Constant based on placeholder?

Post by Brf »

Actually, it is very simple to find the spots the language strings are used. Your "match(es)" example is only used in one place, and it took me a few seconds to find it.

You cannot put such functionality in the language files themselves, since they only fill arrays. The section of PHP code which uses the strings is pulling them from the arrays. The variable filled into the placeholder does not even exist at the time the language files are included, so there is not a way to check it there.

Return to “[3.0.x] Translations”