Skip to content

Commit 065f63f

Browse files
committed
Better selection and translation
1 parent bcd349f commit 065f63f

23 files changed

Lines changed: 824 additions & 288 deletions

assets/js/elp-upload.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,31 +163,40 @@
163163
// If no file selected, show placeholder
164164
if ( ! attributes.attachmentId ) {
165165
return el( MediaUploadCheck, null,
166-
el( MediaUpload, {
167-
onSelect: onSelectFile,
168-
allowedTypes: [ 'application/zip', 'application/x-exe-learning' ],
169-
value: attributes.attachmentId,
170-
render: function( obj ) {
171-
return el( Placeholder, {
172-
icon: 'media-default',
173-
label: __( 'eXeLearning Content', 'exelearning' ),
174-
instructions: __( 'Upload or select a .elpx file from your media library', 'exelearning' ),
175-
className: 'exelearning-upload-placeholder'
176-
},
177-
el( 'div', { className: 'components-placeholder__controls' },
178-
el( Button, {
166+
el( Placeholder, {
167+
icon: 'media-default',
168+
label: __( 'eXeLearning Content', 'exelearning' ),
169+
instructions: __( 'Upload or select a .elpx file from your media library', 'exelearning' ),
170+
className: 'exelearning-upload-placeholder'
171+
},
172+
el( 'div', { className: 'components-placeholder__controls' },
173+
el( MediaUpload, {
174+
onSelect: onSelectFile,
175+
allowedTypes: [ 'application/zip', 'application/x-exe-learning' ],
176+
value: attributes.attachmentId,
177+
mode: 'upload',
178+
render: function( obj ) {
179+
return el( Button, {
179180
isPrimary: true,
180181
onClick: obj.open
181-
}, __( 'Upload .elpx File', 'exelearning' ) ),
182-
el( Button, {
182+
}, __( 'Upload .elpx File', 'exelearning' ) );
183+
}
184+
}),
185+
el( MediaUpload, {
186+
onSelect: onSelectFile,
187+
allowedTypes: [ 'application/zip', 'application/x-exe-learning' ],
188+
value: attributes.attachmentId,
189+
mode: 'browse',
190+
render: function( obj ) {
191+
return el( Button, {
183192
isSecondary: true,
184193
onClick: obj.open,
185194
style: { marginLeft: '10px' }
186-
}, __( 'Media Library', 'exelearning' ) )
187-
)
188-
);
189-
}
190-
})
195+
}, __( 'Media Library', 'exelearning' ) );
196+
}
197+
})
198+
)
199+
)
191200
);
192201
}
193202

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"pot-remove-ctime": "sed -i.bak '/POT-Creation-Date:/d' languages/exelearning.pot && rm languages/exelearning.pot.bak",
2020
"pot-remove-refs": "sed -i.bak '/^#: /d' languages/exelearning.pot && rm languages/exelearning.pot.bak",
2121
"untranslated": "msgattrib --untranslated languages/exelearning-es_ES.po && [ $(msgattrib --untranslated languages/exelearning-es_ES.po | wc -l) -eq 0 ]",
22-
"make-i18n-json": "wp i18n make-json languages/exelearning-es_ES.po languages/ --purge --pretty-print",
2322
"check-untranslated": "composer make-pot && composer pot-remove-ctime && composer pot-remove-refs && composer update-po && composer untranslated && composer make-mo"
2423
},
2524
"config": {

includes/class-elp-upload-block.php

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public function enqueue_block_scripts() {
4949
true
5050
);
5151

52-
wp_set_script_translations(
53-
'exelearning-elp-block',
54-
'exelearning',
55-
plugin_dir_path( __DIR__ ) . 'languages'
56-
);
52+
$this->inject_block_translations();
5753

5854
wp_enqueue_style(
5955
'exelearning-block-editor',
@@ -192,4 +188,45 @@ public function render_block( $attributes ) {
192188

193189
return $html;
194190
}
191+
192+
/**
193+
* Inject JS translations from the already-loaded MO textdomain.
194+
* This avoids needing separate JSON translation files.
195+
*/
196+
private function inject_block_translations() {
197+
$strings = array(
198+
'Settings',
199+
'Height (px)',
200+
'Show Teacher Mode toggler',
201+
'Edit in eXeLearning',
202+
'eXeLearning Content',
203+
'Upload or select a .elpx file from your media library',
204+
'Upload .elpx File',
205+
'Media Library',
206+
'Change file',
207+
'Remove',
208+
'No preview available',
209+
'This is an eXeLearning v2 source file. The content will be displayed on the frontend if exported HTML is available.',
210+
);
211+
212+
$locale_data = array();
213+
foreach ( $strings as $s ) {
214+
$t = __( $s, 'exelearning' ); // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText
215+
if ( $t !== $s ) {
216+
$locale_data[ $s ] = array( $t );
217+
}
218+
}
219+
220+
if ( empty( $locale_data ) ) {
221+
return;
222+
}
223+
224+
$locale_data[''] = array( 'domain' => 'exelearning' );
225+
226+
wp_add_inline_script(
227+
'exelearning-elp-block',
228+
'wp.i18n.setLocaleData(' . wp_json_encode( $locale_data ) . ',"exelearning");',
229+
'before'
230+
);
231+
}
195232
}

languages/exelearning-ca.mo

749 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)