feat: infer autoLocalize template meta fields - #93
Conversation
There was a problem hiding this comment.
Pull request overview
This PR completes the next phase of autoLocalize by adding a unified template-based localization configuration that can generate enum name, item label, and item meta field locale keys at runtime, while also improving TypeScript inference for instance-level template-declared meta fields.
Changes:
- Add
src/auto-localize.tshelper utilities (normalize/merge config, resolve templates, detect template meta fields). - Update enum runtime + types to generate and type-infer
autoLocalize.itemTemplatemeta fields on items anditems.meta. - Add/extend tests and document the new
autoLocalizeAPI in README and Storybook guides (EN/ZH).
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/test-suites/localization.ts | Adds runtime coverage for global templates, instance overrides, shorthand/function templates, and enum name templates. |
| test/test-suites/interface.ts | Adds type-level assertions that instance-level template meta fields are inferred and readonly. |
| test/auto-localize.test.ts | Introduces focused unit tests for helper functions (normalization, template resolution, merge behavior, meta detection). |
| src/global-config.ts | Adds autoLocalize to global Enum.config typing. |
| src/enum.ts | Threads an OP generic through Enum/IEnum typing so instance options can drive inference (including autoLocalize meta fields). |
| src/enum-items.ts | Collects template-declared meta keys into items.meta and updates typing to include inferred template meta arrays. |
| src/enum-item.ts | Generates getters for template-declared meta fields and routes localization through autoLocalize templates. |
| src/enum-collection.ts | Applies autoLocalize.nameTemplate when resolving the enum’s display name. |
| src/auto-localize.ts | New module implementing autoLocalize config normalization/merge, template resolution, and meta-field detection. |
| README-FULL.md | Documents autoLocalize in the full English README, including merge semantics and inference guidance. |
| README-FULL.zh-CN.md | Documents autoLocalize in the full Chinese README, including legacy naming clarifications. |
| .storybook/docs-source/ApiGuide.en-US.md | Adds Storybook API guide documentation for autoLocalize (EN). |
| .storybook/docs-source/ApiGuide.zh-CN.md | Adds Storybook API guide documentation for autoLocalize (ZH). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const config = mergeAutoLocalizeConfig(resolvedOptions?.autoLocalize); | ||
| return field in (config?.itemTemplate ?? {}); |
20d6095 to
ea03ff3
Compare
ea03ff3 to
a51536e
Compare
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Background
Continue issue #89 by completing the second phase of the
autoLocalizework after the runtime support commit.Changes
autoLocalize.itemTemplatemeta fields into enum item anditems.metaTypeScript types.Record<string, any>.autoLocalizeconfig normalization, template resolution, merge behavior, and meta-field detection.autoLocalizein full README and Storybook API guide in both English and Chinese.autoLocalizeMetaremains the correct legacy API name, whileautoLocalizedMetaand!abbrexclusion syntax are not supported.Verification
npm run testnpm run build:libnpm run build-storybooknpm run buildgit diff --checkNotes / Risks
"use client"module directives and large chunks, but completes successfully./usr/bin/ghin this environment.