Language

Set language #

To set language to your application, you simply do:

use koolreport\dashboard\Application;
use \koolreport\dashboard\languages\ES;

class App extends Application
{
    protected function onCreated()
    {
        $this->language(ES::create());
    }
}

Available languages #

Here is the list of languages we have provided inside dashboard framework

use \koolreport\dashboard\languages\DE;     //Germany
use \koolreport\dashboard\languages\EN;     //English
use \koolreport\dashboard\languages\ES;     //Spanish
use \koolreport\dashboard\languages\FR;     //French
use \koolreport\dashboard\languages\ID;     //Indonesian
use \koolreport\dashboard\languages\IT;     //Italian
use \koolreport\dashboard\languages\ML;     //Malay
use \koolreport\dashboard\languages\PTBR;   //Portuguese Brazil
use \koolreport\dashboard\languages\TH;     //Thai
use \koolreport\dashboard\languages\VN;     //Vietnamse

Note: We understand that our number of languages provided is small, we hope to receive your help to get more language translation.

Extra translation texts #

In your application, beside our default translation, you may wish to do extra translation for your text

Example:

// We use Vietnamese as our app language
use koolreport\dashboard\Application;
use \koolreport\dashboard\languages\VN;

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

In our application, anywhere we can use Lang::t() to translate our text

use koolreport\dashboard\Dashboard;
use koolreport\dashboard\Lang;

class MyDashboard extends Dashboard
{
    protected function content()
    {
        return [
            Html::h1(Lang::t("Anything")), // Showing "Bất cứ thứ gì"
            Html::p(Lang::t("amazing")),   // Showing "tuyệt vời"
        ];
    }
}

Multiple languages #

Another great feature of Dashboard Framework is to support multiple language application. Meaning that user of your application can choose the languages that they want. By providing list of available languages into languages() methods of your app, an language selector will be shown to let user choose their preferred language

use koolreport\dashboard\Application;

use \koolreport\dashboard\languages\DE;     //Germany
use \koolreport\dashboard\languages\EN;     //English
use \koolreport\dashboard\languages\ES;     //Spanish
use \koolreport\dashboard\languages\FR;     //French

class App extends Application
{
    protected function languages()
    {
        // Return list of available languages for your users
        return [
            DE::create(),
            EN::create(),
            ES::create(),
            FR::create(),
        ];
    }
}

Now look at your application, you will see a language selector on top right corner. Amazing and save time, is't it?

Manual change language #

When your application has multiple languages, you can change language by calling changeLanguage of Application.

Example:

Button::create()->text("Change language to Spanish")
    ->onClick(
        Client::app()->changeLanguage("ES");
    )

Lang's static methods #

Namedescription
Lang::t(string $text)Return translation of the text
Lang::echo(string $text)Echo translation of text, short-handed of echo Lang::t($text)
Lang::name()Return name of current language

Get started with KoolReport

KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.