Graphql-engine: Localization (l11n) strategy with Hasura for getting data in given locale

Created on 19 Mar 2019  Â·  5Comments  Â·  Source: hasura/graphql-engine

Hi, I'm thinking about how to better implement localization with Hasura Engine and my thought that this should be implemented on HE side somehow.

One possible solution is by send -H "Accept-Language: en_US" header for example, but what will do with this HE to get right localized data from the right column - I have no idea :) This way works Yelp GraphQL API

Currently, I'm sending locale in where clause of GQL input. Here is an example:

Table products: id PK, price, type
Table products_translation:product_id FK, lang, name, description
Hasura array relationship: productValues products_translation :: product_id → id

Query:

{
  products {
    id
    type
    productValues(where: {lang: {_eq: "en_US"}}) {
      name
      description
    }
  }
}
question

Most helpful comment

Do you guys have any project example configuration for this? I want to accomplish something like @coco98 but the links in his post are broken. Thanks for the help in advance

All 5 comments

@pronevich You can set up hasura permissions that pick this up from the header which would have a similar effect to sending the Accept-Language header.

Check it out here:
https://l11n-hasura.herokuapp.com/console/api-explorer
https://l11n-hasura.herokuapp.com/console/data/schema/public/tables/products/permissions

If you look at the user role's select permission you'll see a header x-hasura-lang is used.

Now if you try a graphql query with the right headers (these headers can be sent along with the auth token in production, or can be sent as is if you're using HASURA_GRAPHQL_UNAUTHORIZED_ROLE)

Screenshot 2019-03-20 at 4 36 37 PM
Screenshot 2019-03-20 at 4 36 50 PM

Thanks, @coco98 I was thinking that it is not possible to set _x-hasura_ headers from a client, now I see that this is possible and works great!

Do you guys have any project example configuration for this? I want to accomplish something like @coco98 but the links in his post are broken. Thanks for the help in advance

@pronevich @coco98 the example doesn't work anymore. Can you please document it here for further reference?

@Bessonov send x-hasura-lang header from client and configure SELECT permissions in console based on x-hasura-lang

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codepunkt picture codepunkt  Â·  3Comments

stereobooster picture stereobooster  Â·  3Comments

bogdansoare picture bogdansoare  Â·  3Comments

shahidhk picture shahidhk  Â·  3Comments

tirumaraiselvan picture tirumaraiselvan  Â·  3Comments