Skip to content

fix: weather localization for locale variants like zh_CN#348

Merged
404-Page-Found merged 1 commit into
404-PF:mainfrom
LWWZH:fix/weather-zh-cn
Jun 8, 2026
Merged

fix: weather localization for locale variants like zh_CN#348
404-Page-Found merged 1 commit into
404-PF:mainfrom
LWWZH:fix/weather-zh-cn

Conversation

@LWWZH
Copy link
Copy Markdown
Collaborator

@LWWZH LWWZH commented Jun 7, 2026

Summary

The weather widget ignored Chinese, Portuguese, and English locale variants (e.g. zh_CN, pt_BR, en_US) because getWeatherLabel() and getOpenMeteoLang() compared the full locale string against base language codes. Users on those locales always saw English weather labels and English geocoding results.

What Changed

  • Added normalizeLang() helper in src/features/weather.js that strips the country suffix from locale variants ("zh_CN""zh")
  • Applied it in getOpenMeteoLang() so geocoding requests use the correct API language code for variant locales
  • Applied it in getWeatherLabel() so weather condition labels resolve to the correct label* key in WEATHER_CODES

Verification

  • npm run lint — clean
  • npm test — 431/431 tests passing

Notes

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of regional language variants in the weather feature so weather labels and external service language selection match users' base language (e.g., treating locale variants consistently).
    • Ensures localized weather text and external weather service requests use the normalized base language, reducing mismatches for locale-specific variants (for example, zh_CN → zh) and improving display consistency.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 80164ed9-018e-47ac-8d38-8c8093e3047a

📥 Commits

Reviewing files that changed from the base of the PR and between d9a502f and 3827e06.

📒 Files selected for processing (1)
  • src/features/weather.js

📝 Walkthrough

Walkthrough

Adds a helper normalizeLang(lang) that derives a base language (e.g., zh from zh_CN) and applies it in getOpenMeteoLang() and getWeatherLabel() so locale variants are recognized for weather localization.

Changes

Language Normalization for Weather Localization

Layer / File(s) Summary
Language normalization helper and application
src/features/weather.js
normalizeLang() extracts the base language from locale variants by splitting on _ or - and lowercasing (defaults to 'en'). getOpenMeteoLang() and getWeatherLabel() now use the normalized language instead of raw getLang() to select Open-Meteo codes and localized label keys.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I hopped through locales, small and grand,
Found zh_CN lost in foreign land,
I split and lowercased to find the core,
Now weather speaks in languages galore,
Little helper, big weather band.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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—adding support for locale variants like zh_CN in weather localization.
Linked Issues check ✅ Passed The PR fully addresses issue #256 by implementing normalizeLang() to treat locale variants as their base language, ensuring zh_CN users get Chinese weather labels and geocoding results.
Out of Scope Changes check ✅ Passed All changes are scoped to src/features/weather.js and directly address the weather localization requirements in issue #256.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/weather.js`:
- Around line 9-12: normalizeLang currently only splits on '_' so hyphenated
locales like "zh-CN" won't normalize; update the normalizeLang function to split
on both '_' and '-' (e.g., split on a regex or replace both separators) and
return the base language in a consistent case (lowercase), also guard against
falsy input so it doesn't throw on undefined/null.
🪄 Autofix (Beta)

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4603f076-f862-4b60-8299-11431358a608

📥 Commits

Reviewing files that changed from the base of the PR and between d9a502f and dd3ac7b.

📒 Files selected for processing (1)
  • src/features/weather.js

Comment thread src/features/weather.js
@404-PF 404-PF deleted a comment from coderabbitai Bot Jun 7, 2026
@LWWZH LWWZH force-pushed the fix/weather-zh-cn branch from dd3ac7b to 3827e06 Compare June 7, 2026 23:42
@LWWZH
Copy link
Copy Markdown
Collaborator Author

LWWZH commented Jun 7, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

✅ Action performed

Full review finished.

@404-Page-Found 404-Page-Found merged commit 17ea27f into 404-PF:main Jun 8, 2026
1 check passed
@LWWZH LWWZH deleted the fix/weather-zh-cn branch June 8, 2026 00:10
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.

Weather localization does not recognize the zh_CN language variant

2 participants