KoolReport's Forum

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

How to add new translations to my class? #2840

Closed GHSix opened this topic on on Oct 3, 2022 - 11 comments

GHSix commented on Oct 3, 2022

I see that the new translations files have an array_merge([...], $this->_extra()) but I can't find where and how to add this extra to my classes.

Second, do I need it to be class based or can I have a global extra translations in the Dashboards's App.php or something?

KoolReport commented on Oct 4, 2022

You do this:

use \koolreport\dashboard\languages\PTBR;
class App extends Application
{
    protected function onCreated()
    {
        $this->language(
            PTBR::create()
            ->extra([
                "Customer"=>"Customer in PT language",
                ...
            ])
        );
    }
}

You can create your own class if you want:

class MyPT extends PTBR
{
    protected function onCreated()
    {
        $this->extra([
            "Customer"=>"Customer in PT language"
            ...
        ]);
    }
}

then you set in App: $this->language(MyPT::create());

The language in version 4.x of dashboard is different from 3.x. The previous 3.x language use trait to set language but 4.x use class to provide more flexibility in settings and wider range of usecase.

GHSix commented on Oct 4, 2022

Nice. Thank you.

If I decide to let my Dashboard with only one language, can I hide the flag at top bar?

KoolReport commented on Oct 4, 2022

Remove the method languages in App to disable language selector.

//protected function languages()
//{
//    ...
//}
GHSix commented on Oct 4, 2022

Tryed to comment EN and languages() but Lang::t('Back') stopped working and is printing just "Back".

// use \koolreport\dashboard\languages\EN;
use \koolreport\dashboard\languages\PTBR;

class App extends Application
{

/*protected function languages()
    {
        return [
            PTBR::create(),
            EN::create(),
        ];
    }*/

I know, why use Lang if I will only use PTBR?

If I can let it PTBR only I will probably not need to translate all the rest to EN too. But I'm not sure and, if possible, I want to let all prepared to easy switch to multilanguage if needed.

GHSix commented on Oct 4, 2022

I guess I got it, I may use

Lang::t('Cliente') // In ptbr

and, If needed I can extend EN to translate from PTBR to EN like in

class MyEN extends EN
{
    protected function onCreated()
    {
        $this->extra([
            'Cliente' => 'Customer',
        ]);
    }
}

Am I right? I'm not sure it's the best way.

KoolReport commented on Oct 5, 2022

Yes, it is seems the best way, you use the PTBR as default so that all the English framework text like "Back" is translated to your PT. When you change to MyEN, the default text like "Back" will not be translated (so it is correct in English), but those text in PT like "Cliente" will be translated to "Customer".

KoolReport commented on Oct 5, 2022

Another suggestion:

Since our framework default language is EN, all default text are EN. So in your app, you use PTBR as language, and provide the extra translation like "Customer"=>"Cliente".

In your app, anywhere that you need to output something in PTBR, you do:

Lang::t("Content in English")

And in your translation PTBR, you add:

"Content in English"=>"Content in PTBR"

It is also a good solution.

GHSix commented on Oct 5, 2022

Thank you.

I noticed that Username and Password at Login are not getting translated and even adding 'Username' => 'Usuário', 'Password' => 'Senha' to my translation did not changed it, so I guess it's hard coded.

KoolReport commented on Oct 5, 2022

Thank you for letting us know, I have reported to dev,team

KoolReport commented on Oct 6, 2022

You can upgrade to Dashboard 4.1.3 with KoolReport Pro 6.0.4, the issue has been fixed in Login. And by the way, the FlexView has "historyBack()" method to bring back previous view easier. Thank you very much.

GHSix commented on Oct 6, 2022

Big thank you

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
help needed
solved

Dashboard