This topic contains 2 replies, has 2 voices, and was last updated by  Jeff Drumm 2 years, 5 months ago.

Handy little module to find the type of translator you are in.

  • One little oversight in the API for each translator is there isn’t a built in function to say what kind of translator instance one is in. Jeff Drum asked about this problem this morning so I altered some code from the translator and came up with this little module which adds in an iguana.project.type() library function which returns a short string indicating the type of translator instance one is in.

    It’s written efficiently in that in caches the translator type so you can just use it.

    I dropped the module into the Iguana GIT repo this morning:

    https://github.com/interfaceware/iguana-web-apps/blob/master/shared/translator_type.lua

    Enjoy!

    One handy use of this function is to improve the logging for a channel with multiple translator instances to tell which translator instance is logging:

    privateLogInfo = iguana.logInfo

    iguana.logInfo=function(A, B)
    if B then
    privateLogInfo(iguana.project.type() .. " translator: " .. A, B)
    else
    privateLogInfo(iguana.project.type() .. " translator: " .. A)
    end
    end

    The code above shows how one can replace the built in iguana.logInfo command with one which prefixes the type of the translator instance which is logging.

    I implemented this on a few interfaces yesterday and today, creating wrappers for iguana.logInfo/Warning/Error/Debug in the process. Very useful for debugging when you’re running multiple translators in a single channel!

    Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊ http://www.hicgrp.com

You must be logged in to reply to this topic.