Chumper / Datatable

This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
https://github.com/Chumper/Datatable
388 stars 153 forks source link

Problem with language settings #242

Open fabioi opened 9 years ago

fabioi commented 9 years ago

Hello,

First of all thanks! for your plugin It is incredibly useful!

I am having problems with language settings.

I published the configuration and replaced the content of the config file with the one posted in the last comment of the issue #112 but I keep having English as output (es: search, records per page etc).

I tried clearing caches too but without any result. Any idea of what could cause the issue?

Those are the js I use:

...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.9.4/js/jquery.dataTables.min.js"></script>
<script src="{{asset('assets/js/datatables/datatables-bootstrap.js')}}"></script>
<script src="{{asset('assets/js/datatables/datatables.fnReloadAjax.js')}}"></script>

This it the code in the controller I use to return the data

$places = Place::all();

        return Datatable::collection($places)
                        ->showColumns('name', 'municipality', 'province', 'address', 'zipcode', 'latitude', 'longitude', 'created_at', 'updated_at')
                        ->searchColumns('name')
                        ->orderColumns('name', 'province', 'municipality')
                        ->setAliasMapping(true)//required to use column aliases
                        ->addColumn(
                'actions', function ($places) {
                return '<a href=' . URL::to("admin/places/$places->id/edit") . " class='iframe btn btn-xs btn-default'>" . Lang::get("button.edit") . "</a>" .
                '<a href=' . URL::to("admin/places/$places->id/delete") . " class='iframe btn btn-xs btn-danger'>" . Lang::get("button.delete") . "</a>";
            }
            )
                        ->make();

This is the code in the view

{{ Datatable::table()
      ->addColumn(array(
         'name'           =>  'Nome',
         'municipality'   =>  'Località',
         'province'       =>  'Provincia',
         'address'        =>  'Indirizzo',
         'zipcode'        =>  'CAP',
         'latitude'       =>  'Latitudine',
         'longitude'      =>  'Longitudine',
         'created_at'     =>  'Creato il',
         'updated_at'     =>  'Aggiornato il',
         'actions'        =>  'Azioni'
        ))

       ->setUrl(route('api.places.data'))   // this is the route where data will be retrieved

       ->render() }}

The language part of the config file:

'options' => array(
            "sPaginationType" => "full_numbers",
            "bProcessing" => false,
            'language' => array(

                'processing'=>     'Procesando...',
                'lengthMenu'=>     'Mostrar _MENU_',
                'zeroRecords'=>    'No se encontraron resultados',
                'emptyTable'=>     'Ningún dato disponible en esta tabla',
                'info'=>           'Del _START_ al _END_ de _TOTAL_ registros',
                'infoEmpty'=>      'Del 0 al 0 de un total de 0 registros',
                'infoFiltered'=>   '(filtrado de un total de _MAX_ registros)',
                'infoPostFix'=>    '',
                'search'=>         'Buscar',
                'url'=>            '',
                'infoThousands'=>  ',',
                'loadingRecords'=> 'Cargando...',

                'paginate'=> array(
                    'first'=>    '<<',
                    'last'=>     '>>',
                    'next'=>     '>',
                    'previous'=> '<'
                ),

                'aria'=> array(
                    'sortAscending' =>  'Ordenar la columna de manera ascendente',
                    'sortDescending' => 'Ordenar la columna de manera descendente'
                ),

            ),

        ),
rvbz commented 9 years ago

Hi, good day, Here is how you should do it:

I recommend you to put the lenguaje part on a separate file as a json file. Then in your view just do this:

$langFile = URL::asset("route/to/your/languajeFile.json");
{{ Datatable::table()->setOptions(array('language' => array('url' => $langFile)))
->setUrl(route('api.places.data'))
->render() }}

And that's it, let me know if it works