Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query string translations #54

Open
maweo-mathis opened this issue Jul 20, 2021 · 5 comments
Open

Query string translations #54

maweo-mathis opened this issue Jul 20, 2021 · 5 comments

Comments

@maweo-mathis
Copy link

Hello,

is it possible to query string translations via GraphQL with that plugin?
I didn't find a solution yet...

@maxyudin
Copy link

maxyudin commented Sep 25, 2021

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"
  }
}

@maweo-mathis
Copy link
Author

maweo-mathis commented Oct 29, 2021

@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")
}

@maxyudin
Copy link

Unfortunately, I can't reproduce your issue. Are you sure WP GraphQL Polylang is enabled?

@assef
Copy link

assef commented Oct 8, 2023

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.

@assef
Copy link

assef commented Oct 8, 2023

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.")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants