Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Small question for Lang::get()
  • Hi,

    I have an request for \Lang::get();

    For example, if i do echo \Lang::get('frontend.hello'); and "frontend.hello" doesn't exist in my language file, it's output an empty string.

    It's not better to output "frontend.hello" instead of an empty string if the classe doesn't find the key in language file ?

    With this feature, we can quickly identify no translation made, no ?
  • Good question, didn't think about it.
  • HarroHarro
    Accepted Answer
    It does not return an empty string, it returns null. And it does so because you haven't defined a default value, i.e. something that should be returned if the language value does not exist.

    This is the standard behaviour for the lang class, anything other is considered application specific, and should be dealt with in your application. I have apps that do:

    class Lang extends \Fuel\Core\Lang
    {
        public static function get($line, array $params = array(), $default = null, $language = null)
        {
            if (func_num_args() < 3)
            {
                $default = '<span style="background-color;yellow;color:black;">'.$line.'</span>';
            }

            return parent::get($line, $params, $default, $language);
        }
    }

    to not only return the input, but also make it very obvious you're missing something.
  • Hi,

    I haven't see you can define a default value, it's fix my request.

    And thanks for your code :-)
  • Yes sure, i was convinced that there was no argument "default", sorry for my mistake ;-)
  • For info, i have edited your extends at comment #3

    I have replace "func_num_args() < 3", with "$default === null" because i use __() function

    And it's work fine

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion