KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Bug in the Language Documentation or...? #3366

Closed Eugene opened this topic on on Oct 28 - 4 comments

Eugene commented on Oct 28

Hi, in your documentation https://www.koolreport.com/docs/dashboard/language/ you say that to add some extra translations I have to add them in onCreated() method of App

protected function onCreated()
    {
        $this->language(
            VN::create()->extra([
                "Anything"=>"Bất cứ thứ gì",
                "amazing"=>"tuyệt vời",
            ])
        );
    }

also you say that to add a support of multiple languages I have to do this:

protected function languages()
    {
        // Return list of available languages for your users
        return [
            VN::create(),
            EN::create(),
        ];
    }

But this approach introduces an issue: the create() method is executed twice, and on the second run, without any additional translations. As a result, all custom translations are lost.

If I keep only one

protected function languages()
    {
        // Return list of available languages for your users
        return [
            VN::create()->extra([
                "Anything"=>"Bất cứ thứ gì",
                "amazing"=>"tuyệt vời",
            ]),
            EN::create(),
        ];
    }

it works

Eugene commented on Oct 28

PS of course I meant a Bug in my title

KoolReport commented on Oct 29

You do this:

protected function onCreated()
    {
        Lang::instance()->setLanguageByName("VN");
    }
protected function languages()
    {
        // Return list of available languages for your users
        return [
            VN::create()->extra([
                "Anything"=>"Bất cứ thứ gì",
                "amazing"=>"tuyệt vời",
            ]),
            EN::create(),
        ];
    }

By this way, it does not run twice for VN language.

KoolReport commented on Oct 29

Sorry for above suggestion, the setLanguageByName() will save the selection "VN" into cookie and prevent the language change. So I guess you just remove the language setting in the onCreated and let the dashboard choose the default language (which is the first one or the one that you set default):

protected function languages()
    {
        // Return list of available languages for your users
        return [
            VN::create()->extra([
                "Anything"=>"Bất cứ thứ gì",
                "amazing"=>"tuyệt vời",
            ]),
            EN::create()->default(),
        ];
    }
Eugene commented on Oct 29

Yeah, it is what I meant - you should change a bit your docs to avoid misunderstanding

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

Dashboard