? ? ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
29 Mar 2021

Add an additional filter to the alias generator to remove any apostrophe instead of replacing it with a dash. This has annoyed me forever and I waste so much time doing this manually for every alias

Example

For example the alias for an article "Brian's Pull Request"

before

"brian-s-pull-request"

after

"brians-pull-request"

Note Includes unit test

avatar brianteeman brianteeman - open - 29 Mar 2021
avatar brianteeman brianteeman - change - 29 Mar 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 29 Mar 2021
Category Libraries
avatar richard67
richard67 - comment - 29 Mar 2021

@brianteeman Wouldn't it be better just to add the apostrophe to the list of allowed characters in the existing preg_replace below the one you are adding?

I.e. change

$str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str);

to

$str = preg_replace('/(\s|[^A-Za-z0-9\-\'])+/', '-', $str);

instead of adding the new preg_replace.

avatar brianteeman
brianteeman - comment - 29 Mar 2021

because its not an allowed character. it just needs to be removed - not replaced

avatar richard67
richard67 - comment - 29 Mar 2021

because its not an allowed character. it just needs to be removed - not replaced

Ah, I forgot the removal, silly me.

avatar brianteeman brianteeman - change - 29 Mar 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 29 Mar 2021
Category Libraries Libraries Unit Tests
avatar brianteeman brianteeman - change - 29 Mar 2021
Labels Added: ?
avatar brianteeman brianteeman - change - 29 Mar 2021
The description was changed
avatar brianteeman brianteeman - edited - 29 Mar 2021
avatar PhilETaylor
PhilETaylor - comment - 29 Mar 2021

as you are not using a regular expression, it would be better PHP to use str_replace (Im guessing more performant too, the tiniest bit)

avatar brianteeman brianteeman - change - 29 Mar 2021
Labels Added: ?
Removed: ?
avatar toivo toivo - test_item - 29 Mar 2021 - Tested successfully
avatar toivo
toivo - comment - 29 Mar 2021

I have tested this item successfully on d83aacd

Tested successfully in Beta8-dev of 29 March in Wampserver 3.2.4 using PHP 8.0.2.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32924.

avatar alikon alikon - test_item - 30 Mar 2021 - Tested successfully
avatar alikon
alikon - comment - 30 Mar 2021

I have tested this item successfully on d83aacd


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32924.

avatar alikon alikon - change - 30 Mar 2021
Status Pending Ready to Commit
avatar alikon
alikon - comment - 30 Mar 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/32924.

avatar rdeutz rdeutz - change - 30 Mar 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-03-30 07:44:48
Closed_By rdeutz
Labels Added: ? ?
Removed: ?
avatar rdeutz rdeutz - close - 30 Mar 2021
avatar rdeutz rdeutz - merge - 30 Mar 2021
avatar simbus82
simbus82 - comment - 2 Apr 2021

But it is valid only for english.
Many languages use the apostrophe with the contraction of definite articles before words (elision), so removing the dash (-) generate some problems.

IT
"L'acqua è pulita" -> "lacqua-e-pulita" (the word "lacqua" not exists).
Same for: l'uomo, l'aria, l'ora, l'eternità, l'amico, l'onestà, ecc. and all words that start with vowels.

FR
"l'eau" -> leau
"l'homme" -> lhomme
etc. Same as Italian.

Magento, Prestashop, Drupal, Typo3, and many other doesn't remove the dash for the apostrophe. Only Wordpress.

Maybe should we let the language package drive this choiche?

avatar brianteeman
brianteeman - comment - 2 Apr 2021

Then you have a definite article of just the character "l" which is also wrong as the alias would be "l-acqua"

avatar richard67
richard67 - comment - 2 Apr 2021

The question is what is more wrong to a native speaker of these languages.

avatar infograf768
infograf768 - comment - 3 Apr 2021

Evidently @simbus82 is totally right.
getting leau instead of l-eau just to please brians-pull-request is very much English centered —but we have been used to that behavior for years.

We do have a solution though, @simbus82 , and it is to use unicode aliases.
There, the single quote is still using the dash and we could even make it better by replacing the single quote by a right single quote.

We could add in OutputFilter in the method public static function stringUrlUnicodeSlug($string)

after line 162
$str = str_replace('-', ' ', $str);

the line
$str = str_replace("'", "\xE2\x80\x99", $str);

This would give from the original title
L'acqua è pulita

the alias
l’acqua-è-pulita

Add a Comment

Login with GitHub to post a comment