nl_tokens: Constructor .
pl_tokens: function ResourcesAgent ( resourcesData , language , namespace ) { if ( ! resourcesData || ( resourcesData && typeof resourcesData !== "object" ) ) { throw new Error ( "Expected ResourceData." ) ; } if ( ! language ) { throw new Error ( "Expected argument language." ) ; } if ( ! namespace ) { throw new Error ( "Expected argument namespace." ) ; } if ( ! resourcesData [ language ] ) { throw new Error ( "Resource Language '" + language + "' is not available" ) ; } if ( ! resourcesData [ language ] [ namespace ] ) { throw new Error ( "Resource Namespace '" + namespace + "' is not available" ) ; } // returna a new instance of ResourcesAgent this . getResources = function createNewResourceAgent ( language , namespace ) { return new ResourcesAgent ( resourcesData , language , namespace ) ; } ; // extract this object to another more appropriate module file TODO // not the crafity-resources, but crafity.http. resources this . resourceParser = function resourceParser ( ) { var SIX_MONTHS = ( ( ( ( ( 1000 * 60 ) * 60 ) * 24 ) * 30 ) * 6 ) ; return function requestListener ( req , res , next ) { var languageFromUrl = ( req . url . match ( / ^(?:\/language\/)(\w+)(?:\/{0,1}) / i ) || [ ] ) [ 1 ] , languageFromRequest = languageFromUrl || req . query . lang || req . cookies . lang || language , mustRedirect = languageFromUrl && true // test this TODO , resourceAgent = new ResourcesAgent ( resourcesData , languageFromRequest , namespace ) , url = req . query [ "return" ] || req . headers . referer || "/" ; // the leading language variable for now! req . language = languageFromRequest ; req . resources = resourceAgent ; res . local ( "resources" , resourceAgent ) ; // wat willen we hiermee res . local ( "languages" , resourceAgent . getLanguages ( ) ) ; // wat willen we hiermee res . local ( "language" , languageFromRequest ) ; if ( languageFromRequest ) { res . <mask> ( "lang" , languageFromRequest , { path : "/" , expires : new Date ( Date . now ( ) + SIX_MONTHS ) , httpOnly : true } ) ; } else { res . clearCookie ( 'lang' , { path : "/" , expires : new Date ( Date . now ( ) + SIX_MONTHS ) } ) ; } if ( mustRedirect ) { if ( req . query . layout ) { url += ( url . indexOf ( "?" ) > - 1 ? "&" : "?" ) + "layout=" + req . query . layout ; } res . redirect ( url ) ; } else { next ( ) ; } } ; } ; this . getLanguages = function getLanguages ( ) { return Object . keys ( resourcesData ) ; } ; this . getLanguage = function getLanguage ( ) { return language ; } ; this . get = function get ( ) { var result = resourcesData [ language ] [ namespace ] , args = Array . prototype . slice . call ( arguments ) ; args . forEach ( function ( arg ) { if ( result ) { result = result [ arg ] ; } } ) ; return result || args . join ( "." ) ; } ; }