angular-localization
angular-localization copied to clipboard
locale.getString sometimes give empty string in angular controller
Hi I am passing parameters to dataTable oLanguage: { "sLengthMenu": "MENU "+locale.getString('app.menu-dropdown'), "sSearch": locale.getString('app.search'), "sEmptyTable": locale.getString('app.emptyTable'), "sZeroRecords": locale.getString('app.zeroRecord'), "sInfoFiltered": locale.getString('app.filtereddevices', ['MAX'])+ ')', "sInfo": locale.getString('app.showingdevices' ,['START','END','TOTAL']), "sInfoEmpty": locale.getString('app.emptyRecord') }
Most of the times i do not get the labels in my datatable and locale.getString() return blank. I tried accessing the strings when locale is ready, ie locale.ready("app").then function(){ $scope.emptyTable=locale.getString('app.emptyTable') } when i access the $scope.emptyTable it still returns empty string.
Hi @PRIYA-MAMGAIN ... that is strange, could you provide a full example please?
Allan most of the times it doesn't show up. If you see the locale.getString() method, it gets the bundle and check if the bundle is loading it returns empty string.
Html:
..... JS:
$scope.myDataGrid={ rowId: 'rowIdentifier', dataTableOptions: {
aoColumns:[ { sType:'html', bSortable:false, bSearchable:false, colTitle:'', mData:'rowIdentifier', mRender:function(data,type){ return '' }, { colTitle:locale.getString("app.devicename") mData:'name' } ... .. "bDeferRender":true, "aaSorting":[[2.'desc']], "bSortCellsTop":true, "aLengthMenu":[[10,25,50,100],[10,25,50,100]], "iDisplayLength":10,
oLanguage: { "sLengthMenu": "MENU "+locale.getString('app.menu-dropdown'), "sSearch": locale.getString('app.search'), "sEmptyTable": locale.getString('app.emptyTable'), "sZeroRecords": locale.getString('app.zeroRecord'), "sInfoFiltered": locale.getString('app.filtereddevices', ['MAX'])+ ')', "sInfo": locale.getString('app.showingdevices' ,['START','END','TOTAL']), "sInfoEmpty": locale.getString('app.emptyRecord') } ]
}
If I put a check in my controller to do processing only when the locale is ready, then my dataTable is empty .
locale.ready("app").then(function(){ //Controller code inside })
So it seems like you should be wrapping the entire $scope.myDataGrid
assignment inside
locale.ready('app').then(function() {
$scope.myDataGrid = { /* ... */ };
});