Hi !
We’d also love to see this feature implemented.
Here are two implementations ideas that may help !
Current state
We can query all languages.
query {
myModel {
_allTitleLocales {
value
locale
}
}
}
And then find a value
// Just for the example. It can be optimized
const found = data._allTitleLocales.find(locale => userLocale === locale)
if (found) {
return found
}
return data._allTitleLocales.find(locale => defaultLocale === locale)
However, this solution requires querying all locales when we may just need one (that can be an issue when querying a lot of data on the client side).
Also, this needs more implementation on the client.
GraphQL implementation: new fallbackLocales
query filter
query {
myModel {
title(locale: fr, fallBackLocales: [en, de])
}
}
This query would return the FR
value if it is not empty. Or the EN
value. Or the DE
value.
Admin implementaion: model configuration
An alternative solution would be to add a default language
field on the model configuration.
For example:
When this multi-select value is set to “it, en, fr”.
The following query would return the title value for IT
locale if CN
value is empty.
query {
myModel {
title(locale: cn)
}
}
Required one default value
The advantage of the model-side implementation would allow another linked feature.
Currently, when the field is required
, we need to fill the translations for every locales.
That would be awesome to have a field configuration (in the validation tab) to have a only one default value.
We can mark the field required without requiring all translations.
So, we have :
- 10 locales in our project/model
- Field
Title
i18n
- Field
Title
with default language for en, fr
- Field
Title
with required
at least one locale
We can save the following record (without validation error because there is one value for a default language) :
{
"title": {
"en": "My Title",
"fr": "",
"cn": ""
}
}
The following query
query {
myModel {
title(locale: cn)
}
}
returns
{
"title": "My Title"
}
What’s your thoughts on this ?
Thanks !