wp-graphql-polylang
wp-graphql-polylang copied to clipboard
Query string translations
Hello,
is it possible to query string translations via GraphQL with that plugin? I didn't find a solution yet...
Let's say the site tagline has been translated from English (default) to Spanish (secondary). To get the Spanish string:
query MyQuery {
translateString(language: ES, string: "Just another WordPress site")
}
The result:
{
"data": {
"translateString": "Solo otro sitio de WordPress"
}
}
If I understood right, if you have more secondary languages, you can't get the translations between them directly, leaving out the default one. In this example, trying to get Russian from Spanish will return Spanish again.
query MyQuery {
translateString(language: RU, string: "Solo otro sitio de WordPress")
}
{
"data": {
"translateString": "Solo otro sitio de WordPress"
}
}
@maxyudin
Thanks for the answer, but I get this error:
"message": "Cannot query field \"translateString\" on type \"Query\".",
Query:
query MyQuery {
translateString(language: ES, string: "Just another WordPress site")
}
Unfortunately, I can't reproduce your issue. Are you sure WP GraphQL Polylang is enabled?
I was having trouble using this feature and finally got it. You have to call the $string registered in pll_register_string function, not the $name. For example, I have this string registered pll_register_string("contact-footer", "Contato", "Theme")
and have to call it like this translateString(language: PT, string: "Contato")
. The problem now is how to get multiple strings with only one query.
Solved the problem I mentioned above. To query multiple strings in only one query you have to give it multiple aliases like this:
contactFooter:translateString(language: PT, string: "Contato") subscribeFooterTitle:translateString(language: PT, string: "Inscreva-se em nossa newsletter.")