Changeset 10064
- Timestamp:
- 07/11/2020 04:04:59 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/cli/class-export.php
r8500 r10064 149 149 return $file; 150 150 } 151 151 152 return 'po'; 152 153 }, $entry->references ); … … 187 188 $json_content_decoded->comment = [ 'reference' => $file ]; 188 189 189 $json_content = wp_json_encode( $json_content_decoded );190 191 190 $hash = md5( $file ); 192 191 $dest = "{$base_dest}-{$hash}.json"; 193 192 194 file_put_contents( $dest, $json_content ); 193 /* 194 * Merge translations into an existing JSON file. 195 * 196 * Some strings occur in multiple source files which may be used on the frontend 197 * or in the admin or both, thus they can be part of different translation 198 * projects (wp/dev, wp/dev/admin, wp/dev/admin/network). 199 * Unlike in PHP with gettext, where translations from multiple MO files are merged 200 * automatically, we have do merge the translations before shipping the 201 * single JSON file per reference. 202 */ 203 if ( file_exists( $dest ) ) { 204 $existing_json_content_decoded = json_decode( file_get_contents( $dest ) ); 205 if ( isset( $existing_json_content_decoded->locale_data->messages ) ) { 206 foreach ( $existing_json_content_decoded->locale_data->messages as $key => $translations ) { 207 if ( ! isset( $json_content_decoded->locale_data->messages->{ $key } ) ) { 208 $json_content_decoded->locale_data->messages->{ $key } = $translations; 209 } 210 } 211 } 212 } 213 214 file_put_contents( $dest, wp_json_encode( $json_content_decoded ) ); 195 215 196 216 $files[] = $dest;
Note: See TracChangeset
for help on using the changeset viewer.