| @@ -408,9 +408,17 @@ | ||
| 408 | 408 | // Use built assets in production |
| 409 | 409 | $appJs = YATRA_PLUGIN_PATH . 'assets/admin/dist/js/app.js'; |
| 410 | 410 | |
| 411 | 411 | if (file_exists($appJs)) { |
| 412 | - $jsVersion = YATRA_VERSION . '.' . filemtime($appJs) . '.view-icon-fix.' . time() . '.' . microtime(true); | |
| 412 | + // Version on the plugin version + the bundle's own mtime. That | |
| 413 | + // already changes on every update or rebuild, which is exactly | |
| 414 | + // when the cache must be busted. | |
| 415 | + // | |
| 416 | + // This previously appended time() . microtime(true), making the | |
| 417 | + // URL unique on every single request — so the ~3 MB admin bundle | |
| 418 | + // was re-downloaded on every admin page view and could never be | |
| 419 | + // cached by the browser. | |
| 420 | + $jsVersion = YATRA_VERSION . '.' . filemtime($appJs); | |
| 413 | 421 | |
| 414 | 422 | $localized_data = $this->buildAdminLocalizedData(); |
| 415 | 423 | |
| 416 | 424 | // Enqueue our script with media library as dependency |
| @@ -431,10 +439,30 @@ | ||
| 431 | 439 | $jsVersion, |
| 432 | 440 | true |
| 433 | 441 | ); |
| 434 | 442 | |
| 443 | + // The bundle calls the global wp.i18n.__() (it never ships its | |
| 444 | + // own copy), and scripts/extract-js-pot.mjs writes every admin | |
| 445 | + // string's `#:` reference as this bundle's path precisely so | |
| 446 | + // WordPress's md5(handle src) JSON lookup matches. This call is | |
| 447 | + // the missing last link: it tells WordPress to load | |
| 448 | + // i18n/languages/yatra-{locale}-{md5}.json (or the copy under | |
| 449 | + // WP_LANG_DIR/plugins) for the admin UI. Without it, translated | |
| 450 | + // admin strings never reach the SPA. Mirrors FrontendAssetsProvider. | |
| 451 | + if (function_exists('wp_set_script_translations')) { | |
| 452 | + wp_set_script_translations('yatra-admin', 'yatra', YATRA_PLUGIN_PATH . 'i18n/languages'); | |
| 453 | + } | |
| 454 | + | |
| 435 | 455 | // Localize script data |
| 436 | 456 | wp_localize_script('yatra-admin', 'yatraAdmin', $localized_data); |
| 457 | + | |
| 458 | + // Phone dataset for admin displays (flag + dial-code detection of | |
| 459 | + // stored "+<code><number>" values in booking details). | |
| 460 | + wp_localize_script('yatra-admin', 'yatraPhoneData', [ | |
| 461 | + 'countries' => \Yatra\Helpers\FormatHelper::getPhoneCountries(), | |
| 462 | + 'priority' => \Yatra\Helpers\FormatHelper::getPhonePriority(), | |
| 463 | + 'flagBase' => YATRA_PLUGIN_URL . 'assets/img/flags/', | |
| 464 | + ]); | |
| 437 | 465 | |
| 438 | 466 | // Start fetching the ES module as early as possible (helps shorten white/splash time before React runs) |
| 439 | 467 | $app_js_url = YATRA_PLUGIN_URL . 'assets/admin/dist/js/app.js'; |
| 440 | 468 | add_action('admin_head', static function () use ($app_js_url, $jsVersion): void { |