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

Unique Slugs Multilanguage #1086

Closed
decodedesign opened this issue Apr 22, 2019 · 6 comments

Comments

@decodedesign
Copy link

commented Apr 22, 2019

Hi, really great work here!

I've been trying and failing to achieve multilanguage unique slugs.
I mean, if I have an entry title (in English) like "Test", I'd like that the slug "test" is generated, and if the title translation for the same entry is "Prueba" (in Spanish), the slug "prueba" for the translated title is generated as well.
But for every slug (source language or translation), if the same slug already exists, add a "-$counter" appendix.

Cockpit core handles smoothly multilanguage slugs creation:
-In a collection I configured "title" text field with {"slug":true} in configs, which is localized also.
-But it does not look for previously created slugs, if I have already saved an entry with the same title (in any of the languages).

Unique Slugs addon works great but only if "slug" field is not localized:
-The field "title" is configured as source for slug generation for a collection.
-This entry field ("title") is configured as localized in collection settings.
-I created another field, named "slug", also localized.
-The addon looks for previous slugs, but only for the default title, and the "slug" localized field is empty for the translations.

Is there a way to achieve this?
Thank you very much for your awesome work!

@raffaelj

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2019

@decodedesign I added the support for localized fields.

https://github.com/raffaelj/cockpit_UniqueSlugs/tree/localize

Can you test it, please? Than I'll pull it to the master branch. It worked on my local machine with the following setup:

config:

languages:
    de: Deutsch

unique_slugs:
    collections:
        # testlocale: title
        testlocale:
            - title     # type: text, localize: true
            - fallback  # type: text, localize: true
            - tags|0    # type: tags, localize: true
    localize:
        # testlocale: title
        testlocale:
            - title     # don't add the language postfix - "title" and not "title_de"
            - fallback
            - tags|0

If you omit the localize key, it should work like before.

@decodedesign

This comment has been minimized.

Copy link
Author

commented Apr 23, 2019

Hi @raffaelj,
Thank you very much! It works great!!
With your addon and "slug" text field (which is localized, as well as "title" text field, configurated as source for slugs generation) now all slugs from titles in every language are filled, and also generated with counter appendix if a previous one exists.

Just one comment, I can see (and also disabling localization configs), that if:
-I create a first entry named "Test", it generates "test" as slug.
-I create a second entry, also named "Test", and the slug "test-1" is generated as expected.
-I create a third entry, again named "Test", but the generated slug is "test-1", as the second one.
This third slug should be "test-2".

I tried also with master-branch addon, and it works the same as described above.

Thank you for the great job!
Regards

raffaelj added a commit to raffaelj/cockpit_UniqueSlugs that referenced this issue Apr 23, 2019
oo style rewrite, fixed wrong incremental count
Weird - This addon never worked for more than one duplicate and nobody
realized it before...

see:
agentejo/cockpit#1086 (comment)
@raffaelj

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2019

Thanks @decodedesign for finding this issue. I never realized that behaviour. It actually never worked before with multiple duplicated values... I was so focused on keeping it small and simple, that I forgot the obvious thing.

I rewrote the whole thing and it should work now with the localize branch.

I didn't do any performance tests, yet. My normal use case is to create some pages via ui. For unique checks with massive api calls to create items, you might use the _id instead.

@decodedesign

This comment has been minimized.

Copy link
Author

commented Apr 24, 2019

Hi @raffaelj
Just tested and now it works! I adds the "counter" if any of localized slugs already exists.

I think this use case (localized content, via admin UI, which generates similar slugs) could be pretty common. I'm thinking in some blog posts or news articles, even promotional landing pages, created months later, that could have the same slugs.

Thank you again!

@raffaelj

This comment has been minimized.

Copy link
Contributor

commented Apr 24, 2019

Hi @decodedesign

thanks for testing it. I added one last change to enable checks on user updates. Enable it with check_on_update: true. I also merged everything to the master branch. If you find new bugs, feel free to file a new issue in the addon's issue tracker.

If it works for you, this issue can be closed.

@decodedesign

This comment has been minimized.

Copy link
Author

commented Apr 24, 2019

Great, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.