@repit/lambda-localize
v1.0.6
Published
AWS Lambda response localization.
Downloads
9
Readme
Lambda Localize
AWS Lambda response localization.
Installation
$ npm install @repit/lambda-localize --save
Usage
'use strict'
// Load the Localize class.
const Localize = require('@repit/lambda-localize')
exports.handler = (event, context, callback) => {
// Create a new Localize object.
const localize = new Localize(callback)
// Send a localized response with default structure.
localize.send(200, 'Message:UserCreated', 'fr')
// Send a localized response with custom structure.
localize.send(200, 'Message:UserCreated', 'fr', message => ({
message,
userId: 1000000,
}))
}
Localization
Localization is done using @repit/lambda-query package. For details about how it works see the package page.
Response Structure
Responses are sent using @repit/lambda-send package. Details about how response is formatted can be found on the package page.
Caching
By default Localize
class does not do any caching, but it can internally forward the Cache (@repit/lambda-cache)
object to the Query (@repit/lambda-query)
object and all localization queries will be cached.
Here is a basic example on how to use caching:
'use strict'
const Localize = require('@repit/lambda-localize')
const Cache = require('@repit/lambda-cache')
const cache = new Cache()
exports.handler (event, context, callback) => {
const localize = new Localize(callback, cache)
}
For more details about caching see @repit/lambda-cache package.
License
MIT