angular-localization icon indicating copy to clipboard operation
angular-localization copied to clipboard

locale.getString sometimes give empty string in angular controller

Open PRIYA-MAMGAIN opened this issue 6 years ago • 3 comments

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.

PRIYA-MAMGAIN avatar Aug 30 '17 07:08 PRIYA-MAMGAIN

Hi @PRIYA-MAMGAIN ... that is strange, could you provide a full example please?

doshprompt avatar Sep 06 '17 20:09 doshprompt

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 })

PRIYA-MAMGAIN avatar Sep 19 '17 10:09 PRIYA-MAMGAIN

So it seems like you should be wrapping the entire $scope.myDataGrid assignment inside

locale.ready('app').then(function() {
  $scope.myDataGrid = { /* ... */ };
});

doshprompt avatar Sep 21 '17 07:09 doshprompt