slint-ui 1.9.0-nightly.2024101004 → 1.9.0-nightly.2024101016
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 +4 -4
- package/README.md +6 -6
- package/cover.md +70 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.js +26 -3
- package/package.json +6 -6
- package/rust/lib.rs +8 -0
- package/rust-module.cjs +2 -1
- package/rust-module.d.ts +1 -0
- package/typescript/index.ts +29 -3
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 = "
|
|
45
|
-
i-slint-core = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
46
|
-
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "
|
|
47
|
-
slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
44
|
+
i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "ccf5f04087c5d920c80e7e706230e99a12b9e9ef", version = "=1.9.0", default-features = false }
|
|
45
|
+
i-slint-core = { features = ["default", "gettext-rs"] , git = "https://github.com/slint-ui/slint", rev = "ccf5f04087c5d920c80e7e706230e99a12b9e9ef", version = "=1.9.0", default-features = false }
|
|
46
|
+
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "ccf5f04087c5d920c80e7e706230e99a12b9e9ef", 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 = "ccf5f04087c5d920c80e7e706230e99a12b9e9ef", 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
|
@@ -271,6 +271,75 @@ component.model = component.model.concat(4);
|
|
|
271
271
|
|
|
272
272
|
Another option is to set an object that implements the {@link Model} interface.
|
|
273
273
|
|
|
274
|
+
### structs
|
|
275
|
+
|
|
276
|
+
An exported struct can be created either by defing of an object literal or by using the new keyword.
|
|
277
|
+
|
|
278
|
+
**`my-component.slint`**
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
export struct Person {
|
|
282
|
+
name: string,
|
|
283
|
+
age: int
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export component MyComponent inherits Window {
|
|
287
|
+
in-out property <Person> person;
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**`main.js`**
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
|
|
295
|
+
import * as slint from "slint-ui";
|
|
296
|
+
|
|
297
|
+
let ui = slint.loadFile("my-component.slint");
|
|
298
|
+
let component = new ui.MyComponent();
|
|
299
|
+
|
|
300
|
+
// object literal
|
|
301
|
+
component.person = { name: "Peter", age: 22 };
|
|
302
|
+
|
|
303
|
+
// new keyword (sets property values to default e.g. '' for string)
|
|
304
|
+
component.person = new ui.Person();
|
|
305
|
+
|
|
306
|
+
// new keyword with parameters
|
|
307
|
+
component.person = new ui.Person({ name: "Tim", age: 30 });
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### enums
|
|
311
|
+
|
|
312
|
+
A value of an exported enum can be set as string or by usign the value from the exported enum.
|
|
313
|
+
|
|
314
|
+
**`my-component.slint`**
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
export enum Position {
|
|
318
|
+
top,
|
|
319
|
+
bottom
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export component MyComponent inherits Window {
|
|
323
|
+
in-out property <Position> position;
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**`main.js`**
|
|
328
|
+
|
|
329
|
+
```js
|
|
330
|
+
|
|
331
|
+
import * as slint from "slint-ui";
|
|
332
|
+
|
|
333
|
+
let ui = slint.loadFile("my-component.slint");
|
|
334
|
+
let component = new ui.MyComponent();
|
|
335
|
+
|
|
336
|
+
// set enum value as string
|
|
337
|
+
component.position = "top";
|
|
338
|
+
|
|
339
|
+
// use the value of the enum
|
|
340
|
+
component.position = ui.Position.bottom;
|
|
341
|
+
```
|
|
342
|
+
|
|
274
343
|
### Globals
|
|
275
344
|
|
|
276
345
|
You can declare [globally available singletons](../slint/src/language/syntax/globals) in your
|
|
@@ -302,3 +371,4 @@ component.Logic.to_upper_case = (str) => {
|
|
|
302
371
|
|
|
303
372
|
**Note**: Global singletons are instantiated once per component. When declaring multiple components for `export` to JavaScript,
|
|
304
373
|
each instance will have their own instance of associated globals singletons.
|
|
374
|
+
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.9.0-nightly.2024101016",
|
|
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.
|
|
71
|
-
"@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.
|
|
72
|
-
"@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.
|
|
73
|
-
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.
|
|
74
|
-
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.
|
|
70
|
+
"@slint-ui/slint-ui-binary-linux-x64-gnu": "1.9.0-nightly.2024101016",
|
|
71
|
+
"@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.2024101016",
|
|
72
|
+
"@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.2024101016",
|
|
73
|
+
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.2024101016",
|
|
74
|
+
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.2024101016"
|
|
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
|
package/typescript/index.ts
CHANGED
|
@@ -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
|
|
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(
|
|
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
|
*/
|