Search code examples
jqueryhtmlcssjquery-mobilei18next

jQuery mobile button style is lost on localization


I'm working on jquerymobile project using localization library i18Next.

HTML code:

<div id="messageboxPage" data-role="page" data-theme="a">
    <div data-role="header" data-theme="a"></div>
    <div id="messagePage" data-role="content" data-theme="a">
        <div class="barContainer" id="barContainer">
            <div class="ui-bar ui-bar-b  ui-btn-corner-all" style=" margin-top: 40px; padding-left: 0px;padding-right:10px; ">
                <div style="float: left;  width: 30%;"> <a href="#" id="aNo" onclick="SetActive('aNo')" class="LnkButton" data-theme="a" data-role="button" data-inline="true" data-mini="true">Cancel</a> 
                </div>
                <div style="float: left;   width: 30%;padding-left: 6%; padding-right: 2%;"> <a href="#" id="aAccept" onclick="Supprimer();" data-theme="a" class="LnkButton" data-role="button" data-inline="true" data-mini="true">Delete</a> 
                </div>
                <div style="float: right; width: 30%;"> <a href="#" id="aReply" onclick="Reply();" data-theme="a" class="LnkButton" data-role="button" data-inline="true" data-mini="true">Reply</a> 
                </div>
            </div>
        </div>
    </div>
</div>

js code

 window.opts = {
     lng: 'fr',
     getAsync: true,
     // fallbackLng: 'en',
     ns: {
         namespaces: ['ns.controls'],
         defaultNs: 'ns.controls'
     },
     useLocalStorage: false,
     debug: true
 };
 $.i18n.init(opts).done(function () {
     alert('i18n init function');
     $('#aNo').text("No Merci!");
     $('#aAccept').text("Supprimer");
     $('#aReply').text("Respondre");
     $('#messageboxPage').trigger('pagecreate');
 });

 $(document).ready(function () {
     alert('messagebox document ready');
 });

Now the problem is the text is changed, but the button style is lost. The second problem is setting text with labels; I have tried page create trigger, but it's not working. What do you suggest?

Here is a working JS Fiddle


Solution

  • To change the text of a button you have to modify the text of the .ui-btn-text element, much better than the span > span thing:

    $('#aNo .ui-btn-text').text("No Merci!");
    $('#aAccept .ui-btn-text').text("Supprimer");
    $('#aReply .ui-btn-text').text("Respondre");  
    

    Fiddle