@humandialog/forms.svelte 1.6.0 → 1.6.2

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.
@@ -7,6 +7,7 @@ import { FaChevronDown, FaTimes } from "svelte-icons/fa";
7
7
  import Icon from "../icon.svelte";
8
8
  import { reef } from "@humandialog/auth.svelte/dist/index.js";
9
9
  import { showMenu } from "../menu.js";
10
+ import { ext, i18n } from "../../i18n.js";
10
11
  export let label = "";
11
12
  export let self = null;
12
13
  export let a = "";
@@ -229,7 +230,7 @@ function openDropdownAsMenu() {
229
230
  let operations = [];
230
231
  if (hasNone)
231
232
  operations.push({
232
- caption: "<none>",
233
+ caption: `<${i18n({ en: "blank", es: "blanco", pl: "pusty" })}>`,
233
234
  action: (f) => on_choose(null)
234
235
  });
235
236
  if (definition && definition.collection)
@@ -237,12 +238,11 @@ function openDropdownAsMenu() {
237
238
  const _filtered_source = filtered_source ? filtered_source : definition.source;
238
239
  _filtered_source.forEach((i) => {
239
240
  operations.push({
240
- caption: i.Name ?? i.Key,
241
+ caption: i.Name ? ext(i.Name) : i.Key,
241
242
  icon: i.Icon ?? void 0,
242
243
  action: (f) => on_choose(i)
243
244
  });
244
245
  });
245
- console.log("operations", operations);
246
246
  showMenu(rect, operations);
247
247
  }
248
248
  export function hide() {
@@ -295,7 +295,7 @@ function get_combo_text() {
295
295
  if (!is_dropdown_open) {
296
296
  let found = selected_item(item, a);
297
297
  if (found)
298
- return found.Name ?? found.Key;
298
+ return found.Name ? ext(found.Name) : found.Key;
299
299
  else
300
300
  return placeholder;
301
301
  } else
@@ -1,5 +1,5 @@
1
1
  export function getFormattedStringDate(d: any, type?: string): string;
2
2
  export function getNiceStringDateTime(d: any): string;
3
- export function getNiceStringDate(d: any): string;
4
- export function dayName(d: any): "" | "Sun" | "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat";
5
- export function monthName(m: any): "" | "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec";
3
+ export function getNiceStringDate(d: any): any;
4
+ export function dayName(d: any): any;
5
+ export function monthName(m: any): any;
@@ -1,4 +1,6 @@
1
1
 
2
+ import {getCurrentLanguageKey} from '../i18n.js'
3
+
2
4
  export function getFormattedStringDate(d, type = "datetime")
3
5
  {
4
6
  if(!d)
@@ -86,11 +88,11 @@ export function getNiceStringDate(d)
86
88
 
87
89
  let days_diff = day - current_day;
88
90
  if(days_diff == 0)
89
- return 'Today';
91
+ return today();
90
92
  else if(days_diff == 1)
91
- return 'Tomorrow';
93
+ return tomorrow();
92
94
  else if(days_diff == -1)
93
- return 'Yesterday';
95
+ return yesterday();
94
96
  else if(days_diff > 0 && days_diff <= 7)
95
97
  {
96
98
  if(day_of_week > current_day_of_week)
@@ -122,67 +124,68 @@ export function getNiceStringDate(d)
122
124
  }
123
125
  }
124
126
 
125
- export function dayName(d)
127
+ function today()
126
128
  {
127
- switch(d)
128
- {
129
- case 0:
130
- return 'Sun';
131
-
132
- case 1:
133
- return 'Mon';
134
-
135
- case 2:
136
- return 'Tue';
137
-
138
- case 3:
139
- return 'Wed';
129
+ const lang = getCurrentLanguageKey()
130
+ if(Object.keys(abbrCloseLang).includes(lang))
131
+ return abbrCloseLang[lang][1]
132
+ else
133
+ return abbrCloseLang.en[1]
134
+ }
140
135
 
141
- case 4:
142
- return 'Thu';
136
+ function tomorrow()
137
+ {
138
+ const lang = getCurrentLanguageKey()
139
+ if(Object.keys(abbrCloseLang).includes(lang))
140
+ return abbrCloseLang[lang][2]
141
+ else
142
+ return abbrCloseLang.en[2]
143
+ }
143
144
 
144
- case 5:
145
- return 'Fri';
145
+ function yesterday()
146
+ {
147
+ const lang = getCurrentLanguageKey()
148
+ if(Object.keys(abbrCloseLang).includes(lang))
149
+ return abbrCloseLang[lang][0]
150
+ else
151
+ return abbrCloseLang.en[0]
152
+ }
146
153
 
147
- case 6:
148
- return 'Sat';
149
-
150
- case 7:
151
- return 'Sun';
152
- }
153
154
 
154
- return '';
155
+ export function dayName(d)
156
+ {
157
+ const lang = getCurrentLanguageKey()
158
+ if(Object.keys(abbrDaysLang).includes(lang))
159
+ return abbrDaysLang[lang][d]
160
+ else
161
+ return abbrDaysLang.en[d]
155
162
  }
156
163
 
157
164
  export function monthName(m)
158
165
  {
159
- switch(m)
160
- {
161
- case 0:
162
- return "Jan";
163
- case 1:
164
- return "Feb";
165
- case 2:
166
- return "Mar";
167
- case 3:
168
- return "Apr";
169
- case 4:
170
- return "May";
171
- case 5:
172
- return "Jun";
173
- case 6:
174
- return "Jul";
175
- case 7:
176
- return "Aug";
177
- case 8:
178
- return "Sep";
179
- case 9:
180
- return "Oct";
181
- case 10:
182
- return "Nov";
183
- case 11:
184
- return "Dec";
185
- }
166
+ const lang = getCurrentLanguageKey()
167
+ if(Object.keys(abbrMonthsLang).includes(lang))
168
+ return abbrMonthsLang[lang][m]
169
+ else
170
+ return abbrMonthsLang.en[m]
171
+ }
172
+
173
+ // translations
174
+
175
+ const abbrCloseLang = {
176
+ en: ['yesterday', 'today', 'tomorrow'],
177
+ es: ['ayer', 'hoy', 'mañana'],
178
+ pl: ['wczoraj', 'dziś', 'jutro']
179
+ }
180
+
181
+ const abbrDaysLang = {
182
+ en: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
183
+ es: ['dom', 'lun', 'mar', 'miérc', 'juev', 'vier', 'sáb', 'dom'],
184
+ pl: ['nie', 'pon', 'wto', 'śro', 'czw', 'pią', 'sob', 'nie']
185
+ }
186
186
 
187
- return '';
187
+ const abbrMonthsLang = {
188
+ en: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
189
+ es: ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'set', 'oct', 'nov', 'dic'],
190
+ pl: ['sty', 'lut', 'mar', 'kwi', 'maj', 'cze', 'lip', 'sie', 'wrz', 'paź', 'lis', 'gru']
188
191
  }
@@ -18,6 +18,7 @@ import { rList_definition, rList_property_type } from "../List";
18
18
  import { push, link } from "svelte-spa-router";
19
19
  import { FaExternalLinkAlt } from "svelte-icons/fa/";
20
20
  import Tags from "../../tags.svelte";
21
+ import { ext } from "../../../i18n";
21
22
  export let item;
22
23
  export let title = "";
23
24
  export let summary = "";
@@ -250,7 +251,7 @@ export function scrollToView() {
250
251
 
251
252
  <!-- svelte-ignore a11y-click-events-have-key-events -->
252
253
  {#if item}
253
- {@const element_title = item[title]}
254
+ {@const element_title = ext(item[title])}
254
255
 
255
256
  <section class="my-1 flex flex-row w-full text-stone-900 dark:text-stone-300 cursor-default rounded-md border border-transparent {selected_class} {focused_class} scroll-mt-[50px] sm:scroll-mt-[40px]"
256
257
  role="menu"
@@ -328,8 +329,9 @@ export function scrollToView() {
328
329
  </section>
329
330
 
330
331
  {#if summary && (item[summary] || placeholder=='Summary')}
332
+ {@const summaryText = ext(item[summary])}
331
333
  {@const element_id = `__hd_list_ctrl_${getItemKey(item)}_Summary`}
332
- {#key item[summary] }
334
+ {#key summaryText }
333
335
  {#if is_row_active}
334
336
  <p id={element_id}
335
337
  class=" text-sm
@@ -340,14 +342,14 @@ export function scrollToView() {
340
342
  onFinish: (d) => {placeholder='';},
341
343
  active: true
342
344
  }}>
343
- {item[summary]}
345
+ {summaryText}
344
346
  </p>
345
347
  {:else}
346
348
  <p id={element_id}
347
349
  class=" text-sm
348
350
  text-stone-600 dark:text-stone-400"
349
351
  on:click={(e) => on_active_row_clicked(e, 'bottom')}>
350
- {item[summary]}
352
+ {summaryText}
351
353
  </p>
352
354
  {/if}
353
355
  {/key}
@@ -1,5 +1,7 @@
1
1
  <script>
2
2
 
3
+ import {i18n} from '../i18n.js'
4
+
3
5
  export let pageNo
4
6
  export let allPagesNo
5
7
  export let onPage
@@ -67,7 +69,9 @@
67
69
  <li>
68
70
  <button on:click={onPrevPage}
69
71
  class="flex items-center justify-center px-3 h-8 ms-0 leading-tight text-stone-500 bg-white border border-e-0 border-stone-300 rounded-s-lg hover:bg-stone-100 hover:text-stone-700 dark:bg-stone-800 dark:border-stone-700 dark:text-stone-400 dark:hover:bg-stone-700 dark:hover:text-white">
70
- <span class="sr-only">Previous</span>
72
+ <span class="sr-only">
73
+ { i18n({en: 'Previous', es: 'Anterior', pl: 'Wcześniejsze'}) }
74
+ </span>
71
75
  <svg class="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
72
76
  <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 1 1 5l4 4"/>
73
77
  </svg>
@@ -94,7 +98,11 @@
94
98
  <!--a href="#" aria-current="page" class="">3</a-->
95
99
  <li>
96
100
  <button on:click={onNextPage} class="flex items-center justify-center px-3 h-8 leading-tight text-stone-500 bg-white border border-stone-300 rounded-e-lg hover:bg-stone-100 hover:text-stone-700 dark:bg-stone-800 dark:border-stone-700 dark:text-stone-400 dark:hover:bg-stone-700 dark:hover:text-white">
97
- <span class="sr-only">Next</span>
101
+ <span class="sr-only">
102
+
103
+ { i18n({en: 'Next', es: 'Siguiente', pl: 'Następne'}) }
104
+
105
+ </span>
98
106
  <svg class="w-2.5 h-2.5 rtl:rotate-180" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 6 10">
99
107
  <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 9 4-4-4-4"/>
100
108
  </svg>
@@ -4,6 +4,7 @@
4
4
  import TagColorsPalette from './tag.colors.svelte'
5
5
  import { tick } from 'svelte';
6
6
  import { isDeviceSmallerThan } from '../utils';
7
+ import {i18n} from '../i18n'
7
8
 
8
9
  export let usedTags = []
9
10
  export let allTags = []
@@ -194,9 +195,13 @@
194
195
  onCustomClick={(e) => onTagSelected(tag)}/>
195
196
  {/each}
196
197
  {:else if allowNewTags}
197
- <p>Create tag:</p>
198
+ <p>
199
+ { i18n({en: 'Create tag:', es: 'Crear etiqueta:', pl: 'Utwrórz etykietę:'}) }
200
+ </p>
198
201
  {:else}
199
- <p>No tags</p>
202
+ <p>
203
+ { i18n({en: 'No tags', es: 'Sin etiquetas', pl: 'Żadnych etykiet'}) }
204
+ </p>
200
205
  {/if}
201
206
 
202
207
  {/key}
@@ -211,7 +216,7 @@
211
216
  on:input={onTextInput}
212
217
  on:blur={onTextBlur}
213
218
  on:keydown={onKeyDown}
214
- placeholder="Type to filter or create tag">
219
+ placeholder={i18n({en: 'Type to filter or create tag', es: 'Escriba para filtrar o crear una etiqueta', pl: 'Wpisz, aby filtrować lub utworzyć tag'})}>
215
220
  {#if allowNewTags}
216
221
  <button class="block w-5 h-5 mt-0.5 ml-auto mr-2
217
222
  text-stone-600 hover:text-stone-800 hover:bg-stone-200 active:bg-stone-200 border-stone-200
package/i18n.d.ts CHANGED
@@ -28,3 +28,5 @@ export function getCurrentLanguageKey(): string;
28
28
  * i18n("EN; ES; PL") => "EN" albo "ES" albo "PL"
29
29
  */
30
30
  export function i18n(list: any): any;
31
+ export function extractTranslated(str: any): any;
32
+ export function ext(str: any): any;
package/i18n.js CHANGED
@@ -160,3 +160,32 @@ export function i18n(list)
160
160
  }
161
161
  }
162
162
 
163
+ export function extractTranslated(str)
164
+ {
165
+ if(!str)
166
+ return ""
167
+
168
+ if(str.startsWith('_;'))
169
+ {
170
+ const body = str.replace(/^_;\s*/, ''); // cut prefix "_; "
171
+ return i18n(body);
172
+ }
173
+ else if(str.startsWith('__;'))
174
+ {
175
+ const body = str.replace(/^__;\s*/, ''); // cut prefix "__; "
176
+ const PAIRS = /([A-Za-z]{2})\s*:\s*([^;]*)/g;
177
+ const dict = {};
178
+
179
+ for (const [, code, text] of body.matchAll(PAIRS))
180
+ dict[code.toLowerCase()] = text.trim();
181
+
182
+ return i18n(dict)
183
+ }
184
+ else
185
+ return str
186
+ }
187
+
188
+ export function ext(str)
189
+ {
190
+ return extractTranslated(str)
191
+ }
package/index.d.ts CHANGED
@@ -72,5 +72,5 @@ export { default as IcH2 } from './components/document/internal/h2.icon.svelte';
72
72
  export { default as IcH3 } from './components/document/internal/h3.icon.svelte';
73
73
  export { default as IcH4 } from './components/document/internal/h4.icon.svelte';
74
74
  export { registerKicksObserver, unregisterKicksObserver, forceKicksChecking } from './kicks.js';
75
- export { i18n, setLanguages, getLanguages, setCurrentLanguage, getCurrentLanguage, getCurrentLanguageIdx, getCurrentLanguageKey } from './i18n.js';
75
+ export { i18n, extractTranslated, ext, setLanguages, getLanguages, setCurrentLanguage, getCurrentLanguage, getCurrentLanguageIdx, getCurrentLanguageKey } from './i18n.js';
76
76
  export { i18nPreprocess } from './i18n-preprocess.js';
package/index.js CHANGED
@@ -78,5 +78,5 @@ export { default as IcH2 } from './components/document/internal/h2.icon.svelte';
78
78
  export { default as IcH3 } from './components/document/internal/h3.icon.svelte';
79
79
  export { default as IcH4 } from './components/document/internal/h4.icon.svelte';
80
80
  export { registerKicksObserver, unregisterKicksObserver, forceKicksChecking } from './kicks.js';
81
- export { i18n, setLanguages, getLanguages, setCurrentLanguage, getCurrentLanguage, getCurrentLanguageIdx, getCurrentLanguageKey } from './i18n.js';
81
+ export { i18n, extractTranslated, ext, setLanguages, getLanguages, setCurrentLanguage, getCurrentLanguage, getCurrentLanguageIdx, getCurrentLanguageKey } from './i18n.js';
82
82
  export { i18nPreprocess } from './i18n-preprocess.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humandialog/forms.svelte",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Basic Svelte UI components for Object Reef applications",
5
5
  "devDependencies": {
6
6
  "@playwright/test": "^1.28.1",