Skip to content

Commit 404ecd8

Browse files
author
George Stephanis
committed
Precompile module tags for translation dynamically
This ensures that any new tags added later will be included in the translation set.
1 parent 7277a01 commit 404ecd8

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

class.jetpack.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -1328,17 +1328,9 @@ public static function get_file_data( $file, $headers ) {
13281328
}
13291329

13301330
public static function translate_module_tag( $untranslated_tag ) {
1331+
// Tags are aggregated by tools/build-module-headings-translations.php
1332+
// and output in modules/module-headings.php
13311333
return _x( $untranslated_tag, 'Module Tag', 'jetpack' );
1332-
1333-
// Calls here are to populate translation files.
1334-
_x( 'Photos and Videos', 'Module Tag', 'jetpack' );
1335-
_x( 'Social', 'Module Tag', 'jetpack' );
1336-
_x( 'WordPress.com Stats', 'Module Tag', 'jetpack' );
1337-
_x( 'Writing', 'Module Tag', 'jetpack' );
1338-
_x( 'Appearance', 'Module Tag', 'jetpack' );
1339-
_x( 'Developers', 'Module Tag', 'jetpack' );
1340-
_x( 'Mobile', 'Module Tag', 'jetpack' );
1341-
_x( 'Other', 'Module Tag', 'jetpack' );
13421334
}
13431335

13441336
/**

modules/module-headings.php

+62
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,65 @@
143143
// modules/widgets.php
144144
_x( 'Extra Sidebar Widgets', 'Module Name', 'jetpack' );
145145
_x( 'Add images, Twitter streams, your site’s RSS links, and more to your sidebar.', 'Module Description', 'jetpack' );
146+
147+
// Modules with `Other` tag:
148+
// - modules/contact-form.php
149+
// - modules/notes.php
150+
// - modules/site-icon.php
151+
_x( 'Other', 'Module Tag', 'jetpack' );
152+
153+
// Modules with `Writing` tag:
154+
// - modules/after-the-deadline.php
155+
// - modules/custom-content-types.php
156+
// - modules/enhanced-distribution.php
157+
// - modules/json-api.php
158+
// - modules/latex.php
159+
// - modules/markdown.php
160+
// - modules/post-by-email.php
161+
// - modules/shortcodes.php
162+
_x( 'Writing', 'Module Tag', 'jetpack' );
163+
164+
// Modules with `Photos and Videos` tag:
165+
// - modules/carousel.php
166+
// - modules/photon.php
167+
// - modules/shortcodes.php
168+
// - modules/tiled-gallery.php
169+
// - modules/videopress.php
170+
_x( 'Photos and Videos', 'Module Tag', 'jetpack' );
171+
172+
// Modules with `Social` tag:
173+
// - modules/comments.php
174+
// - modules/gravatar-hovercards.php
175+
// - modules/likes.php
176+
// - modules/publicize.php
177+
// - modules/sharedaddy.php
178+
// - modules/shortcodes.php
179+
// - modules/shortlinks.php
180+
// - modules/subscriptions.php
181+
// - modules/widgets.php
182+
_x( 'Social', 'Module Tag', 'jetpack' );
183+
184+
// Modules with `Appearance` tag:
185+
// - modules/custom-css.php
186+
// - modules/gravatar-hovercards.php
187+
// - modules/infinite-scroll.php
188+
// - modules/minileven.php
189+
// - modules/photon.php
190+
// - modules/shortcodes.php
191+
// - modules/widget-visibility.php
192+
// - modules/widgets.php
193+
_x( 'Appearance', 'Module Tag', 'jetpack' );
194+
195+
// Modules with `Developers` tag:
196+
// - modules/json-api.php
197+
// - modules/omnisearch.php
198+
// - modules/sso.php
199+
_x( 'Developers', 'Module Tag', 'jetpack' );
200+
201+
// Modules with `Mobile` tag:
202+
// - modules/minileven.php
203+
_x( 'Mobile', 'Module Tag', 'jetpack' );
204+
205+
// Modules with `WordPress.com Stats` tag:
206+
// - modules/stats.php
207+
_x( 'WordPress.com Stats', 'Module Tag', 'jetpack' );

tools/build-module-headings-translations.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
";
1313

1414
$jp_dir = dirname( dirname( __FILE__ ) ) . '/';
15-
$files = glob( "{$jp_dir}modules/*.php" );
15+
$files = glob( "{$jp_dir}modules/*.php" );
16+
$tags = array(
17+
'Other' => array(),
18+
);
1619
foreach ( $files as $file ) {
1720
$absolute_path = $file;
1821
$relative_path = str_replace( $jp_dir, '', $file );
@@ -28,12 +31,20 @@
2831
$all_headers = array(
2932
'name' => 'Module Name',
3033
'description' => 'Module Description',
34+
'tags' => 'Module Tags',
3135
);
3236

3337
foreach ( $all_headers as $field => $regex ) {
3438
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
3539
$string = trim( preg_replace( "/\s*(?:\*\/|\?>).*/", '', $match[1] ) );
36-
$_file_contents .= "_x( '{$string}', '{$regex}', 'jetpack' );\r\n";
40+
if ( 'Module Tags' === $regex ) {
41+
$module_tags = array_map( 'trim', explode( ',', $string ) );
42+
foreach ( $module_tags as $tag ) {
43+
$tags[ $tag ][] = $relative_path;
44+
}
45+
} else {
46+
$_file_contents .= "_x( '{$string}', '{$regex}', 'jetpack' );\r\n";
47+
}
3748
}
3849
}
3950

@@ -44,4 +55,12 @@
4455

4556
}
4657

58+
foreach ( $tags as $tag => $files ) {
59+
$file_contents .= "\r\n// Modules with `{$tag}` tag:\r\n";
60+
foreach ( $files as $file ) {
61+
$file_contents .= "// - {$file}\r\n";
62+
}
63+
$file_contents .= "_x( '{$tag}', 'Module Tag', 'jetpack' );\r\n";
64+
}
65+
4766
file_put_contents( "{$jp_dir}modules/module-headings.php", $file_contents );

0 commit comments

Comments
 (0)