Repository navigation
Conversation
…raphs The slug preview in the block editor was wrong for locales that require digraph replacements rather than simple diacritic stripping. For de_DE, ä became 'a' instead of 'ae', ö became 'o' instead of 'oe', etc. This caused a data-integrity problem: when a user clicks the slug field to edit it (standard SEO workflow), the field was pre-filled with the wrong JS-generated value, permanently baking in wrong transliterations. Fix: add an optional locale param to cleanForSlug() in @wordpress/url, applying the same digraph rules as PHP remove_accents() before the removeAccents() call. The PostURL component reads getSite().language from the core store and passes it through. Locales covered (mirroring PHP formatting.php lines 1957-1989): - de_* (de_DE, de_CH, de_AT): ä->ae, ö->oe, ü->ue, ß->ss - da_DK: æ->ae, ø->oe, å->aa - ca: l·l->ll - sr_RS, bs_BA: Đ->DJ Fixes WordPress#12907
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Dominic-t3ch, @IIM-Arvid, @Steve-Fenton, @anubisthejackle. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @apermo! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
@fabiankaegy would be especially nice to have your review, as german you're destined to test it :) |
|
Note: I've opened a trac ticket and a PR on Core to add the uppercase eszett, so depending on how fast that PR is accepted, we should consider to add this here too if the PR is accepted. WordPress/wordpress-develop#11188 |
|
As @dmsnell already updated my PR for the |
Mirrors WordPress/wordpress-develop#11188 which adds the same mapping to PHP remove_accents(). ẞ (U+1E9E) was standardized in German orthography in 2017 (DIN 5008) and should map to SS, not fall through to URL-encoded output.
|
Unfortunately, the options request won’t work for users with lower capabilities. Can we just update mappings in upstream library? Cc @tyxla |
I'm a bit preoccupied this week, but happy to take a look at this next week. Note that eszett's were historically debatable and we've had pushback before:
So reintroducing is unfortunate, but I'm happy to make a tradeoff in favor of alignment with WordPress. |
@tyxla there is probably conflation of two things: the pushback you linked was specifically in your not saying anything specific about this proposed PR, other than noting that the pushback was for a different problem than this PR is proposing, and it can be valid while also leaving this PR valid. |
Haven't got to this one yet, and I admit I may have overlooked it the last time since I never dove into the discussion thoroughly 😉 I was just instinctively responding to @Mamaduka's Thank you for this clarification @dmsnell, I'll keep this in mind once I get to it. |
|
Just circling back to this:
I believe slug handling should remain separate from the accent removal, and it's reasonable to have locale-aware-specific slug-only functionality, especially if it achieves parity with how we're doing it with PHP. So doing that as part of |
|
apart from bloating the JS bundles, is there any opposition to this? by bloat I mean continuing to expand this until it matches the PHP side. have we looked at replacing this duplicate JS library with a |
I don't think we have, but wouldn't be against if we find an elegant way to do it that covers all the necessary use cases. |
| * @return {string} The current slug to be displayed in the editor | ||
| */ | ||
| export function getEditedPostSlug( state ) { | ||
| export function getEditedPostSlug( state, locale = '' ) { |
There was a problem hiding this comment.
when no locale is provided, would we want to set the default to the one provided by the browser?
things are odd here between site locale and browser locale, but probably there’s a good chance they are the same.
| // str_starts_with( $locale, 'de' ) covers de_DE, de_CH, de_AT, etc. | ||
| if ( locale.startsWith( 'de' ) ) { | ||
| return LOCALE_CHAR_MAP.de; | ||
| } |
There was a problem hiding this comment.
just noticed this late in the review, but BCP47 specifies how to match these, see also the W3C spec.
so I think we would want to do something like this, just to avoid problem sin the future with added locales
const mostSpecificLocaleTag = ( objectWithTagKeys, givenTag ) => {
if ( objectWithTagKeys.hasOwnProperty( givenTag ) ) {
return givenTag;
}
// @todo verify the difference between _ and - here, with Core
const lastSeparatorAt = givenTag.lastIndexOf( '_' );
if ( -1 === lastSeparatorAt ) {
return null;
}
return mostSpecificLocaleTag( objectWithTagKeys, givenTag.slice( 0, lastSeparatorAt );
}and then…
const mostSpecificLocale = mostSpecificLocalTag( LOCALE_CHAR_MAP, locale );
return mostSpecificLocale
? LOCALE_CHAR_MAP[ mostSpecificLocale ]
: null;that was nobody comes in and adds de_CH and wonders why it’s ignored; it will choose de_CH if it’s available, then fall back to de
What?
Closes #12907
Adds an optional
localeparameter tocleanForSlug()in@wordpress/urlso the slug preview in the block editor matches what WordPress generates server-side for locales that require digraph replacements.Why?
The slug preview has been wrong for German (and other) locales since the block editor launched.
äbecomesainstead ofae,öbecomesoinstead ofoe, etc. This is not just cosmetic:Data integrity bug: When a user clicks the slug field to edit it (standard SEO workflow — shorten/optimize the auto-generated slug), the field is pre-filled with the wrong JS-generated value. Any manual edit at that point bakes the wrong transliteration in permanently. WordPress locks the slug after the first manual edit, so the post has the wrong URL for its entire lifetime.
This was the original 2019 report and is still present today.
How?
cleanForSlug()in@wordpress/urluses theremove-accentsnpm package which has no locale concept. PHP'sremove_accents()handles this via a locale check (str_starts_with($locale, 'de'), etc.). The fix mirrors that exact locale block in JS, running the digraph replacements beforeremoveAccents()so thatübecomesuerather than being stripped tou.The
PostURLcomponent readsgetSite().languagefrom thecorestore and passes it togetEditedPostSlug()and to theonBlursanitization call.Locales covered (mirroring
wp-includes/formatting.phplines 1957–1989):de_*da_DKcasr_RS,bs_BAThe capital Eszett (
ẞ, U+1E9E) mapping is included in anticipation of WordPress/wordpress-develop#11188, which adds the same mapping to PHP'sremove_accents().All other locales are unaffected — the function is a no-op when
localeis empty or unrecognised, preserving existing behaviour exactly.All expected values were verified against
remove_accents( $input, $locale )+sanitize_title_with_dashes()running insidewp-env. A dedicated parity test is atpackages/url/src/test/compare-slug-php-parity.test.js.Testing Instructions
Künstler überraschen Hörerkuenstler-ueberraschen-hoererimmediately ✓To verify the data integrity fix:
kuenstler-ueberraschen-hoerer(notkunstler-uberraschen-horer)Testing Instructions for Keyboard
Navigate to the Permalink panel via Tab, enter the title, then Tab into the slug field and verify the pre-filled value is correct.
Research and implementation by Claude (Anthropic). Reviewed, tested, and steered by @apermo.