Skip to content

Conversation

@NicoCanada
Copy link
Collaborator

@NicoCanada NicoCanada commented Jan 30, 2025

Fixes #310
Added Chinese translation

Summary by CodeRabbit

  • New Features
    • Introduced Simplified Chinese language support. Users can now select Chinese from the settings menu, complete with a representative flag icon.
    • Expanded localization so that all language options now reflect the addition of Chinese, enhancing language consistency throughout the app.
  • Bug Fixes
    • Corrected the alt text for the Indonesian flag to improve accessibility and clarity.

@vercel
Copy link

vercel bot commented Jan 30, 2025

Someone is attempting to deploy a commit to the Creative Programming group Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

This pull request integrates Simplified Chinese (zh-CN) support into the project. It adds a new Chinese translation file and updates the i18n configuration in both the locale index and Next.js config to include zh-CN. The settings page now features a dedicated Chinese language selection button with a corresponding Chinese flag image, while a minor correction was made to the Indonesian flag's alt text. Additionally, existing locale files (English, German, Indonesian) have been updated to incorporate a new translation entry for the Chinese language option.

Changes

Files Change Summary
apps/web/src/locales/index.ts Added zh-CN locale to the createI18n function call for dynamic import of the Chinese locale.
apps/web/src/locales/zh-CN.ts New TypeScript translation file containing Simplified Chinese texts for various application sections.
apps/web/src/locales/en.ts, de.ts, id.ts Added new translation entry "settings.chinese": "中文" to support the Chinese language option.
apps/web/src/pages/settings/index.tsx Added a Chinese language selection button with the Chinese flag image (alt: "Flag of PRC"); corrected the alt text for the Indonesian flag.
apps/web/next.config.mjs Updated the i18n configuration to include "zh-CN" in the locales array.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant S as Settings Page
    participant I as i18n Engine
    participant T as zh-CN Translations

    U->>S: Clicks Chinese language button
    S->>I: Request to switch locale to "zh-CN"
    I->>T: Dynamically import Chinese translations
    T-->>I: Return translation object
    I-->>S: Update displayed texts with zh-CN content
Loading

Assessment against linked issues

Objective Addressed Explanation
Add Chinese Translation (#310)

Poem

I'm a rabbit with a twitching nose, 🐰
Hopping through code where language grows,
Chinese words now join the fray,
Flags and texts lead the way,
With every hop, our project shines bright!
Carrots and code, a delightful sight!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bc3d51f and 843d1e7.

📒 Files selected for processing (1)
  • apps/web/src/locales/zh-CN.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/src/locales/zh-CN.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

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: 1

🧹 Nitpick comments (2)
apps/web/src/locales/zh_cn.ts (2)

37-40: Language names should be in their native script.

For consistency and better user experience, language names should be displayed in their native script.

-  "settings.english": "English",
-  "settings.german": "German",
-  "settings.indonesian": "Indonesian",
-  "settings.chinese": "Chinese",
+  "settings.english": "English",
+  "settings.german": "Deutsch",
+  "settings.indonesian": "Bahasa Indonesia",
+  "settings.chinese": "中文",

130-131: Maintain consistency in quote usage for HTML content.

Some translations use different quote styles for HTML content. Standardize to use double quotes for HTML attributes.

-    '由以下人员<span class="text-4xl" style="color: rgb(239 68 68)">♥\uFE0F</span> 精心制作: ',
+    "由以下人员<span class=\"text-4xl\" style=\"color: rgb(239 68 68)\">♥\uFE0F</span> 精心制作: ",

Also applies to: 182-183

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 400efee and 597820f.

📒 Files selected for processing (2)
  • apps/web/src/locales/index.ts (1 hunks)
  • apps/web/src/locales/zh_cn.ts (1 hunks)
🔇 Additional comments (4)
apps/web/src/locales/index.ts (1)

13-13: LGTM! Correct implementation of Chinese locale.

The addition follows the established pattern and uses proper dynamic importing.

apps/web/src/locales/zh_cn.ts (3)

88-102: Excellent localization of weather descriptions!

The translations effectively maintain the playful tone while using culturally appropriate Chinese expressions. Well done!


20-26: Accurate translation of technical weather terms.

The translations correctly use standard Chinese meteorological terminology, maintaining technical accuracy while being understandable to users.

Also applies to: 73-81


1-1: Good TypeScript implementation with proper type safety.

The use of as const assertion and consistent object structure ensures type safety throughout the translations.

Also applies to: 188-188

Comment on lines 146 to 148
"home.moon phase card title": "Current Moon Phase",
"home.moon phase card content":
"The moon phase is the shape of the directly sunlit portion of the Moon as viewed from Earth.",
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 30, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Translate moon phase card title and content to Chinese.

These strings are still in English and need to be translated:

-  "home.moon phase card title": "Current Moon Phase",
+  "home.moon phase card title": "当前月相",
-  "home.moon phase card content":
-    "The moon phase is the shape of the directly sunlit portion of the Moon as viewed from Earth.",
+  "home.moon phase card content":
+    "月相是从地球上看到的月球被阳光直接照射部分的形状。",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"home.moon phase card title": "Current Moon Phase",
"home.moon phase card content":
"The moon phase is the shape of the directly sunlit portion of the Moon as viewed from Earth.",
"home.moon phase card title": "当前月相",
"home.moon phase card content":
"月相是从地球上看到的月球被阳光直接照射部分的形状。",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Followed suggestions

Copy link
Contributor

Choose a reason for hiding this comment

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

@NicoCanada Thank you for implementing the translations! The moon phase section is now properly localized in Simplified Chinese.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

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: 2

🧹 Nitpick comments (3)
apps/web/src/locales/zh-CN.ts (3)

68-68: Clarify the German law reference for Chinese users.

The reference to German law might be unclear to Chinese users. Consider adding context:

- "legal.information disclaimer": "根据《德国电信和信息服务法》第5条的规定",
+ "legal.information disclaimer": "根据《德国电信和信息服务法》(German Telemedia Act) 第5条的规定",

97-98: Consider a more culturally relevant metaphor.

The penguin reference might be replaced with a more familiar Chinese cultural reference:

- "home.feels like phrase cold": "企鹅们都因为寒冷去喝热巧克力了!",
+ "home.feels like phrase cold": "寒得连熊猫都要喝姜茶暖身了!",

47-51: Adjust punctuation for natural Chinese reading.

The exclamation marks feel excessive in Chinese. Consider a more natural approach:

- "locationsettings.at least one city toast": "至少需要一个城市!",
- "locationsettings.switched to city toast": "切换到城市!",
- "locationsettings.added city toast": "添加城市!",
- "locationsettings.city not found toast": "城市未找到!",
- "locationsettings.try again toast": "请再试一次!",
+ "locationsettings.at least one city toast": "至少需要一个城市",
+ "locationsettings.switched to city toast": "已切换到所选城市",
+ "locationsettings.added city toast": "已添加城市",
+ "locationsettings.city not found toast": "未找到该城市",
+ "locationsettings.try again toast": "请重试",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8f9dac and 25846ce.

📒 Files selected for processing (2)
  • apps/web/src/locales/index.ts (1 hunks)
  • apps/web/src/locales/zh-CN.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/src/locales/index.ts
🔇 Additional comments (2)
apps/web/src/locales/zh-CN.ts (2)

150-157: Excellent use of traditional Chinese astronomical terms!

The moon phase translations accurately use traditional Chinese astronomical terminology, which maintains cultural authenticity while being easily understood by modern Chinese readers.


1-188: Verify translation completeness against other locale files.

Let's ensure no translations are missing compared to other locale files.

✅ Verification successful

All translations are complete and correctly structured

The Chinese locale file contains all required translations and maintains consistent structure with other locale files. The additional "settings.chinese" key is intentionally present only in the Chinese locale file, as it represents the language's name in its native form.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Compare keys between locale files to ensure completeness
# Expected: All keys present in other locale files should exist in zh-CN.ts

# Find all locale files
echo "Searching for locale files..."
fd -e ts -e js --full-path "locales" --exclude "index.ts"

# Extract and compare keys
for locale in $(fd -e ts -e js --full-path "locales" --exclude "index.ts" --exclude "zh-CN.ts"); do
  echo "Comparing keys with $locale..."
  # Extract keys (lines containing quotes followed by colon)
  grep -o '"[^"]*":' "$locale" | sort > /tmp/other_keys
  grep -o '"[^"]*":' "apps/web/src/locales/zh-CN.ts" | sort > /tmp/zh_keys
  
  # Show missing keys
  echo "Keys in $locale but missing in zh-CN.ts:"
  comm -23 /tmp/other_keys /tmp/zh_keys
done

Length of output: 2066


Script:

#!/bin/bash
# Description: Compare locale files using diff and check structure

echo "=== Analyzing locale files ==="

# Function to extract and sort keys
extract_keys() {
    grep -o '"[^"]*":' "$1" | sort > "/tmp/keys_$2"
}

# Process zh-CN keys first
extract_keys "apps/web/src/locales/zh-CN.ts" "zh"

# Compare with other locales
for locale in $(fd -e ts -e js --full-path "locales" --exclude "index.ts" --exclude "zh-CN.ts"); do
    echo -e "\nComparing with $locale:"
    extract_keys "$locale" "other"
    
    # Compare keys
    echo "Differences (< means missing in zh-CN, > means extra in zh-CN):"
    diff "/tmp/keys_other" "/tmp/keys_zh" || true
    
    # Check export structure
    echo -e "\nChecking export structure:"
    head -n1 "$locale"
    grep -c "export default {" "$locale"
    
    # Check closing structure
    echo "Checking closing structure:"
    tail -n1 "$locale"
done

# Additional structure check for zh-CN
echo -e "\nChecking zh-CN structure:"
head -n1 "apps/web/src/locales/zh-CN.ts"
grep -c "export default {" "apps/web/src/locales/zh-CN.ts"
tail -n1 "apps/web/src/locales/zh-CN.ts"

Length of output: 2918

Comment on lines +130 to +132
"home.9 day forecast card content":
"未来9天的天气预报。<br /> <span class=\"font-semibold\">温度</span> 为每日的平均温度,分别代表白天和夜晚的温度。",

Copy link
Contributor

@coderabbitai coderabbitai bot Jan 30, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using template interpolation instead of HTML in translations.

HTML markup embedded in translations can be fragile and harder to maintain. Consider using template interpolation:

- "home.9 day forecast card content": "未来9天的天气预报。<br /> <span class=\"font-semibold\">温度</span> 为每日的平均温度,分别代表白天和夜晚的温度。",
+ "home.9 day forecast card content": {
+   text: "未来9天的天气预报。{break}温度为每日的平均温度,分别代表白天和夜晚的温度。",
+   bold: ["温度"]
+ }

This approach:

  1. Separates content from presentation
  2. Reduces risk of HTML-related bugs
  3. Makes translations easier to maintain

Also applies to: 141-142, 182-183

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The way of coding is not seen in other locales.

Copy link
Contributor

Choose a reason for hiding this comment

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

@NicoCanada You're absolutely right. I apologize for my earlier suggestion. After checking all locale files, I can see that HTML markup is consistently used across all translations. Your implementation matches the established pattern in the codebase, so we should keep it as is.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the "home.9 day forecast card content" translation across all locale files
ast-grep --pattern 'export default {
  $$$
  "home.9 day forecast card content": $VALUE,
  $$$
}'

Length of output: 99


Script:

#!/bin/bash
# Search for the forecast card content translation in locale files
rg -A 1 -B 1 "home\.9 day forecast card content" apps/web/src/locales/

Length of output: 1167


✏️ Learnings added
Learnt from: NicoCanada
PR: The-Creative-Programming-Group/Weather-App#311
File: apps/web/src/locales/zh-CN.ts:130-132
Timestamp: 2025-01-30T23:04:08.252Z
Learning: In the Weather App project, translations in locale files use direct HTML markup (like <br /> and <span>) rather than template interpolation, as established by the existing implementation in en.ts, de.ts, and id.ts files.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@FleetAdmiralJakob
Copy link
Member

Could you add Chinese as a settings option too? https://github.com/The-Creative-Programming-Group/Weather-App/blob/master/apps%2Fweb%2Fsrc%2Fpages%2Fsettings%2Findex.tsx#L141-L202

<Image
src={indonesianFlag}
alt="Flag of the Netherladns"
alt="Flag of the Republic of Indonesia"
Copy link
Member

Choose a reason for hiding this comment

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

LMAO, good spot

@vercel
Copy link

vercel bot commented Feb 3, 2025

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

Name Status Preview Comments Updated (UTC)
weather-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 0:36am

@github-actions
Copy link

github-actions bot commented Feb 3, 2025

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 72
🟢 Accessibility 100
🟢 Best practices 96
🟢 SEO 92
🟢 PWA 100

Lighthouse ran on https://weather-app-git-fork-nicocana-d682d7-creative-programming-group.vercel.app/

@FleetAdmiralJakob
Copy link
Member

FleetAdmiralJakob commented Feb 3, 2025

Things that still need to be done before I can merge this PR:

  • Add Chinese flag DONE
  • Add the locale to the next.config.mjs too DONE
  • Add Chinese to the other translations too DONE

Here are some references: https://github.com/The-Creative-Programming-Group/Weather-App/pull/302/files

@FleetAdmiralJakob
Copy link
Member

@FleetAdmiralJakob
Copy link
Member

Things that stop this PR from being merged:

  • Merge errors need to be resolved
  • Decide on whether to take a round flag to match the aesthetics of the other flags or to use a square Chinese flag

@vercel
Copy link

vercel bot commented Feb 3, 2025

Deployment failed with the following error:

Resource is limited - try again in 32 minutes (more than 100, code: "api-deployments-free-per-day").

@FleetAdmiralJakob
Copy link
Member

Thank you continuing in this now: #321

@NicoCanada NicoCanada deleted the chinese_translation branch February 4, 2025 06:19
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.

Add Chinese Translation

2 participants