Add support for mode=json
Switch to implementation from localizr
Include more tests from localizr