[wp-trac] [WordPress Trac] #26511: Introduce a locale-switching function

WordPress Trac noreply at wordpress.org
Sat Sep 24 22:04:29 UTC 2016


#26511: Introduce a locale-switching function
--------------------------------------+------------------------
 Reporter:  johnbillion               |       Owner:
     Type:  feature request           |      Status:  reviewing
 Priority:  normal                    |   Milestone:  4.7
Component:  I18N                      |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------

Comment (by swissspidy):

 Replying to [comment:60 ocean90]:
 > Not sure if we really have to be consistent with a naming which is
 semantically incorrect. But maybe we can provide both functions?
 `restore_current_locale()` would empty the stack and set the locale to
 `$original_locale`.

 Added in the latest patch.

 > Can't we move it to `default-filters.php` as `add_filter( 'locale',
 array( $GLOBALS['wp_locale_switcher'], 'filter_locale' );`? Or a simple
 `init()` method which gets called in `wp-settings.php`.

 `default-filters.php` is loaded in `wp-settings.php` on line 113, while
 `$GLOBALS['wp_locale_switcher']` is initialized on line 395, so that
 doesn't really work. Going with the `init()` method for now.

 Replying to [comment:61 ocean90]:
 > Something I missed to mention earlier: There is an issue with functions
 like `get_post_type_labels()`/`_get_custom_object_labels()`. Post type
 labels are initially registered via `register_post_type()` which means
 they don't change when calling `switch_to_locale()`. You can see that with
 [https://core.trac.wordpress.org/attachment/ticket/29783/user-language-
 admin-toolbar.php the example plugin] in the Add New menu for the Post and
 Page items.

 Ugh, I experienced that once when testing but thought it was fixed
 eventually. Since post type labels are cached it's a bit hacky to reload
 them. The latest patch tries it anyway.

 Replying to [comment:62 tfrommen]:
 > There are even more issues, for example, when you have a Custom Post
 Type or Custom Taxonomy registered by using a translated slug. When you
 switch to a different locale, the rewrite rules (and thus the generated
 permalinks) do '''not''' get adapted.
 >
 > The question is if coping with these things should be handled by the
 locale switcher, or not.

 We definitely can't accommodate for rewrite rules (especially as long as
 they are stored in the database, see #36292) as we'd have no idea which
 part was translated.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26511#comment:63>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list