# (*) @translate
Directive @translate
executes a translation of a field using the API service under field argument provider
, or using the default provider if this field argument is empty.
Currently, only the implementation for Google Translate has been done.
Running this query:
query {
posts(limit:3) {
title
spanish: title @translate(from: "en", to: "es")
}
}
...produces this response:
{
"data": {
"posts": [
{
"title": "Scheduled by Leo",
"spanish": "Programado por Leo"
},
{
"title": "COPE with WordPress: Post demo containing plenty of blocks",
"spanish": "COPE con WordPress: Publicar demo que contiene muchos bloques"
},
{
"title": "A lovely tango, not with leo",
"spanish": "Un tango encantador, no con leo."
}
]
}
}
View PQL queries
//1. @translate calls the Google Translate API
/?query=
posts(limit:5).
title|
title@spanish<
translate(en,es)
>
//2. Translate to Spanish and back to English
/?query=
posts(limit:5).
title|
title@translateAndBack<
translate(en,es),
translate(es,en)
>
//3. Change the provider through arguments (link gives error: Azure is not implemented)
/?query=
posts(limit:5).
title|
title@spanish<
translate(en,es,provider:azure)
>