Skip to content

Commit f608a2c

Browse files
committed
I18N: Read both revision date header names in .l10n.php files.
Language packs from translate.wordpress.org store the revision date as `translation-revision-date`, while files converted from a PO or MO source store it as `po-revision-date`. `wp_get_l10n_php_file_data()` only read the latter, so `PO-Revision-Date` came back empty for language packs, and `wp_get_installed_translations()` could then offer an installed, up-to-date pack for update again when no `.po` file sits next to it. Both names are now read, with the first one present used. Developed in: #12844 Props bejignesh, irozum, swissspidy. Fixes #65809. git-svn-id: https://develop.svn.wordpress.org/trunk@65803 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9f0201d commit f608a2c

3 files changed

Lines changed: 50 additions & 8 deletions

File tree

‎src/wp-includes/l10n.php‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,11 +1828,13 @@ function wp_get_l10n_php_file_data( $php_file ) {
18281828
$data = (array) include $php_file;
18291829

18301830
unset( $data['messages'] );
1831+
1832+
// The revision date field has a different name depending on the source, support both.
18311833
$headers = array(
1832-
'POT-Creation-Date' => 'pot-creation-date',
1833-
'PO-Revision-Date' => 'po-revision-date',
1834-
'Project-Id-Version' => 'project-id-version',
1835-
'X-Generator' => 'x-generator',
1834+
'POT-Creation-Date' => array( 'pot-creation-date' ),
1835+
'PO-Revision-Date' => array( 'translation-revision-date', 'po-revision-date' ),
1836+
'Project-Id-Version' => array( 'project-id-version' ),
1837+
'X-Generator' => array( 'x-generator' ),
18361838
);
18371839

18381840
$result = array(
@@ -1842,9 +1844,12 @@ function wp_get_l10n_php_file_data( $php_file ) {
18421844
'X-Generator' => '',
18431845
);
18441846

1845-
foreach ( $headers as $po_header => $php_header ) {
1846-
if ( isset( $data[ $php_header ] ) && is_string( $data[ $php_header ] ) ) {
1847-
$result[ $po_header ] = $data[ $php_header ];
1847+
foreach ( $headers as $po_header => $php_headers ) {
1848+
foreach ( $php_headers as $php_header ) {
1849+
if ( isset( $data[ $php_header ] ) && is_string( $data[ $php_header ] ) ) {
1850+
$result[ $po_header ] = $data[ $php_header ];
1851+
break;
1852+
}
18481853
}
18491854
}
18501855

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?php
2-
return ['po-revision-date'=>'2024-01-31 19:08:22+0000','mime-version'=>'1.0','content-type'=>'text/plain; charset=UTF-8','content-transfer-encoding'=>'8bit','plural-forms'=>'nplurals=2; plural=n != 1;','x-generator'=>'GlotPress/4.0.0-beta.2','language'=>'de','project-id-version'=>'WordPress - 6.4.x - Development','messages'=>['html_lang_attribute'=>'de-CH','text directionltr'=>'ltr','number_format_decimal_point'=>',','number_format_thousands_sep'=>'.','Update %s now'=>'Jetzt %s aktualisieren','[%1$s] Confirm Action: %2$s'=>'[%1$s] Aktion bestätigen: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Löschauftrag ausgeführt','[%s] Personal Data Export'=>'[%s] Export personenbezogener Daten']];
2+
return ['translation-revision-date'=>'2024-01-31 19:08:22+0000','mime-version'=>'1.0','content-type'=>'text/plain; charset=UTF-8','content-transfer-encoding'=>'8bit','plural-forms'=>'nplurals=2; plural=n != 1;','x-generator'=>'GlotPress/4.0.0-beta.2','language'=>'de','project-id-version'=>'WordPress - 6.4.x - Development','messages'=>['html_lang_attribute'=>'de-CH','text directionltr'=>'ltr','number_format_decimal_point'=>',','number_format_thousands_sep'=>'.','Update %s now'=>'Jetzt %s aktualisieren','[%1$s] Confirm Action: %2$s'=>'[%1$s] Aktion bestätigen: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Löschauftrag ausgeführt','[%s] Personal Data Export'=>'[%s] Export personenbezogener Daten']];

‎tests/phpunit/tests/l10n.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,43 @@ public function test_wp_get_installed_translations_for_core() {
126126
$this->assertSame( 'GlotPress/4.0.0-beta.2', $data_en_gb['X-Generator'] );
127127
}
128128

129+
/**
130+
* Language packs from translate.wordpress.org carry the revision date as
131+
* `translation-revision-date`.
132+
*
133+
* @ticket 65809
134+
*
135+
* @covers ::wp_get_l10n_php_file_data
136+
*/
137+
public function test_wp_get_l10n_php_file_data_reads_translation_revision_date() {
138+
$data = wp_get_l10n_php_file_data( DIR_TESTDATA . '/l10n/plural-complex.php' );
139+
140+
$this->assertSame( '2024-01-18 05:40:05+0000', $data['PO-Revision-Date'] );
141+
$this->assertSame( 'GlotPress/4.0.0-beta.2', $data['X-Generator'] );
142+
}
143+
144+
/**
145+
* Files converted from a PO or MO source carry it as `po-revision-date`,
146+
* which is the PO header name lowercased.
147+
*
148+
* @ticket 65809
149+
*
150+
* @covers ::wp_get_l10n_php_file_data
151+
*/
152+
public function test_wp_get_l10n_php_file_data_reads_po_revision_date() {
153+
$php_file = wp_tempnam( 'example-simple.l10n.php' );
154+
file_put_contents(
155+
$php_file,
156+
WP_Translation_File::transform( DIR_TESTDATA . '/l10n/example-simple.mo', 'php' )
157+
);
158+
159+
$data = wp_get_l10n_php_file_data( $php_file );
160+
161+
unlink( $php_file );
162+
163+
$this->assertSame( '2016-01-05 18:45:32+1000', $data['PO-Revision-Date'] );
164+
}
165+
129166
/**
130167
* @ticket 35284
131168
*

0 commit comments

Comments
 (0)