• Adding i18n to a Cordova App

    Date: 2014.02.14 | Category: cordova, developer, developing, development

    i18n (Internationalization) in applications roughly means adding support for translations and other languages.  In this blog post I will talk you through a general approach to implementing i18n in Cordova Apps.  If your app isn’t open-source, move along, the 90s is on another website.

    As Cordova apps are written in HTML/CSS/JS we can easily leverage existing web platforms and services to provide i18n at break-neck speeds.

    TLDR Services/frameworks used:
    * Translatewiki to provide translations
    * Marcel’s html10n i18n implementation
    * Handlebars for templating
    * Etherpad implementation of detecting locale/language also written by Marcel

    Implementation steps

    * Ensure your app fulfills Translatewiki’s requirements (Open source etc)
    * Talk to Translate / Internationalization team at Wikimedia foundation before creating Gerrit commit
    * Gerrit commit to TranslateWiki adding support for your App.
    * Include handlebars and html10n libraries in your app
    * Modify your HTML putting markup in handlebar script tags
    * Move your text strings into locales files.
    * Include a handlebars html10n render helper
    * Use the Etherpad implementation of detecting locale/language* Give someone at WMF access to commit to your Repo

    Sit back and enjoy..

    Once you have completed your implementation and it’s approved by the WMF the WMF translation team will translate all of your strings and commit them back to your repo. You might want to provide the WMF team with the ability to see each of your strings in situ in a browser, this means providing a mechanism to fake Cordova events..

    Summary

    This implementation is basically a straight copy of how we handle i18n in Etherpad, it’s pretty robust and clean to implement. All in all a complete refactor of the NFC Ring Control App while implementing i18n took about a week of full time commitment, well worth doing as now the larger community can provide translations which if I was to do hans solo would take months icon smile Adding i18n to a Cordova App

  • Cordova Windows Phone 8 Exit Application

    Date: 2014.01.23 | Category: cordova

    If you have a Phonegap/cordova app that goes from page1.html to page2.html then follows a link back to page1.html the standard backbutton behavior wont exit the app.

    Page1 >> Page 2 >> Page 1 — Windows Phone will take you to page 2 instead of exiting the app. It’s expected behavior but it’s kinda poorly documented..

    Anyway I searched around for ages but didn’t find a fix that worked for me..

    Diff friendly folks see the commit that includes this fix

    TLDR of how I fixed this is to use a JS value to track which page I’m on..

    IE in page1.html you could have..

    var currentPage = "index";
    

    Then in your app.deviceready function include..

    if(currentPage == "index"){
      history.go(-(history.length-9999));
      document.addEventListener("backbutton", handleBack, true);
    }else{
      document.addEventListener("backbutton", handleBack, false);
    }
    function handleBack(){
      // handle other logic here such as handling the back events from page2 to page1..
    }
    

    The real magic here is history.go(-(history.length-9999)) which basically tells the history stack to reset. Also the true statement on addEventListener allows the original registered event to fire (Native back button)..

    Anyway give it a try and let me know if it works for you.

  • Getting started with Explore NFC on Raspberry Pi in 60 seconds (Also Raspbmc)

    Date: 2014.01.20 | Category: nfc, nfc ring

    The docs from NXP are slightly over verboose, here I make the assumption you already have a Pi installed and know a little about SSH and using the Linux Terminal. It’s worth noting I’m doing some of these steps on Raspbmc too so things may differ slightly from your environment. I will try cover both wheezy and Raspbmc

    Put module onto Raspberry Pi by y’know, putting it on the Pi.. Reboot..

    SSH into your Pi username pi, password raspberry
    ssh pi@your-pi-ip-address

    Update your Pi and install some deps
    SPI was added late 2013 so it might not be available in your Kernel, doing an update is easy, do..
    sudo apt-get update && sudo apt-get upgrade && sudo apt-get install ca-certificates git-core cmake
    – Make a cup of tea

    cd ~ && sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
    sudo chmod +x /usr/bin/rpi-update && sudo rpi-update
    sudo ldconfig

    Note: If you get a prompt saying you might not need this firmware or it’s the wrong update then just skip this step.

    Enable SPI (not required on Raspbmc)
    sudo nano /etc/modprobe.d/raspi-blacklist.conf
    – Comment out blacklist spi-bcm2708
    – Change it to read (note the hash)
    # blacklist spi-bcm2708

    Enable Pi on Rasmbmc
    sudo boblightd
    For posterity further information about this fix is on this thread — Note that sudo boblightd toggles SPI pins so running it twice might not work..

    Reboot
    sudo shutdown -r now
    – Make a cup of tea

    Grab the demo polling app from my Git Repo of the NXP S/W
    cd ~
    git clone https://github.com/JohnMcLear/NXP-Raspberry-Pi-Card-Polling-Demo.git
    cd NXP-Raspberry-Pi-Card-Polling-Demo
    cmake source
    make

    – Make a cup of tea

    Test
    sudo ./card_polling

    My end goal here is to use my NFC Ring to start/play/pause videos in xbmc using the Pi shield.. Wish me luck..

    Q: I get Failed to open bal.
    A: You forgot to run card_polling as sudo.. sudo ./card_polling

  • Crest SVG

    Date: 2014.01.18 | Category: Uncategorized

    Cookies go to Gareth Pullen who figured out why the text wasn’t showing properlycoat of arms mclear crest 550x417 2 Crest SVG

     

  • Why NFC Keyboard emulators / readers are a bad idea

    Date: 2014.01.14 | Category: nfc, nfc ring

    For a while I was using an NFC Keyboard reader to automatically type my password into linux until one event really changed my perspective on this..

    Obviously from a security perspective storing your password in plain text on an NFC tag is suicide, but let’s assume for a second only your computer has the key to read the NDEF record on your NFC Ring so even if someone else was able to read the NFC Ring they wouldn’t be able to figure out your password..

    It doesn’t seem like such a bad idea now to emulate a keyboard and type in your password? Wrong.. You see what happens is that your computer can read that data at any point, so let’s say you are on IRC chatting away to your buddies and by accident you scan your NFC Ring. Boom, your password is pasted into the chat window, this is what happened to me and it sucked. To be fair to recover I only had to type passwd and provide my old and new password but still, it could have been way more painful..

    Obviously a work around is to only enable keyboard emulation on the login screen but it’s still an interior and inadequete solution for logging into your desktop.

    Basically Keyboard emulation for Auth sucks, don’t do it, or if you be fully aware of the pitfalls!

- My Brain made this.