i18n support for sicp
Description
updated router to read language params from url and request for the corresponding page in the backend added button in sicp page to switch between languages
Type of change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Code quality improvements
How to test
use the updated backend that supports i18n when starting the frontend navigate to the sicp page in the frontend and switch between languages
Checklist
- [ ] I have tested this code
- [ ] I have updated the documentation
Summary by CodeRabbit
-
New Features
- Added bilingual support (English and Chinese) for the SICP textbook, including a language toggle button.
- Language preference is now saved and restored using local storage.
- URLs can now include a language prefix to directly access content in a specific language.
-
Enhancements
- Table of contents and content are dynamically loaded based on the selected language, with improved error handling and loading indicators.
- Added route support for language-prefixed URLs under the SICP path.
Please take whatever Copilot says with a big mountain of salt, I will review it properly later…
[!NOTE]
Other AI code review bot(s) detected
CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.
Walkthrough
The changes introduce bilingual support (English and Chinese) for the SICP textbook interface. Language preference is now managed via local storage, URL parameters, and a UI toggle. The table of contents and content fetching logic are updated to dynamically load language-specific resources. Routing is enhanced to recognize language-prefixed URLs.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
SICP Language Preference Utilitiessrc/features/sicp/utils/SicpUtils.ts |
Adds constants and functions for managing SICP language preference in local storage, including setting, reading, and dispatching a language change event. |
SICP Main Page Language Supportsrc/pages/sicp/Sicp.tsx |
Integrates language selection state, initialization from local storage or URL, language toggle UI, content fetching by language, and updates effects and navigation to support bilingual content. |
SICP Table of Contents Refactor & i18nsrc/pages/sicp/subcomponents/SicpToc.tsx |
Refactors TOC rendering into a child component, adds language-aware dynamic TOC fetching with loading and error handling, and listens for language change events. |
Routing for Language Parametersrc/routes/routerConfig.tsx |
Adds a new route pattern to support URLs with a language parameter before the section, enabling navigation to language-specific SICP content. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant SicpPage
participant LocalStorage
participant Router
participant TOCComponent
participant Backend
User->>SicpPage: Visit /sicpjs or /sicpjs/:param_lang/:section?
SicpPage->>LocalStorage: Read language preference
SicpPage->>Router: Parse URL for :param_lang
alt Language in URL
SicpPage->>LocalStorage: Set language from URL
SicpPage->>Router: Navigate to URL without :param_lang
end
SicpPage->>TOCComponent: Render with selected language
TOCComponent->>Backend: Fetch TOC JSON for language
alt Fetch fails
TOCComponent->>TOCComponent: Load static fallback TOC
end
User->>SicpPage: Click language toggle button
SicpPage->>LocalStorage: Update language
SicpPage->>TOCComponent: Trigger re-render with new language
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~40 minutes
Poem
In fields of code where languages grow,
A toggle appears—now SICP’s bilingual, you know!
English and Chinese, side by side,
With local storage where settings reside.
URLs now speak in many a tongue—
Rabbits rejoice, their work is well done!
🐇✨
[!NOTE]
🔌 MCP (Model Context Protocol) integration is now available in Early Access!
Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
‼️ IMPORTANT Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai generate unit teststo generate unit tests for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@coderabbitai full review
✅ Actions performed
Full review triggered.
Pull Request Test Coverage Report for Build 16858394883
Details
- 62 of 115 (53.91%) changed or added relevant lines in 4 files are covered.
- 6 unchanged lines in 1 file lost coverage.
- Overall coverage increased (+0.003%) to 43.288%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| src/features/sicp/utils/SicpUtils.ts | 7 | 10 | 70.0% |
| src/pages/sicp/subcomponents/SicpToc.tsx | 30 | 53 | 56.6% |
| src/pages/sicp/Sicp.tsx | 24 | 51 | 47.06% |
| <!-- | Total: | 62 | 115 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| src/pages/sicp/subcomponents/SicpToc.tsx | 6 | 51.16% |
| <!-- | Total: | 6 |
| Totals | |
|---|---|
| Change from base Build 16858234296: | 0.003% |
| Covered Lines: | 20574 |
| Relevant Lines: | 49714 |
💛 - Coveralls
@sayomaki this should be ok now but can you review my code? Though it's still blocked by the SICP PR https://github.com/source-academy/sicp/pull/1082