Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[2.1] [WIP] Zend\I18n\Filter\SlugUrl - Made a filter to convert text to slugs #2190

Closed
wants to merge 4 commits into from

Conversation

agutoli
Copy link

@agutoli agutoli commented Aug 17, 2012

This filter does the job of converting text with special characters to a slug that can be used in a url.

@ghost ghost assigned DASPRiD Aug 17, 2012
@b-durand
Copy link
Contributor

Usefull +1 👍

But, I disagree with some parts of your implementation. IMHO a slug is more than the filter of Dasprid or Matthew.

EDIT: can you add a unit test to have all parts of a real slug?

Input value is "C'est l'histoire de la contrefaçon !", and the excepted value must be "cest-lhistoire-de-la-contrefacon".

setlocale(LC_ALL, "en_US.{$enc}");

//suppress errors @iconv
$filtered = @iconv($enc, 'ASCII//TRANSLIT', $value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use the @ operateur.

@agutoli
Copy link
Author

agutoli commented Aug 17, 2012

yes, in Portuguese for example we have characters that do not have in English.

ex.

Profissão (profession)
alimentação (feed)
ação (action)

This filter will convert these special characters to an ASCII character nearest "á" to "a" or "é" to "e"
ex.

$str = "Alimentação";
$slugFIlter->filter( $str );//Alimentacao

referring to the code, now intend to improve it because it was a plugin for Zend 1.x did not do much better on it (yet), I would like to know if there is a community interest in having this filter, because I always I needed something.

What do you think, we disregard this "pull request", I make the changes and resend?

@b-durand
Copy link
Contributor

This filter will convert these special characters to an ASCII character nearest "á" to "a" or "é" to "e"

That's why I was talking about languages ​​with non-Latin alphabet.

What do you think, we disregard this "pull request", I make the changes and resend?

Do you know that your can update a PR?
No, my advice is: add tag WIP (ie Work In Progress) in the title. And, commit on the same branch on your GitHub account when you have a new version. I like to keep the history of a topic 😃

@agutoli
Copy link
Author

agutoli commented Aug 17, 2012

About

Input value is "C'est l'histoire de la contrefaçon !", and the excepted value must be "cest-lhistoire-de-la-contrefacon".

I totally agree!

@travisbot
Copy link

This pull request fails (merged dd8ffd1 into 9d829dc).

@travisbot
Copy link

This pull request passes (merged 55d7438 into 9d829dc).

*/
public function filter($value)
{
if (!function_exists('iconv')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that you must move this test in the constructor, because the class is useless without this extension. Why do you test the function insteadof the extension is loaded?

@bakura10
Copy link
Contributor

I agree with b-durant. This implementation looks quite complicated. I had a similar implementation as Dasprid and so far it worked really well.

public function testRemoveGreekCharacters()
{
$filter = new SlugUrlFilter();
$this->assertEquals('aaaabbbb', $filter->filter('φψξAAAAωϑBBBB'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if it's the right usage: slug is available only for a latin website at this time. How does the developer of a Greek blog?

You can use PR 2105 maybe (like DASPRiD).

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I saw that there is already "DASPRiD" that does the same thing and more! ... I did not know there was already something in ZF2, thank you friends.

We can close this PR?

@DASPRiD
Copy link
Member

DASPRiD commented Aug 20, 2012

@agutoli I'm going to port my slugifier and unidecoder to ZF. I earlier planned to get it done for 2.0, but ran out of time, so it'll be in in 2.1. As you said that you're fine with closing the PR, I'll do so now.

@DASPRiD DASPRiD closed this Aug 20, 2012
@agutoli
Copy link
Author

agutoli commented Aug 20, 2012

@DASPRiD I fully agree with the closure, after their class is much more comprehensive and better defined, have no doubt.

Anyway, glad to have learned more about the Zend.

Thank you all!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants