Laravel Datatables Localization Example

In this article, we will see laravel datatables localization example. jquery datatable plugin can localize all the displayed strings by setting the localization property to default localization members. You can localization of datatable column headings or website localization is the process of rendering your app in multiple languages.

So, let's see laravel 8 localization, jquery datatable localization, datatables change language dynamically, Internationalisation, localization laravel 8, multi language in laravel 8, datatable jquery localization.

Laravel localization features provide a convenient way to retrieve text in different languages here we are using jquery datatable.

Step 1 : Create a Localization File

In this step, we will create a localization file language wise. here I create two files first one for English and the second one is Chinese.

1. resources/lang/en/datatable.php
2. resources/lang/zhh/datatable.php

Now, we need to create an array in this file location resources/lang/zhh/datatable.php file. Same as also creating datatable.php for English string and add text in that file.


return [

    'General' =>
        'Cancelled' => '取消',
        'Delete' => '删除',
        'Delivered' => '递送',
        'Edit' => '修改',
        'emptyTable' => '表中没有可用数据',
        'History' => '历史记录',
        'info' => '显示_TOTAL_条目的_START_到_END_',
        'infoEmpty' => '显示0个条目中的0到0',
        'infoFiltered' => '(从_MAX_条目总数中过滤)',
        'lengthMenu' => '显示:_MENU_',
        'loadingRecords' => '加载中...',
        'processing' => '处理中...',
        'search' => '搜索:',
        'searchPlaceholder' => '搜索记录',
        'zeroRecords' => '没有找到匹配的记录',


Step 2 : Add Localization Code in Blade File

Now, add the below code to your script tag or data table.



Example 1 : Using trans() function

In this example, we will use the trans() function to translate the text of the datatable.

"language": {
           "emptyTable":     "{{trans('datatable.General.emptyTable')}}",
           "info":           "{{trans('')}}",
           "infoEmpty":      "{{trans('datatable.General.infoEmpty')}}",
           "infoFiltered":   "{{trans('datatable.General.infoFiltered')}}",
           "lengthMenu": "{{trans('datatable.General.lengthMenu')}}",
           "loadingRecords": "{{trans('datatable.General.loadingRecords')}}",
           "processing":     "{{trans('datatable.General.processing')}}",
           "search":         "{{trans('')}}",
           "searchPlaceholder": "{{trans('datatable.General.searchPlaceholder')}}",
           "zeroRecords":    "{{trans('datatable.General.zeroRecords')}}",


Example 2 : Using @json() function

In this example, we will use the @json() function to translate the text of the datatable.

language: {
            paginate: { 'first': 'First', 'last': 'Last', 'next': '&rarr;', 'previous': '&larr;' },
            emptyTable:     @json(__('datatable.General.emptyTable')),
            info:           @json(__('')),
            infoEmpty:      @json(__('datatable.General.infoEmpty')),
            infoFiltered:   @json(__('datatable.General.infoFiltered')),
            loadingRecords: @json(__('datatable.General.loadingRecords')),
            processin:     @json(__('datatable.General.processing')),
            zeroRecords:    @json(__('datatable.General.zeroRecords')),
            lengthMenu: @json(__('datatable.General.lengthMenu')),
            search:         @json(__('')),
            searchPlaceholder: @json(__('datatable.General.searchPlaceholder')),


You might also like :