Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#35442 closed defect (bug) (duplicate)

Remove ambiguousness from return value of `is_textdomain_loaded()`

Reported by: jrf's profile jrf Owned by: ocean90's profile ocean90
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch has-unit-tests
Focuses: Cc:


The is_textdomain_loaded() function - as per the doc block - is supposed to answer the question whether there are any translations loaded for a textdomain.

It currently does not do so.

It only checks whether the $i10n['domain'] key isset, not whether there are any translations.

As the first time the get_translations_for_domain() function is called, it will also set the text domain, this can lead to false positives, i.e. is_textdomain_loaded() reporting true for a textdomain which hasn't been loaded.

Simple example to reproduce the issue:

var_dump( is_textdomain_loaded( 'does-not-exist' ) );
echo __( 'just some string', 'does-not-exist' );
var_dump( is_textdomain_loaded( 'does-not-exist' ) );

will currently result in:

just some string

With the patch the result will be:

just some string

This patch will improve the results for patch #35439 as well.

Attachments (2)

35442 fix-is_textdomain_loaded.patch (707 bytes) - added by jrf 9 years ago.
35442 is_textdomain_loaded-unit-test.patch (968 bytes) - added by jrf 9 years ago.
Example code as unit test for this issue

Download all attachments as: .zip

Change History (7)

#1 @jrf
9 years ago

  • Keywords has-patch added

9 years ago

Example code as unit test for this issue

#2 @jrf
9 years ago

  • Keywords has-unit-tests added

#3 @ocean90
9 years ago

  • Milestone changed from Awaiting Review to 4.5
  • Owner set to ocean90
  • Status changed from new to accepted

#4 @ocean90
9 years ago

  • Milestone 4.5 deleted
  • Resolution set to duplicate
  • Status changed from accepted to closed

Duplicate of #21319.

#5 @jrf
9 years ago

@ocean90 your search was obviously better than mine ;-)
I considered changing the get_translations_for_domain() function as well like in the other issue, but felt that the risk of breaking things which expected an object would be too big.

Note: See TracTickets for help on using tickets.