-
Notifications
You must be signed in to change notification settings - Fork 26
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
Locale Support #121
Comments
Hi @ekasprzyk To achieve localized entries, I suggest a transformation on type level: Here is a little example how it would look like. type LocalizedFields<Fields, Locales extends keyof any> = {
[FieldName in keyof Fields]?: {
[LocaleName in Locales]?: Fields[FieldName];
}
}
type LocalizedEntry<EntryType, Locales extends keyof any> = {
[Key in keyof EntryType] :
Key extends 'fields'
? LocalizedFields<EntryType[Key], Locales>
: EntryType[Key]
}
type MyFields = {
a: string
b?: number
}
type MyEntry = Entry<MyFields>
type MyLocale = 'en-US' | 'de-DE';
type MyLocalizedEntry = LocalizedEntry<MyEntry, MyLocale>;
const myEntry: MyEntry = {
sys: {
id: "my-id"
},
fields: {
a: "hello"
}
}
const myLocalizedEntry: MyLocalizedEntry = {
sys : {
id: 'my-id'
},
fields: {
a: {
"de-DE": 'german translation',
"en-US": 'english translation'
}
}
} In the example, |
Hello! I really wanted to not forget to say, many thanks for this, and it works! I utterly didn't realise at the time that the management API adds in the locales and the delivery API doesn't (depite having worked with both, this utterly escaped me), and I managed to level up my For anyone else looking to work with the management API, this is a working solution. Elizabeth P.S. Closing the issue as fixed, but might be worth adding to any documentation you have, so other don't get tripped up! P.P.S.happy to update the docs with a PR if you don't mind. |
@ekasprzyk Happy to hear that it helped! A PR to add documentation for this would be very welcome 🥇 |
@ekasprzyk |
I came across this tool and it's really nice. However, I'm a bit confused at the typing on the fields, because as far as I can see, this isn't going to work for anyone, unless we have some special config here.
All our fields from Contentful always have the format:
and not
as this library generates.
We have typings for the locales, if you want them.
The text was updated successfully, but these errors were encountered: