Skip to content

Commit e21e43b

Browse files
authored
Internationalization: remove all custom language handling and let language packs do the work (#16518)
1 parent 01eeddd commit e21e43b

File tree

159 files changed

+9
-398599
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+9
-398599
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/_inc/postmessage.js
88
/docker/wordpress-develop/
99
/docker/wordpress/
10-
/languages/
1110
/modules/custom-css/custom-css/js/core-customizer-css-preview.js
1211
/modules/custom-css/custom-css/js/core-customizer-css.core-4.9.js
1312
/modules/custom-css/custom-css/js/core-customizer-css.js

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ vendor/automattic/jetpack-autoloader
2121
/docker/compose-extras.yml
2222
# File for personal customiziations, if desired.
2323
/docker/mu-plugins/0-sandbox.php
24-
languages/messages.pot
2524
.idea
2625
*.iml
2726
npm-debug.log

.svnignore

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ postcss.config.js
4545
gulpfile.js
4646
gulpfile.babel.js
4747
node_modules
48-
languages/jetpack.pot
4948
LICENSE.txt
5049
modules/widgets/follow-button.php
5150
modules/calypsoify/*.css.map

_inc/client/admin.js

+1-25
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import ReactDOM from 'react-dom';
55
import React from 'react';
66
import { Provider } from 'react-redux';
77
import { HashRouter, Route, Switch } from 'react-router-dom';
8-
import { assign, get } from 'lodash';
9-
import i18n from 'i18n-calypso';
8+
import { assign } from 'lodash';
109
import { _x } from '@wordpress/i18n';
1110

1211
/**
@@ -20,29 +19,6 @@ import * as actionTypes from 'state/action-types';
2019
// Initialize the accessibile focus to allow styling specifically for keyboard navigation
2120
accessibleFocus();
2221

23-
const Initial_State = window.Initial_State;
24-
25-
Initial_State.locale = JSON.parse( Initial_State.locale );
26-
Initial_State.locale = get( Initial_State.locale, [ 'locale_data', 'jetpack' ], {} );
27-
28-
if ( 'undefined' !== typeof Initial_State.locale[ '' ] ) {
29-
Initial_State.locale[ '' ].localeSlug = Initial_State.localeSlug;
30-
31-
// Overloading the toLocaleString method to use the set locale
32-
Number.prototype.realToLocaleString = Number.prototype.toLocaleString;
33-
34-
Number.prototype.toLocaleString = function( locale, options ) {
35-
locale = locale || Initial_State.localeSlug;
36-
options = options || {};
37-
38-
return this.realToLocaleString( locale, options );
39-
};
40-
} else {
41-
Initial_State.locale = { '': { localeSlug: Initial_State.localeSlug } };
42-
}
43-
44-
i18n.setLocale( Initial_State.locale );
45-
4622
// Add dispatch and actionTypes to the window object so we can use it from the browser's console
4723
if ( 'undefined' !== typeof window && process.env.NODE_ENV === 'development' ) {
4824
assign( window, {

_inc/jetpack-strings.php

-721
This file was deleted.

_inc/lib/admin-pages/class.jetpack-react-page.php

-2
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,6 @@ function get_initial_state() {
319319
'infinite-scroll' => current_theme_supports( 'infinite-scroll' ) || in_array( $current_theme->get_stylesheet(), $inf_scr_support_themes, true ),
320320
),
321321
),
322-
'locale' => Jetpack::get_i18n_data_json(),
323-
'localeSlug' => join( '-', explode( '_', get_user_locale() ) ),
324322
'jetpackStateNotices' => array(
325323
'messageCode' => Jetpack::state( 'message' ),
326324
'errorCode' => Jetpack::state( 'error' ),

class.jetpack.php

-42
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ public function configure() {
832832
* @action plugins_loaded
833833
*/
834834
public function late_initialization() {
835-
add_action( 'plugins_loaded', array( 'Jetpack', 'plugin_textdomain' ), 99 );
836835
add_action( 'plugins_loaded', array( 'Jetpack', 'load_modules' ), 100 );
837836

838837
Partner::init();
@@ -1125,16 +1124,6 @@ public function require_jetpack_authentication() {
11251124
$this->connection_manager->require_jetpack_authentication();
11261125
}
11271126

1128-
/**
1129-
* Load language files
1130-
*
1131-
* @action plugins_loaded
1132-
*/
1133-
public static function plugin_textdomain() {
1134-
// Note to self, the third argument must not be hardcoded, to account for relocated folders.
1135-
load_plugin_textdomain( 'jetpack', false, dirname( plugin_basename( JETPACK__PLUGIN_FILE ) ) . '/languages/' );
1136-
}
1137-
11381127
/**
11391128
* Register assets for use in various modules and the Jetpack admin page.
11401129
*
@@ -2649,37 +2638,6 @@ public static function translate_module_tag( $tag ) {
26492638
return jetpack_get_module_i18n_tag( $tag );
26502639
}
26512640

2652-
/**
2653-
* Get i18n strings as a JSON-encoded string
2654-
*
2655-
* @return string The locale as JSON
2656-
*/
2657-
public static function get_i18n_data_json() {
2658-
2659-
// WordPress 5.0 uses md5 hashes of file paths to associate translation
2660-
// JSON files with the file they should be included for. This is an md5
2661-
// of '_inc/build/admin.js'.
2662-
$path_md5 = '1bac79e646a8bf4081a5011ab72d5807';
2663-
2664-
$i18n_json =
2665-
JETPACK__PLUGIN_DIR
2666-
. 'languages/json/jetpack-'
2667-
. get_user_locale()
2668-
. '-'
2669-
. $path_md5
2670-
. '.json';
2671-
2672-
if ( is_file( $i18n_json ) && is_readable( $i18n_json ) ) {
2673-
$locale_data = @file_get_contents( $i18n_json );
2674-
if ( $locale_data ) {
2675-
return $locale_data;
2676-
}
2677-
}
2678-
2679-
// Return valid empty Jed locale
2680-
return '{ "locale_data": { "messages": { "": {} } } }';
2681-
}
2682-
26832641
/**
26842642
* Return module name translation. Uses matching string created in modules/module-headings.php.
26852643
*

gulpfile.babel.js

-184
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
/**
22
* External dependencies
33
*/
4-
import del from 'del';
5-
import deleteLines from 'gulp-rm-lines';
6-
import fs from 'fs';
74
import gulp from 'gulp';
8-
import i18n_calypso from 'i18n-calypso-cli';
9-
import json_transform from 'gulp-json-transform';
105
import log from 'fancy-log';
11-
import po2json from 'gulp-po2json';
12-
import rename from 'gulp-rename';
13-
import request from 'request';
14-
import tap from 'gulp-tap';
156
import { spawn } from 'child_process';
167

178
/**
189
* Internal dependencies
1910
*/
20-
const meta = require( './package.json' );
2111
import frontendcss from './tools/builder/frontend-css';
2212
import admincss from './tools/builder/admin-css';
2313
import { watch as react_watch, build as react_build } from './tools/builder/react';
@@ -50,114 +40,6 @@ gulp.task( 'search:watch', function() {
5040
} );
5141
} );
5242

53-
/*
54-
I18n land
55-
*/
56-
57-
// Should not be run independently, run gulp languages instead
58-
gulp.task( 'languages:get', function( callback ) {
59-
const process = spawn( 'php', [
60-
'tools/export-translations.php',
61-
'.',
62-
'https://translate.wordpress.org/projects/wp-plugins/jetpack/dev',
63-
] );
64-
65-
process.stderr.on( 'data', function( data ) {
66-
log( data.toString() );
67-
} );
68-
process.stdout.on( 'data', function( data ) {
69-
log( data.toString() );
70-
} );
71-
process.on( 'exit', function( code ) {
72-
if ( 0 !== code ) {
73-
log( 'Failed getting languages: process exited with code ', code );
74-
// Make the task fail if there was a problem as this could mean that we were going to ship a Jetpack version
75-
// with the languages not properly built
76-
return callback( new Error() );
77-
}
78-
callback();
79-
} );
80-
} );
81-
82-
// Should not be run independently, run gulp languages instead
83-
gulp.task( 'languages:build', function( done ) {
84-
const terms = [];
85-
86-
// Defining global that will be used from jetpack-strings.js
87-
global.$jetpack_strings = [];
88-
global.array = function() {};
89-
90-
// Plural gettext call doesn't make a difference for Jed, the singular value is still used as the key.
91-
global.__ = global._n = function( term ) {
92-
terms[ term ] = '';
93-
};
94-
95-
// Context prefixes the term and is separated with a unicode character U+0004
96-
global._x = function( term, context ) {
97-
terms[ context + '\u0004' + term ] = '';
98-
};
99-
100-
gulp
101-
.src( [ '_inc/jetpack-strings.php' ] )
102-
.pipe(
103-
deleteLines( {
104-
filters: [ /<\?php/ ],
105-
} )
106-
)
107-
.pipe( rename( 'jetpack-strings.js' ) )
108-
.pipe( gulp.dest( '_inc' ) )
109-
.on( 'end', function() {
110-
// Requiring the file that will call __, _x and _n
111-
require( './_inc/jetpack-strings.js' );
112-
113-
return (
114-
gulp
115-
.src( [ 'languages/*.po' ] )
116-
.pipe(
117-
po2json( {
118-
format: 'jed1.x',
119-
domain: 'jetpack',
120-
} )
121-
)
122-
.pipe(
123-
json_transform( function( data ) {
124-
const localeData = data.locale_data.jetpack;
125-
const filtered = {
126-
'': localeData[ '' ],
127-
};
128-
129-
Object.keys( localeData ).forEach( function( term ) {
130-
if ( terms.hasOwnProperty( term ) ) {
131-
filtered[ term ] = localeData[ term ];
132-
133-
// Having a &quot; in the JSON might cause errors with the JSON later
134-
if ( typeof filtered[ term ] === 'string' ) {
135-
filtered[ term ] = filtered[ term ].replace( '&quot;', '"' );
136-
}
137-
}
138-
} );
139-
140-
return {
141-
locale_data: {
142-
jetpack: filtered,
143-
},
144-
};
145-
} )
146-
)
147-
148-
// WordPress 5.0 uses md5 hashes of file paths to associate translation
149-
// JSON files with the file they should be included for. This is an md5
150-
// of '_inc/build/admin.js'.
151-
.pipe( rename( { suffix: '-1bac79e646a8bf4081a5011ab72d5807' } ) )
152-
.pipe( gulp.dest( 'languages/json/' ) )
153-
.on( 'end', function() {
154-
fs.unlinkSync( './_inc/jetpack-strings.js' );
155-
done();
156-
} )
157-
);
158-
} );
159-
} );
160-
16143
gulp.task( 'php:module-headings', function( callback ) {
16244
const process = spawn( 'php', [ 'tools/build-module-headings-translations.php' ] );
16345
process.stderr.on( 'data', function( data ) {
@@ -174,64 +56,6 @@ gulp.task( 'php:module-headings', function( callback ) {
17456
} );
17557
} );
17658

177-
// Should not be run independently, run gulp languages instead
178-
gulp.task( 'languages:cleanup', function( done ) {
179-
const language_packs = [];
180-
181-
request(
182-
'https://api.wordpress.org/translations/plugins/1.0/?slug=jetpack&version=' + meta.version,
183-
function( error, response, body ) {
184-
if ( error || 200 !== response.statusCode ) {
185-
done( 'Failed to reach wordpress.org translation API: ' + error );
186-
}
187-
188-
body = JSON.parse( body );
189-
190-
body.translations.forEach( function( language ) {
191-
language_packs.push( './languages/jetpack-' + language.language + '.*' );
192-
} );
193-
194-
log( 'Cleaning up languages for which Jetpack has language packs:' );
195-
del( language_packs ).then( function( paths ) {
196-
paths.forEach( function( item ) {
197-
log( item );
198-
} );
199-
done();
200-
} );
201-
}
202-
);
203-
} );
204-
205-
gulp.task( 'languages:extract', function( done ) {
206-
const paths = [];
207-
208-
return gulp
209-
.src( [
210-
'_inc/client/**/*.js',
211-
'_inc/client/**/*.jsx',
212-
'_inc/blocks/*.js',
213-
'_inc/blocks/**/*.js',
214-
] )
215-
.pipe(
216-
tap( function( file ) {
217-
paths.push( file.path );
218-
} )
219-
)
220-
.on( 'end', function() {
221-
i18n_calypso( {
222-
projectName: 'Jetpack',
223-
inputPaths: paths,
224-
output: '_inc/jetpack-strings.php',
225-
phpArrayName: 'jetpack_strings',
226-
format: 'PHP',
227-
textdomain: 'jetpack',
228-
keywords: [ 'translate', '__', '_n', '_x', '_nx' ],
229-
} );
230-
231-
done();
232-
} );
233-
} );
234-
23559
gulp.task( 'old-styles', gulp.parallel( frontendcss, admincss, 'sass:old', 'sass:packages' ) );
23660

23761
// Default task
@@ -256,11 +80,3 @@ gulp.task( 'sass:build', sass_build );
25680
gulp.task( 'react:build', react_build );
25781
gulp.task( 'sass:watch', gulp.parallel( sass_watch, sass_watch_packages ) );
25882
gulp.task( 'react:watch', react_watch );
259-
260-
gulp.task(
261-
'languages',
262-
gulp.parallel(
263-
gulp.series( 'languages:extract' ),
264-
gulp.series( 'languages:get', 'languages:build', 'languages:cleanup' )
265-
)
266-
);

jetpack.php

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* Author URI: https://jetpack.com
99
* License: GPL2+
1010
* Text Domain: jetpack
11-
* Domain Path: /languages/
1211
* Requires at least: 5.4
1312
* Requires PHP: 5.6
1413
*

languages/jetpack-af.mo

-12.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)