- This topic has 4 replies, 2 voices, and was last updated 11 years, 6 months ago by lemorlenny.
-
AuthorPosts
-
lemorlennyMemberHi all,
I’m building an multilanguage app and I have a problem to save e recover the language selected.
I have a splash screen with 3 image buttons with a national flag each.
In the OnClick of that buttons event I inserted this code:localStorage.setItem("nation","FR"); // 'FR' change in 'UK' and 'SP' in the other buttons
Then inside the same page I wrote:
phoneui.documentReadyHandler = function() { idNation = localStorage.getItem("nation"); if(idNation =='FR') { .....} else if(idNation =='UK') { ..... } else if(idNation =='SP') { ..... } }
but the getItem return null always until I reload the page, after this the value is correct.
How can I correct this behaviour?
Many thanks in advance
Lenny
Stu WadeMemberIs this not simply a matter of timing?
Surely the document handler is called before you have had a chance to save the value.
On re-entry the value is ready for you – the null return from the handler simply indicates that this is the very first time in, or am I missing something?
lemorlennyMember@Stu Wade wrote:
Is this not simply a matter of timing?
Surely the document handler is called before you have had a chance to save the value.
On re-entry the value is ready for you – the null return from the handler simply indicates that this is the very first time in, or am I missing something?So you suggest to place a delay after the “localStorage.setItem()” instruction?
Stu WadeMemberNo, the document ready handler executes once only literally as soon as the project is ready to display – this will always be before any on click event can possibly occur.
I would suggest catching the null storage and going directly to a choose language (for the first time) page.
lemorlennyMemberI found the solution,
its necessary insert the language variables reading in the prePageTransition event and here place the translation operations too.// main page phoneui.prePageTransition = function(currentScreenId,targetScreenId) { idNation = localStorage.getItem("Nation"); Translate(); return true; } function Translate() { if(idNation =='IT') { $('#m1-YourPage-txtHeader').text("Trova"); } else if(idNation =='UK') { $('#m1-YourPage-txtHeader').text("Find"); } else if(idNation =='FR') { $('#m1-YourPage-txtHeader').text("Trouvez"); } }
Best regards
Lenny
-
AuthorPosts