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

WordPress Trac noreply at wordpress.org
Wed Sep 21 16:11:35 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 ocean90):

 Replying to [comment:56 swissspidy]:
  > > * Is there a reason why `$GLOBALS['wp_locale'] = new WP_Locale();`
 happens after the actions?
 >
 > I think I did this after your [comment:41:ticket:26511 previous
 comment]:
 >
 > > The actions `restore_locale` and switch_locale are running _after_ the
 locale has been switched. Should they be named `locale_restored` and
 `locale_switched`?
 >
 > Instead of removing the actions I moved them up, similar to
 `switch_to_blog()`.
 >

 I see, but isn't loading the new text domain also part of switching the
 locale?
 Also, "Fires when the locale is switch'''ed'''" isn't accurate right now.
 If I'd hook into `switch_locale` and use a function like `is_rtl()` I'd
 expect that it returns the data of the new locale. Currently it doesn't.

 > > * The docs for `WP_Locale_Switcher` can be improved:
 > >    * 'Class for switching locales.' => 'Core class used for switching
 locales.'
 > >    * 'Locale switcher object.' => 'Locale API: WP_Locale_Switcher
 class'
 >
 > Agreed, though the whole class name might still change. See #38098.

 You're saying that this ticket now depends on introducing an interface?
 I'm not sure I like that. _If_ there would be an interface in the future
 we still can use it even if the name is different. IMO
 `WP_Locale_Switcher` is self-explaining, `WP_Locale_State` not.

 > > * Is the `get_translations_for_domain()` call in
 `WP_Locale_Switcher::load_translations()` required? Tests are still
 passing when removing the line.
 >
 > I think it can be removed as it's a leftover from the caching in the
 previous patches. Again, needs some benchmarking to decide if caching
 should be considered.

 Okay, I'll try to do some benchmarking.

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


More information about the wp-trac mailing list