fix(api): parse zh-locale usage labels and reset phrases - #2
Conversation
|
Hi @waknow , 1. Rebase on the latest main: Your branch seems to be slightly behind the current main branch. Could you please rebase your changes on top of the latest code? This will ensure we don't run into any merge conflicts. 2. Add screenshots: It would be great if you could add some screenshots demonstrating the Chinese UI to the assets/ folder. This will help future users see the new localization in action. Let me know if you need any guidance on how to rebase or anything else. Thanks again for making this project better! 🚀 |
The opencode.ai dashboard renders usage labels in the UI locale. For a cookie with oc_locale=zh the labels are Chinese (rolling/weekly/monthly usage) and the reset phrase is '重置于' instead of 'Resets in', so the SSR scrape parsed every window as empty and the chip showed <err:http302> (cookie expired or invalid?) despite the cookie being valid. - labelToKind: recognize the Chinese labels - reset-time regex: accept both 'Resets in' and '重置于' - parseDurationToSec: accept Chinese time units (秒/分钟/小时/天/周/月/年) Adds a zh-locale SSR fixture and zh unit tests.
2763d3f to
21416b6
Compare
|
Hi @v587d, Thanks for the review and the kind words! Both points are now handled:
Thanks again! |
Problem
The opencode.ai dashboard renders the usage page in the UI locale negotiated from the cookie. With oc_locale=zh the data-slot=usage-label values come back as Chinese (rolling/weekly/monthly usage in Chinese) and the reset phrase as Chinese instead of Resets in.
The SSR scraper in src/api.ts only recognizes the English labels and the English reset phrase, so with a zh-locale cookie:
Net effect: the chip shows err:http302 even though the cookie is perfectly valid.
Fix
Also rebuilt lib/ (the checked-in build output) so GitHub/npm installs work without a local build.
Tests
All 48 tests pass (pnpm test), typecheck and build pass.