Skip to content

feat: infer autoLocalize template meta fields - #93

Open
shijistar wants to merge 2 commits into
masterfrom
feat/auto-localize-config
Open

feat: infer autoLocalize template meta fields#93
shijistar wants to merge 2 commits into
masterfrom
feat/auto-localize-config

Conversation

@shijistar

Copy link
Copy Markdown
Owner

Background

Continue issue #89 by completing the second phase of the autoLocalize work after the runtime support commit.

Changes

  • Infer instance-level autoLocalize.itemTemplate meta fields into enum item and items.meta TypeScript types.
  • Preserve global-only template fields as runtime-capable without widening item types to Record<string, any>.
  • Add helper-level tests for autoLocalize config normalization, template resolution, merge behavior, and meta-field detection.
  • Add runtime coverage for function shorthand, function templates, enum name templates, and omitted raw meta fields.
  • Document autoLocalize in full README and Storybook API guide in both English and Chinese.
  • Clarify that autoLocalizeMeta remains the correct legacy API name, while autoLocalizedMeta and !abbr exclusion syntax are not supported.

Verification

  • npm run test
  • npm run build:lib
  • npm run build-storybook
  • npm run build
  • git diff --check

Notes / Risks

  • Storybook build emits existing Vite warnings about Ant Design "use client" module directives and large chunks, but completes successfully.
  • Git push required temporarily overriding the broken Git credential helper path with /usr/bin/gh in this environment.

Copilot AI review requested due to automatic review settings July 2, 2026 00:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.ts helper utilities (normalize/merge config, resolve templates, detect template meta fields).
  • Update enum runtime + types to generate and type-infer autoLocalize.itemTemplate meta fields on items and items.meta.
  • Add/extend tests and document the new autoLocalize API 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.

Comment thread src/auto-localize.ts
Comment on lines +121 to +122
const config = mergeAutoLocalizeConfig(resolvedOptions?.autoLocalize);
return field in (config?.itemTemplate ?? {});
@shijistar
shijistar force-pushed the feat/auto-localize-config branch from 20d6095 to ea03ff3 Compare July 2, 2026 14:41
@shijistar
shijistar force-pushed the feat/auto-localize-config branch from ea03ff3 to a51536e Compare July 5, 2026 13:32
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20a61821-8ce8-4090-aa4f-ba2c99fea38d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

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.

2 participants