@syware/jlib 0.8.0 → 0.9.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.
Files changed (91) hide show
  1. package/README.md +2 -1
  2. package/dist/all.js +2 -2
  3. package/dist/atoms/jl-chip.d.ts +1 -0
  4. package/dist/atoms/jl-chip.js +4 -2
  5. package/dist/atoms/jl-input.d.ts +2 -0
  6. package/dist/atoms/jl-input.js +9 -3
  7. package/dist/atoms/jl-rating.d.ts +2 -0
  8. package/dist/atoms/jl-rating.js +13 -5
  9. package/dist/atoms/jl-spinner.d.ts +2 -0
  10. package/dist/atoms/jl-spinner.js +6 -2
  11. package/dist/base/jl-element.d.ts +6 -0
  12. package/dist/base/jl-element.js +5 -0
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +2 -2
  15. package/dist/lib/texts-de.d.ts +108 -0
  16. package/dist/lib/texts-de.js +111 -0
  17. package/dist/lib/texts-fr.d.ts +108 -0
  18. package/dist/lib/texts-fr.js +111 -0
  19. package/dist/lib/texts.d.ts +177 -91
  20. package/dist/lib/texts.js +174 -9
  21. package/dist/molecules/jl-alert.d.ts +1 -0
  22. package/dist/molecules/jl-alert.js +4 -2
  23. package/dist/molecules/jl-breadcrumb.d.ts +2 -0
  24. package/dist/molecules/jl-breadcrumb.js +12 -6
  25. package/dist/molecules/jl-calendar.d.ts +1 -0
  26. package/dist/molecules/jl-calendar.js +7 -4
  27. package/dist/molecules/jl-chip-group.d.ts +1 -0
  28. package/dist/molecules/jl-chip-group.js +4 -1
  29. package/dist/molecules/jl-code-block.js +1 -1
  30. package/dist/molecules/jl-combobox.d.ts +3 -1
  31. package/dist/molecules/jl-combobox.js +12 -7
  32. package/dist/molecules/jl-copy-button.d.ts +1 -0
  33. package/dist/molecules/jl-copy-button.js +7 -5
  34. package/dist/molecules/jl-date-picker.d.ts +1 -0
  35. package/dist/molecules/jl-date-picker.js +10 -7
  36. package/dist/molecules/jl-file-drop.d.ts +1 -0
  37. package/dist/molecules/jl-file-drop.js +15 -6
  38. package/dist/molecules/jl-input-list.d.ts +3 -2
  39. package/dist/molecules/jl-input-list.js +10 -7
  40. package/dist/molecules/jl-load-more.d.ts +4 -2
  41. package/dist/molecules/jl-load-more.js +15 -8
  42. package/dist/molecules/jl-load-state.d.ts +4 -0
  43. package/dist/molecules/jl-load-state.js +13 -9
  44. package/dist/molecules/jl-number-input.d.ts +1 -0
  45. package/dist/molecules/jl-number-input.js +6 -3
  46. package/dist/molecules/jl-pagination.d.ts +2 -0
  47. package/dist/molecules/jl-pagination.js +17 -9
  48. package/dist/molecules/jl-radio-group.d.ts +1 -0
  49. package/dist/molecules/jl-radio-group.js +4 -1
  50. package/dist/molecules/jl-search-button.d.ts +2 -1
  51. package/dist/molecules/jl-search-button.js +6 -4
  52. package/dist/molecules/jl-search.d.ts +2 -0
  53. package/dist/molecules/jl-search.js +9 -3
  54. package/dist/molecules/jl-steps.d.ts +2 -0
  55. package/dist/molecules/jl-steps.js +9 -4
  56. package/dist/molecules/jl-tag-input.d.ts +1 -0
  57. package/dist/molecules/jl-tag-input.js +8 -4
  58. package/dist/molecules/jl-toast.d.ts +1 -0
  59. package/dist/molecules/jl-toast.js +4 -2
  60. package/dist/organisms/jl-command-palette.d.ts +3 -1
  61. package/dist/organisms/jl-command-palette.js +13 -11
  62. package/dist/organisms/jl-confirm.d.ts +3 -0
  63. package/dist/organisms/jl-confirm.js +12 -11
  64. package/dist/organisms/jl-dialog.d.ts +1 -0
  65. package/dist/organisms/jl-dialog.js +4 -2
  66. package/dist/organisms/jl-drawer.d.ts +1 -0
  67. package/dist/organisms/jl-drawer.js +4 -2
  68. package/dist/organisms/jl-flow.d.ts +2 -0
  69. package/dist/organisms/jl-flow.js +25 -16
  70. package/dist/organisms/jl-navbar.d.ts +3 -0
  71. package/dist/organisms/jl-navbar.js +16 -7
  72. package/dist/organisms/jl-side-nav.d.ts +4 -2
  73. package/dist/organisms/jl-side-nav.js +17 -11
  74. package/dist/organisms/jl-tab-bar.d.ts +1 -0
  75. package/dist/organisms/jl-tab-bar.js +5 -2
  76. package/dist/organisms/jl-table.d.ts +2 -1
  77. package/dist/organisms/jl-table.js +9 -6
  78. package/dist/organisms/jl-toaster.d.ts +2 -1
  79. package/dist/organisms/jl-toaster.js +12 -9
  80. package/dist/organisms/jl-tree.d.ts +6 -4
  81. package/dist/organisms/jl-tree.js +21 -15
  82. package/dist/templates/jl-app-shell.d.ts +1 -0
  83. package/dist/templates/jl-app-shell.js +4 -2
  84. package/dist/templates/jl-auth-layout.d.ts +4 -3
  85. package/dist/templates/jl-auth-layout.js +13 -11
  86. package/dist/templates/jl-page.d.ts +1 -0
  87. package/dist/templates/jl-page.js +4 -1
  88. package/dist/templates/jl-split-view.d.ts +1 -0
  89. package/dist/templates/jl-split-view.js +5 -4
  90. package/dist/types/texts.types.d.ts +29 -4
  91. package/package.json +3 -3
@@ -0,0 +1,111 @@
1
+ import { DEFAULT_TEXTS } from "./texts.js";
2
+ import { defineTranslations } from "@jadis/core";
3
+ // src/lib/texts-fr.ts
4
+ /** jlib's texts in French. */
5
+ var texts_fr_default = defineTranslations(DEFAULT_TEXTS, {
6
+ addedNamed: "Ajouté : {names}",
7
+ addTag: "Ajoutez au moins une étiquette.",
8
+ addValue: "Ajouter une valeur",
9
+ authOrigin: "Conçu en Suisse par SyWare",
10
+ back: "Retour",
11
+ breadcrumb: "Fil d'Ariane",
12
+ browse: "Parcourir",
13
+ cancel: "Annuler",
14
+ chooseDate: "Choisir une date",
15
+ chooseDateFrom: "Choisissez le {date} ou plus tard.",
16
+ chooseDateMissing: "Choisissez une date.",
17
+ chooseDateUntil: "Choisissez le {date} ou plus tôt.",
18
+ chooseFile: "Choisissez un fichier.",
19
+ chooseOption: "Choisissez une option.",
20
+ chooseRating: "Choisissez une note.",
21
+ chosenFiles: "Fichiers choisis",
22
+ clear: "Effacer",
23
+ clearSearch: "Effacer la recherche",
24
+ close: "Fermer",
25
+ closeMenu: "Fermer le menu",
26
+ collapseMenu: "Replier le menu",
27
+ commandPalette: "Palette de commandes",
28
+ commandPlaceholder: "Tapez une commande ou cherchez…",
29
+ commands: "Commandes",
30
+ confirm: "Confirmer",
31
+ copied: "Copié",
32
+ copy: "Copier",
33
+ decrease: "Diminuer",
34
+ details: "Détails",
35
+ detailsOf: "Détails de {name}",
36
+ dismiss: "Fermer",
37
+ downloadCancel: "Annuler",
38
+ downloadFailed: "Non téléchargé : {error}",
39
+ downloadPreparing: "Préparation du fichier… {time}",
40
+ downloadReceived: "{received} reçus",
41
+ downloadReceivedOf: "{received} sur {total}",
42
+ downloadSaved: "Enregistré sous {name}, {size}",
43
+ dragToConnect: "Glissez vers un autre nœud pour les relier",
44
+ dropFile: "Déposez un fichier ici",
45
+ dropFiles: "Déposez des fichiers ici",
46
+ expandMenu: "Déplier le menu",
47
+ failedStep: ", en échec",
48
+ fileTooLarge: "dépasse {size}",
49
+ fileTooMany: "est de trop : le champ prend un seul fichier",
50
+ fileUpTo: "jusqu'à {size}",
51
+ fileWrongType: "n'est pas d'un type accepté ({types})",
52
+ fillField: "Veuillez remplir ce champ.",
53
+ fitView: "Afficher tous les nœuds",
54
+ flow: "Flux",
55
+ flowEmpty: "Rien ici pour l'instant.",
56
+ hidePassword: "Masquer le mot de passe",
57
+ increase: "Augmenter",
58
+ leave: "Quitter",
59
+ leaveHeading: "Quitter sans enregistrer ?",
60
+ leaveText: "Vos modifications seront perdues.",
61
+ loadError: "Le chargement n'a pas abouti.",
62
+ loading: "Chargement",
63
+ loadingMore: "Chargement…",
64
+ loadStateError: "Vérifiez la connexion, puis réessayez. Rien n'a été modifié.",
65
+ loadStateHeading: "Le chargement n'a pas abouti",
66
+ mainNavigation: "Principal",
67
+ menu: "Menu",
68
+ navigation: "Navigation",
69
+ nextMonth: "Mois suivant",
70
+ nextPage: "Page suivante",
71
+ noCommands: "Aucune commande ne correspond",
72
+ noData: "Aucune donnée",
73
+ node: "nœud",
74
+ noRating: "Aucune note",
75
+ noResults: "Aucun résultat",
76
+ notifications: "Notifications",
77
+ page: "Page",
78
+ pageNumber: "Page {page}",
79
+ pageOfTotal: "{page} sur {total}",
80
+ pagination: "Pagination",
81
+ previousMonth: "Mois précédent",
82
+ previousPage: "Page précédente",
83
+ progress: "Progression",
84
+ rating: "Note",
85
+ ratingOf: "{value} sur {max}",
86
+ remove: "Retirer",
87
+ removedNamed: "Retiré : {name}",
88
+ removeEdge: "Retirer ce lien",
89
+ removeNamed: "Retirer {name}",
90
+ removeValue: "Retirer cette valeur",
91
+ resizePanes: "Redimensionner les panneaux",
92
+ retry: "Réessayer",
93
+ search: "Rechercher",
94
+ selectAllRows: "Sélectionner toutes les lignes",
95
+ selectNamed: "Sélectionner {name}",
96
+ selectOption: "Veuillez choisir une de ces options.",
97
+ shortcuts: "Raccourcis",
98
+ showMore: "Afficher plus",
99
+ showMoreCount: "Afficher {count} de plus",
100
+ shownOfTotal: "{shown} sur {total}",
101
+ showOptions: "Afficher les options",
102
+ showPagesOf: "Afficher les pages de {name}",
103
+ showPassword: "Afficher le mot de passe",
104
+ stay: "Continuer l'édition",
105
+ stepCurrent: ", étape en cours",
106
+ stepDone: ", terminée",
107
+ tidyLayout: "Ranger la disposition",
108
+ zoomIn: "Zoomer",
109
+ zoomOut: "Dézoomer"
110
+ });
111
+ export { texts_fr_default as default };
@@ -1,99 +1,185 @@
1
- import type { JlTextKey, JlTexts } from '../types/texts.types';
1
+ import { Bus } from '@jadis/core';
2
+ import type { PlaceholderValue, TranslationArgs, TranslationLoader, TranslationOf } from '@jadis/core';
3
+ import type { AddedLocale, FollowedTranslator, JlLanguage, JlLanguageTexts, JlSourceTexts, JlTextKey } from '../types/texts.types';
4
+ /** The languages jlib translates itself. English is shown until a page chooses another, and every text's source. */
5
+ export declare const JL_LANGUAGES: readonly ['en', 'fr', 'de'];
2
6
  /**
3
7
  * Every text jlib's components show or say on their own, in English: labels for screen readers, buttons, states,
4
8
  * the defaults of their text inputs. `{placeholders}` are filled when the text is shown.
5
9
  */
6
10
  export declare const DEFAULT_TEXTS: {
7
- readonly addTag: 'Add at least one tag.';
8
- readonly addValue: 'Add a value';
9
- readonly back: 'Back';
10
- readonly breadcrumb: 'Breadcrumb';
11
- readonly browse: 'Browse';
12
- readonly chooseDate: 'Choose a date';
13
- readonly chooseDateMissing: 'Choose a date.';
14
- readonly chooseFile: 'Choose a file.';
15
- readonly chooseOption: 'Choose an option.';
16
- readonly chooseRating: 'Choose a rating.';
17
- readonly chosenFiles: 'Chosen files';
18
- readonly clear: 'Clear';
19
- readonly clearSearch: 'Clear the search';
20
- readonly close: 'Close';
21
- readonly closeMenu: 'Close the menu';
22
- readonly collapseMenu: 'Collapse the menu';
23
- readonly commandPalette: 'Command palette';
24
- readonly commandPlaceholder: 'Type a command or search…';
25
- readonly commands: 'Commands';
26
- readonly copied: 'Copied';
27
- readonly copy: 'Copy';
28
- readonly decrease: 'Decrease';
29
- readonly details: 'Details';
30
- readonly detailsOf: 'Details of {name}';
31
- readonly dismiss: 'Dismiss';
32
- readonly downloadCancel: 'Cancel';
33
- readonly downloadFailed: 'Not downloaded: {error}';
34
- readonly downloadPreparing: 'Preparing the file… {time}';
35
- readonly downloadReceived: '{received} received';
36
- readonly downloadReceivedOf: '{received} of {total}';
37
- readonly downloadSaved: 'Saved as {name}, {size}';
38
- readonly dragToConnect: 'Drag to another node to connect';
39
- readonly dropFile: 'Drop a file here';
40
- readonly dropFiles: 'Drop files here';
41
- readonly expandMenu: 'Expand the menu';
42
- readonly failedStep: ', failed';
43
- readonly fileTooLarge: 'is larger than {size}';
44
- readonly fileTooMany: 'is one too many: the field takes a single file';
45
- readonly fileUpTo: 'up to {size}';
46
- readonly fileWrongType: 'is not an accepted type ({types})';
47
- readonly fillField: 'Please fill in this field.';
48
- readonly fitView: 'Show every node';
49
- readonly flow: 'Flow';
50
- readonly hidePassword: 'Hide the password';
51
- readonly increase: 'Increase';
52
- readonly leave: 'Leave';
53
- readonly leaveText: 'Your changes are lost.';
54
- readonly loadError: 'This could not be loaded.';
55
- readonly loading: 'Loading';
56
- readonly loadingMore: 'Loading…';
57
- readonly loadStateError: 'Check the connection, then try again. Nothing was changed.';
58
- readonly mainNavigation: 'Main';
59
- readonly menu: 'Menu';
60
- readonly navigation: 'Navigation';
61
- readonly nextMonth: 'Next month';
62
- readonly nextPage: 'Next page';
63
- readonly noCommands: 'No matching commands';
64
- readonly noData: 'No data';
65
- readonly noResults: 'No results';
66
- readonly notifications: 'Notifications';
67
- readonly pagination: 'Pagination';
68
- readonly previousMonth: 'Previous month';
69
- readonly previousPage: 'Previous page';
70
- readonly progress: 'Progress';
71
- readonly rating: 'Rating';
72
- readonly remove: 'Remove';
73
- readonly removeEdge: 'Remove this edge';
74
- readonly removeNamed: 'Remove {name}';
75
- readonly removeValue: 'Remove this value';
76
- readonly resizePanes: 'Resize the panes';
77
- readonly retry: 'Try again';
78
- readonly search: 'Search';
79
- readonly selectOption: 'Please select one of these options.';
80
- readonly shortcuts: 'Shortcuts';
81
- readonly showMore: 'Show more';
82
- readonly showMoreCount: 'Show {count} more';
83
- readonly shownOfTotal: '{shown} of {total}';
84
- readonly showOptions: 'Show the options';
85
- readonly showPassword: 'Show the password';
86
- readonly stay: 'Keep editing';
87
- readonly stepCurrent: ', current step';
88
- readonly stepDone: ', completed';
89
- readonly tidyLayout: 'Tidy up the layout';
90
- readonly zoomIn: 'Zoom in';
91
- readonly zoomOut: 'Zoom out';
11
+ readonly addedNamed: "Added {names}";
12
+ readonly addTag: "Add at least one tag.";
13
+ readonly addValue: "Add a value";
14
+ readonly authOrigin: "Made in Switzerland by SyWare";
15
+ readonly back: "Back";
16
+ readonly breadcrumb: "Breadcrumb";
17
+ readonly browse: "Browse";
18
+ readonly cancel: "Cancel";
19
+ readonly chooseDate: "Choose a date";
20
+ readonly chooseDateFrom: "Choose {date} or later.";
21
+ readonly chooseDateMissing: "Choose a date.";
22
+ readonly chooseDateUntil: "Choose {date} or earlier.";
23
+ readonly chooseFile: "Choose a file.";
24
+ readonly chooseOption: "Choose an option.";
25
+ readonly chooseRating: "Choose a rating.";
26
+ readonly chosenFiles: "Chosen files";
27
+ readonly clear: "Clear";
28
+ readonly clearSearch: "Clear the search";
29
+ readonly close: "Close";
30
+ readonly closeMenu: "Close the menu";
31
+ readonly collapseMenu: "Collapse the menu";
32
+ readonly commandPalette: "Command palette";
33
+ readonly commandPlaceholder: "Type a command or search…";
34
+ readonly commands: "Commands";
35
+ readonly confirm: "Confirm";
36
+ readonly copied: "Copied";
37
+ readonly copy: "Copy";
38
+ readonly decrease: "Decrease";
39
+ readonly details: "Details";
40
+ readonly detailsOf: "Details of {name}";
41
+ readonly dismiss: "Dismiss";
42
+ readonly downloadCancel: "Cancel";
43
+ readonly downloadFailed: "Not downloaded: {error}";
44
+ readonly downloadPreparing: "Preparing the file… {time}";
45
+ readonly downloadReceived: "{received} received";
46
+ readonly downloadReceivedOf: "{received} of {total}";
47
+ readonly downloadSaved: "Saved as {name}, {size}";
48
+ readonly dragToConnect: "Drag to another node to connect";
49
+ readonly dropFile: "Drop a file here";
50
+ readonly dropFiles: "Drop files here";
51
+ readonly expandMenu: "Expand the menu";
52
+ readonly failedStep: ", failed";
53
+ readonly fileTooLarge: "is larger than {size}";
54
+ readonly fileTooMany: "is one too many: the field takes a single file";
55
+ readonly fileUpTo: "up to {size}";
56
+ readonly fileWrongType: "is not an accepted type ({types})";
57
+ readonly fillField: "Please fill in this field.";
58
+ readonly fitView: "Show every node";
59
+ readonly flow: "Flow";
60
+ readonly flowEmpty: "Nothing here yet.";
61
+ readonly hidePassword: "Hide the password";
62
+ readonly increase: "Increase";
63
+ readonly leave: "Leave";
64
+ readonly leaveHeading: "Leave without saving?";
65
+ readonly leaveText: "Your changes are lost.";
66
+ readonly loadError: "This could not be loaded.";
67
+ readonly loading: "Loading";
68
+ readonly loadingMore: "Loading…";
69
+ readonly loadStateError: "Check the connection, then try again. Nothing was changed.";
70
+ readonly loadStateHeading: "This could not be loaded";
71
+ readonly mainNavigation: "Main";
72
+ readonly menu: "Menu";
73
+ readonly navigation: "Navigation";
74
+ readonly nextMonth: "Next month";
75
+ readonly nextPage: "Next page";
76
+ readonly noCommands: "No matching commands";
77
+ readonly noData: "No data";
78
+ readonly node: "node";
79
+ readonly noRating: "No rating";
80
+ readonly noResults: "No results";
81
+ readonly notifications: "Notifications";
82
+ readonly page: "Page";
83
+ readonly pageNumber: "Page {page}";
84
+ readonly pageOfTotal: "{page} of {total}";
85
+ readonly pagination: "Pagination";
86
+ readonly previousMonth: "Previous month";
87
+ readonly previousPage: "Previous page";
88
+ readonly progress: "Progress";
89
+ readonly rating: "Rating";
90
+ readonly ratingOf: "{value} of {max}";
91
+ readonly remove: "Remove";
92
+ readonly removedNamed: "Removed {name}";
93
+ readonly removeEdge: "Remove this edge";
94
+ readonly removeNamed: "Remove {name}";
95
+ readonly removeValue: "Remove this value";
96
+ readonly resizePanes: "Resize the panes";
97
+ readonly retry: "Try again";
98
+ readonly search: "Search";
99
+ readonly selectAllRows: "Select all rows";
100
+ readonly selectNamed: "Select {name}";
101
+ readonly selectOption: "Please select one of these options.";
102
+ readonly shortcuts: "Shortcuts";
103
+ readonly showMore: "Show more";
104
+ readonly showMoreCount: "Show {count} more";
105
+ readonly shownOfTotal: "{shown} of {total}";
106
+ readonly showOptions: "Show the options";
107
+ readonly showPagesOf: "Show the pages of {name}";
108
+ readonly showPassword: "Show the password";
109
+ readonly stay: "Keep editing";
110
+ readonly stepCurrent: ", current step";
111
+ readonly stepDone: ", completed";
112
+ readonly tidyLayout: "Tidy up the layout";
113
+ readonly zoomIn: "Zoom in";
114
+ readonly zoomOut: "Zoom out";
92
115
  };
93
116
  /**
94
- * Gives jlib's components their texts in the page's language, before they are drawn: once at start, as a page
95
- * reads its own messages. A text left out stays English.
117
+ * jlib's texts, in the language they are shown in: English until a page chooses another. jlib translates English,
118
+ * French and German itself; a page fixes some of their texts, adds a language, or has them follow its translator.
96
119
  */
97
- export declare function setTexts(texts: JlTexts): void;
98
- /** One of jlib's texts, in the language the page set, its `{placeholders}` filled. */
99
- export declare const jlText: (key: JlTextKey, values?: Readonly<Record<string, string>>) => string;
120
+ declare class JlTexts {
121
+ /** Emits `change` with the locale shown, once its texts are the ones `jlText` gives. */
122
+ readonly bus: Bus<{
123
+ change: string;
124
+ }>;
125
+ private readonly _languages;
126
+ private readonly _fixes;
127
+ private readonly _loaded;
128
+ private _shown;
129
+ /** The locale asked last: a slower load asked before it is not shown. */
130
+ private _wanted;
131
+ private _following?;
132
+ /** The locale whose texts are shown. */
133
+ get locale(): string;
134
+ /**
135
+ * Shows jlib's texts in a locale: its own, else its language's (`fr-CH` shows `fr`), with the fixes given for
136
+ * either. Loads them the first time, then emits `change`. When it is called again before the texts are loaded,
137
+ * the locale asked last wins.
138
+ * @throws When jlib has no texts for the locale: add them with `add`.
139
+ */
140
+ setLocale(locale: string): Promise<void>;
141
+ /**
142
+ * Fixes some of jlib's texts in one locale, each with the placeholders of its English text. Fixes given for a
143
+ * language (`de`) apply to its regions (`de-CH`) too.
144
+ */
145
+ fix<const T>(locale: string, fixes: T extends Partial<TranslationOf<T, JlSourceTexts>> ? T : Partial<TranslationOf<T, JlSourceTexts>>): void;
146
+ /**
147
+ * Adds a language jlib does not translate: one of jlib's own languages shown for it (`add('es', 'en')`), or all
148
+ * of jlib's texts in it, as they are or with their loader (`add('es', () => import('./jl-es'))`).
149
+ */
150
+ add<const Locale extends string>(locale: AddedLocale<Locale>, language: JlLanguage): void;
151
+ add<const Locale extends string>(locale: AddedLocale<Locale>, loader: TranslationLoader<JlLanguageTexts>): void;
152
+ add<const Locale extends string, const T>(locale: AddedLocale<Locale>, texts: T extends TranslationOf<T, JlSourceTexts> ? T : TranslationOf<T, JlSourceTexts>): void;
153
+ /**
154
+ * Shows jlib's texts in the language of a translator, now and at each of its changes. Loads them for each of
155
+ * its locales first, so they change with the page's own texts.
156
+ * @throws When jlib has no texts for one of the translator's locales: add them with `add`.
157
+ */
158
+ follow<Locale extends string>(translator: FollowedTranslator<Locale>): Promise<void>;
159
+ /** A text in the locale shown, its placeholders filled; a number is written the way the locale writes it. */
160
+ text(key: JlTextKey, values: Readonly<Record<string, PlaceholderValue>>): string;
161
+ /** A text in the locale shown, as it is written. */
162
+ template(key: JlTextKey): string;
163
+ private assertShown;
164
+ /** The language whose texts a locale shows: its own, else its language's. */
165
+ private languageFor;
166
+ private compose;
167
+ /** A language's texts; a load that fails is forgotten, so the next `setLocale` tries again. */
168
+ private textsOf;
169
+ private read;
170
+ private shows;
171
+ private redrawWhenShown;
172
+ private redraw;
173
+ private show;
174
+ private formatted;
175
+ }
176
+ /** jlib's texts: shown in English until a page chooses another language, or has them follow its translator. */
177
+ export declare const jlTexts: JlTexts;
178
+ /** One of jlib's texts, in the language shown, its `{placeholders}` filled. */
179
+ export declare function jlText<K extends JlTextKey>(key: K, ...params: TranslationArgs<JlSourceTexts, K>): string;
180
+ /**
181
+ * One of jlib's texts in the language shown, as it is written, its `{placeholders}` left for the component to fill:
182
+ * the default of an input that holds a text with placeholders.
183
+ */
184
+ export declare const jlTemplate: (key: JlTextKey) => string;
185
+ export {};
package/dist/lib/texts.js CHANGED
@@ -1,17 +1,32 @@
1
+ import { safeLocale } from "./locale.js";
1
2
  import { fillText } from "./text.js";
3
+ import { Bus, assert, defineTranslations } from "@jadis/core";
2
4
  // src/lib/texts.ts
5
+ /** The languages jlib translates itself. English is shown until a page chooses another, and every text's source. */
6
+ var JL_LANGUAGES = [
7
+ "en",
8
+ "fr",
9
+ "de"
10
+ ];
11
+ var DEFAULT_LANGUAGE = "en";
12
+ var LOCALE_SEPARATOR = "-";
3
13
  /**
4
14
  * Every text jlib's components show or say on their own, in English: labels for screen readers, buttons, states,
5
15
  * the defaults of their text inputs. `{placeholders}` are filled when the text is shown.
6
16
  */
7
- var DEFAULT_TEXTS = {
17
+ var DEFAULT_TEXTS = defineTranslations({
18
+ addedNamed: "Added {names}",
8
19
  addTag: "Add at least one tag.",
9
20
  addValue: "Add a value",
21
+ authOrigin: "Made in Switzerland by SyWare",
10
22
  back: "Back",
11
23
  breadcrumb: "Breadcrumb",
12
24
  browse: "Browse",
25
+ cancel: "Cancel",
13
26
  chooseDate: "Choose a date",
27
+ chooseDateFrom: "Choose {date} or later.",
14
28
  chooseDateMissing: "Choose a date.",
29
+ chooseDateUntil: "Choose {date} or earlier.",
15
30
  chooseFile: "Choose a file.",
16
31
  chooseOption: "Choose an option.",
17
32
  chooseRating: "Choose a rating.",
@@ -24,6 +39,7 @@ var DEFAULT_TEXTS = {
24
39
  commandPalette: "Command palette",
25
40
  commandPlaceholder: "Type a command or search…",
26
41
  commands: "Commands",
42
+ confirm: "Confirm",
27
43
  copied: "Copied",
28
44
  copy: "Copy",
29
45
  decrease: "Decrease",
@@ -48,14 +64,17 @@ var DEFAULT_TEXTS = {
48
64
  fillField: "Please fill in this field.",
49
65
  fitView: "Show every node",
50
66
  flow: "Flow",
67
+ flowEmpty: "Nothing here yet.",
51
68
  hidePassword: "Hide the password",
52
69
  increase: "Increase",
53
70
  leave: "Leave",
71
+ leaveHeading: "Leave without saving?",
54
72
  leaveText: "Your changes are lost.",
55
73
  loadError: "This could not be loaded.",
56
74
  loading: "Loading",
57
75
  loadingMore: "Loading…",
58
76
  loadStateError: "Check the connection, then try again. Nothing was changed.",
77
+ loadStateHeading: "This could not be loaded",
59
78
  mainNavigation: "Main",
60
79
  menu: "Menu",
61
80
  navigation: "Navigation",
@@ -63,26 +82,36 @@ var DEFAULT_TEXTS = {
63
82
  nextPage: "Next page",
64
83
  noCommands: "No matching commands",
65
84
  noData: "No data",
85
+ node: "node",
86
+ noRating: "No rating",
66
87
  noResults: "No results",
67
88
  notifications: "Notifications",
89
+ page: "Page",
90
+ pageNumber: "Page {page}",
91
+ pageOfTotal: "{page} of {total}",
68
92
  pagination: "Pagination",
69
93
  previousMonth: "Previous month",
70
94
  previousPage: "Previous page",
71
95
  progress: "Progress",
72
96
  rating: "Rating",
97
+ ratingOf: "{value} of {max}",
73
98
  remove: "Remove",
99
+ removedNamed: "Removed {name}",
74
100
  removeEdge: "Remove this edge",
75
101
  removeNamed: "Remove {name}",
76
102
  removeValue: "Remove this value",
77
103
  resizePanes: "Resize the panes",
78
104
  retry: "Try again",
79
105
  search: "Search",
106
+ selectAllRows: "Select all rows",
107
+ selectNamed: "Select {name}",
80
108
  selectOption: "Please select one of these options.",
81
109
  shortcuts: "Shortcuts",
82
110
  showMore: "Show more",
83
111
  showMoreCount: "Show {count} more",
84
112
  shownOfTotal: "{shown} of {total}",
85
113
  showOptions: "Show the options",
114
+ showPagesOf: "Show the pages of {name}",
86
115
  showPassword: "Show the password",
87
116
  stay: "Keep editing",
88
117
  stepCurrent: ", current step",
@@ -90,15 +119,151 @@ var DEFAULT_TEXTS = {
90
119
  tidyLayout: "Tidy up the layout",
91
120
  zoomIn: "Zoom in",
92
121
  zoomOut: "Zoom out"
122
+ });
123
+ /** jlib's other languages, each loaded the first time it is shown. */
124
+ var LANGUAGE_LOADERS = {
125
+ de: () => import("./texts-de.js"),
126
+ fr: () => import("./texts-fr.js")
93
127
  };
94
- var current = { ...DEFAULT_TEXTS };
128
+ var missingLanguages = (locales) => `jlib has no texts for ${locales.join(", ")}: add them with jlTexts.add('${locales[0]}', …), or show one of jlib's languages for it with jlTexts.add('${locales[0]}', 'en')`;
129
+ var languageOf = (locale) => (locale.split(LOCALE_SEPARATOR)[0] ?? locale).toLowerCase();
130
+ var isJlLanguage = (value) => JL_LANGUAGES.some((language) => language === value);
95
131
  /**
96
- * Gives jlib's components their texts in the page's language, before they are drawn: once at start, as a page
97
- * reads its own messages. A text left out stays English.
132
+ * jlib's texts, in the language they are shown in: English until a page chooses another. jlib translates English,
133
+ * French and German itself; a page fixes some of their texts, adds a language, or has them follow its translator.
98
134
  */
99
- function setTexts(texts) {
100
- Object.assign(current, texts);
135
+ var JlTexts = class {
136
+ /** Emits `change` with the locale shown, once its texts are the ones `jlText` gives. */
137
+ bus = new Bus();
138
+ _languages = new Map([[DEFAULT_LANGUAGE, DEFAULT_TEXTS], ...Object.entries(LANGUAGE_LOADERS)]);
139
+ _fixes = /* @__PURE__ */ new Map();
140
+ _loaded = /* @__PURE__ */ new Map();
141
+ _shown = {
142
+ locale: DEFAULT_LANGUAGE,
143
+ numbers: new Intl.NumberFormat(DEFAULT_LANGUAGE),
144
+ texts: DEFAULT_TEXTS
145
+ };
146
+ /** The locale asked last: a slower load asked before it is not shown. */
147
+ _wanted = DEFAULT_LANGUAGE;
148
+ _following;
149
+ /** The locale whose texts are shown. */
150
+ get locale() {
151
+ return this._shown.locale;
152
+ }
153
+ /**
154
+ * Shows jlib's texts in a locale: its own, else its language's (`fr-CH` shows `fr`), with the fixes given for
155
+ * either. Loads them the first time, then emits `change`. When it is called again before the texts are loaded,
156
+ * the locale asked last wins.
157
+ * @throws When jlib has no texts for the locale: add them with `add`.
158
+ */
159
+ async setLocale(locale) {
160
+ this.assertShown([locale]);
161
+ this._wanted = locale;
162
+ const texts = await this.compose(locale);
163
+ if (this._wanted !== locale || this._shown.locale === locale) return;
164
+ this.show(locale, texts);
165
+ }
166
+ fix(locale, fixes) {
167
+ this._fixes.set(locale, {
168
+ ...this._fixes.get(locale),
169
+ ...fixes
170
+ });
171
+ this.redrawWhenShown(locale);
172
+ }
173
+ add(locale, entry) {
174
+ assert(!isJlLanguage(locale), `jlib translates ${locale} itself: fix its texts with jlTexts.fix('${locale}', …)`);
175
+ this._languages.set(locale, entry);
176
+ this._loaded.delete(locale);
177
+ this.redrawWhenShown(locale);
178
+ }
179
+ /**
180
+ * Shows jlib's texts in the language of a translator, now and at each of its changes. Loads them for each of
181
+ * its locales first, so they change with the page's own texts.
182
+ * @throws When jlib has no texts for one of the translator's locales: add them with `add`.
183
+ */
184
+ async follow(translator) {
185
+ this.assertShown(translator.locales);
186
+ this._following?.abort();
187
+ this._following = new AbortController();
188
+ translator.bus.register("change", (locale) => void this.setLocale(locale), this._following.signal);
189
+ await Promise.all(translator.locales.map((locale) => this.compose(locale)));
190
+ await this.setLocale(translator.locale);
191
+ }
192
+ /** A text in the locale shown, its placeholders filled; a number is written the way the locale writes it. */
193
+ text(key, values) {
194
+ return fillText(this._shown.texts[key], this.formatted(values));
195
+ }
196
+ /** A text in the locale shown, as it is written. */
197
+ template(key) {
198
+ return this._shown.texts[key];
199
+ }
200
+ assertShown(locales) {
201
+ const missing = locales.filter((locale) => this.languageFor(locale) === void 0);
202
+ assert(missing.length === 0, missingLanguages(missing));
203
+ }
204
+ /** The language whose texts a locale shows: its own, else its language's. */
205
+ languageFor(locale) {
206
+ if (this._languages.has(locale)) return locale;
207
+ const language = languageOf(locale);
208
+ return this._languages.has(language) ? language : void 0;
209
+ }
210
+ async compose(locale) {
211
+ const language = this.languageFor(locale) ?? DEFAULT_LANGUAGE;
212
+ const texts = await this.textsOf(language);
213
+ const ownFixes = locale === language ? void 0 : this._fixes.get(locale);
214
+ return {
215
+ ...texts,
216
+ ...this._fixes.get(language),
217
+ ...ownFixes
218
+ };
219
+ }
220
+ /** A language's texts; a load that fails is forgotten, so the next `setLocale` tries again. */
221
+ textsOf(language) {
222
+ const known = this._loaded.get(language);
223
+ if (known) return known;
224
+ const loading = this.read(language);
225
+ this._loaded.set(language, loading);
226
+ loading.catch(() => this._loaded.delete(language));
227
+ return loading;
228
+ }
229
+ async read(language) {
230
+ const entry = this._languages.get(language) ?? DEFAULT_TEXTS;
231
+ if (isJlLanguage(entry)) return this.textsOf(entry);
232
+ return typeof entry === "function" ? (await entry()).default : entry;
233
+ }
234
+ shows(locale) {
235
+ return this._shown.locale === locale || this.languageFor(this._shown.locale) === locale;
236
+ }
237
+ redrawWhenShown(locale) {
238
+ if (!this.shows(locale)) return;
239
+ this.redraw();
240
+ }
241
+ async redraw() {
242
+ const { locale } = this._shown;
243
+ const texts = await this.compose(locale);
244
+ if (this._wanted !== locale) return;
245
+ this.show(locale, texts);
246
+ }
247
+ show(locale, texts) {
248
+ this._shown = {
249
+ locale,
250
+ numbers: new Intl.NumberFormat(safeLocale(locale)),
251
+ texts
252
+ };
253
+ this.bus.emit("change", locale);
254
+ }
255
+ formatted(values) {
256
+ return Object.fromEntries(Object.entries(values).map(([name, value]) => [name, typeof value === "number" ? this._shown.numbers.format(value) : value]));
257
+ }
258
+ };
259
+ /** jlib's texts: shown in English until a page chooses another language, or has them follow its translator. */
260
+ var jlTexts = new JlTexts();
261
+ function jlText(key, values = {}) {
262
+ return jlTexts.text(key, values);
101
263
  }
102
- /** One of jlib's texts, in the language the page set, its `{placeholders}` filled. */
103
- var jlText = (key, values = {}) => fillText(current[key], values);
104
- export { DEFAULT_TEXTS, jlText, setTexts };
264
+ /**
265
+ * One of jlib's texts in the language shown, as it is written, its `{placeholders}` left for the component to fill:
266
+ * the default of an input that holds a text with placeholders.
267
+ */
268
+ var jlTemplate = (key) => jlTexts.template(key);
269
+ export { DEFAULT_TEXTS, JL_LANGUAGES, jlTemplate, jlText, jlTexts };
@@ -38,6 +38,7 @@ export declare class JlAlert extends JlElement {
38
38
  dismiss(): void;
39
39
  templateHtml(): Node;
40
40
  templateCss(): string;
41
+ protected drawTexts(): void;
41
42
  onConnect(): void;
42
43
  /** Empty parts take no room: an alert with only a description has no blank line under it. */
43
44
  private renderSlots;