slint-ui 1.9.0-nightly.2024101004 → 1.9.0-nightly.2024101112

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/Cargo.toml CHANGED
@@ -41,10 +41,10 @@ accessibility = ["slint-interpreter/accessibility"]
41
41
  [dependencies]
42
42
  napi = { version = "2.14.0", default-features = false, features = ["napi8"] }
43
43
  napi-derive = "2.14.0"
44
- i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "499a522f993e107a1c1195b1119aa04d2fb17a6c", version = "=1.9.0", default-features = false }
45
- i-slint-core = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "499a522f993e107a1c1195b1119aa04d2fb17a6c", version = "=1.9.0", default-features = false }
46
- i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "499a522f993e107a1c1195b1119aa04d2fb17a6c", version = "=1.9.0", default-features = false }
47
- slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "499a522f993e107a1c1195b1119aa04d2fb17a6c", version = "=1.9.0"}
44
+ i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "f8f1d468a0aba1b11e7f9fb71739e46a178d4415", version = "=1.9.0", default-features = false }
45
+ i-slint-core = { features = ["default", "gettext-rs"] , git = "https://github.com/slint-ui/slint", rev = "f8f1d468a0aba1b11e7f9fb71739e46a178d4415", version = "=1.9.0", default-features = false }
46
+ i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "f8f1d468a0aba1b11e7f9fb71739e46a178d4415", version = "=1.9.0", default-features = false }
47
+ slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "f8f1d468a0aba1b11e7f9fb71739e46a178d4415", version = "=1.9.0"}
48
48
  spin_on = { version = "0.1" }
49
49
  css-color-parser2 = { version = "1.0.1" }
50
50
  itertools = { version = "0.13" }
package/README.md CHANGED
@@ -57,7 +57,7 @@ Combining these two steps leads us to the obligatory "Hello World" example:
57
57
 
58
58
  ```js
59
59
  import * as slint from "slint-ui";
60
- let ui = slint.loadFile(".ui/main.slint");
60
+ let ui = slint.loadFile(new URL(".ui/main.slint", import.meta.url));
61
61
  let main = new ui.Main();
62
62
  main.run();
63
63
  ```
@@ -94,7 +94,7 @@ an object which allow to initialize the value of public properties or callbacks.
94
94
  import * as slint from "slint-ui";
95
95
  // In this example, the main.slint file exports a module which
96
96
  // has a counter property and a clicked callback
97
- let ui = slint.loadFile("ui/main.slint");
97
+ let ui = slint.loadFile(new URL("ui/main.slint", import.meta.url));
98
98
  let component = new ui.MainWindow({
99
99
  counter: 42,
100
100
  clicked: function() { console.log("hello"); }
@@ -135,7 +135,7 @@ The callbacks in Slint are exposed as properties in JavaScript and that can be c
135
135
  ```js
136
136
  import * as slint from "slint-ui";
137
137
 
138
- let ui = slint.loadFile("ui/my-component.slint");
138
+ let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
139
139
  let component = new ui.MyComponent();
140
140
 
141
141
  // connect to a callback
@@ -168,7 +168,7 @@ If the function is marked `public`, it can also be called from JavaScript.
168
168
  ```js
169
169
  import * as slint from "slint-ui";
170
170
 
171
- let ui = slint.loadFile("ui/my-component.slint");
171
+ let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
172
172
  let component = new ui.MyComponent();
173
173
 
174
174
  // call a public function
@@ -297,7 +297,7 @@ export component MyComponent inherits Window {
297
297
 
298
298
  import * as slint from "slint-ui";
299
299
 
300
- let ui = slint.loadFile("my-component.slint");
300
+ let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
301
301
  let component = new ui.MyComponent();
302
302
 
303
303
  // object literal
@@ -333,7 +333,7 @@ export component MyComponent inherits Window {
333
333
 
334
334
  import * as slint from "slint-ui";
335
335
 
336
- let ui = slint.loadFile("my-component.slint");
336
+ let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
337
337
  let component = new ui.MyComponent();
338
338
 
339
339
  // set enum value as string
package/cover.md CHANGED
@@ -66,9 +66,9 @@ This file declares the user interface.
66
66
 
67
67
  4. Create a new file called `index.mjs` with the following contents:
68
68
 
69
- ```
69
+ ```js
70
70
  import * as slint from "slint-ui";
71
- let ui = slint.loadFile("main.slint");
71
+ let ui = slint.loadFile(new URL("main.slint", import.meta.url));
72
72
  let demo = new ui.Demo();
73
73
 
74
74
  await demo.run();
@@ -124,9 +124,9 @@ This file declares the user interface.
124
124
 
125
125
  3. Create a new file called `index.ts` with the following contents:
126
126
 
127
- ```
127
+ ```ts
128
128
  import * as slint from "slint-ui";
129
- let ui = slint.loadFile("main.slint");
129
+ let ui = slint.loadFile(new URL("main.slint", import.meta.url));
130
130
  let demo = new ui.Demo();
131
131
 
132
132
  await demo.run();
@@ -142,6 +142,54 @@ This is your main JavaScript entry point:
142
142
 
143
143
  1. Run the example with `deno run --allow-read --allow-ffi --allow-sys index.ts`
144
144
 
145
+
146
+ ## Getting Started (bun)
147
+
148
+ 1. In a new directory, create a new `bun` project by calling [`bun init`](https://bun.sh/docs/cli/init).
149
+ 2. Install Slint for your project using [`bun install slint-ui`](https://bun.sh/docs/cli/install).
150
+ 3. Create a new file called `main.slint` with the following contents:
151
+
152
+ ```
153
+ import { AboutSlint, Button, VerticalBox } from "std-widgets.slint";
154
+ export component Demo inherits Window {
155
+ in-out property <string> greeting <=> label.text;
156
+ VerticalBox {
157
+ alignment: start;
158
+ label := Text {
159
+ text: "Hello World!";
160
+ font-size: 24px;
161
+ horizontal-alignment: center;
162
+ }
163
+ AboutSlint {
164
+ preferred-height: 150px;
165
+ }
166
+ HorizontalLayout { alignment: center; Button { text: "OK!"; } }
167
+ }
168
+ }
169
+ ```
170
+
171
+ This file declares the user interface.
172
+
173
+ 4. Clear the conent of`index.ts` and add the following code:
174
+
175
+ ```ts
176
+ import * as slint from "slint-ui";
177
+ let ui = slint.loadFile(new URL("main.slint", import.meta.url)) as any;
178
+ let demo = new ui.Demo();
179
+
180
+ await demo.run();
181
+ ```
182
+
183
+ This is your main TypeScript entry point:
184
+
185
+ * Import the Slint API as an [ECMAScript module](https://nodejs.org/api/esm.html#modules-ecmascript-modules) module.
186
+ * Invoke `loadFile()` to compile and load the `.slint` file.
187
+ * Instantiate the `Demo` component declared in `main.slint`.
188
+ * Run it by showing it on the screen and reacting to user input.
189
+
190
+ 5. Run the example with `bun run index.ts`
191
+
192
+
145
193
  ## API Overview
146
194
 
147
195
  ### Instantiating a Component
@@ -176,7 +224,7 @@ an object which allow to initialize the value of public properties or callbacks.
176
224
  import * as slint from "slint-ui";
177
225
  // In this example, the main.slint file exports a module which
178
226
  // has a counter property and a clicked callback
179
- let ui = slint.loadFile("ui/main.slint");
227
+ let ui = slint.loadFile(new URL("ui/main.slint", import.meta.url));
180
228
  let component = new ui.MainWindow({
181
229
  counter: 42,
182
230
  clicked: function() { console.log("hello"); }
@@ -194,7 +242,7 @@ export component MainWindow {
194
242
  }
195
243
 
196
244
  ```js
197
- let ui = slint.loadFile("main.slint");
245
+ let ui = slint.loadFile(new URL("main.slint", import.meta.url));
198
246
  let instance = new ui.MainWindow();
199
247
  console.log(instance.age); // Prints 42
200
248
  instance.name = "Joe";
@@ -223,7 +271,7 @@ export component MyComponent inherits Window {
223
271
  ```js
224
272
  import * as slint from "slint-ui";
225
273
 
226
- let ui = slint.loadFile("ui/my-component.slint");
274
+ let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
227
275
  let component = new ui.MyComponent();
228
276
 
229
277
  // connect to a callback
@@ -271,6 +319,75 @@ component.model = component.model.concat(4);
271
319
 
272
320
  Another option is to set an object that implements the {@link Model} interface.
273
321
 
322
+ ### structs
323
+
324
+ An exported struct can be created either by defing of an object literal or by using the new keyword.
325
+
326
+ **`my-component.slint`**
327
+
328
+ ```
329
+ export struct Person {
330
+ name: string,
331
+ age: int
332
+ }
333
+
334
+ export component MyComponent inherits Window {
335
+ in-out property <Person> person;
336
+ }
337
+ ```
338
+
339
+ **`main.js`**
340
+
341
+ ```js
342
+
343
+ import * as slint from "slint-ui";
344
+
345
+ let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
346
+ let component = new ui.MyComponent();
347
+
348
+ // object literal
349
+ component.person = { name: "Peter", age: 22 };
350
+
351
+ // new keyword (sets property values to default e.g. '' for string)
352
+ component.person = new ui.Person();
353
+
354
+ // new keyword with parameters
355
+ component.person = new ui.Person({ name: "Tim", age: 30 });
356
+ ```
357
+
358
+ ### enums
359
+
360
+ A value of an exported enum can be set as string or by usign the value from the exported enum.
361
+
362
+ **`my-component.slint`**
363
+
364
+ ```
365
+ export enum Position {
366
+ top,
367
+ bottom
368
+ }
369
+
370
+ export component MyComponent inherits Window {
371
+ in-out property <Position> position;
372
+ }
373
+ ```
374
+
375
+ **`main.js`**
376
+
377
+ ```js
378
+
379
+ import * as slint from "slint-ui";
380
+
381
+ let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
382
+ let component = new ui.MyComponent();
383
+
384
+ // set enum value as string
385
+ component.position = "top";
386
+
387
+ // use the value of the enum
388
+ component.position = ui.Position.bottom;
389
+ ```
390
+
274
391
  ### Globals
275
392
 
276
393
  You can declare [globally available singletons](../slint/src/language/syntax/globals) in your
@@ -292,7 +409,7 @@ previous section, you can access `Logic` like this:
292
409
  ```js
293
410
  import * as slint from "slint-ui";
294
411
 
295
- let ui = slint.loadFile("ui/my-component.slint");
412
+ let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
296
413
  let component = new ui.MyComponent();
297
414
 
298
415
  component.Logic.to_upper_case = (str) => {
@@ -302,3 +419,4 @@ component.Logic.to_upper_case = (str) => {
302
419
 
303
420
  **Note**: Global singletons are instantiated once per component. When declaring multiple components for `export` to JavaScript,
304
421
  each instance will have their own instance of associated globals singletons.
422
+
package/dist/index.d.ts CHANGED
@@ -194,7 +194,7 @@ export interface LoadFileOptions {
194
194
  * main.greeting = "Hello friends";
195
195
  * ```
196
196
  *
197
- * @param filePath The path to the file to load. Relative paths are resolved against the process' current working directory.
197
+ * @param filePath The path to the file to load as `string` or `URL`. Relative paths are resolved against the process' current working directory.
198
198
  * @param options An optional {@link LoadFileOptions} to configure additional Slint compilation settings,
199
199
  * such as include search paths, library imports, or the widget style.
200
200
  * @returns Returns an object that is immutable and provides a constructor function for each exported Window component found in the `.slint` file.
@@ -203,7 +203,7 @@ export interface LoadFileOptions {
203
203
  * For further information on the available properties, refer to [Instantiating A Component](../index.html#md:instantiating-a-component).
204
204
  * @throws {@link CompileError} if errors occur during compilation.
205
205
  */
206
- export declare function loadFile(filePath: string, options?: LoadFileOptions): Object;
206
+ export declare function loadFile(filePath: string | URL, options?: LoadFileOptions): Object;
207
207
  /**
208
208
  * Loads the given Slint source code and returns an object that contains a functions to construct the exported
209
209
  * components of the Slint source code.
@@ -404,6 +404,24 @@ export declare namespace private_api {
404
404
  rowData(row: number): U | undefined;
405
405
  }
406
406
  }
407
+ /**
408
+ * Initialize translations.
409
+ *
410
+ * Call this with the path where translations are located. This function internally calls the [bindtextdomain](https://man7.org/linux/man-pages/man3/bindtextdomain.3.html) function from gettext.
411
+ *
412
+ * Translations are expected to be found at <path>/<locale>/LC_MESSAGES/<domain>.mo, where path is the directory passed as an argument to this function, locale is a locale name (e.g., en, en_GB, fr), and domain is the package name.
413
+ *
414
+ * @param domain defines the domain name e.g. name of the package.
415
+ * @param path specifies the directory as `string` or as `URL` in which gettext should search for translations.
416
+ *
417
+ * For example, assuming this is in a package called example and the default locale is configured to be French, it will load translations at runtime from ``/path/to/example/translations/fr/LC_MESSAGES/example.mo`.
418
+ *
419
+ * ```js
420
+ * import * as slint from "slint-ui";
421
+ * slint.initTranslations("example", new URL("translations/", import.meta.url));
422
+ * ````
423
+ */
424
+ export declare function initTranslations(domain: string, path: string | URL): void;
407
425
  /**
408
426
  * @hidden
409
427
  */
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright © SixtyFPS GmbH <info@slint.dev>
3
3
  // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.private_api = exports.quitEventLoop = exports.runEventLoop = exports.loadSource = exports.loadFile = exports.CompileError = exports.ArrayModel = exports.Model = exports.Brush = exports.RgbaColor = exports.DiagnosticLevel = exports.Diagnostic = void 0;
5
+ exports.initTranslations = exports.private_api = exports.quitEventLoop = exports.runEventLoop = exports.loadSource = exports.loadFile = exports.CompileError = exports.ArrayModel = exports.Model = exports.Brush = exports.RgbaColor = exports.DiagnosticLevel = exports.Diagnostic = void 0;
6
6
  const napi = require("../rust-module.cjs");
7
7
  var rust_module_cjs_1 = require("../rust-module.cjs");
8
8
  Object.defineProperty(exports, "Diagnostic", { enumerable: true, get: function () { return rust_module_cjs_1.Diagnostic; } });
@@ -319,7 +319,7 @@ function loadSlint(loadData) {
319
319
  * main.greeting = "Hello friends";
320
320
  * ```
321
321
  *
322
- * @param filePath The path to the file to load. Relative paths are resolved against the process' current working directory.
322
+ * @param filePath The path to the file to load as `string` or `URL`. Relative paths are resolved against the process' current working directory.
323
323
  * @param options An optional {@link LoadFileOptions} to configure additional Slint compilation settings,
324
324
  * such as include search paths, library imports, or the widget style.
325
325
  * @returns Returns an object that is immutable and provides a constructor function for each exported Window component found in the `.slint` file.
@@ -329,8 +329,9 @@ function loadSlint(loadData) {
329
329
  * @throws {@link CompileError} if errors occur during compilation.
330
330
  */
331
331
  function loadFile(filePath, options) {
332
+ const pathname = filePath instanceof URL ? filePath.pathname : filePath;
332
333
  return loadSlint({
333
- fileData: { filePath, options },
334
+ fileData: { filePath: pathname, options },
334
335
  from: "file",
335
336
  });
336
337
  }
@@ -603,6 +604,28 @@ var private_api;
603
604
  }
604
605
  private_api.MapModel = MapModel;
605
606
  })(private_api || (exports.private_api = private_api = {}));
607
+ /**
608
+ * Initialize translations.
609
+ *
610
+ * Call this with the path where translations are located. This function internally calls the [bindtextdomain](https://man7.org/linux/man-pages/man3/bindtextdomain.3.html) function from gettext.
611
+ *
612
+ * Translations are expected to be found at <path>/<locale>/LC_MESSAGES/<domain>.mo, where path is the directory passed as an argument to this function, locale is a locale name (e.g., en, en_GB, fr), and domain is the package name.
613
+ *
614
+ * @param domain defines the domain name e.g. name of the package.
615
+ * @param path specifies the directory as `string` or as `URL` in which gettext should search for translations.
616
+ *
617
+ * For example, assuming this is in a package called example and the default locale is configured to be French, it will load translations at runtime from ``/path/to/example/translations/fr/LC_MESSAGES/example.mo`.
618
+ *
619
+ * ```js
620
+ * import * as slint from "slint-ui";
621
+ * slint.initTranslations("example", new URL("translations/", import.meta.url));
622
+ * ````
623
+ */
624
+ function initTranslations(domain, path) {
625
+ const pathname = path instanceof URL ? path.pathname : path;
626
+ napi.initTranslations(domain, pathname);
627
+ }
628
+ exports.initTranslations = initTranslations;
606
629
  /**
607
630
  * @hidden
608
631
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slint-ui",
3
- "version": "1.9.0-nightly.2024101004",
3
+ "version": "1.9.0-nightly.2024101112",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "homepage": "https://github.com/slint-ui/slint",
@@ -67,10 +67,10 @@
67
67
  "@napi-rs/cli": "2.16.5"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@slint-ui/slint-ui-binary-linux-x64-gnu": "1.9.0-nightly.2024101004",
71
- "@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.2024101004",
72
- "@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.2024101004",
73
- "@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.2024101004",
74
- "@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.2024101004"
70
+ "@slint-ui/slint-ui-binary-linux-x64-gnu": "1.9.0-nightly.2024101112",
71
+ "@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.2024101112",
72
+ "@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.2024101112",
73
+ "@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.2024101112",
74
+ "@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.2024101112"
75
75
  }
76
76
  }
package/rust/lib.rs CHANGED
@@ -2,6 +2,8 @@
2
2
  // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
3
 
4
4
  mod interpreter;
5
+ use std::path::PathBuf;
6
+
5
7
  pub use interpreter::*;
6
8
 
7
9
  mod types;
@@ -86,6 +88,12 @@ pub fn init_testing() {
86
88
  i_slint_backend_testing::init_integration_test_with_mock_time();
87
89
  }
88
90
 
91
+ #[napi]
92
+ pub fn init_translations(domain: String, dir_name: String) -> napi::Result<()> {
93
+ i_slint_core::translations::gettext_bindtextdomain(domain.as_str(), PathBuf::from(dir_name))
94
+ .map_err(|e| napi::Error::from_reason(e.to_string()))
95
+ }
96
+
89
97
  pub fn print_to_console(env: Env, function: &str, arguments: core::fmt::Arguments) {
90
98
  let Ok(global) = env.get_global() else {
91
99
  eprintln!("Unable to obtain global object");
package/rust-module.cjs CHANGED
@@ -252,7 +252,7 @@ if (!nativeBinding) {
252
252
  throw new Error(`Failed to load native binding`)
253
253
  }
254
254
 
255
- const { DiagnosticLevel, ComponentCompiler, ComponentDefinition, ComponentInstance, ValueType, Property, Window, SlintRgbaColor, SlintBrush, SlintImageData, SharedModelNotify, jsModelNotifyNew, jsModelNotifyRowDataChanged, jsModelNotifyRowAdded, jsModelNotifyRowRemoved, jsModelNotifyReset, ReadOnlyRustModel, ModelIterator, SlintPoint, SlintSize, mockElapsedTime, getMockedTime, ProcessEventsResult, processEvents, invokeFromEventLoop, setQuitOnLastWindowClosed, initTesting } = nativeBinding
255
+ const { DiagnosticLevel, ComponentCompiler, ComponentDefinition, ComponentInstance, ValueType, Property, Window, SlintRgbaColor, SlintBrush, SlintImageData, SharedModelNotify, jsModelNotifyNew, jsModelNotifyRowDataChanged, jsModelNotifyRowAdded, jsModelNotifyRowRemoved, jsModelNotifyReset, ReadOnlyRustModel, ModelIterator, SlintPoint, SlintSize, mockElapsedTime, getMockedTime, ProcessEventsResult, processEvents, invokeFromEventLoop, setQuitOnLastWindowClosed, initTesting, initTranslations } = nativeBinding
256
256
 
257
257
  module.exports.DiagnosticLevel = DiagnosticLevel
258
258
  module.exports.ComponentCompiler = ComponentCompiler
@@ -281,3 +281,4 @@ module.exports.processEvents = processEvents
281
281
  module.exports.invokeFromEventLoop = invokeFromEventLoop
282
282
  module.exports.setQuitOnLastWindowClosed = setQuitOnLastWindowClosed
283
283
  module.exports.initTesting = initTesting
284
+ module.exports.initTranslations = initTranslations
package/rust-module.d.ts CHANGED
@@ -83,6 +83,7 @@ export declare function processEvents(): ProcessEventsResult
83
83
  export declare function invokeFromEventLoop(callback: (...args: any[]) => any): void
84
84
  export declare function setQuitOnLastWindowClosed(quitOnLastWindowClosed: boolean): void
85
85
  export declare function initTesting(): void
86
+ export declare function initTranslations(domain: string, dirName: string): void
86
87
  export type JsComponentCompiler = ComponentCompiler
87
88
  /**
88
89
  * ComponentCompiler is the entry point to the Slint interpreter that can be used
@@ -605,7 +605,7 @@ function loadSlint(loadData: LoadData): Object {
605
605
  * main.greeting = "Hello friends";
606
606
  * ```
607
607
  *
608
- * @param filePath The path to the file to load. Relative paths are resolved against the process' current working directory.
608
+ * @param filePath The path to the file to load as `string` or `URL`. Relative paths are resolved against the process' current working directory.
609
609
  * @param options An optional {@link LoadFileOptions} to configure additional Slint compilation settings,
610
610
  * such as include search paths, library imports, or the widget style.
611
611
  * @returns Returns an object that is immutable and provides a constructor function for each exported Window component found in the `.slint` file.
@@ -614,9 +614,13 @@ function loadSlint(loadData: LoadData): Object {
614
614
  * For further information on the available properties, refer to [Instantiating A Component](../index.html#md:instantiating-a-component).
615
615
  * @throws {@link CompileError} if errors occur during compilation.
616
616
  */
617
- export function loadFile(filePath: string, options?: LoadFileOptions): Object {
617
+ export function loadFile(
618
+ filePath: string | URL,
619
+ options?: LoadFileOptions,
620
+ ): Object {
621
+ const pathname = filePath instanceof URL ? filePath.pathname : filePath;
618
622
  return loadSlint({
619
- fileData: { filePath, options },
623
+ fileData: { filePath: pathname, options },
620
624
  from: "file",
621
625
  });
622
626
  }
@@ -918,6 +922,28 @@ export namespace private_api {
918
922
  }
919
923
  }
920
924
 
925
+ /**
926
+ * Initialize translations.
927
+ *
928
+ * Call this with the path where translations are located. This function internally calls the [bindtextdomain](https://man7.org/linux/man-pages/man3/bindtextdomain.3.html) function from gettext.
929
+ *
930
+ * Translations are expected to be found at <path>/<locale>/LC_MESSAGES/<domain>.mo, where path is the directory passed as an argument to this function, locale is a locale name (e.g., en, en_GB, fr), and domain is the package name.
931
+ *
932
+ * @param domain defines the domain name e.g. name of the package.
933
+ * @param path specifies the directory as `string` or as `URL` in which gettext should search for translations.
934
+ *
935
+ * For example, assuming this is in a package called example and the default locale is configured to be French, it will load translations at runtime from ``/path/to/example/translations/fr/LC_MESSAGES/example.mo`.
936
+ *
937
+ * ```js
938
+ * import * as slint from "slint-ui";
939
+ * slint.initTranslations("example", new URL("translations/", import.meta.url));
940
+ * ````
941
+ */
942
+ export function initTranslations(domain: string, path: string | URL) {
943
+ const pathname = path instanceof URL ? path.pathname : path;
944
+ napi.initTranslations(domain, pathname);
945
+ }
946
+
921
947
  /**
922
948
  * @hidden
923
949
  */