Posts: 32
Threads: 22
Joined: Jun 2015
Reputation:
0
Dear all,
I have the string with passing parameters as below:
$lang["error"]="this is error {0} with msg {1}"
How to pass {0} and {1} to $lang["error"] and show on php webpage??
$this->lang->line("error", "crazy", "want to do something good");
Is it possible??
Posts: 1,315
Threads: 21
Joined: Jan 2014
Reputation:
70
Here's the idea...
$lang["error"]="this is error %s with msg %s"
then
$result = sprintf($this->lang('error'),"crazy,"want to do something good");
Display $result on your webpage or whatever.
Posts: 157
Threads: 35
Joined: Jun 2015
Reputation:
2
10-02-2015, 06:19 AM
(This post was last modified: 10-02-2015, 06:21 AM by jLinux.)
(10-02-2015, 05:22 AM)ciadmin Wrote: Here's the idea...
$lang["error"]="this is error %s with msg %s"
then
$result = sprintf($this->lang('error'),"crazy,"want to do something good");
Display $result on your webpage or whatever. This is the exact solution I was going to suggest.
If you want, you could do something like extend the lang library and either create a new method that will do this, or change the Lang::line method to look for parameters via Variadic functions, or if you dont have PHP 5.6 or later, use func_num_args to check if any arguments were passed, if not, just use the parent::line(), if there were, then handle them using func_get_args and sprintf, thats what I would do anyways.
Posts: 22
Threads: 1
Joined: Nov 2014
Reputation:
3
(10-02-2015, 06:19 AM)jLinux Wrote: (10-02-2015, 05:22 AM)ciadmin Wrote: Here's the idea...
$lang["error"]="this is error %s with msg %s"
then
$result = sprintf($this->lang('error'),"crazy,"want to do something good");
Display $result on your webpage or whatever. This is the exact solution I was going to suggest.
If you want, you could do something like extend the lang library and either create a new method that will do this, or change the Lang::line method to look for parameters via Variadic functions, or if you dont have PHP 5.6 or later, use func_num_args to check if any arguments were passed, if not, just use the parent::line(), if there were, then handle them using func_get_args and sprintf, thats what I would do anyways.
the Variadic functions got my attention... So its like extending the Lang classs to use lang->line(line, args, args) instead of sprintf(lang->line(), ..., ...). I'd try that
TastyIgniter - Open Source Restaurant Ordering and Management System
Posts: 157
Threads: 35
Joined: Jun 2015
Reputation:
2
(10-04-2015, 10:23 AM)sampoyigi Wrote: (10-02-2015, 06:19 AM)jLinux Wrote: (10-02-2015, 05:22 AM)ciadmin Wrote: Here's the idea...
$lang["error"]="this is error %s with msg %s"
then
$result = sprintf($this->lang('error'),"crazy,"want to do something good");
Display $result on your webpage or whatever. This is the exact solution I was going to suggest.
If you want, you could do something like extend the lang library and either create a new method that will do this, or change the Lang::line method to look for parameters via Variadic functions, or if you dont have PHP 5.6 or later, use func_num_args to check if any arguments were passed, if not, just use the parent::line(), if there were, then handle them using func_get_args and sprintf, thats what I would do anyways.
the Variadic functions got my attention... So its like extending the Lang classs to use lang->line(line, args, args) instead of sprintf(lang->line(), ..., ...). I'd try that
Yep, thats very possible! Ive thought about doing it, but I havent gotten to the part of my app where I work on the multi-lingual stuff
Posts: 644
Threads: 13
Joined: Oct 2014
Reputation:
37
If there are enough people wanting this feature, the following topic could be reconsidered: https://github.com/bcit-ci/CodeIgniter/pull/3223
Posts: 157
Threads: 35
Joined: Jun 2015
Reputation:
2
Nice, the code in here is exactly what i planned on doing: https://github.com/bcit-ci/CodeIgniter/p...t-54707715
Posts: 22
Threads: 1
Joined: Nov 2014
Reputation:
3
(10-04-2015, 01:58 PM)ivantcholakov Wrote: If there are enough people wanting this feature, the following topic could be reconsidered: https://github.com/bcit-ci/CodeIgniter/pull/3223
Thank you sharing. Looking at the code gives a better idea of the logic.
TastyIgniter - Open Source Restaurant Ordering and Management System
|