-
-
Notifications
You must be signed in to change notification settings - Fork 2
Compile-time validation for string constraints (length, character set) via a pattern option #72
Copy link
Copy link
Open
Labels
package: babel-pluginRelated to babel-plugin-saykitRelated to babel-plugin-saykitpackage: configRelated to @saykit/config and the CLIRelated to @saykit/config and the CLIpackage: coreRelated to the core saykit packageRelated to the core saykit packagepackage: format-jsonRelated to @saykit/format-jsonRelated to @saykit/format-jsonpackage: format-poRelated to @saykit/format-poRelated to @saykit/format-popackage: reactRelated to @saykit/reactRelated to @saykit/reactpackage: transform-jsRelated to @saykit/transform-jsRelated to @saykit/transform-jspackage: transform-jsxRelated to @saykit/transform-jsxRelated to @saykit/transform-jsxpackage: unpluginRelated to unplugin-saykitRelated to unplugin-saykitrequestA request for a new feature or a change in behaviourA request for a new feature or a change in behaviour
Description
Metadata
Metadata
Assignees
Labels
package: babel-pluginRelated to babel-plugin-saykitRelated to babel-plugin-saykitpackage: configRelated to @saykit/config and the CLIRelated to @saykit/config and the CLIpackage: coreRelated to the core saykit packageRelated to the core saykit packagepackage: format-jsonRelated to @saykit/format-jsonRelated to @saykit/format-jsonpackage: format-poRelated to @saykit/format-poRelated to @saykit/format-popackage: reactRelated to @saykit/reactRelated to @saykit/reactpackage: transform-jsRelated to @saykit/transform-jsRelated to @saykit/transform-jspackage: transform-jsxRelated to @saykit/transform-jsxRelated to @saykit/transform-jsxpackage: unpluginRelated to unplugin-saykitRelated to unplugin-saykitrequestA request for a new feature or a change in behaviourA request for a new feature or a change in behaviour
Problem
Some strings have constraints beyond their literal content: a fixed max length (fits a button, a tab label), or a restricted character set (no punctuation, digits only). Translators can easily produce a string that's technically a valid translation but breaks the constraint - too long, too short, or containing characters the UI can't handle. Today that only surfaces at runtime (or visually, after the fact), not at compile time.
Idea
Let a string declare its own constraint, and catch violations against translated strings as part of the build/typecheck step rather than at runtime. Something like:
or as a component prop:
Any translation that fails the pattern would fail the build (or at least surface as a lint-style warning) instead of shipping.
Prior art / is there a standard for this?
Checked whether existing i18n formats have a convention for this so saykit could align to it rather than invent something:
#, fuzzy, etc.) but nothing for length/charset validation.messages.json: supportsplaceholderswith example content, but no validation/constraint fields.@keymetadata likedescriptionand placeholderexample, but nothing for pattern/length constraints.None of the major file formats have this as a first-class, standardized concept. Where it exists at all, it's a platform-level feature bolted on by a TMS - Crowdin, Lokalise, and Phrase all have their own proprietary "QA checks" / "validation rules" config (max length, forbidden characters, etc.), separate from and not portable across the underlying file format.
So there's no standard to match here - if saykit does this, it'd be one of the few tools offering it at the source/type level instead of as a TMS dashboard feature. Worth deciding whether the constraint should live in the source call (
say/Say) or as metadata alongside the extracted string catalog, since a TMS-side check would need to read it from somewhere.