I have a data model called Podcast which doesnât have translation currently enabled, however it is queried within a generic function that often does have translated content, so it is queried for various locales.
My issue is that no matter what locale is queried, the content is returned.
For example, this query returns 3 results despite no Japanese content being available:
Actually this is worse than I thought. The locale filter doesnât work right at all. Even on translated content types itâs returning results that arenât of the locale requested.
records do not have a âlocaleâ per se. Localization is a setting you enable/disable on a single field. So, this means that itâs a field that has some locales, not a record.
I suppose that the Podcast model has a localized field. Letâs call it title. If you wanna fetch all of the podcasts ids where the title has a japanese locale, then you should do a graphql query like this:
query MyQuery {
allPodcasts(locale: ja) {
id
title
}
}
means: fetch all podcasts and for each podcast, get me the id and the title. If title has a japanese content, show me that content in japanese, otherwise returns me an empty string.
If you wanna retrieve only the podcasts with a title in japanese, then you need to filter like in the previous post
The filter that rejects records with an empty title does not seem to work anymore.
But using the filter filter: {title: {isPresent: true}} does work.
Another filter that also works is: {_locales: {allIn: [ja]}. In my case I use {_locales: {allIn: [$locale]} and provide the locale as a variable that I use both for the locale property and for the filter:
This is how I tested the filter: filter: {title: {neq: ""}}
Create a new model called LocaleTest
Add the localizable, single line field title
Create two records, one in English with the title âOnly Englishâ and one in two languages (in my case English and Swedish) with the title âMultilingualâ in both languages
Run the below query and note that both records are returned, one with an empty title
Is this still the way to do this? Or is there a more reliable way to know if thereâs any localized content in a certain page, other than checking a specific field?
The advice above is still generally applicable, namely that localization happens per-field, not per-record (in the CMS) or per-page (on your frontend). Those are three separate concerns, and the CMS doesnât âknowâ which pages on your website correspond to which models/records/fields/locales â you would define all of that in your queries.
But from the frontend via the GraphQL CDA, generally you can use some combination of locales + fallbacks (definable at a field, record, or query level) to get the right data.
If you can please explain your use case a bit more, maybe we can help find the best approach?
Iâm trying to set up a condition on the code to create pages only for languages where we have localized fields filled out. But it seems like Iâve accomplished it with the param filter: {_locales: {anyIn: [de]}}.