Localized labels returning empty strings

Localized labels returning empty strings

PRIYA-MAMGAINPRIYA-MAMGAIN Posts: 4Questions: 0Answers: 0

I am using jquery.dataTables.js. I need to pass searchStrings and other customizable texts in dataTable as per locale's language. I am not using server side pagination and followed 2 approaches as shown below:

*APPROACH 1
Pass parameters in sLanguage and define keys in app.lang.json
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')
}
The issue in this approach is that sometimes the messages dont show up as locale bundle is not loaded, so empty strings are returned in labels

*** APPROACH 2**
oLanguage: {
"sUrl": "languages/"+locale.getLocale()+"/datTable.lang.json"
}
The issue in this approach is although I am getting correct labels but my data in the table sometimes shows and sometimes doesn't

I tried using locale.ready('app) for getting messages doesnt seem to work

Replies

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    as locale bundle is not loaded

    I would probably investigate why this is. Is it just a missing package that can be added on those pages?

    Allan

  • PRIYA-MAMGAINPRIYA-MAMGAIN Posts: 4Questions: 0Answers: 0

    Thanks Allan for the quick reply. The locale service is injected in my controller and I am able to retrieve the dataTable headers using locale.getString("app.Name"). Its just that the parameters passed in oLanguage: sometimes dont show up using locale.getString

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    edited August 2017

    Can that not be resolved? Why wouldn't they sometimes show up?

    Allan

  • PRIYA-MAMGAINPRIYA-MAMGAIN Posts: 4Questions: 0Answers: 0

    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 '<input type="checkbox" class="rowcheck" value="' + data +'">'
    },
    {
    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
    });

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    It sounds like an issue with locale.getString() in that case. I don't understand why it would sometimes work and sometimes not.

    Allan

  • PRIYA-MAMGAINPRIYA-MAMGAIN Posts: 4Questions: 0Answers: 0

    Allan
    locale.getString() checks whether the bundle is loaded or not and if its still loading it return empty string. QUestion is why everytime the locale bundle is getting loaded whenever oLanguage is passed in datatable.

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin

    QUestion is why everytime the locale bundle is getting loaded whenever oLanguage is passed in datatable.

    I honestly couldn't say without seeing the source code for however you are building the language information.

    Allan

This discussion has been closed.