| @@ -341,8 +341,33 @@ | ||
| 341 | 341 | } |
| 342 | 342 | }); |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | + // Translatable strings used by the dynamically rendered plugin list. | |
| 346 | + const upkI18n = <?php echo wp_json_encode( array( | |
| 347 | + 'noPlugins' => __( 'No plugins found.', 'ultimate-post-kit' ), | |
| 348 | + 'recommended' => __( 'Recommended', 'ultimate-post-kit' ), | |
| 349 | + 'active' => __( 'ACTIVE', 'ultimate-post-kit' ), | |
| 350 | + /* translators: %s: number of active installs, or the "Fewer than 10" phrase. */ | |
| 351 | + 'activeInstalls' => __( 'Active Installs: %s', 'ultimate-post-kit' ), | |
| 352 | + 'fewerThanTen' => __( 'Fewer than 10', 'ultimate-post-kit' ), | |
| 353 | + /* translators: %s: formatted download count. */ | |
| 354 | + 'downloads' => __( 'Downloads: %s', 'ultimate-post-kit' ), | |
| 355 | + /* translators: %s: plugin rating, e.g. 4.5. */ | |
| 356 | + 'ratingTitle' => __( '%s out of 5 stars', 'ultimate-post-kit' ), | |
| 357 | + /* translators: %s: plugin rating, e.g. 4.5. */ | |
| 358 | + 'ratingText' => __( '%s out of 5 stars.', 'ultimate-post-kit' ), | |
| 359 | + /* translators: %s: number of ratings. */ | |
| 360 | + 'ratingCount' => __( '(%s ratings)', 'ultimate-post-kit' ), | |
| 361 | + /* translators: %s: how long ago the plugin was updated. */ | |
| 362 | + 'lastUpdated' => __( 'Last Updated: %s', 'ultimate-post-kit' ), | |
| 363 | + ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); ?>; | |
| 364 | + | |
| 365 | + // Minimal printf-style substitution so translators keep control of word order. | |
| 366 | + function upkFormat(template, value) { | |
| 367 | + return String(template).replace('%s', value); | |
| 368 | + } | |
| 369 | + | |
| 345 | 370 | // Function to render plugin list |
| 346 | 371 | function renderPluginList(plugins) { |
| 347 | 372 | const $pluginList = $('#upk-integration-plugin-list'); |
| 348 | 373 | let html = ''; |
| @@ -347,9 +372,9 @@ | ||
| 347 | 372 | const $pluginList = $('#upk-integration-plugin-list'); |
| 348 | 373 | let html = ''; |
| 349 | 374 | |
| 350 | 375 | if (plugins.length === 0) { |
| 351 | - html = '<div class="upk-no-plugins" style="text-align: center; padding: 40px;"><p>No plugins found.</p></div>'; | |
| 376 | + html = `<div class="upk-no-plugins" style="text-align: center; padding: 40px;"><p>${upkEsc(upkI18n.noPlugins)}</p></div>`; | |
| 352 | 377 | } else { |
| 353 | 378 | plugins.forEach(function(plugin) { |
| 354 | 379 | // Skip own plugin (Ultimate Post Kit) when printing only; data still includes it for other plugins |
| 355 | 380 | if (plugin.slug === 'ultimate-post-kit') return; |
| @@ -362,10 +387,10 @@ | ||
| 362 | 387 | <span class="bdt-plugin-logo"> |
| 363 | 388 | ${generatePluginLogo(plugin)} |
| 364 | 389 | </span> |
| 365 | 390 | <div class="bdt-plugin-badge-switch-wrap"> |
| 366 | - ${isRecommended ? '<span class="recommended-badge">Recommended</span>' : ''} | |
| 367 | - ${isActive ? '<span class="active-badge">ACTIVE</span>' : ''} | |
| 391 | + ${isRecommended ? `<span class="recommended-badge">${upkEsc(upkI18n.recommended)}</span>` : ''} | |
| 392 | + ${isActive ? `<span class="active-badge">${upkEsc(upkI18n.active)}</span>` : ''} | |
| 368 | 393 | ${!isActive ? ` |
| 369 | 394 | <label class="switch"> |
| 370 | 395 | <input type="checkbox" class="plugin-slider-checkbox" ${plugin.recommended ? 'checked' : ''} name="plugins[]${upkEsc(plugin.slug)}"> |
| 371 | 396 | <span class="slider round"></span> |
| @@ -376,22 +401,21 @@ | ||
| 376 | 401 | <div class="bdt-flex bdt-flex-middle"> |
| 377 | 402 | <span class="bdt-plugin-name">${upkEsc(plugin.name)}</span> |
| 378 | 403 | </div> |
| 379 | 404 | <span class="active-installs"> |
| 380 | - Active Installs: | |
| 381 | - <span class="installs-count">${plugin.active_installs_count > 0 ? plugin.active_installs_count.toLocaleString() + '+' : 'Fewer than 10'}</span> | |
| 405 | + ${upkFormat(upkEsc(upkI18n.activeInstalls), `<span class="installs-count">${plugin.active_installs_count > 0 ? upkEsc(plugin.active_installs_count.toLocaleString() + '+') : upkEsc(upkI18n.fewerThanTen)}</span>`)} | |
| 382 | 406 | </span> |
| 383 | - ${plugin.downloaded_formatted ? `<span class="downloads">Downloads: ${upkEsc(plugin.downloaded_formatted)}</span>` : ''} | |
| 407 | + ${plugin.downloaded_formatted ? `<span class="downloads">${upkFormat(upkEsc(upkI18n.downloads), upkEsc(plugin.downloaded_formatted))}</span>` : ''} | |
| 384 | 408 | <div class="rating-section"> |
| 385 | - <div class="wporg-ratings" title="${upkEsc(plugin.rating)} out of 5 stars" style="color:var(--wp--preset--color--pomegrade-1, #e26f56);"> | |
| 409 | + <div class="wporg-ratings" title="${upkEsc(upkFormat(upkI18n.ratingTitle, plugin.rating))}" style="color:var(--wp--preset--color--pomegrade-1, #e26f56);"> | |
| 386 | 410 | ${generateStarRating(plugin.rating)} |
| 387 | 411 | </div> |
| 388 | 412 | <span class="rating-text"> |
| 389 | - ${upkEsc(plugin.rating)} out of 5 stars. | |
| 390 | - ${plugin.num_ratings > 0 ? `<span class="rating-count">(${plugin.num_ratings.toLocaleString()} ratings)</span>` : ''} | |
| 413 | + ${upkEsc(upkFormat(upkI18n.ratingText, plugin.rating))} | |
| 414 | + ${plugin.num_ratings > 0 ? `<span class="rating-count">${upkEsc(upkFormat(upkI18n.ratingCount, plugin.num_ratings.toLocaleString()))}</span>` : ''} | |
| 391 | 415 | </span> |
| 392 | 416 | </div> |
| 393 | - ${plugin.last_updated_formatted ? `<span class="last-updated">Last Updated: ${upkEsc(plugin.last_updated_formatted)}</span>` : ''} | |
| 417 | + ${plugin.last_updated_formatted ? `<span class="last-updated">${upkFormat(upkEsc(upkI18n.lastUpdated), upkEsc(plugin.last_updated_formatted))}</span>` : ''} | |
| 394 | 418 | </label> |
| 395 | 419 | `; |
| 396 | 420 | }); |
| 397 | 421 | } |