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

Use transliterator_transliterate to generate "url_key" #4315

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Oct 27, 2024

Description (*)

@luigifab had a great idea to use intl-extension for generating url key with translating all special chars. For me the PR did not work, so tried myself.

This is a non-BC-breaking try of it. It does not change method-signaturer and should be BC-safe. (I did not add all features of #1631. That could be done in another PR.)

To not reinvent the wheel for locale-mapping if have added symfony/string that exactly does what we need.

See: https://symfony.com/doc/current/string.html#slugger

Related Pull Requests

  1. See Used transliterator_transliterate to generate url_key #1631

Manual testing scenarios (*)

  • have multiple store with different languages assigned (eg sample data)
  • edit product title to have some locale specific character/words
    • de_DE: umlauts (äöü)
    • use trademark/copyright/etc.
  • generate new url-key (e.g. changing name) ...

Test product/category before and after ...

$urlKey = 'a & B, x%, ä, ö, ü';
$model = new Mage_Catalog_Model_Product_Url();
if (method_exists($model, 'setLocale')) {
    # $locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, <store_id>);
    $model->setLocale('de_DE');
}
var_dump($model->formatUrlKey($urlKey));

Before url-key

'a-b-x-a-o-u'

After url-key

en_US
a-and-b-x-percent-a-o-u
de_DE
a-und-b-x-prozent-ae-oe-ue

Questions or comments

Locale config in xml should be changed to not have language-specif config in core. Any ideas?

Magento already had an unsused config for it ... Mage_Catalog_Helper_Product_Url::__construct looks for Mage::getConfig()->getNode('default/url/convert'); XML.

@github-actions github-actions bot added Component: Core Relates to Mage_Core Component: Catalog Relates to Mage_Catalog Component: ImportExport Relates to Mage_ImportExport composer Relates to composer.json labels Oct 27, 2024
@sreichel sreichel marked this pull request as draft October 27, 2024 16:12
@sreichel sreichel marked this pull request as ready for review October 27, 2024 17:00
@sreichel sreichel changed the title Used transliterator_transliterate to generate "url_key" Use transliterator_transliterate to generate "url_key" Oct 27, 2024
# Conflicts:
#	tests/unit/Mage/Catalog/Model/CategoryTest.php
#	tests/unit/Mage/Catalog/Model/ProductTest.php
#	tests/unit/Mage/Catalog/Model/UrlTest.php
@fballiano
Copy link
Contributor

#1631 is already merged since many months, what is the point of creating this PR when next should be released? or maybe not? this PR, if merged, will create discrepancies between the branches since IMHO do not have any reasons to exist.

@fballiano
Copy link
Contributor

@colinmollenhour

@sreichel
Copy link
Contributor Author

@fballiano

#1631 was merged to next-branch only. b/c of breaking changes (#1631 (comment)) - and it does not work. See my last comment there.

@sreichel sreichel marked this pull request as draft October 29, 2024 14:47
@fballiano
Copy link
Contributor

I tested it on next and it was working for me.

and anyway your answer doesn't answer my question.

@colinmollenhour

@sreichel
Copy link
Contributor Author

@fballiano

It formated the titles as explained, to default latin something, but localization never worked.

This code does not work ... b/c there is no de-de_Latn/BGN

            $opts = transliterator_list_ids();
            $code = str_replace('_', '-', strtolower($locale)) . '_Latn/BGN';
            if (in_array($code, $opts)) {

this PR, if merged, will create discrepancies between the branches since IMHO do not have any reasons to exist.

imho next branch has a not working PR in, that has to be fixed/replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Relates to Mage_Catalog Component: Core Relates to Mage_Core Component: ImportExport Relates to Mage_ImportExport composer Relates to composer.json phpstan
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants