dadi / web

Web is a drop in front end for websites and web apps. Consumes data from DADI API and others
https://dadi.cloud/en/web/
Other
48 stars 16 forks source link

support for @dadi/api 4.2 (multi-lang) #417

Closed abovedave closed 6 years ago

abovedave commented 6 years ago

Closes #405

You can now add the bool i18n to a datasource.json schema to enable the passing of the variable lang directly to API to filter the data by a given language.

This works similarly to paginate and the param page, except i18n is enabled by default.

Example

articles.json

{
  "datasource": {
    "key": "articles",
    "source": {
      "type": "dadiapi",
      "endpoint": "1.0/blog/articles"
    },
    "count": 4,
    "paginate": true,
    "sort": {
      "publishedAt": -1
    },
    "requestParams": [{
      "param": "title",
      "field": "slug"
    }]
  }
}

If you don't want it passed you must explicitly set it to false.

    "i18n": false

page.json

{
  "page": {
    "key": "article"
  },
  "datasources": [
    "articles"
  ],
  "requiredDatasources": [
    "articles"
  ],
  "routes": [
    {
      "path": "/:lang/:title"
    }
  ]
}

You could also forgo the url param and just use a normal query param ...?lang=en