added translation for charts
This commit is contained in:
@ -199,6 +199,8 @@ abstract class Report
|
||||
|
||||
$chart->setType('bar')
|
||||
->setOptions($options)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($this->dates))
|
||||
->setDataset($this->tables[$table_key], 'column', array_values($this->footer_totals[$table_key]));
|
||||
|
||||
@ -246,6 +248,8 @@ abstract class Report
|
||||
|
||||
$chart->setType('donut')
|
||||
->setOptions($options)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($labels))
|
||||
->setColors(array_values($colors))
|
||||
->setDataset($this->tables[$table_key], 'donut', array_values($values));
|
||||
|
@ -60,6 +60,8 @@ trait Charts
|
||||
$chart->setType('donut')
|
||||
->setWidth($width)
|
||||
->setHeight($height)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($labels))
|
||||
->setColors(array_values($colors))
|
||||
->setDataset($name, 'donut', array_values($values));
|
||||
@ -81,6 +83,8 @@ trait Charts
|
||||
$chart->setType('bar')
|
||||
->setWidth($width)
|
||||
->setHeight($height)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($this->bar['labels']))
|
||||
->setColors($this->bar['colors']);
|
||||
|
||||
@ -165,4 +169,44 @@ trait Charts
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
public function getDefaultLocaleOfChart(): string
|
||||
{
|
||||
$default = 'en';
|
||||
|
||||
$short = language()->getShortCode();
|
||||
$long = language()->getLongCode();
|
||||
|
||||
$short_path = public_path('vendor/apexcharts/locales/' . $short . '.json');
|
||||
$long_path = public_path('vendor/apexcharts/locales/' . $long . '.json');
|
||||
|
||||
if (is_file($short_path)) {
|
||||
return $short;
|
||||
}
|
||||
|
||||
if (is_file($long_path)) {
|
||||
return $long;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getLocaleTranslationOfChart(?string $locale = null): array
|
||||
{
|
||||
$translations = [];
|
||||
|
||||
$user_locale = $locale ?: $this->getDefaultLocaleOfChart();
|
||||
|
||||
$locales = ($user_locale == 'en') ? [$user_locale] : [$user_locale, 'en'];
|
||||
|
||||
foreach ($locales as $loc) {
|
||||
$translations[] = json_decode(
|
||||
file_get_contents(
|
||||
public_path('vendor/apexcharts/locales/' . $loc . '.json')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $translations;
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ class CashFlow extends Widget
|
||||
|
||||
$chart->setType('line')
|
||||
->setOptions($options)
|
||||
->setDefaultLocale($this->getDefaultLocaleOfChart())
|
||||
->setLocales($this->getLocaleTranslationOfChart())
|
||||
->setLabels(array_values($labels))
|
||||
->setColors($colors)
|
||||
->setDataset(trans('general.incoming'), 'column', $income)
|
||||
|
Reference in New Issue
Block a user