Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Allow placeholders in language lines #1502

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants

webspy commented Jun 18, 2012

I'm proposing a new function to be added to the language helper, lang_format(), which adds support for placeholders in the line of text. These placeholders can be replaced with actual values:

// $lang['language_key1'] = 'You have ? new messages.';
// $lang['language_key2'] = 'Are you sure you want to remove %s from %s ?';

echo lang_format('language_key1', 10);
// outputs: You have 10 new messages.

echo lang_format('language_key2', array('Item 1', 'Category 1'), '%s');
// outputs: Are you sure you want to remove Item 1 from Category 1 ?

Please excuse any mistakes in the pull procedure, I'm new to GitHub.

Contributor

mpmont commented Jun 19, 2012

why not just use sprintf http://php.net/manual/pt_BR/function.sprintf.php on your lang key using the normal lang() helper method?

webspy commented Jun 19, 2012

You do have a point, I just thought having the ability to replace placeholders and have custom placeholder characters/strings in one simple function might be a nice addition to the language helper.

Contributor

philsturgeon commented Jun 24, 2012

It's one of those things, that if lang() had only 1 parameter I'd suggest adding it as the 2nd param, but as we have 2 this array would have to be a new third parameter which is ugly.

Adding a new function for something similar to an existing function, when the new function does something that can be done with a native function... well I don't think it needs to be in there.

sprintf + lang = lang_format, so no need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment