@vectoriox/iox-ui 5.193.0 → 5.194.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1255,12 +1255,13 @@ interface RegisteredField {
1255
1255
  *
1256
1256
  * Translation belongs to the consumer, not the library: the CMS client has ngx-translate, the SSR
1257
1257
  * engine has the page's locale bundle. Providing this token is how each one plugs its own in. The
1258
- * default below interpolates the built-in English strings, so a consumer that provides nothing
1259
- * still shows real sentences rather than raw keys.
1258
+ * default below reads forms-core's ONE message catalog (`formMessage`) in the PAGE's language — the third argument,
1259
+ * `pageLanguageOf` the field — so a consumer that provides nothing (the engine, the builder's Preview) shows the site's
1260
+ * sentences, never raw keys and never English on a Hebrew page (iox-client-engine#15).
1260
1261
  */
1261
- type FormMessageResolver = (key: string, params?: Record<string, any>) => string;
1262
+ type FormMessageResolver = (key: string, params?: Record<string, any>, lang?: string | null) => string;
1262
1263
  declare const IOX_FORM_MESSAGES: InjectionToken<FormMessageResolver>;
1263
- /** `{{n}}` / `{{field}}` interpolation over the built-in English catalog. */
1264
+ /** The catalog's sentence in the page's language, `{{n}}` / `{{field}}` placed — forms-core `formMessage`. */
1264
1265
  declare const defaultMessageResolver: FormMessageResolver;
1265
1266
  /**
1266
1267
  * Per-form runtime. **Provided by `IoxFormComponent`**, so every Field created into that form's
@@ -1531,7 +1532,8 @@ declare class IoxFieldComponent implements OnInit, AfterViewInit, OnDestroy {
1531
1532
  get fieldName(): string;
1532
1533
  /** Failing AND allowed to say so — or forced, while an author designs the state. */
1533
1534
  get invalid(): boolean;
1534
- /** The message a visitor reads. Translation is the consumer's, via IOX_FORM_MESSAGES. */
1535
+ /** The message a visitor reads, in the page's language (`pageLanguageOf`) — IOX_FORM_MESSAGES, whose default is
1536
+ * forms-core's ONE catalog (iox-client-engine#15). */
1535
1537
  get errorText(): string;
1536
1538
  /** The field's spec under the name its form gave it — forms-core `fieldSpecOf`, the reading the saved spec uses. */
1537
1539
  private toSpec;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriox/iox-ui",
3
- "version": "5.193.0",
3
+ "version": "5.194.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=20.0.0",
6
6
  "@angular/core": ">=20.0.0",
@@ -8,6 +8,7 @@
8
8
  // the page's locale bundle). The backend returns the key too, so a server-side rejection renders in
9
9
  // the visitor's language rather than in the server's.
10
10
 
11
+ import { formLanguageOf } from './form-words';
11
12
  import { RuleName } from './form.model';
12
13
 
13
14
  /** Namespace for every forms validation key. Keep in sync with `en.json` / `he.json`. */
@@ -79,7 +80,8 @@ export const FORM_ERROR_KEYS = Object.freeze({
79
80
  Server: `${MESSAGE_NAMESPACE}.form.server`,
80
81
  });
81
82
 
82
- /** The English defaults, so a consumer that has not added the keys yet still shows real text. */
83
+ /** The English column of the ONE forms message catalog (`formMessage`) — what a site in any language the catalog does not
84
+ * hold reads, and what a consumer that has not added the keys yet still shows. */
83
85
  export const DEFAULT_EN_MESSAGES: Readonly<Record<string, string>> = Object.freeze({
84
86
  [RULE_MESSAGE_KEYS[RuleName.Required]]: 'This field is required',
85
87
  [RULE_MESSAGE_KEYS[RuleName.MinLength]]: 'Use at least {{n}} characters',
@@ -111,3 +113,72 @@ export const DEFAULT_EN_MESSAGES: Readonly<Record<string, string>> = Object.free
111
113
  [DATE_MESSAGE_KEYS.Max]: 'Choose an earlier date',
112
114
  [SUBMIT_MESSAGE_KEYS.Sent]: 'Sent',
113
115
  });
116
+
117
+ /**
118
+ * The Hebrew column (iox-client-engine#15). A visitor is spoken to in the plural imperative, like every other word a site
119
+ * says (`form-words.ts`: בחרו, כתבו לנו). Every key of the English column has its entry here — a spec holds that.
120
+ */
121
+ const HE_MESSAGES: Readonly<Record<string, string>> = /* @__PURE__ */ Object.freeze({
122
+ [RULE_MESSAGE_KEYS[RuleName.Required]]: 'שדה חובה',
123
+ [RULE_MESSAGE_KEYS[RuleName.MinLength]]: 'כתבו לפחות {{n}} תווים',
124
+ [RULE_MESSAGE_KEYS[RuleName.MaxLength]]: 'כתבו עד {{n}} תווים',
125
+ [RULE_MESSAGE_KEYS[RuleName.Min]]: 'הזינו {{n}} או יותר',
126
+ [RULE_MESSAGE_KEYS[RuleName.Max]]: 'הזינו {{n}} או פחות',
127
+ [RULE_MESSAGE_KEYS[RuleName.Pattern]]: 'בדקו את צורת הערך',
128
+ [RULE_MESSAGE_KEYS[RuleName.Matches]]: 'הערך צריך להתאים לשדה {{field}}',
129
+ [RULE_MESSAGE_KEYS[RuleName.Accepted]]: 'סמנו כדי להמשיך',
130
+ [RULE_MESSAGE_KEYS[RuleName.FileType]]: 'סוג הקובץ הזה לא מתקבל',
131
+ [RULE_MESSAGE_KEYS[RuleName.FileSize]]: 'הקובץ גדול מ-{{n}}MB',
132
+ [PATTERN_MESSAGE_KEYS['email']]: 'הזינו כתובת אימייל תקינה',
133
+ [PATTERN_MESSAGE_KEYS['phone']]: 'הזינו מספר טלפון תקין',
134
+ [PATTERN_MESSAGE_KEYS['url']]: 'הזינו כתובת אתר תקינה',
135
+ [PATTERN_MESSAGE_KEYS['digits']]: 'ספרות בלבד',
136
+ [PATTERN_MESSAGE_KEYS['letters']]: 'אותיות בלבד',
137
+ [PATTERN_MESSAGE_KEYS['slug']]: 'אותיות לטיניות קטנות, ספרות ומקפים',
138
+ [FORM_ERROR_KEYS.Network]: 'לא הצלחנו להגיע לשרת — בדקו את החיבור ונסו שוב',
139
+ [FORM_ERROR_KEYS.Rejected]: 'יש תשובות שצריך לתקן',
140
+ [FORM_ERROR_KEYS.Spam]: 'לא יכולנו לקבל את השליחה הזו',
141
+ [FORM_ERROR_KEYS.RateLimited]: 'יותר מדי ניסיונות — חכו רגע ונסו שוב',
142
+ [FORM_ERROR_KEYS.Server]: 'משהו השתבש אצלנו — התשובות שלכם עדיין כאן',
143
+ [RULE_MESSAGE_KEYS[RuleName.OneOf]]: 'בחרו אחת מהאפשרויות',
144
+ [RULE_MESSAGE_KEYS[RuleName.ValidDate]]: 'בחרו תאריך מלוח השנה',
145
+ [CHOICE_MESSAGE_KEYS.One]: 'בחרו אפשרות',
146
+ [CHOICE_MESSAGE_KEYS.Some]: 'בחרו לפחות אחת',
147
+ [CHOICE_MESSAGE_KEYS.Date]: 'בחרו תאריך',
148
+ [DATE_MESSAGE_KEYS.Min]: 'בחרו תאריך מאוחר יותר',
149
+ [DATE_MESSAGE_KEYS.Max]: 'בחרו תאריך מוקדם יותר',
150
+ [SUBMIT_MESSAGE_KEYS.Sent]: 'נשלח',
151
+ });
152
+
153
+ /** The catalog, by the language `formLanguageOf` reads. */
154
+ const FORM_MESSAGES: Readonly<Record<string, Readonly<Record<string, string>>>> = /* @__PURE__ */ Object.freeze({
155
+ en: DEFAULT_EN_MESSAGES,
156
+ he: HE_MESSAGES,
157
+ });
158
+
159
+ /** The languages the catalog holds. */
160
+ export const FORM_MESSAGE_LANGUAGES: readonly string[] = Object.freeze(['en', 'he']);
161
+
162
+ /** The whole column for `lang` (`he-IL` → he, `iw` → he) — English for a language the catalog does not hold. */
163
+ export function formMessages(lang?: string | null): Readonly<Record<string, string>> {
164
+ const language = formLanguageOf(lang);
165
+ return Object.prototype.hasOwnProperty.call(FORM_MESSAGES, language) ? FORM_MESSAGES[language] : DEFAULT_EN_MESSAGES;
166
+ }
167
+
168
+ /** `{{n}}` / `{{field}}` placed where the sentence's grammar put them; a missing param reads as ''. */
169
+ export function interpolateMessage(template: string, params?: Readonly<Record<string, unknown>> | null): string {
170
+ if (!params) return template;
171
+ return template.replace(/\{\{(\w+)\}\}/g, (_, name: string) => String(params[name] ?? ''));
172
+ }
173
+
174
+ /**
175
+ * A message KEY as the sentence a visitor reads, in the page's language — THE reading both renderers make (the
176
+ * component path's default `IOX_FORM_MESSAGES`, the string runtime's): `lang`'s sentence, else the English one, else the
177
+ * key itself (an author's own message, which travels as its text).
178
+ */
179
+ export function formMessage(key: string, params?: Readonly<Record<string, unknown>> | null, lang?: string | null): string {
180
+ const own = formMessages(lang);
181
+ const template = Object.prototype.hasOwnProperty.call(own, key) ? own[key]
182
+ : Object.prototype.hasOwnProperty.call(DEFAULT_EN_MESSAGES, key) ? DEFAULT_EN_MESSAGES[key] : key;
183
+ return interpolateMessage(template, params);
184
+ }
@@ -11,6 +11,7 @@
11
11
 
12
12
  import { FeedbackTiming, FieldSpec, FormSpec } from './form.model';
13
13
  import { formLanguageOf, formWords } from './form-words';
14
+ import { formMessage, SUBMIT_MESSAGE_KEYS } from './messages';
14
15
  import { SubmitResponse } from './transport';
15
16
  import { FieldError } from './validate';
16
17
 
@@ -146,12 +147,10 @@ export enum SubmitLabelClass {
146
147
  export const SUBMIT_CHECK_SVG = `<svg class="${SubmitLabelClass.Check}" width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false">` +
147
148
  '<path d="M5 12.5l4.5 4.5L19 7.5" pathLength="100" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/></svg>';
148
149
 
149
- /** "Sent" in the site's language, for a button whose author wrote no Sent words (a string-rendered site has no
150
- * translation service — the document's `lang` picks, like the date picker's words). */
151
- const SENT_WORDS: Readonly<Record<string, string>> = Object.freeze({ en: 'Sent', he: 'נשלח' });
152
-
150
+ /** "Sent" in the site's language, for a button whose author wrote no Sent words — the forms message catalog's
151
+ * (`formMessage`), the document's `lang` picking, like the date picker's words. */
153
152
  export function sentWord(lang: string | null | undefined): string {
154
- return SENT_WORDS[formLanguageOf(lang)] ?? SENT_WORDS['en'];
153
+ return formMessage(SUBMIT_MESSAGE_KEYS.Sent, null, lang);
155
154
  }
156
155
 
157
156
  /** "While sending" in the site's language (iox-ui#158). The English one is the SubmitButton's baseline
@@ -82,18 +82,23 @@ export interface LookCondition {
82
82
  readonly between?: ReadonlyArray<string>;
83
83
  }
84
84
 
85
- export interface LookRule {
86
- readonly when: LookCondition;
85
+ /** A rule's line, in English and in Hebrew (vectoriox/iox-cms-client#128 — the contract's `sayHe`, gated by build-spec). */
86
+ export interface RuleLine {
87
87
  readonly say: string;
88
+ readonly sayHe: string;
89
+ }
90
+
91
+ export interface LookRule extends RuleLine {
92
+ readonly when: LookCondition;
88
93
  }
89
94
 
90
- export type CheckRule =
91
- | { readonly check: `${AvoidCheck.NeedsFamily}`; readonly family: string; readonly say: string }
92
- | { readonly check: `${AvoidCheck.NeedsFact}`; readonly fact: FactKey; readonly say: string }
93
- | { readonly check: `${AvoidCheck.ImageHero}`; readonly say: string }
94
- | { readonly check: `${AvoidCheck.NoPattern}`; readonly pattern: string; readonly say: string }
95
- | { readonly check: `${AvoidCheck.BrandHue}`; readonly from: number; readonly to: number; readonly minChroma: number; readonly say: string }
96
- | { readonly check: `${AvoidCheck.CopyLength}`; readonly max: `${CopyLength}`; readonly say: string };
95
+ export type CheckRule = RuleLine & (
96
+ | { readonly check: `${AvoidCheck.NeedsFamily}`; readonly family: string }
97
+ | { readonly check: `${AvoidCheck.NeedsFact}`; readonly fact: FactKey }
98
+ | { readonly check: `${AvoidCheck.ImageHero}` }
99
+ | { readonly check: `${AvoidCheck.NoPattern}`; readonly pattern: string }
100
+ | { readonly check: `${AvoidCheck.BrandHue}`; readonly from: number; readonly to: number; readonly minChroma: number }
101
+ | { readonly check: `${AvoidCheck.CopyLength}`; readonly max: `${CopyLength}` });
97
102
 
98
103
  export type AvoidRule = LookRule | CheckRule;
99
104