Skip to content

Instantly share code, notes, and snippets.

@ricardodovalle
Last active November 15, 2018 01:22
Show Gist options
  • Save ricardodovalle/7244900 to your computer and use it in GitHub Desktop.
Save ricardodovalle/7244900 to your computer and use it in GitHub Desktop.
Rails and jQuery Datatables i18n
jQuery ->
tableContainer = $('#cards_datatable')
tableContainer.dataTable
sDom: "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
sPaginationType: "bootstrap"
bProcessing: true
bServerSide: true
bAutoWidth: false
bStateSave: true
sWrapper: "dataTables_wrapper form-inline"
sAjaxSource: $('#cards_datatable').data('source')
oLanguage:{
sUrl: "datatable_i18n"
}
class DatatablesController < ApplicationController
def datatable_i18n
if params[:locale] == 'pt-BR'
locale = {
'sEmptyTable' => 'Nenhum dado encontrado na tabela',
'sInfo' => 'Mostrando de _START_ ate _END_ de _TOTAL_ registros',
'sInfoEmpty' => 'Mostrando de 0 ate 0 de 0 registros',
'sInfoFiltered' => '(filtrado de _MAX_ registros no total)',
'sInfoPostFix' => '',
'sInfoThousands' => ',',
'sLengthMenu' => '_MENU_ registros por pagina',
'sLoadingRecords' => 'Carregando...',
'sProcessing' => 'Processando...',
'sSearch' => 'Buscar:',
'sZeroRecords' => 'Nenhum dado encontrado',
'oPaginate' => {
'sFirst' => 'Primeiro',
'sLast' => 'Ultimo',
'sNext' => 'Seguinte',
'sPrevious' => 'Anterior'
},
'oAria' => {
'sSortAscending' => ': ativar ordenacaoo crescente na coluna',
'sSortDescending' => ': ativar ordenacaoo decrescente na coluna'
}
}
else
locale = {
'sEmptyTable'=> 'No data available in table',
'sInfo'=> 'Showing _START_ to _END_ of _TOTAL_ entries',
'sInfoEmpty'=> 'Showing 0 to 0 of 0 entries',
'sInfoFiltered'=> '(filtered from _MAX_ total entries)',
'sInfoPostFix'=> '',
'sInfoThousands'=> ',',
'sLengthMenu'=> '_MENU_ records per page',
'sLoadingRecords'=> 'Loading...',
'sProcessing'=> 'Processing...',
'sSearch'=> 'Search:',
'sZeroRecords'=> 'No matching records found',
'oPaginate'=> {
'sFirst'=> 'First',
'sLast'=> 'Last',
'sNext'=> 'Next',
'sPrevious'=> 'Previous'
},
'oAria'=> {
'sSortAscending'=> ': activate to sort column ascending',
'sSortDescending'=> ': activate to sort column descending'
}
}
end
render :json => locale
end
end
Dummy::Application.routes.draw do
scope '(:locale)', locale: /#{I18n.available_locales.join('|')}/ do
...
get 'datatable_i18n', to: 'datatables#datatable_i18n'
...
end
get '*path', to: redirect("/#{I18n.default_locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }
get '', to: redirect("/#{I18n.default_locale}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment