Skip to content

Conversation

@akshitvigg
Copy link

@akshitvigg akshitvigg commented Nov 30, 2025

Fixes #661

Describe the changes you have made in this PR -

Converted i18n.js to TypeScript while maintaining the logic and functionality same

Note: Please check Allow edits from maintainers. if you would like us to assist in the PR.

Summary by CodeRabbit


  • Refactor
    • Enhanced the internationalization module with improved TypeScript type safety and comprehensive type definitions. Implemented explicit interface declarations for message objects and extended the Window interface to properly type locale properties. Added detailed type annotations across all i18n initialization functions and maintained backward compatibility. These improvements increase code reliability and enable better IDE support and error detection throughout the development process.

Summary by CodeRabbit

  • Refactor
    • Modernized internationalization module infrastructure with enhanced type safety and improved locale handling. The localization support remains fully functional with better language switching capabilities.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 30, 2025

Walkthrough

The i18n module is converted from JavaScript to TypeScript, maintaining identical functionality while adding type safety. The module initializes banana-i18n, configures locale handling from the global window object, loads English messages as default with dynamic locale-specific message loading via require, and exports the configured Banana instance.

Changes

Cohort / File(s) Summary
JavaScript to TypeScript migration for i18n module
src/simulator/src/i18n.jssrc/simulator/src/i18n.ts
Converted i18n module from JavaScript to TypeScript. Added type annotations: Window interface augmentation with optional locale property, Messages type for locale-to-message mapping, and proper typing for Banana instance initialization. Preserved original logic: locale configuration from window.locale with 'en' fallback, preloaded English messages, dynamic runtime locale-specific JSON loading with silent error fallback, and Banana instance export.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify Window interface augmentation is properly declared
  • Confirm Messages type interface correctly maps locale strings to message dictionaries
  • Check dynamic require error handling is properly typed and maintains fallback behavior
  • Validate Banana instance initialization remains functionally equivalent to original JavaScript implementation

Suggested reviewers

  • JoshVarga
  • Arnabdaz

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting i18n.js to TypeScript, which is reflected in the file modifications.
Linked Issues check ✅ Passed The PR successfully converts i18n.js to TypeScript while maintaining existing logic and improving type safety, meeting all coding requirements from issue #661.
Out of Scope Changes check ✅ Passed All changes are directly related to converting i18n.js to TypeScript; no out-of-scope modifications are present in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify
Copy link

netlify bot commented Nov 30, 2025

Deploy Preview for circuitverse ready!

Name Link
🔨 Latest commit 6b9ddd4
🔍 Latest deploy log https://app.netlify.com/projects/circuitverse/deploys/692c7fb591518d00081ac1d0
😎 Deploy Preview https://deploy-preview-681--circuitverse.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 45 (🟢 up 1 from production)
Accessibility: 73 (no change from production)
Best Practices: 92 (no change from production)
SEO: 82 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/simulator/src/i18n.ts (3)

1-4: Use lightweight type declarations instead of @ts-ignore on imports

These @ts-ignore directives effectively make Banana and enMessages any, which undercuts the goal of adding type safety. In a follow-up, consider adding a small ambient declaration for banana-i18n and JSON modules (e.g., declare module 'banana-i18n' { ... } and declare module '*.json' { ... } or enabling resolveJsonModule) so you can drop these ignores or at least convert them to @ts-expect-error with a clear TODO.


6-24: Global Window augmentation is correct; Messages typing could be tighter if shape is known

Using declare global { interface Window { locale?: string } } inside this module is the right pattern to satisfy window.locale usage. The Messages index signature as Record<string, unknown> is safe but quite loose; if your locale JSON files are plain key→string maps (or some known structure), tightening this to a more specific type (e.g., Record<string, string> or a dedicated MessageMap type) would give better autocomplete and earlier errors without changing runtime behavior.


25-32: Silent catch on dynamic locale require may hide configuration problems

This try/catch keeps behavior the same—falling back to the preloaded en messages when a locale JSON can’t be required—but swallowing err entirely can make missing/broken locale bundles hard to diagnose. In a future cleanup, you might at least log a console.warn with the failing locale, or only attempt the require when locale !== finalFallback, to make misconfigurations easier to spot while preserving the fallback semantics.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11b4883 and 6b9ddd4.

📒 Files selected for processing (2)
  • src/simulator/src/i18n.js (0 hunks)
  • src/simulator/src/i18n.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/simulator/src/i18n.js
🔇 Additional comments (1)
src/simulator/src/i18n.ts (1)

34-35: Initialization and export preserve original behavior; just verify imports and runtime

The sequence setLocale → derive locale → build messagesload → default export matches the described JS behavior, so consumers should see the same preconfigured Banana instance. It’s worth double-checking that no code still imports i18n.js explicitly and that locale switching still works at runtime.

You can quickly verify call sites and extensions with:

#!/bin/bash
# Ensure no stale imports still reference i18n.js
rg -n "i18n\\.js" .

# Spot-check references to this module (should generally be extensionless: './i18n')
rg -n "['\"]/i18n['\"]" src

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Javascript to Typescript conversion in the src folder

1 participant