PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.0
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.0
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / functions / i18n.php

i18n.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.0, at inc/functions/i18n.php

344 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Imagify\Imagifybeat\Actions;
4 use Imagify\Imagifybeat\Core;
5 use Imagify\Stats\OptimizedMediaWithoutNextGen;
6
7 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
8
9 /**
10 * Get all translations we can use with wp_localize_script().
11 *
12 * @since 1.5
13 *
14 * @param string $context The translation context.
15 *
16 * @return array $translations The translations.
17 */
18 function get_imagify_localize_script_translations( $context ) {
19 global $post_id;
20
21 $imagifybeat_actions = Actions::get_instance();
22
23 switch ( $context ) {
24 case 'admin-bar':
25 if ( is_admin() ) {
26 return [];
27 }
28
29 return [
30 'ajaxurl' => admin_url( 'admin-ajax.php' ),
31 ];
32
33 case 'notices':
34 return [
35 'labels' => [
36 /* translators: Don't use escaped HTML entities here (like &nbsp;). */
37 'signupTitle' => __( 'Let\'s get you started!', 'imagify' ),
38 'signupText' => __( 'Enter your email to get an API key:', 'imagify' ),
39 'signupConfirmButtonText' => __( 'Sign Up', 'imagify' ),
40 'signupErrorEmptyEmail' => __( 'You need to specify an email!', 'imagify' ),
41 /* translators: Don't use escaped HTML entities here (like &nbsp;). */
42 'signupSuccessTitle' => __( 'Congratulations!', 'imagify' ),
43 'signupSuccessText' => __( 'Your account has been successfully created. Please check your mailbox, you are going to receive an email with API key.', 'imagify' ),
44 /* translators: Don't use escaped HTML entities here (like &nbsp;). */
45 'saveApiKeyTitle' => __( 'Connect to Imagify!', 'imagify' ),
46 'saveApiKeyText' => __( 'Paste your API key below:', 'imagify' ),
47 'saveApiKeyConfirmButtonText' => __( 'Connect me', 'imagify' ),
48 'ApiKeyErrorEmpty' => __( 'You need to specify your API key!', 'imagify' ),
49 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ),
50 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ),
51 ],
52 ];
53
54 case 'sweetalert':
55 return [
56 'labels' => [
57 'cancelButtonText' => __( 'Cancel' ),
58 ],
59 ];
60
61 case 'options':
62 $translations = [
63 'getFilesTree' => imagify_can_optimize_custom_folders() ? get_imagify_admin_url( 'get-files-tree' ) : false,
64 'resetInternalState' => [
65 'action' => 'imagify_reset_internal_state',
66 'confirm' => __( 'Are you sure you want to reset the Imagify internal state? This will clear optimization locks and cancel any pending jobs.', 'imagify' ),
67 'success' => __( 'Imagify internal state has been reset successfully.', 'imagify' ),
68 'error' => __( 'An error occurred while resetting the internal state. Please try again.', 'imagify' ),
69 ],
70 'labels' => [
71 'ValidApiKeyText' => __( 'Your API key is valid.', 'imagify' ),
72 'waitApiKeyCheckText' => __( 'Check in progress...', 'imagify' ),
73 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ),
74 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ),
75 'noBackupTitle' => __( 'Don\'t Need a Parachute?', 'imagify' ),
76 'noBackupText' => __( 'If you keep this option deactivated, you won\'t be able to re-optimize your images to another compression level and restore your original images in case of need.', 'imagify' ),
77 'removeFolder' => _x( 'Remove', 'custom folder', 'imagify' ),
78 'filesTreeTitle' => __( 'Select Folders', 'imagify' ),
79 'filesTreeSubTitle' => __( 'Select one or several folders to optimize.', 'imagify' ),
80 'cleaningInfo' => __( 'Some folders that do not contain any images are hidden.', 'imagify' ),
81 'confirmFilesTreeBtn' => __( 'Select Folders', 'imagify' ),
82 'customFilesLegend' => __( 'Choose the folders to optimize', 'imagify' ),
83 'error' => __( 'Error', 'imagify' ),
84 'themesAdded' => __( 'Added! All Good!', 'imagify' ),
85 ],
86 ];
87
88 if ( OptimizedMediaWithoutNextGen::get_instance()->get_cached_stat() ) {
89 $contexts = imagify_get_context_names();
90 $translations['bulk'] = [
91 'curlMissing' => ! Imagify_Requirements::supports_curl(),
92 'editorMissing' => ! Imagify_Requirements::supports_image_editor(),
93 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(),
94 'apiDown' => ! Imagify_Requirements::is_api_up(),
95 'keyIsValid' => Imagify_Requirements::is_api_key_valid(),
96 'isOverQuota' => Imagify_Requirements::is_over_quota(),
97 'imagifybeatIDs' => [
98 'progress' => $imagifybeat_actions->get_imagifybeat_id( 'options_optimization_status' ),
99 'requirements' => $imagifybeat_actions->get_imagifybeat_id( 'requirements' ),
100 ],
101 'ajaxActions' => [
102 'MissingNextGen' => 'imagify_missing_nextgen_generation',
103 ],
104 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ),
105 'contexts' => $contexts,
106 'progress_next_gen' => [
107 'remaining' => OptimizedMediaWithoutNextGen::get_instance()->get_stat(),
108 'total' => get_transient( 'imagify_missing_next_gen_total' ),
109 ],
110 'labels' => [
111 'curlMissing' => __( 'cURL is not available on the server.', 'imagify' ),
112 'editorMissing' => sprintf(
113 // translators: %s is a "More info?" link.
114 __( 'No php extensions are available to edit images on the server. ImageMagick or GD is required. %s', 'imagify' ),
115 '<a href="' . esc_url( imagify_get_external_url( 'documentation-imagick-gd' ) ) . '" target="_blank">' . __( 'More info?', 'imagify' ) . '</a>'
116 ),
117 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ),
118 'apiDown' => __( 'Sorry, our servers are temporarily unavailable. Please, try again in a couple of minutes.', 'imagify' ),
119 'invalidAPIKeyTitle' => __( 'Your API key is not valid!', 'imagify' ),
120 'overQuotaTitle' => __( 'You have used all your credits!', 'imagify' ),
121 'nothingToDoTitle' => __( 'Hold on!', 'imagify' ),
122 'nothingToDoText' => __( 'All your optimized images already have a next-gen version. Congratulations!', 'imagify' ),
123 'nothingToDoNoBackupText' => __( 'Because the selected images did not have a backup copy, Imagify was unable to create next-gen versions.', 'imagify' ),
124 'error' => __( 'Error', 'imagify' ),
125 'ajaxErrorText' => __( 'The operation failed.', 'imagify' ),
126 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
127 'getUnoptimizedImagesErrorText' => __( 'An unknown error occurred when we tried to get all your unoptimized media files. Try again and if the issue still persists, please contact us!', 'imagify' ),
128 ],
129 ];
130
131 /**
132 * Filter the number of parallel queries generating WebP images by bulk method.
133 *
134 * @since 1.9
135 * @author Grégory Viguier
136 *
137 * @param int $bufferSize Number of parallel queries.
138 */
139 $translations['bulk']['bufferSize'] = apply_filters( 'imagify_bulk_generate_webp_buffer_size', 4 );
140 $translations['bulk']['bufferSize'] = max( 1, (int) $translations['bulk']['bufferSize'] );
141 }
142
143 return $translations;
144
145 case 'pricing-modal':
146 $translations = [
147 'imagify_app_domain' => IMAGIFY_APP_DOMAIN,
148 'labels' => [
149 'errorCouponAPI' => __( 'Error with checking this coupon.', 'imagify' ),
150 'successCouponAPI' => sprintf(
151 /* translators: 1 is a percentage, 2 is a coupon code. */
152 _x( '%1$s off with %2$s', 'coupon validated', 'imagify' ),
153 '<span class="imagify-coupon-offer"></span>',
154 '<strong class="imagify-coupon-word"></strong>'
155 ),
156 'errorPriceAPI' => __( 'Something went wrong with getting our updated offers. Please retry later.', 'imagify' ),
157 'defaultCouponLabel' => __( 'If you have a <strong>coupon code</strong><br> use it here:', 'imagify' ),
158 'errorCouponPlan' => __( 'This coupon is not valid with this plan.', 'imagify' ),
159 ],
160 ];
161
162 if ( Imagify_Requirements::is_api_key_valid() ) {
163 $translations['userDataCache'] = [
164 'deleteAction' => 'imagify_delete_user_data_cache',
165 'deleteNonce' => wp_create_nonce( 'imagify_delete_user_data_cache' ),
166 ];
167 }
168
169 return $translations;
170
171 case 'twentytwenty':
172 $image = [
173 'src' => '',
174 'width' => 0,
175 'height' => 0,
176 ];
177
178 if ( imagify_is_screen( 'attachment' ) && wp_attachment_is_image( $post_id ) ) {
179 $process = imagify_get_optimization_process( $post_id, 'wp' );
180
181 if ( $process->is_valid() ) {
182 $media = $process->get_media();
183
184 if ( $media->is_image() ) {
185 $dimensions = $media->get_dimensions();
186 $image = [
187 'src' => $media->get_fullsize_url(),
188 'width' => $dimensions['width'],
189 'height' => $dimensions['height'],
190 ];
191 }
192 }
193 }
194
195 return [
196 'imageSrc' => $image['src'],
197 'imageWidth' => $image['width'],
198 'imageHeight' => $image['height'],
199 'widthLimit' => 360, // See _imagify_add_actions_to_media_list_row().
200 'labels' => [
201 'filesize' => __( 'File Size:', 'imagify' ),
202 'saving' => __( 'Original Saving:', 'imagify' ),
203 'close' => __( 'Close', 'imagify' ),
204 'originalL' => __( 'Original File', 'imagify' ),
205 'optimizedL' => __( 'Optimized File', 'imagify' ),
206 'compare' => __( 'Compare Original VS Optimized', 'imagify' ),
207 'optimize' => __( 'Optimize', 'imagify' ),
208 ],
209 ];
210
211 case 'beat':
212 return Core::get_instance()->get_settings();
213
214 case 'media-modal':
215 return [
216 'imagifybeatID' => $imagifybeat_actions->get_imagifybeat_id( 'library_optimization_status' ),
217 ];
218
219 case 'library':
220 return [
221 'backupOption' => get_imagify_option( 'backup' ),
222 'labels' => [
223 'bulkActionsOptimize' => __( 'Optimize', 'imagify' ),
224 'bulkActionsOptimizeMissingSizes' => __( 'Optimize Missing Sizes', 'imagify' ),
225 'bulkActionsRestore' => __( 'Restore Original', 'imagify' ),
226 ],
227 ];
228
229 case 'bulk':
230 $translations = [
231 'curlMissing' => ! Imagify_Requirements::supports_curl(),
232 'editorMissing' => ! Imagify_Requirements::supports_image_editor(),
233 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(),
234 'apiDown' => Imagify_Requirements::is_imagify_blocked() || ! Imagify_Requirements::is_api_up(),
235 'keyIsValid' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid(),
236 'isOverQuota' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid() && Imagify_Requirements::is_over_quota(),
237 'imagifybeatIDs' => [
238 'stats' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_stats' ),
239 'queue' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_status' ),
240 'requirements' => $imagifybeat_actions->get_imagifybeat_id( 'requirements' ),
241 ],
242 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg',
243 'ajaxActions' => [
244 'bulkProcess' => 'imagify_bulk_optimize',
245 'getFolderData' => 'imagify_get_folder_type_data',
246 'bulkInfoSeen' => 'imagify_bulk_info_seen',
247 ],
248 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ),
249 'bufferSizes' => [
250 'wp' => 4,
251 'custom-folders' => 4,
252 ],
253 'optimizing' => get_transient( 'imagify_custom-folders_optimize_running' ) || get_transient( 'imagify_wp_optimize_running' ),
254 'labels' => [
255 'overviewChartLabels' => [
256 'unoptimized' => __( 'Unoptimized', 'imagify' ),
257 'optimized' => __( 'Optimized', 'imagify' ),
258 'error' => __( 'Error', 'imagify' ),
259 ],
260 'curlMissing' => __( 'cURL is not available on the server.', 'imagify' ),
261 'editorMissing' => sprintf(
262 /* translators: %s is a "More info?" link. */
263 __( 'No php extensions are available to edit images on the server. ImageMagick or GD is required. %s', 'imagify' ),
264 '<a href="' . esc_url( imagify_get_external_url( 'documentation-imagick-gd' ) ) . '" target="_blank">' . __( 'More info?', 'imagify' ) . '</a>'
265 ),
266 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ),
267 'apiDown' => __( 'Sorry, our servers are temporarily unavailable. Please, try again in a couple of minutes.', 'imagify' ),
268 'invalidAPIKeyTitle' => __( 'Your API key is not valid!', 'imagify' ),
269 'overQuotaTitle' => __( 'You have used all your credits!', 'imagify' ),
270 'waitTitle' => __( 'Please wait...', 'imagify' ),
271 'waitText' => __( 'We are trying to get your unoptimized media files, it may take time depending on the number of files.', 'imagify' ),
272 'nothingToDoTitle' => __( 'Hold on!', 'imagify' ),
273 'nothingToDoText' => [
274 'optimize' => __( 'All your media files have been optimized by Imagify. Congratulations!', 'imagify' ),
275 'generate_webp' => __( 'All your optimized images already have a next-gen version. Congratulations!', 'imagify' ),
276 ],
277 'optimizing' => __( 'Optimizing', 'imagify' ),
278 'error' => __( 'Error', 'imagify' ),
279 'ajaxErrorText' => __( 'The operation failed.', 'imagify' ),
280 'complete' => _x( 'Complete', 'adjective', 'imagify' ),
281 'alreadyOptimized' => _x( 'Already Optimized', 'file', 'imagify' ),
282 /* translators: %s is a number. Don't use %d. */
283 'nbrFiles' => __( '%s file(s)', 'imagify' ),
284 'notice' => _x( 'Notice', 'noun', 'imagify' ),
285 /* translators: %s is a number. Don't use %d. */
286 'nbrErrors' => __( '%s error(s)', 'imagify' ),
287 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
288 'getUnoptimizedImagesErrorText' => __( 'An unknown error occurred when we tried to get all your unoptimized media files. Try again and if the issue still persists, please contact us!', 'imagify' ),
289 'waitingOtimizationsText' => __( 'Waiting other optimizations to finish.', 'imagify' ),
290 /* translators: %s is a formatted number, dont use %d. */
291 'imagesOptimizedText' => __( '%s Media File(s) Optimized', 'imagify' ),
292 /* translators: %s is a formatted number, dont use %d. */
293 'imagesErrorText' => __( '%s Error(s)', 'imagify' ),
294 'bulkInfoTitle' => __( 'Information', 'imagify' ),
295 'confirmBulk' => __( 'Start the optimization', 'imagify' ),
296 ],
297 ];
298
299 if ( get_transient( 'imagify_large_library' ) ) {
300 // On huge media libraries, don't use Imagifybeat, and fetch stats only when the process ends.
301 $translations['ajaxActions']['getStats'] = 'imagify_bulk_get_stats';
302 }
303
304 if ( isset( $translations['bufferSizes']['wp'] ) ) {
305 /**
306 * Filter the number of parallel queries during the Bulk Optimization (library).
307 *
308 * @since 1.5.4
309 * @since 1.7 Deprecated
310 * @deprecated
311 *
312 * @param int $buffer_size Number of parallel queries.
313 */
314 $translations['bufferSizes']['wp'] = apply_filters_deprecated( 'imagify_bulk_buffer_size', [ $translations['bufferSizes']['wp'] ], '1.7', 'imagify_bulk_buffer_sizes' );
315 }
316
317 /**
318 * Filter the number of parallel queries during the Bulk Optimization.
319 *
320 * @since 1.7
321 * @author Grégory Viguier
322 *
323 * @param array $buffer_sizes An array of number of parallel queries, keyed by context.
324 */
325 $translations['bufferSizes'] = apply_filters( 'imagify_bulk_buffer_sizes', $translations['bufferSizes'] );
326
327 return $translations;
328
329 case 'files-list':
330 return [
331 'backupOption' => get_imagify_option( 'backup' ),
332 'context' => 'custom-folders',
333 'imagifybeatID' => $imagifybeat_actions->get_imagifybeat_id( 'custom_folders_optimization_status' ),
334 'labels' => [
335 'bulkActionsOptimize' => __( 'Optimize', 'imagify' ),
336 'bulkActionsRestore' => __( 'Restore Original', 'imagify' ),
337 ],
338 ];
339
340 default:
341 return [];
342 }
343 }
344