PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.2.8
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.2.8
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.2.8, at inc/functions/i18n.php

338 lines 16.0 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 'labels' => [
65 'ValidApiKeyText' => __( 'Your API key is valid.', 'imagify' ),
66 'waitApiKeyCheckText' => __( 'Check in progress...', 'imagify' ),
67 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ),
68 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ),
69 'noBackupTitle' => __( 'Don\'t Need a Parachute?', 'imagify' ),
70 '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' ),
71 'removeFolder' => _x( 'Remove', 'custom folder', 'imagify' ),
72 'filesTreeTitle' => __( 'Select Folders', 'imagify' ),
73 'filesTreeSubTitle' => __( 'Select one or several folders to optimize.', 'imagify' ),
74 'cleaningInfo' => __( 'Some folders that do not contain any images are hidden.', 'imagify' ),
75 'confirmFilesTreeBtn' => __( 'Select Folders', 'imagify' ),
76 'customFilesLegend' => __( 'Choose the folders to optimize', 'imagify' ),
77 'error' => __( 'Error', 'imagify' ),
78 'themesAdded' => __( 'Added! All Good!', 'imagify' ),
79 ],
80 ];
81
82 if ( OptimizedMediaWithoutNextGen::get_instance()->get_cached_stat() ) {
83 $contexts = imagify_get_context_names();
84 $translations['bulk'] = [
85 'curlMissing' => ! Imagify_Requirements::supports_curl(),
86 'editorMissing' => ! Imagify_Requirements::supports_image_editor(),
87 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(),
88 'apiDown' => ! Imagify_Requirements::is_api_up(),
89 'keyIsValid' => Imagify_Requirements::is_api_key_valid(),
90 'isOverQuota' => Imagify_Requirements::is_over_quota(),
91 'imagifybeatIDs' => [
92 'progress' => $imagifybeat_actions->get_imagifybeat_id( 'options_optimization_status' ),
93 'requirements' => $imagifybeat_actions->get_imagifybeat_id( 'requirements' ),
94 ],
95 'ajaxActions' => [
96 'MissingNextGen' => 'imagify_missing_nextgen_generation',
97 ],
98 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ),
99 'contexts' => $contexts,
100 'progress_next_gen' => [
101 'remaining' => OptimizedMediaWithoutNextGen::get_instance()->get_stat(),
102 'total' => get_transient( 'imagify_missing_next_gen_total' ),
103 ],
104 'labels' => [
105 'curlMissing' => __( 'cURL is not available on the server.', 'imagify' ),
106 'editorMissing' => sprintf(
107 // translators: %s is a "More info?" link.
108 __( 'No php extensions are available to edit images on the server. ImageMagick or GD is required. %s', 'imagify' ),
109 '<a href="' . esc_url( imagify_get_external_url( 'documentation-imagick-gd' ) ) . '" target="_blank">' . __( 'More info?', 'imagify' ) . '</a>'
110 ),
111 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ),
112 'apiDown' => __( 'Sorry, our servers are temporarily unavailable. Please, try again in a couple of minutes.', 'imagify' ),
113 'invalidAPIKeyTitle' => __( 'Your API key is not valid!', 'imagify' ),
114 'overQuotaTitle' => __( 'You have used all your credits!', 'imagify' ),
115 'nothingToDoTitle' => __( 'Hold on!', 'imagify' ),
116 'nothingToDoText' => __( 'All your optimized images already have a next-gen version. Congratulations!', 'imagify' ),
117 'nothingToDoNoBackupText' => __( 'Because the selected images did not have a backup copy, Imagify was unable to create next-gen versions.', 'imagify' ),
118 'error' => __( 'Error', 'imagify' ),
119 'ajaxErrorText' => __( 'The operation failed.', 'imagify' ),
120 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
121 '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' ),
122 ],
123 ];
124
125 /**
126 * Filter the number of parallel queries generating WebP images by bulk method.
127 *
128 * @since 1.9
129 * @author Grégory Viguier
130 *
131 * @param int $bufferSize Number of parallel queries.
132 */
133 $translations['bulk']['bufferSize'] = apply_filters( 'imagify_bulk_generate_webp_buffer_size', 4 );
134 $translations['bulk']['bufferSize'] = max( 1, (int) $translations['bulk']['bufferSize'] );
135 }
136
137 return $translations;
138
139 case 'pricing-modal':
140 $translations = [
141 'imagify_app_domain' => IMAGIFY_APP_DOMAIN,
142 'labels' => [
143 'errorCouponAPI' => __( 'Error with checking this coupon.', 'imagify' ),
144 'successCouponAPI' => sprintf(
145 /* translators: 1 is a percentage, 2 is a coupon code. */
146 _x( '%1$s off with %2$s', 'coupon validated', 'imagify' ),
147 '<span class="imagify-coupon-offer"></span>',
148 '<strong class="imagify-coupon-word"></strong>'
149 ),
150 'errorPriceAPI' => __( 'Something went wrong with getting our updated offers. Please retry later.', 'imagify' ),
151 'defaultCouponLabel' => __( 'If you have a <strong>coupon code</strong><br> use it here:', 'imagify' ),
152 'errorCouponPlan' => __( 'This coupon is not valid with this plan.', 'imagify' ),
153 ],
154 ];
155
156 if ( Imagify_Requirements::is_api_key_valid() ) {
157 $translations['userDataCache'] = [
158 'deleteAction' => 'imagify_delete_user_data_cache',
159 'deleteNonce' => wp_create_nonce( 'imagify_delete_user_data_cache' ),
160 ];
161 }
162
163 return $translations;
164
165 case 'twentytwenty':
166 $image = [
167 'src' => '',
168 'width' => 0,
169 'height' => 0,
170 ];
171
172 if ( imagify_is_screen( 'attachment' ) && wp_attachment_is_image( $post_id ) ) {
173 $process = imagify_get_optimization_process( $post_id, 'wp' );
174
175 if ( $process->is_valid() ) {
176 $media = $process->get_media();
177
178 if ( $media->is_image() ) {
179 $dimensions = $media->get_dimensions();
180 $image = [
181 'src' => $media->get_fullsize_url(),
182 'width' => $dimensions['width'],
183 'height' => $dimensions['height'],
184 ];
185 }
186 }
187 }
188
189 return [
190 'imageSrc' => $image['src'],
191 'imageWidth' => $image['width'],
192 'imageHeight' => $image['height'],
193 'widthLimit' => 360, // See _imagify_add_actions_to_media_list_row().
194 'labels' => [
195 'filesize' => __( 'File Size:', 'imagify' ),
196 'saving' => __( 'Original Saving:', 'imagify' ),
197 'close' => __( 'Close', 'imagify' ),
198 'originalL' => __( 'Original File', 'imagify' ),
199 'optimizedL' => __( 'Optimized File', 'imagify' ),
200 'compare' => __( 'Compare Original VS Optimized', 'imagify' ),
201 'optimize' => __( 'Optimize', 'imagify' ),
202 ],
203 ];
204
205 case 'beat':
206 return Core::get_instance()->get_settings();
207
208 case 'media-modal':
209 return [
210 'imagifybeatID' => $imagifybeat_actions->get_imagifybeat_id( 'library_optimization_status' ),
211 ];
212
213 case 'library':
214 return [
215 'backupOption' => get_imagify_option( 'backup' ),
216 'labels' => [
217 'bulkActionsOptimize' => __( 'Optimize', 'imagify' ),
218 'bulkActionsOptimizeMissingSizes' => __( 'Optimize Missing Sizes', 'imagify' ),
219 'bulkActionsRestore' => __( 'Restore Original', 'imagify' ),
220 ],
221 ];
222
223 case 'bulk':
224 $translations = [
225 'curlMissing' => ! Imagify_Requirements::supports_curl(),
226 'editorMissing' => ! Imagify_Requirements::supports_image_editor(),
227 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(),
228 'apiDown' => Imagify_Requirements::is_imagify_blocked() || ! Imagify_Requirements::is_api_up(),
229 'keyIsValid' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid(),
230 'isOverQuota' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid() && Imagify_Requirements::is_over_quota(),
231 'imagifybeatIDs' => [
232 'stats' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_stats' ),
233 'queue' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_status' ),
234 'requirements' => $imagifybeat_actions->get_imagifybeat_id( 'requirements' ),
235 ],
236 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg',
237 'ajaxActions' => [
238 'bulkProcess' => 'imagify_bulk_optimize',
239 'getFolderData' => 'imagify_get_folder_type_data',
240 'bulkInfoSeen' => 'imagify_bulk_info_seen',
241 ],
242 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ),
243 'bufferSizes' => [
244 'wp' => 4,
245 'custom-folders' => 4,
246 ],
247 'optimizing' => get_transient( 'imagify_custom-folders_optimize_running' ) || get_transient( 'imagify_wp_optimize_running' ),
248 'labels' => [
249 'overviewChartLabels' => [
250 'unoptimized' => __( 'Unoptimized', 'imagify' ),
251 'optimized' => __( 'Optimized', 'imagify' ),
252 'error' => __( 'Error', 'imagify' ),
253 ],
254 'curlMissing' => __( 'cURL is not available on the server.', 'imagify' ),
255 'editorMissing' => sprintf(
256 /* translators: %s is a "More info?" link. */
257 __( 'No php extensions are available to edit images on the server. ImageMagick or GD is required. %s', 'imagify' ),
258 '<a href="' . esc_url( imagify_get_external_url( 'documentation-imagick-gd' ) ) . '" target="_blank">' . __( 'More info?', 'imagify' ) . '</a>'
259 ),
260 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ),
261 'apiDown' => __( 'Sorry, our servers are temporarily unavailable. Please, try again in a couple of minutes.', 'imagify' ),
262 'invalidAPIKeyTitle' => __( 'Your API key is not valid!', 'imagify' ),
263 'overQuotaTitle' => __( 'You have used all your credits!', 'imagify' ),
264 'waitTitle' => __( 'Please wait...', 'imagify' ),
265 'waitText' => __( 'We are trying to get your unoptimized media files, it may take time depending on the number of files.', 'imagify' ),
266 'nothingToDoTitle' => __( 'Hold on!', 'imagify' ),
267 'nothingToDoText' => [
268 'optimize' => __( 'All your media files have been optimized by Imagify. Congratulations!', 'imagify' ),
269 'generate_webp' => __( 'All your optimized images already have a next-gen version. Congratulations!', 'imagify' ),
270 ],
271 'optimizing' => __( 'Optimizing', 'imagify' ),
272 'error' => __( 'Error', 'imagify' ),
273 'ajaxErrorText' => __( 'The operation failed.', 'imagify' ),
274 'complete' => _x( 'Complete', 'adjective', 'imagify' ),
275 'alreadyOptimized' => _x( 'Already Optimized', 'file', 'imagify' ),
276 /* translators: %s is a number. Don't use %d. */
277 'nbrFiles' => __( '%s file(s)', 'imagify' ),
278 'notice' => _x( 'Notice', 'noun', 'imagify' ),
279 /* translators: %s is a number. Don't use %d. */
280 'nbrErrors' => __( '%s error(s)', 'imagify' ),
281 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ),
282 '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' ),
283 'waitingOtimizationsText' => __( 'Waiting other optimizations to finish.', 'imagify' ),
284 /* translators: %s is a formatted number, dont use %d. */
285 'imagesOptimizedText' => __( '%s Media File(s) Optimized', 'imagify' ),
286 /* translators: %s is a formatted number, dont use %d. */
287 'imagesErrorText' => __( '%s Error(s)', 'imagify' ),
288 'bulkInfoTitle' => __( 'Information', 'imagify' ),
289 'confirmBulk' => __( 'Start the optimization', 'imagify' ),
290 ],
291 ];
292
293 if ( get_transient( 'imagify_large_library' ) ) {
294 // On huge media libraries, don't use Imagifybeat, and fetch stats only when the process ends.
295 $translations['ajaxActions']['getStats'] = 'imagify_bulk_get_stats';
296 }
297
298 if ( isset( $translations['bufferSizes']['wp'] ) ) {
299 /**
300 * Filter the number of parallel queries during the Bulk Optimization (library).
301 *
302 * @since 1.5.4
303 * @since 1.7 Deprecated
304 * @deprecated
305 *
306 * @param int $buffer_size Number of parallel queries.
307 */
308 $translations['bufferSizes']['wp'] = apply_filters_deprecated( 'imagify_bulk_buffer_size', [ $translations['bufferSizes']['wp'] ], '1.7', 'imagify_bulk_buffer_sizes' );
309 }
310
311 /**
312 * Filter the number of parallel queries during the Bulk Optimization.
313 *
314 * @since 1.7
315 * @author Grégory Viguier
316 *
317 * @param array $buffer_sizes An array of number of parallel queries, keyed by context.
318 */
319 $translations['bufferSizes'] = apply_filters( 'imagify_bulk_buffer_sizes', $translations['bufferSizes'] );
320
321 return $translations;
322
323 case 'files-list':
324 return [
325 'backupOption' => get_imagify_option( 'backup' ),
326 'context' => 'custom-folders',
327 'imagifybeatID' => $imagifybeat_actions->get_imagifybeat_id( 'custom_folders_optimization_status' ),
328 'labels' => [
329 'bulkActionsOptimize' => __( 'Optimize', 'imagify' ),
330 'bulkActionsRestore' => __( 'Restore Original', 'imagify' ),
331 ],
332 ];
333
334 default:
335 return [];
336 }
337 }
338