@colixsystems/widget-sdk 0.326.0 → 0.327.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.
@@ -14,36 +14,33 @@
14
14
  // component is defined once here so the hosts cannot drift (CLAUDE.md §3, §8).
15
15
 
16
16
  import React from "react";
17
- import { useHostTheme } from "./hooks.js";
17
+ import { useHostTheme, useSdkText } from "./hooks.js";
18
18
  import { resolveRichTextTokens } from "./richtext-tokens.js";
19
19
  import { makeMarkdownLinkDialog } from "./markdown-link-dialog.js";
20
20
 
21
+ // A `label` is shown as is; a `labelText` / `spokenText` is a key in the SDK
22
+ // text table, shown in the app's language.
21
23
  const TOOLS = Object.freeze([
22
- { key: "bold", label: "B", accessibilityLabel: "Bold", weight: "700" },
23
- { key: "italic", label: "I", accessibilityLabel: "Italic", italic: true },
24
- { key: "code", label: "‹›", accessibilityLabel: "Code" },
25
- { key: "heading2", label: "H2", accessibilityLabel: "Heading" },
26
- { key: "heading3", label: "H3", accessibilityLabel: "Subheading" },
27
- { key: "bullet", label: "•", accessibilityLabel: "Bulleted list" },
28
- { key: "ordered", label: "1.", accessibilityLabel: "Numbered list" },
29
- { key: "table", label: "Table", accessibilityLabel: "Insert table" },
24
+ { key: "bold", label: "B", spokenText: "format_bold", weight: "700" },
25
+ { key: "italic", label: "I", spokenText: "format_italic", italic: true },
26
+ { key: "code", label: "‹›", spokenText: "format_code" },
27
+ { key: "heading2", label: "H2", spokenText: "format_heading" },
28
+ { key: "heading3", label: "H3", spokenText: "format_subheading" },
29
+ { key: "bullet", label: "•", spokenText: "format_bulleted_list" },
30
+ { key: "ordered", label: "1.", spokenText: "format_numbered_list" },
31
+ { key: "table", labelText: "table", spokenText: "insert_table" },
30
32
  // sc-7349: a link needs a target no selection supplies, so this opens a form.
31
- {
32
- key: "link",
33
- label: "Link",
34
- accessibilityLabel: "Insert link",
35
- opensDialog: true,
36
- },
33
+ { key: "link", labelText: "link", spokenText: "insert_link", opensDialog: true },
37
34
  ]);
38
35
 
39
36
  // Shown while the caret is in a table: a phone keyboard has no Tab key to
40
37
  // grow one, and a table must be removable without selecting around it.
41
38
  const TABLE_TOOLS = Object.freeze([
42
- { key: "addRow", label: "+ Row", accessibilityLabel: "Add row" },
43
- { key: "addColumn", label: "+ Column", accessibilityLabel: "Add column" },
44
- { key: "removeRow", label: "− Row", accessibilityLabel: "Remove row" },
45
- { key: "removeColumn", label: "− Column", accessibilityLabel: "Remove column" },
46
- { key: "removeTable", label: "Delete table", accessibilityLabel: "Delete table" },
39
+ { key: "addRow", labelText: "table_row_short", spokenText: "table_add_row" },
40
+ { key: "addColumn", labelText: "table_column_short", spokenText: "table_add_column" },
41
+ { key: "removeRow", labelText: "table_remove_row_short", spokenText: "table_remove_row" },
42
+ { key: "removeColumn", labelText: "table_remove_column_short", spokenText: "table_remove_column" },
43
+ { key: "removeTable", labelText: "delete_table", spokenText: "delete_table" },
47
44
  ]);
48
45
 
49
46
  export function makeMarkdownInput(rn, Modal, Button, EditorField) {
@@ -66,6 +63,7 @@ export function makeMarkdownInput(rn, Modal, Button, EditorField) {
66
63
  editable = true,
67
64
  }) {
68
65
  const theme = useHostTheme();
66
+ const text = useSdkText();
69
67
  const tokens = React.useMemo(() => resolveRichTextTokens(theme), [theme]);
70
68
  const fieldRef = React.useRef(null);
71
69
  const [linkLabel, setLinkLabel] = React.useState(null);
@@ -123,7 +121,7 @@ export function makeMarkdownInput(rn, Modal, Button, EditorField) {
123
121
  onPress: () => pressTool(tool),
124
122
  disabled: !editable,
125
123
  accessibilityRole: "button",
126
- accessibilityLabel: tool.accessibilityLabel,
124
+ accessibilityLabel: text(tool.spokenText),
127
125
  testID: testID ? `${testID}-${tool.key}` : undefined,
128
126
  style: {
129
127
  minWidth: 36,
@@ -149,7 +147,7 @@ export function makeMarkdownInput(rn, Modal, Button, EditorField) {
149
147
  fontStyle: tool.italic ? "italic" : "normal",
150
148
  },
151
149
  },
152
- tool.label,
150
+ tool.labelText ? text(tool.labelText) : tool.label,
153
151
  ),
154
152
  ),
155
153
  ),
@@ -11,7 +11,7 @@
11
11
  // (see markdown-input.js / .native.js), so the two hosts cannot drift.
12
12
 
13
13
  import React from "react";
14
- import { useHostTheme } from "./hooks.js";
14
+ import { useHostTheme, useSdkText } from "./hooks.js";
15
15
  import { resolveRichTextTokens } from "./richtext-tokens.js";
16
16
 
17
17
  // The page list scrolls rather than growing an app's 40 pages past the panel.
@@ -45,6 +45,7 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
45
45
  function LinkForm({ form, pageList, canPickPage, testID }) {
46
46
  const { label, setLabel, url, setUrl, pageId, setPageId, mode, setMode } = form;
47
47
  const theme = useHostTheme();
48
+ const text = useSdkText();
48
49
  const tokens = React.useMemo(() => resolveRichTextTokens(theme), [theme]);
49
50
 
50
51
  const inputStyle = {
@@ -58,7 +59,7 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
58
59
  padding: tokens.markerGap,
59
60
  };
60
61
 
61
- const tab = (key, text) =>
62
+ const tab = (key, title) =>
62
63
  React.createElement(
63
64
  Pressable,
64
65
  {
@@ -90,7 +91,7 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
90
91
  color: mode === key ? tokens.onAccent : tokens.color,
91
92
  },
92
93
  },
93
- text,
94
+ title,
94
95
  ),
95
96
  );
96
97
 
@@ -99,13 +100,13 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
99
100
  null,
100
101
  React.createElement(
101
102
  Field,
102
- { label: "Link text", tokens },
103
+ { label: text("link_text"), tokens },
103
104
  React.createElement(TextInput, {
104
105
  value: label,
105
106
  onChangeText: setLabel,
106
- placeholder: "Text the reader sees",
107
+ placeholder: text("link_text_placeholder"),
107
108
  placeholderTextColor: tokens.mutedColor,
108
- accessibilityLabel: "Link text",
109
+ accessibilityLabel: text("link_text"),
109
110
  style: inputStyle,
110
111
  testID: testID ? `${testID}-label` : undefined,
111
112
  }),
@@ -120,15 +121,15 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
120
121
  accessibilityRole: "tablist",
121
122
  style: { flexDirection: "row", marginBottom: tokens.blockGap },
122
123
  },
123
- tab("page", "A page in this app"),
124
- tab("url", "An external URL"),
124
+ tab("page", text("link_to_page")),
125
+ tab("url", text("link_to_url")),
125
126
  )
126
127
  : null,
127
128
 
128
129
  mode === "page" && canPickPage
129
130
  ? React.createElement(
130
131
  Field,
131
- { label: "Page", tokens },
132
+ { label: text("link_page"), tokens },
132
133
  React.createElement(
133
134
  ScrollView,
134
135
  {
@@ -176,13 +177,13 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
176
177
  )
177
178
  : React.createElement(
178
179
  Field,
179
- { label: "Address", tokens },
180
+ { label: text("link_address"), tokens },
180
181
  React.createElement(TextInput, {
181
182
  value: url,
182
183
  onChangeText: setUrl,
183
184
  placeholder: "https://example.com",
184
185
  placeholderTextColor: tokens.mutedColor,
185
- accessibilityLabel: "Link address",
186
+ accessibilityLabel: text("link_address_label"),
186
187
  autoCapitalize: "none",
187
188
  autoCorrect: false,
188
189
  keyboardType: "url",
@@ -211,6 +212,7 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
211
212
  initialLabel,
212
213
  testID,
213
214
  }) {
215
+ const text = useSdkText();
214
216
  const pageList = Array.isArray(pages) ? pages.filter((p) => p && p.id) : [];
215
217
  const canPickPage = pageList.length > 0;
216
218
 
@@ -247,10 +249,10 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
247
249
  const actions = React.createElement(
248
250
  React.Fragment,
249
251
  null,
250
- action("cancel", "Cancel", { variant: "secondary", onPress: onClose }),
252
+ action("cancel", text("cancel"), { variant: "secondary", onPress: onClose }),
251
253
  // Disabled until there is somewhere to go — an empty target would
252
254
  // write `[text]()`, which reads as a link and goes nowhere.
253
- action("insert", "Insert link", { disabled: !target, onPress: submit }),
255
+ action("insert", text("insert_link"), { disabled: !target, onPress: submit }),
254
256
  );
255
257
 
256
258
  return React.createElement(
@@ -259,7 +261,7 @@ export function makeMarkdownLinkDialog(rn, Modal, Button) {
259
261
  visible: !!visible,
260
262
  onRequestClose: onClose,
261
263
  size: "sm",
262
- title: "Insert link",
264
+ title: text("insert_link"),
263
265
  footer: actions,
264
266
  testID: testID ? `${testID}-dialog` : undefined,
265
267
  },
@@ -5,7 +5,7 @@
5
5
  // primitives come from, so the web Player and the Expo export cannot drift.
6
6
 
7
7
  import React from "react";
8
- import { ThemeScope, useHostTheme } from "./hooks.js";
8
+ import { ThemeScope, useHostTheme, useSdkText } from "./hooks.js";
9
9
  import { DEFAULT_THEME_TOKENS } from "./_theme-tokens.js";
10
10
  import { Icon } from "./icon.js";
11
11
  import { overlayCornerStyle } from "./overlay-tokens.js";
@@ -107,7 +107,7 @@ export function makeModal(rn, Overlay) {
107
107
  * native has no equivalent.
108
108
  * @param {{current: any}} [props.initialFocusRef] — the element focused on
109
109
  * open instead of the dialog itself; web only, a no-op on native.
110
- * @param {string} [props.closeAccessibilityLabel] — default "Close".
110
+ * @param {string} [props.closeAccessibilityLabel] — default "Close", in the app's language.
111
111
  * @param {string} [props.accessibilityLabel] — names a dialog with no title.
112
112
  * @param {string} [props.testID] — on the panel; the close button, body and
113
113
  * footer take `-close`, `-body` and `-footer`.
@@ -123,12 +123,13 @@ export function makeModal(rn, Overlay) {
123
123
  dismissOnBackdropPress = true,
124
124
  role = "dialog",
125
125
  initialFocusRef,
126
- closeAccessibilityLabel = "Close",
126
+ closeAccessibilityLabel,
127
127
  accessibilityLabel,
128
128
  testID,
129
129
  children,
130
130
  }) {
131
131
  const theme = useHostTheme() || DEFAULT_THEME_TOKENS;
132
+ const closeText = useSdkText()("close");
132
133
  const deviceInsets = useSafeAreaInsets();
133
134
  const titleId = React.useId();
134
135
  const t = React.useMemo(
@@ -187,7 +188,7 @@ export function makeModal(rn, Overlay) {
187
188
  {
188
189
  onPress: close,
189
190
  accessibilityRole: "button",
190
- accessibilityLabel: closeAccessibilityLabel,
191
+ accessibilityLabel: closeAccessibilityLabel === undefined ? closeText : closeAccessibilityLabel,
191
192
  testID: part("close"),
192
193
  style: ({ pressed }) => closeStyle(pressed),
193
194
  },
@@ -15,7 +15,7 @@
15
15
  // the hosts cannot drift (CLAUDE.md §3, §8).
16
16
 
17
17
  import React from "react";
18
- import { useHostTheme } from "./hooks.js";
18
+ import { useHostTheme, useSdkText } from "./hooks.js";
19
19
  import { overlayFrameStyles, resolveOverlayTokens } from "./overlay-tokens.js";
20
20
 
21
21
  // Kept clickable, but out of the tab order and the accessibility tree.
@@ -95,7 +95,7 @@ export function makeOverlay(rn) {
95
95
  role = "dialog",
96
96
  accessibilityLabel,
97
97
  accessibilityLabelledBy,
98
- closeAccessibilityLabel = "Close",
98
+ closeAccessibilityLabel,
99
99
  initialFocusRef,
100
100
  panelFrame: PanelFrame,
101
101
  anchoredAt,
@@ -106,6 +106,7 @@ export function makeOverlay(rn) {
106
106
  children,
107
107
  }) {
108
108
  const theme = useHostTheme();
109
+ const closeText = useSdkText()("close");
109
110
  const tokens = React.useMemo(
110
111
  () => resolveOverlayTokens(theme, size, presentation),
111
112
  [theme, size, presentation],
@@ -166,7 +167,7 @@ export function makeOverlay(rn) {
166
167
  ...(backdropAccessible
167
168
  ? {
168
169
  accessibilityRole: "button",
169
- accessibilityLabel: closeAccessibilityLabel,
170
+ accessibilityLabel: closeAccessibilityLabel === undefined ? closeText : closeAccessibilityLabel,
170
171
  }
171
172
  : SILENT_BACKDROP),
172
173
  })
@@ -15,6 +15,7 @@ import {
15
15
  useDatastoreSchema,
16
16
  useDirectory,
17
17
  useGroups,
18
+ useSdkTextDefaults,
18
19
  } from "./hooks.js";
19
20
  import {
20
21
  answersQuery,
@@ -38,6 +39,8 @@ const h = React.createElement;
38
39
  const NO_ROWS = Object.freeze([]);
39
40
  const NO_LOOKUPS = Object.freeze({ pending: [], next: 0 });
40
41
 
42
+ const PICKER_TEXT_KEYS = Object.freeze({ unknownText: "unknown", loadingText: "loading" });
43
+
41
44
  function serialize(query) {
42
45
  try {
43
46
  return JSON.stringify(query);
@@ -143,7 +146,8 @@ export function makePeoplePicker(rn) {
143
146
  );
144
147
  }
145
148
 
146
- function SourcePicker(props) {
149
+ function SourcePicker(ownProps) {
150
+ const props = useSdkTextDefaults(ownProps, PICKER_TEXT_KEYS);
147
151
  const {
148
152
  source,
149
153
  table,
@@ -155,8 +159,8 @@ export function makePeoplePicker(rn) {
155
159
  excludeIds,
156
160
  pageSize,
157
161
  showAvatars = true,
158
- unknownText = "Unknown",
159
- loadingText = "Loading…",
162
+ unknownText,
163
+ loadingText,
160
164
  loadErrorText,
161
165
  multiple = false,
162
166
  value,
@@ -6,7 +6,7 @@
6
6
  // an icon or a tab role. This one has the radio role and the app's look.
7
7
 
8
8
  import React from "react";
9
- import { useHostSharedText, useHostTheme, useStrictProps } from "./hooks.js";
9
+ import { useHostTheme, useSdkText, useStrictProps } from "./hooks.js";
10
10
  import { DEFAULT_THEME_TOKENS } from "./_theme-tokens.js";
11
11
  import { Icon } from "./icon.js";
12
12
  import { CHECKBOX_SIZE, CONTROL_MIN_TARGET, focusHaloStyle } from "./form-control-tokens.js";
@@ -173,7 +173,8 @@ export function makeRadioGroup(rn) {
173
173
  containerStyle,
174
174
  ...rest
175
175
  } = props;
176
- const requiredWord = useHostSharedText("required", "Required");
176
+ const text = useSdkText();
177
+ const requiredWord = text("required");
177
178
  const theme = useHostTheme() || DEFAULT_THEME_TOKENS;
178
179
  const t = resolveRadioGroupTokens(theme);
179
180
  const kind = radioGroupVariant(variant);
@@ -8,7 +8,7 @@
8
8
  // hosts; only the input differs. Touch screens on the web are left unchanged.
9
9
 
10
10
  import React from "react";
11
- import { useHostSharedText, useHostTheme } from "./hooks.js";
11
+ import { useHostTheme, useSdkText } from "./hooks.js";
12
12
  import { DEFAULT_THEME_TOKENS } from "./_theme-tokens.js";
13
13
  import { flattenStyle } from "./flatten-style.js";
14
14
  import { Icon } from "./icon.js";
@@ -113,8 +113,9 @@ export function makeScrollView({ ScrollView: BaseScrollView, View, Pressable })
113
113
  const ScrollView = React.forwardRef(function ScrollView(props, ref) {
114
114
  const { showsScrollAffordance = true, ...rest } = props;
115
115
  const theme = useHostTheme() || DEFAULT_THEME_TOKENS;
116
- const previousLabel = useHostSharedText("previous", "Previous");
117
- const nextLabel = useHostSharedText("next", "Next");
116
+ const text = useSdkText();
117
+ const previousLabel = text("previous");
118
+ const nextLabel = text("next");
118
119
  const [finePointer] = React.useState(() => matches(FINE_POINTER));
119
120
  const [edges, setEdges] = React.useState("none");
120
121
  const [hovered, setHovered] = React.useState(false);
@@ -0,0 +1,164 @@
1
+ // GENERATED from sdk-texts.js by scripts/generate-cjs.js — DO NOT EDIT.
2
+ // Change sdk-texts.js, then run `npm run generate:cjs` in packages/widget-sdk.
3
+ "use strict";
4
+
5
+ // The words SDK components show when the author passes none, in the app's
6
+ // language (ctx.i18n.locale on both hosts). contract.js joins this table with
7
+ // the shared translation keys into the ONE table every component reads, so no
8
+ // component carries its own translation (CLAUDE.md §3).
9
+ //
10
+ // These texts are never seeded into a workspace's dictionary: several carry a
11
+ // `{count}` or `{label}` slot that machine translation at seeding would mangle.
12
+ // Languages follow the shared keys: English and a hand-written Swedish; every
13
+ // other language falls back to English.
14
+
15
+ /**
16
+ * Per key: the text in each shipped language, English always present. A text
17
+ * with a `{count}` slot is `{ one, other }`, picked by the language's plural rule.
18
+ */
19
+ const COMPONENT_TEXTS = Object.freeze({
20
+ select_placeholder: { en: "Select", sv: "Välj" },
21
+ no_options: { en: "No options", sv: "Inga alternativ" },
22
+ done: { en: "Done", sv: "Klar" },
23
+ selected_count: {
24
+ en: { one: "{count} selected", other: "{count} selected" },
25
+ sv: { one: "{count} vald", other: "{count} valda" },
26
+ },
27
+ options_load_failed: { en: "Could not load the options", sv: "Det gick inte att läsa in alternativen" },
28
+ clear: { en: "Clear", sv: "Rensa" },
29
+ clear_search: { en: "Clear search", sv: "Rensa sökningen" },
30
+ unknown: { en: "Unknown", sv: "Okänd" },
31
+ dismiss: { en: "Dismiss", sv: "Stäng" },
32
+ select_date: { en: "Select date", sv: "Välj datum" },
33
+ select_time: { en: "Select time", sv: "Välj tid" },
34
+ select_date_time: { en: "Select date & time", sv: "Välj datum och tid" },
35
+
36
+ choose_file: { en: "Choose file", sv: "Välj fil" },
37
+ choose_files: { en: "Choose files", sv: "Välj filer" },
38
+ uploading: { en: "Uploading…", sv: "Laddar upp…" },
39
+ no_file_chosen: { en: "No file chosen", sv: "Ingen fil vald" },
40
+ no_files_chosen: { en: "No files chosen", sv: "Inga filer valda" },
41
+ file_type_rejected: { en: "That file type isn't accepted here.", sv: "Den filtypen tas inte emot här." },
42
+ single_file_kept: {
43
+ en: "Only one file can be added here, so the first was kept.",
44
+ sv: "Här går det bara att lägga till en fil, så den första behölls.",
45
+ },
46
+ drop_file: { en: "or drop a file here", sv: "eller släpp en fil här" },
47
+ drop_files: { en: "or drop files here", sv: "eller släpp filer här" },
48
+ file_choice_unavailable: { en: "Choosing files isn't available here.", sv: "Det går inte att välja filer här." },
49
+
50
+ filter_any: { en: "Any", sv: "Alla" },
51
+ filters: { en: "Filters", sv: "Filter" },
52
+ filters_active_count: {
53
+ en: { one: "{count} active", other: "{count} active" },
54
+ sv: { one: "{count} aktivt", other: "{count} aktiva" },
55
+ },
56
+ clear_all: { en: "Clear all", sv: "Rensa alla" },
57
+ apply: { en: "Apply", sv: "Använd" },
58
+ active_filters: { en: "Active filters", sv: "Aktiva filter" },
59
+ remove_named: { en: "Remove {label}", sv: "Ta bort {label}" },
60
+ sort: { en: "Sort", sv: "Sortera" },
61
+ sorted_ascending: { en: "sorted ascending", sv: "sorterad stigande" },
62
+ sorted_descending: { en: "sorted descending", sv: "sorterad fallande" },
63
+
64
+ move_item: { en: "Move {item}", sv: "Flytta {item}" },
65
+ move_hint: {
66
+ en: "Drag to move it, or open the move options. The arrow keys move it too.",
67
+ sv: "Dra för att flytta, eller öppna flyttalternativen. Piltangenterna flyttar också.",
68
+ },
69
+ move_up: { en: "Move up", sv: "Flytta upp" },
70
+ move_down: { en: "Move down", sv: "Flytta ned" },
71
+ move_to_top: { en: "Move to top", sv: "Flytta högst upp" },
72
+ move_to_bottom: { en: "Move to bottom", sv: "Flytta längst ned" },
73
+ move_to_column: { en: "Move to {column}", sv: "Flytta till {column}" },
74
+ moved: { en: "{item} moved to position {position} of {total}", sv: "{item} flyttades till plats {position} av {total}" },
75
+ moved_to_column: { en: "{item} moved to {column}, position {position}", sv: "{item} flyttades till {column}, plats {position}" },
76
+
77
+ choose_emoji: { en: "Choose an emoji", sv: "Välj en emoji" },
78
+ close_emoji_picker: { en: "Close the emoji picker", sv: "Stäng emojiväljaren" },
79
+ search_emoji: { en: "Search emoji", sv: "Sök emoji" },
80
+ no_emoji_found: { en: "No emoji found", sv: "Inga emojier hittades" },
81
+ emoji_recent: { en: "Recent", sv: "Senaste" },
82
+ emoji_smileys: { en: "Smileys & Emotion", sv: "Smileys och känslor" },
83
+ emoji_people: { en: "People & Body", sv: "Människor och kropp" },
84
+ emoji_animals: { en: "Animals & Nature", sv: "Djur och natur" },
85
+ emoji_food: { en: "Food & Drink", sv: "Mat och dryck" },
86
+ emoji_activity: { en: "Activity", sv: "Aktiviteter" },
87
+ emoji_travel: { en: "Travel & Places", sv: "Resor och platser" },
88
+ emoji_objects: { en: "Objects", sv: "Föremål" },
89
+ emoji_symbols: { en: "Symbols", sv: "Symboler" },
90
+ emoji_flags: { en: "Flags", sv: "Flaggor" },
91
+
92
+ format_bold: { en: "Bold", sv: "Fetstil" },
93
+ format_italic: { en: "Italic", sv: "Kursiv" },
94
+ format_code: { en: "Code", sv: "Kod" },
95
+ format_heading: { en: "Heading", sv: "Rubrik" },
96
+ format_subheading: { en: "Subheading", sv: "Underrubrik" },
97
+ format_bulleted_list: { en: "Bulleted list", sv: "Punktlista" },
98
+ format_numbered_list: { en: "Numbered list", sv: "Numrerad lista" },
99
+ table: { en: "Table", sv: "Tabell" },
100
+ insert_table: { en: "Insert table", sv: "Infoga tabell" },
101
+ link: { en: "Link", sv: "Länk" },
102
+ insert_link: { en: "Insert link", sv: "Infoga länk" },
103
+ table_row_short: { en: "+ Row", sv: "+ Rad" },
104
+ table_add_row: { en: "Add row", sv: "Lägg till rad" },
105
+ table_column_short: { en: "+ Column", sv: "+ Kolumn" },
106
+ table_add_column: { en: "Add column", sv: "Lägg till kolumn" },
107
+ table_remove_row_short: { en: "− Row", sv: "− Rad" },
108
+ table_remove_row: { en: "Remove row", sv: "Ta bort rad" },
109
+ table_remove_column_short: { en: "− Column", sv: "− Kolumn" },
110
+ table_remove_column: { en: "Remove column", sv: "Ta bort kolumn" },
111
+ delete_table: { en: "Delete table", sv: "Ta bort tabell" },
112
+ link_text: { en: "Link text", sv: "Länktext" },
113
+ link_text_placeholder: { en: "Text the reader sees", sv: "Texten som läsaren ser" },
114
+ link_to_page: { en: "A page in this app", sv: "En sida i appen" },
115
+ link_to_url: { en: "An external URL", sv: "En extern webbadress" },
116
+ link_page: { en: "Page", sv: "Sida" },
117
+ link_address: { en: "Address", sv: "Adress" },
118
+ link_address_label: { en: "Link address", sv: "Länkadress" },
119
+ });
120
+
121
+ /** The language of `entry` that `locale` reads: itself, its primary language (`sv-SE` reads `sv`), else English. */
122
+ function languageIn(entry, locale) {
123
+ const ships = (language) => Object.prototype.hasOwnProperty.call(entry, language);
124
+ if (typeof locale === "string" && locale) {
125
+ if (ships(locale)) return locale;
126
+ const primary = locale.split(/[-_]/)[0].toLowerCase();
127
+ if (ships(primary)) return primary;
128
+ }
129
+ return "en";
130
+ }
131
+
132
+ function pluralCategory(language, count) {
133
+ try {
134
+ return new Intl.PluralRules(language).select(count);
135
+ } catch {
136
+ return count === 1 ? "one" : "other";
137
+ }
138
+ }
139
+
140
+ /**
141
+ * `entry`'s text in `locale`, slots filled from `values`. A plural text takes
142
+ * the form `values.count` needs, and `other` when no count is given.
143
+ */
144
+ function textInLanguage(entry, locale, values) {
145
+ const language = languageIn(entry, locale);
146
+ const text = entry[language];
147
+ if (typeof text === "string") return fillSdkText(text, values);
148
+ const count = values ? Number(values.count) : NaN;
149
+ const form = Number.isFinite(count) ? text[pluralCategory(language, count)] : undefined;
150
+ return fillSdkText(form || text.other, values);
151
+ }
152
+
153
+ /** `text` with each `{name}` slot replaced by `values[name]`. */
154
+ function fillSdkText(text, values) {
155
+ if (!values) return text;
156
+ return String(text).replace(/\{(\w+)\}/g, (slot, name) =>
157
+ Object.prototype.hasOwnProperty.call(values, name) ? String(values[name]) : slot,
158
+ );
159
+ }
160
+ module.exports = {
161
+ COMPONENT_TEXTS,
162
+ textInLanguage,
163
+ fillSdkText,
164
+ };