Hi guys ! I’m new with GraphCool and i search some...
# prisma-whats-new
j
Hi guys ! I’m new with GraphCool and i search some resources about how to manage translation/multilanguage inside the Schema logic (and after surely use i18next for the front). Any help or tutorial ? Thanks ! 🙂
h
What kind of data do you have in mind? Some product info or something different?
j
Yes like a product info, with a title, desc and other details which can be translate in English/French for example. To make simpler, it’s like trying to create a WordPress blog with WPML/Polylang to add multilingual to post, page an custom types.
I already talk with an other GraphQL dev who advised me to simply add a locale field and find a solution to link the same entity in the different languages (maybe like a master/slave relation)
h
You can have:
Copy code
{
  product {
      translations {
         language
         title
         description
     }
  }
}
And then query product with translation where you can define language for example
j
and I suppose an ID for the product + each translation ?
I looking but i don’t see how to create a type with depth. You mean create a type Product and Translation and link it ? (and so have a query like you show me?)
I see this approch, but i think that it add complexity about the query : https://gist.github.com/mikeparisstuff/82a3689e075f96c9f962e893a6a8ab51 (i’m not yet familiar with edge/node concept)
h
me tooo i would just skip it and do query like:
Copy code
query {
  product(where:{id:"ID"}) {
    translations(where: { language_is: "de"}){
      title
      description
    }
	}
}
👍🏻 1
j
ok thanks, and so in this case you will create a type “Product” and “ProductMetada” (or “ProductTranslation”) and do it for all main types (Page, Category, etc.) ?
h
You can create type translation and have relation to every other type what you want to translate
j
Ok i see, thanks for you help, i will look it quickly and make some tests 🙂
a
As id's are globally unique, in theory that means that you don't even have to specify the relationship to every other type from that translation table.
Then you need to do this however:
Copy code
query {
  product(where:{id:"ID"}) {
    translations(where: { recordId: ID, language_is: "de"}){
      title
      description
    }
    }
}
So it's a trade-off between easy querying and easy schema setup.
j
hi @agartha
👋🏻 1
Yes the real problem isn’t about make it, but make it the simplest way as possible 😉
a
In that case, I think my solution is easier, because it doesn't require a relationship field for every type you need translation for
h
But you need to supply ID of translation right?
a
No, ID of the record you want to translate. Sorry, I didn't pick my field names right. Updated the answer...