pauloamgomes / contentful-better-slugs

The Better Slugs is a simple UI extension for Contentful CMS that provides a more enhanced way to deal with slug fields.
MIT License
30 stars 16 forks source link

Feature request: slug pattern per locale #8

Closed nbaosullivan closed 3 years ago

nbaosullivan commented 3 years ago

Thanks for your work on this - it's been invaluable on a recent proejct.

I've bumped into a limitation with this otherwise fantastic extension: there can't be a pattern variation per locale in Contentful. An example is: pattern for the field is set to articles/[field:title], but when there are multiple locales, this will be the same for non-english languages. So I can't, for example, use the pattern artikel/[field:title] for German content.

What would be great is, when there are multiple locales in Contentful, have a field per locale to define what pattern should be used for the given locale. This will help a lot when keep slugs consistent and automatically generated.

Let me know your thoughts, or if there is another approach.

pauloamgomes commented 3 years ago

Hey @nbaosullivan , thanks for flagging that. It's indeed something that makes sense, however, is not simple to solve as the configuration fields are defined in the extension.json and therefore there is no programmatic access when configuring the field.

One possible solution would be to have another token value, so you can compose the slug pattern as:

[trans:(en:articles|de:artikel)]/[field:title]

so it would use articles when locale is en and artikel when locale is de, but I need to check better.

nbaosullivan commented 3 years ago

Hi @pauloamgomes, thanks for the quick response.

I see, thanks for explaining that - I haven't worked with Contentful plugins and thought the fields might be able to be created dynamically based on the locales retrieved from the sdk object.

Thanks for thinking about this and coming up with an alternative solution. Just to be clear: this token doesn't exist yet does it? And would need development work, right?

pauloamgomes commented 3 years ago

The issue is that at the config level (when you are in the appearance screen) you don't have programmatic access, you can just declare the configuration fields you want and that makes things a bit more tricky. Anyway found a workaround, resuming, on your example you have in the slug pattern:

articles/[field:title]

you can use now the translations field in the field appearance screen like:

articles=de:artikel

if you have more locales, you can separate using comma like articles=de:artikel,pt:artigos

image

please confirm that works.

nbaosullivan commented 3 years ago

Hi @pauloamgomes, thank you so much. I've just tested this out after updating and can say it works really well. I needed path translations for de-CH and that works brilliantly with your update guide. I have not used the third string translation field yet, but String translations 2 works well. Thanks again.