WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 13 months ago

#32939 assigned enhancement

Add filter for get_locale() in remove_accents()

Reported by: akirk Owned by: Dualcube
Milestone: Future Release Priority: normal
Severity: normal Version: 4.3
Component: I18N Keywords: needs-docs good-first-bug has-patch
Focuses: Cc:

Description

In the remove_accents() function, a filter for the call of get_locale() is needed for installations that want to make use of the special cases for hardcoded locales when those are different in their local installation.

Attachments (2)

32939.diff (555 bytes) - added by akirk 3 years ago.
formatting.diff (654 bytes) - added by Dualcube 17 months ago.
We added a filter called update_locale_for_remove_accents which could be used to change the WP default locale for installations that want to make use of the special cases for hardcoded locales when those are different in their local installation.

Download all attachments as: .zip

Change History (8)

@akirk
3 years ago

#1 @dd32
3 years ago

Would it be better to have a parameter to the function? or to attach the custom-locale replacements via a filter of some kind?

I guess I'm just not clear on the use-case of this filter.

#2 @akirk
3 years ago

Not sure where you'd suggest to put a parameter?

For example, when creating a slug for a new post, the blog language is German but with a different locale than de_DE. So to have a way to rewrite the locale to the expected value (to make use of the special cases defined here), a filter (as in the patch) works as a simple solution.

Another option would be to remove the hardcoded de_DE and do that with a filter:

if ( apply_filters( 'locale_de_DE', 'de_DE' ) === $locale ) {
...
} elseif ( apply_filters( 'locale_da_DK', 'da_DK' ) === $locale ) {
...
}

To me the solution from the current patch seems a bit more flexible.

#3 @obenland
3 years ago

  • Milestone changed from Awaiting Review to Future Release

#4 @SergeyBiryukov
3 years ago

  • Keywords needs-docs added

The filter needs to be documented as per the documentation standards.

#5 @swissspidy
18 months ago

  • Keywords good-first-bug needs-patch added

In the meantime, one could probably do something like this:

<?php
function wp32939_change_locale( $title, $raw_title, $context ) {
  remove_filter( 'sanitize_title', 'wp32939_change_locale ' );
  add_filter( 'locale', function() { return 'de_DE';  } );
  return sanitize_title( $raw_title, '', $context );
}

add_filter( 'sanitize_title', 'wp32939_change_locale', 10, 3 );

@Dualcube
17 months ago

We added a filter called update_locale_for_remove_accents which could be used to change the WP default locale for installations that want to make use of the special cases for hardcoded locales when those are different in their local installation.

#6 @DrewAPicture
13 months ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to Dualcube
  • Status changed from new to assigned

Assigning ownership to mark the good-first-bug as "claimed".

Note: See TracTickets for help on using tickets.