WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 18 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 needs-refresh
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 6 years ago.
formatting.diff (654 bytes) - added by Dualcube 4 years 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 (14)

@akirk
6 years ago

#1 @dd32
6 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
6 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
6 years ago

  • Milestone changed from Awaiting Review to Future Release

#4 @SergeyBiryukov
6 years ago

  • Keywords needs-docs added

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

#5 @swissspidy
5 years 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
4 years 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
4 years 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".

This ticket was mentioned in Slack in #core by sergey. View the logs.


20 months ago

#8 @SergeyBiryukov
20 months ago

  • Milestone changed from Future Release to 5.4

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


19 months ago

#10 @davidbaumwald
19 months ago

  • Keywords needs-refresh added

This will need a @since refresh whichever cycle it ends up landing in.

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


18 months ago

#12 @davidbaumwald
18 months ago

  • Milestone changed from 5.4 to Future Release

This ticket still needs a refresh and review, and with 5.4 Beta 1 landing tomorrow, this is being moved to Future Release. If any maintainer or committer feels this can be included in 5.4 or wishes to assume ownership during a specific cycle, feel free to update the milestone accordingly.

Note: See TracTickets for help on using tickets.