Skip to content

refactor: replace i18n HTTP requests with build-time bundling#22422

Merged
keithwillcode merged 23 commits intomainfrom
devin/1752247164-refactor-i18n-build-time-bundling
Jul 12, 2025
Merged

refactor: replace i18n HTTP requests with build-time bundling#22422
keithwillcode merged 23 commits intomainfrom
devin/1752247164-refactor-i18n-build-time-bundling

Conversation

@keithwillcode
Copy link
Contributor

@keithwillcode keithwillcode commented Jul 11, 2025

Refactor i18n system to use build-time bundling and eliminate runtime HTTP requests

Summary

This PR refactors the i18n system to eliminate runtime HTTP requests for translation files, which were causing 60-second timeouts in production. The key changes include:

  • Build-time bundling: Replaced runtime HTTP requests with direct file system reads using a new translationBundler.ts
  • Eliminated circular dependencies: Moved translation files from apps/web/public/static/locales/ to packages/lib/server/locales/ so packages don't need to reach into the web app
  • Maintained cache invalidation: Uses CalComVersion for cache busting similar to the frontend pattern
  • Preserved build compatibility: Added copy-locales-static.js script to copy files to public folder during build
  • Serverless optimization: Only loads the specific locale requested instead of all locales upfront

The refactor maintains backward compatibility while significantly improving performance and eliminating the HTTP timeout issues.

Review & Testing Checklist for Human

This is a high-risk architectural change that requires thorough testing:

  • Test translation loading in different locales (en, es, fr, de, etc.) and verify all translations display correctly
  • Verify build process works correctly by running yarn build and checking that locale files are copied to apps/web/public/static/locales/
  • Test in production environment to ensure path resolution works correctly in serverless/deployed contexts
  • Check for missed import references by searching codebase for any remaining references to old translation paths
  • Verify cache invalidation by changing CALCOM_VERSION and confirming translations update properly

Recommended test plan: Deploy to staging environment and test booking flows in multiple languages, especially the ones that were previously timing out.


Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    subgraph "Translation Loading Flow"
        A["packages/lib/server/i18n.ts"]:::major-edit
        B["packages/lib/server/translationBundler.ts"]:::major-edit
        C["packages/lib/server/locales/{locale}/common.json"]:::major-edit
        D["apps/web/scripts/copy-locales-static.js"]:::major-edit
        E["apps/web/public/static/locales/{locale}/common.json"]:::context
        F["apps/web/package.json build script"]:::minor-edit
    end
    
    subgraph "Updated Import Paths"
        G["packages/platform/atoms/vite.config.ts"]:::minor-edit
        H["apps/api/v2/next-i18next.config.js"]:::minor-edit
        I["Multiple booking pages"]:::minor-edit
    end
    
    A -->|"dynamic import"| B
    B -->|"readFileSync"| C
    D -->|"copies during build"| E
    F -->|"runs copy-static"| D
    G -->|"updated alias"| C
    H -->|"updated localePath"| C
    I -->|"updated imports"| A
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit
        L3[Context/No Edit]:::context
    end
    
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Session: Requested by Keith Williams (@keithwillcode) - Devin session
  • Performance impact: This should significantly reduce server response times by eliminating 60-second HTTP timeouts
  • Breaking change risk: While designed to be backward compatible, the architectural change from HTTP requests to file system reads could behave differently in various deployment environments
  • Merge conflicts resolved: Used Benny's safer 2-step approach to integrate latest translations from main branch
  • All CI checks passing: 35 pass, 0 fail - including all E2E test suites that were previously failing due to translation loading issues

- Create translationBundler.ts for build-time translation loading
- Replace HTTP fetch in loadTranslations with file system reads
- Add CalComVersion cache invalidation to prevent stale translations
- Fix TypeScript errors in booking page components
- Eliminate 60s timeout issues by removing network dependency

Resolves translation timeout issues by bundling translations at build time
instead of making runtime HTTP requests to /static/locales/ endpoints.

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link

vercel bot commented Jul 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Visit Preview Jul 12, 2025 7:32am
cal-eu ⬜️ Ignored (Inspect) Visit Preview Jul 12, 2025 7:32am

@keithwillcode keithwillcode added core area: core, team members only foundation labels Jul 11, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jul 11, 2025

No security or compliance issues detected. Reviewed everything up to c1e0018.

Security Overview
  • 🔎 Scanned files: 64 changed file(s)
Detected Code Changes
Change Type Relevant files
Configuration changes ► next-i18next.config.js
    Update locale path
► next.config.js
    Update translation import path
► i18n.json
    Update locale path configuration
Refactor ► i18n.ts
    Refactor translation loading mechanism
► translationBundler.ts
    Add new translation bundling system
► copy-locales-static.js
    Add script for copying locale files
Enhancement ► Move all locale files from /apps/web/public/static/locales to /packages/lib/server/locales
    Centralize translation files location

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2025

E2E results are ready!

devin-ai-integration bot and others added 3 commits July 11, 2025 16:26
- Move i18n.ts and translationBundler.ts back to packages/lib/server/
- Replace all relative imports with @calcom/lib/server/i18n pattern
- Fix LOCALES_PATH to point to correct directory
- Maintain optimized serverless-friendly translation loading

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…lar deps

- Move all locale files from apps/web/public/static/locales to packages/lib/server/locales
- Create copy-locales-static.js script to copy files during build
- Update all references to use new location for build-time access
- Maintain public folder copying for Next.js runtime access
- Update platform atoms, scripts, and config files
- Fix copy script relative path issue

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Fix import paths in test files updated by pre-commit hooks
- Ensure all tests use correct locale import paths

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
devin-ai-integration bot and others added 2 commits July 11, 2025 17:22
…ver/i18n

- Revert all test file imports back to @calcom/lib/server/i18n as requested
- Addresses GitHub comment feedback to stick with packages/lib/server location
- Fixes import paths in 6 test files that were incorrectly changed

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Update @calcom/web/public/static/locales/en/common.json to @calcom/lib/server/locales/en/common.json
- Addresses GitHub comment about updating platform atoms vite config
- Maintains correct path resolution after locale files moved to packages/lib/server

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
devin-ai-integration bot and others added 2 commits July 11, 2025 18:24
- Use process.cwd() instead of __dirname for locale file path resolution
- Ensures locale files can be found in both development and production environments
- Fixes E2E test failures caused by missing locale files in .next/server/chunks/

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Change from process.cwd() to __dirname with relative paths
- Ensures locale files can be found in both development and production environments
- Fixes E2E test failures caused by incorrect path resolution in Next.js builds

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
devin-ai-integration bot and others added 2 commits July 11, 2025 19:09
- Change from __dirname to process.cwd() with relative paths
- Ensures locale files can be found when bundled into Next.js server chunks
- Fixes E2E test failures caused by incorrect path resolution in production environment
- Follows same pattern used in getStaticProps.tsx for cross-package file access

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… access

- Change from process.cwd() to path.resolve(process.cwd(), '..', '..', 'packages/lib/server/locales')
- Follows same pattern used in sendVerificationRequest.ts for cross-environment file access
- Should resolve E2E test failures by ensuring locale files can be found when bundled into Next.js server chunks
- Pattern navigates up from current working directory to reach packages directory consistently

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Replace relative path resolution with dynamic monorepo root finder
- Ensures locale files can be found from any working directory (root, apps/web, apps/api/v2)
- Update API v2 i18n config to use new locale path
- Fixes remaining E2E test failures in API v2 and E2E (1/4) test suites

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…l contexts

- Replace __dirname with require.resolve(__filename) in monorepo root detection
- Ensures locale files can be found when running from any working directory
- Fixes E2E API v2 test failures where __dirname resolves to '.' instead of actual file path

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… source of truth

- Delete all common.json files from apps/web/public/static/locales/
- Eliminates developer confusion about which files are authoritative
- copy-locales-static.js script now clearly the only mechanism for populating public folder
- packages/lib/server/locales/ remains the definitive source of truth for translations

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
@vercel vercel bot temporarily deployed to Preview – api July 12, 2025 06:08 Inactive
hbjORbj and others added 7 commits July 12, 2025 02:19
- Remove unnecessary second while loop using process.cwd()
- The first loop from __dirname will always find the monorepo root
- Add clear error message for fail-fast behavior if repo structure is corrupted
- Improves code clarity and maintainability

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
…calcom/cal.com into devin/1752247164-refactor-i18n-build-time-bundling
- Restore all common.json files from main branch to apps/web/public/static/locales/
- Overwrite packages/lib/server/locales/ with up-to-date translation content
- Resolve merge conflicts using Benny's safer 2-step approach
- Ensure translation source of truth remains in packages/lib/server/locales/
- Complete safer conflict resolution to eliminate merge conflicts on PR #22422

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
- Update dependencies after ts-node installation for pre-commit hooks
- Ensure yarn.lock reflects current dependency state
- Complete translation integration process

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
… source of truth

- Delete all common.json files from apps/web/public/static/locales/
- Maintain packages/lib/server/locales/ as the single source of truth for translations
- copy-locales-static.js script will populate public folder during build process
- Complete Benny's safer 2-step approach: restore from main, then remove duplicates
- Resolve merge conflicts and eliminate developer confusion about translation file locations

Co-Authored-By: keith@cal.com <keithwillcode@gmail.com>
@vercel vercel bot temporarily deployed to Preview – api July 12, 2025 06:54 Inactive
@keithwillcode keithwillcode marked this pull request as ready for review July 12, 2025 07:16
@keithwillcode keithwillcode requested a review from a team July 12, 2025 07:16
@keithwillcode keithwillcode requested a review from a team as a code owner July 12, 2025 07:16
@keithwillcode keithwillcode enabled auto-merge (squash) July 12, 2025 07:16
@dosubot dosubot bot added i18n area: i18n, translations 💻 refactor labels Jul 12, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic found 5 issues across 58 files. Review them in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

@keithwillcode keithwillcode added this to the v5.5 milestone Jul 12, 2025
@keithwillcode keithwillcode merged commit 163c7ff into main Jul 12, 2025
38 of 39 checks passed
@keithwillcode keithwillcode deleted the devin/1752247164-refactor-i18n-build-time-bundling branch July 12, 2025 07:49
@hbjORbj hbjORbj mentioned this pull request Jul 13, 2025
3 tasks
hbjORbj added a commit that referenced this pull request Jul 14, 2025
dakshgup added a commit to dakshgup/cal.com that referenced this pull request Jul 14, 2025
…s with build-time bundling (calcom#22422)"

Originally by: hbjORbj
This reverts commit 163c7ff.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Refactor**
  * Updated all localization logic and configuration to load translation files from the web app's public static directory instead of server-side directories.
  * Removed unused scripts and code related to previous translation bundling and copying mechanisms.
  * Adjusted build and test configurations to align with new locale file locations.
* **Style**
  * Minor formatting changes in locale JSON files (e.g., removal of trailing newlines, spacing adjustments).
* **Chores**
  * Updated workflow and configuration files to reflect new paths for localization resources.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
emrysal pushed a commit that referenced this pull request Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only foundation i18n area: i18n, translations ready-for-e2e 💻 refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants