Skip to content

Mattchewone/feathers-internationalisation-hook

Repository files navigation

feathers-internationalisation-hook

Build Status Dependency Status Download Status

Parse internationalisation nested data for query and results

Only tested with FeathersJS V3

Installation

npm i feathers-internationalisation-hook

Complete Example

Here's an example of using the hooks

Parsing Query

const { parseI18nQuery } = require('feathers-internationalisation-hook')

module.exports = {
  before: {
    find: [ parseI18nQuery({ fields: ['title', 'description'] }) ]
  }
}

// Query:
service.find({ query: { title: 'Post' } })
// Converts to:
params: {
  query: {
    title: {
      en: 'Post'
    }
  }
}

Parsing Data

const { parseI18nData } = require('feathers-internationalisation-hook')

module.exports = {
  before: {
    find: [ parseI18nData({ fields: ['title', 'description'] }) ]
  }
}

// Create:
service.create({ title: 'Post' })
// Converts to:
params: {
  data: {
    title: {
      en: 'Post'
    }
  }
}

Parsing Result

const { parseI18nQuery, parseI18nResult } = require('feathers-internationalisation-hook')

module.exports = {
  before: {
    find: [ parseI18nQuery({ fields: ['title', 'description'], language: 'fr' }) ]
  },
  after: {
    find: [ parseI18nResult({ fields: ['title', 'description'], language: 'fr' }) ]
  }
}

// Find:
service.find({ query: { title: 'Lé Post' } })
// Converts this record:
{ id: 1, title: { en: 'The Post', fr: 'Lé Post' } }
// To:
context: {
  result: {
    data: [
      { id: 1, title: 'Lé Post' }
    ]
  }
}

License

Copyright (c) 2018

Licensed under the MIT license.