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

Add emoji support for url slugger #6916

Merged
merged 4 commits into from
Dec 9, 2022

Conversation

nozarashi20
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets fixes #6882
License MIT

What's in this PR?

Add emoji support for url slugger

Why?

Currently emojis are just removed and not replaced by the name when slugging a title with emoji for it.

@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Sulu label Nov 28, 2022
Copy link
Member

@alexander-schranz alexander-schranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nozarashi20 Really thank you for working on this 👍 . I think the IntlException should not happen in case of the slugger. In which case it does happen? I think we should create an issue on symfony side for this. If it is resolved we could maybe move the whole withEmoji into the service definition if possible.

$slug = $this->slugger->slug($part, '-', $languageCode);
try {
$slug = $this->slugger->slug($part, '-', $languageCode);
} catch (\IntlException $e) { // handle unknown emoji transliterator id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like something which should be reported to symfony itself. I think the slugger should just ignore if it does not know something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-schranz , this is the condition that triggers the IntlException.

It happens when there is no mapping file for a locale. For instance, there is no emoji-de_at.php file; which leads to this error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for detailed debugging here. Let see if symfony will change here something. Created an issue here: symfony/symfony#48364

Else I think we should just in the constructor created a $this->sluggerWithEmoji and $this->sluggerWithoutEmoji to avoid creating new objects always inside the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we not longer need the sluggerWithEmoji? Since symfony/symfony#48395?

Also I think we should do str_replace('-', '_', $languageCode) to convert it into a valid intl locale. @nozarashi20 What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @alexander-schranz , the code will be much simpler.
And I agree on replacing dashes with underscore. We'll then be able to handle codes like en-US.
Have you already encounter this case ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On other cases we did also just output the language this way explode('-', $locale)[0] but as it could be that the slugger support en-us and en-uk I would give the whole intl locale into it, if possible.

I think for general handling we should create an own issue how we maybe normalize the locale better in future. So maybe all things are handle by intl based format like en_UK problem is that most website don't want to have domain.com/en_UK´ instead domain.com/en-uk` in it. But as said that is an own issue by itself, so first concentrate on the slugger case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code and tests

@alexander-schranz alexander-schranz merged commit 55be798 into sulu:2.6 Dec 9, 2022
@alexander-schranz
Copy link
Member

@nozarashi20 Thank you! Good work 👍

@alexander-schranz alexander-schranz added this to the Release 2.6 milestone Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Sulu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants