Hello,
could somebody explain me how I can translate my Datatable? For example
localhost/en/page
| id | fistname | lastname |
localhost/de/page
| id | vorname | nachname |
I am using this package for localization: https://github.com/mcamara/laravel-localization
I am not really using any localization yet on any of my projects so I may not be able to answer this. Lets wait for other users feedback I guess.
Anyways, have you tried using trans() or __() helper when rendering the table markup?
Use trans or __ helper to localize server-side strings: column title, contents...
Use language datatables option to localize datatables.js: "Loading..." "No matching records found", etc, see https://datatables.net/plug-ins/i18n/
The problem is where to add the code?
I added the language parameter into the parameter function in html function according to this link.
I put the lang file under public\vendor\datatables\lang\{lang}.json.
public function html()
{
return $this->builder()
->columns($this->getColumns())
->addAction(['width' => '150px', 'title' => trans('labels.general.actions')])
->ajax('')
->parameters([
'language' => [
'url' => url('/vendor/datatables/lang/'.config('app.locale').'.json'),//<--here
],
// other configs
]);
}
@skys215 also the same problem here... could solve?
my code:
$html = $builder->parameters([
'paging' => true,
'searching' => true,
'info' => true,
'searchDelay' => 350,
'language' => [
'url' => url('vendor/datatables/Portuguese-Brasil.lang')
],
])->columns([
['data' => 'id', 'title' => '#', 'footer' => 'Id'],
['data' => 'created_at', 'title' => 'Created At', 'footer' => 'Created At'],
['data' => 'updated_at', 'title' => 'Updated At', 'footer' => 'Updated At']
]);
I tested it with CDN and apparently it worked, it should be something with the file = S
Thanks!!!
Most helpful comment
I added the language parameter into the
parameterfunction inhtmlfunction according to this link.I put the lang file under
public\vendor\datatables\lang\{lang}.json.