@gtkx/i18n 0.0.1
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/README.md +174 -0
- package/dist/backend.d.ts +12 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +49 -0
- package/dist/backend.js.map +1 -0
- package/dist/bootstrap.d.ts +2 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +2 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/gettext.d.ts +44 -0
- package/dist/gettext.d.ts.map +1 -0
- package/dist/gettext.js +49 -0
- package/dist/gettext.js.map +1 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +99 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/locale.d.ts +3 -0
- package/dist/locale.d.ts.map +1 -0
- package/dist/locale.js +27 -0
- package/dist/locale.js.map +1 -0
- package/dist/lookup.d.ts +6 -0
- package/dist/lookup.d.ts.map +1 -0
- package/dist/lookup.js +30 -0
- package/dist/lookup.js.map +1 -0
- package/dist/types.d.ts +639 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +86 -0
- package/src/backend.ts +73 -0
- package/src/bootstrap.ts +1 -0
- package/src/i18n.ts +157 -0
- package/src/index.ts +73 -0
- package/src/locale.ts +39 -0
- package/src/types.ts +1081 -0
- package/src/virtual-config.d.ts +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/logo.svg" alt="GTKX" width="100" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">GTKX</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
The React framework for Linux, built on GTK.<br />
|
|
9
|
+
Write native GTK4 desktop applications with React and TypeScript.
|
|
10
|
+
Real GTK widgets, the GNOME stack, and standard web tooling.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/v/create-gtkx?color=cb3837&logo=npm&label=create-gtkx" alt="npm version" /></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/create-gtkx"><img src="https://img.shields.io/npm/dm/create-gtkx?color=cb3837&logo=npm&label=downloads" alt="npm downloads" /></a>
|
|
16
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A524-339933?logo=node.js&logoColor=white" alt="Node >= 24" />
|
|
17
|
+
<a href="https://github.com/gtkx-org/gtkx/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MPL--2.0-blue.svg" alt="License: MPL-2.0" /></a>
|
|
18
|
+
<a href="https://github.com/gtkx-org/gtkx/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/gtkx-org/gtkx/ci.yml?branch=main&logo=github&label=CI" alt="CI status" /></a>
|
|
19
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="https://gtkx.dev">Homepage</a> ·
|
|
24
|
+
<a href="https://gtkx.dev/guide/getting-started">Documentation</a> ·
|
|
25
|
+
<a href="https://github.com/gtkx-org/gtkx/tree/main/examples">Examples</a> ·
|
|
26
|
+
<a href="https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md">Contributing</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/examples/tutorial/assets/screenshot.png" alt="The Tasks app: an Adwaita window with a sidebar of smart views and colored lists on the left, and a boxed task list on the right." />
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<em>The Tasks app you build in the <a href="https://gtkx.dev/tutorial/">tutorial</a>.</em>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
## Demo
|
|
40
|
+
|
|
41
|
+
The intrinsic elements in this snippet render GTK4 widgets, and ordinary React hooks and events drive them:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
45
|
+
import { GtkApplication, GtkApplicationWindow, GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
|
|
46
|
+
import { createRoot, quit } from "@gtkx/react";
|
|
47
|
+
import { useState } from "react";
|
|
48
|
+
|
|
49
|
+
const Counter = () => {
|
|
50
|
+
const [count, setCount] = useState(0);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<GtkApplicationWindow
|
|
54
|
+
title="Hello GTKX"
|
|
55
|
+
defaultWidth={400}
|
|
56
|
+
defaultHeight={300}
|
|
57
|
+
onCloseRequest={quit}
|
|
58
|
+
>
|
|
59
|
+
<GtkBox
|
|
60
|
+
orientation={Gtk.Orientation.VERTICAL}
|
|
61
|
+
spacing={20}
|
|
62
|
+
marginTop={40}
|
|
63
|
+
marginBottom={40}
|
|
64
|
+
marginStart={40}
|
|
65
|
+
marginEnd={40}
|
|
66
|
+
valign={Gtk.Align.CENTER}
|
|
67
|
+
halign={Gtk.Align.CENTER}
|
|
68
|
+
>
|
|
69
|
+
<GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
|
|
70
|
+
<GtkLabel cssClasses={["title-2"]}>{`Count: ${count}`}</GtkLabel>
|
|
71
|
+
<GtkButton
|
|
72
|
+
label="Increment"
|
|
73
|
+
onClicked={() => setCount((c) => c + 1)}
|
|
74
|
+
cssClasses={["suggested-action", "pill"]}
|
|
75
|
+
/>
|
|
76
|
+
</GtkBox>
|
|
77
|
+
</GtkApplicationWindow>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const App = () => (
|
|
82
|
+
<GtkApplication>
|
|
83
|
+
<Counter />
|
|
84
|
+
</GtkApplication>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
createRoot().render(<App />);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This is the [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world) example, with `app.tsx` and `index.tsx` combined into a single snippet. `@gtkx/gi` and `@gtkx/jsx` are per-project bindings generated by the CLI, not packages you install from npm.
|
|
91
|
+
|
|
92
|
+
## Why GTKX
|
|
93
|
+
|
|
94
|
+
### A declarative layer for the GNOME stack
|
|
95
|
+
|
|
96
|
+
GTK4 is mature, and GtkBuilder XML can lay out a static interface, but nothing re-renders that interface when your application state changes, and nothing hot-reloads it as you work. GTKX adds that missing layer, and the tooling around it, on top of the stack you already know:
|
|
97
|
+
|
|
98
|
+
- a React reconciler that exposes every GObject as a JSX element,
|
|
99
|
+
- a CLI for scaffolding, development, and production builds,
|
|
100
|
+
- a dev server with Fast Refresh that patches your running UI in place,
|
|
101
|
+
- CSS-in-JS styling, React Hook Form-powered Adwaita controls, React Spring animations, React Navigation stack, tab, drawer, and split view navigators, and high-level list, grid, and dialog components,
|
|
102
|
+
- a Testing Library-style API for querying and driving your widgets in tests,
|
|
103
|
+
- and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
|
|
104
|
+
|
|
105
|
+
### The full GNOME API surface
|
|
106
|
+
|
|
107
|
+
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX exposes it: GTK4, Adwaita, and any other GObject-Introspection library on your system. Linux-only by design.
|
|
108
|
+
|
|
109
|
+
### Why Node.js, and why generated bindings
|
|
110
|
+
|
|
111
|
+
GTKX runs on Node.js, which puts native modules, the npm ecosystem, and the tooling built for Node.js APIs within reach. GJS is GNOME's own runtime, built on SpiderMonkey rather than V8; node-gtk runs on Node.js but is lightly maintained, on the older nan/V8 ABI rather than N-API, and still centered on GTK3. The [Why GTKX guide](https://gtkx.dev/guide/why-gtkx) covers what running on Node.js means day to day.
|
|
112
|
+
|
|
113
|
+
GTKX generates the TypeScript types and the native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. Codegen covers the whole GTK4 and Adwaita surface.
|
|
114
|
+
|
|
115
|
+
At runtime, the native Rust core calls straight into the system GTK4, Adwaita, and GLib libraries through libffi, without loading libgirepository at all.
|
|
116
|
+
|
|
117
|
+
## Quick start
|
|
118
|
+
|
|
119
|
+
GTKX is Linux-only and needs Node.js 24 or later. See [Requirements](#requirements).
|
|
120
|
+
|
|
121
|
+
Scaffold a new app with the `create-gtkx` initializer:
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
npm create gtkx
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The same command works with other package managers: `pnpm create gtkx` or `yarn create gtkx`.
|
|
128
|
+
|
|
129
|
+
Then run your new app:
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
cd my-app
|
|
133
|
+
npm run dev
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
To go further, follow the [tutorial](https://gtkx.dev/tutorial/).
|
|
137
|
+
|
|
138
|
+
## Documentation
|
|
139
|
+
|
|
140
|
+
The documentation at **[gtkx.dev](https://gtkx.dev)** includes a step-by-step tutorial that builds a complete GNOME app, from scaffolding to packaging and shipping, plus guides and a full API reference.
|
|
141
|
+
|
|
142
|
+
**[Read the docs →](https://gtkx.dev/guide/why-gtkx)**
|
|
143
|
+
|
|
144
|
+
## Requirements
|
|
145
|
+
|
|
146
|
+
GTKX is Linux-only. You need:
|
|
147
|
+
|
|
148
|
+
- Linux with the GTK4 (4.20 or later) and GLib development libraries, plus Adwaita (1.8 or later) once your project binds `Adw-1`
|
|
149
|
+
- Node.js 24 or later
|
|
150
|
+
|
|
151
|
+
The `@gtkx/native` addon ships prebuilt for x64 and arm64 glibc Linux; other targets need to build it from the GTKX repository, which requires a Rust toolchain.
|
|
152
|
+
|
|
153
|
+
## Examples
|
|
154
|
+
|
|
155
|
+
Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
156
|
+
|
|
157
|
+
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the counter above.
|
|
158
|
+
- [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): a React port of the official GTK4 widget showcase, covering lists, dialogs, gestures, CSS, and OpenGL.
|
|
159
|
+
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): a WebKitWebView-based web browser.
|
|
160
|
+
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): a tour of `@gtkx/animated`, React Spring animations driven by the GTK frame clock.
|
|
161
|
+
- [`navigation`](https://github.com/gtkx-org/gtkx/tree/main/examples/navigation): a tour of `@gtkx/navigation`, React Navigation's stack, tab, and drawer navigators rendered with libadwaita.
|
|
162
|
+
- [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
|
|
163
|
+
|
|
164
|
+
## Status
|
|
165
|
+
|
|
166
|
+
GTKX is stable and ready for production use.
|
|
167
|
+
|
|
168
|
+
## Contributing
|
|
169
|
+
|
|
170
|
+
Contributions are welcome. See [CONTRIBUTING.md](https://github.com/gtkx-org/gtkx/blob/main/CONTRIBUTING.md), the [Code of Conduct](https://github.com/gtkx-org/gtkx/blob/main/CODE_OF_CONDUCT.md), and the [security policy](https://github.com/gtkx-org/gtkx/blob/main/SECURITY.md). Building the repo needs Node.js 24 or later, pnpm, and a Rust toolchain.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
GTKX is licensed under [MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BackendModule } from "i18next";
|
|
2
|
+
type GettextCatalog = {
|
|
3
|
+
gettext(msgid: string): string;
|
|
4
|
+
ngettext(msgid: string, msgidPlural: string, count: number | bigint): string;
|
|
5
|
+
npgettext(context: string, msgid: string, msgidPlural: string, count: number | bigint): string;
|
|
6
|
+
pgettext(context: string, msgid: string): string;
|
|
7
|
+
};
|
|
8
|
+
declare const GETTEXT_RESOURCE_KEY = "__gtkx_gettext_catalog__";
|
|
9
|
+
declare const gettextBackend: BackendModule;
|
|
10
|
+
declare const isGettextCatalog: (value: unknown) => value is GettextCatalog;
|
|
11
|
+
export { GETTEXT_RESOURCE_KEY, gettextBackend, isGettextCatalog, type GettextCatalog };
|
|
12
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,KAAK,cAAc,GAAG;IAClB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC7E,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAC/F,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CACpD,CAAC;AAGF,QAAA,MAAM,oBAAoB,6BAA6B,CAAC;AA+BxD,QAAA,MAAM,cAAc,EAAE,aAQrB,CAAC;AAmBF,QAAA,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,cAA0C,CAAC;AAE/F,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,CAAC"}
|
package/dist/backend.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as GLib from "@gtkx/gi/glib";
|
|
2
|
+
import { applicationId } from "virtual:gtkx-config";
|
|
3
|
+
const CONTEXT_SEPARATOR = "\u{4}";
|
|
4
|
+
const GETTEXT_RESOURCE_KEY = "__gtkx_gettext_catalog__";
|
|
5
|
+
const gettextCatalog = {
|
|
6
|
+
gettext(msgid) {
|
|
7
|
+
return GLib.dgettext(applicationId, msgid);
|
|
8
|
+
},
|
|
9
|
+
ngettext(msgid, msgidPlural, count) {
|
|
10
|
+
return GLib.dngettext(applicationId, msgid, msgidPlural, normalizeCount(count));
|
|
11
|
+
},
|
|
12
|
+
pgettext(context, msgid) {
|
|
13
|
+
return GLib.dpgettext2(applicationId, context, msgid);
|
|
14
|
+
},
|
|
15
|
+
npgettext(context, msgid, msgidPlural, count) {
|
|
16
|
+
const contextualSingular = contextualMsgid(context, msgid);
|
|
17
|
+
const contextualPlural = contextualMsgid(context, msgidPlural);
|
|
18
|
+
const translated = GLib.dngettext(applicationId, contextualSingular, contextualPlural, normalizeCount(count));
|
|
19
|
+
if (translated === contextualSingular) {
|
|
20
|
+
return msgid;
|
|
21
|
+
}
|
|
22
|
+
return translated === contextualPlural ? msgidPlural : translated;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const gettextBackend = {
|
|
26
|
+
type: "backend",
|
|
27
|
+
init() {
|
|
28
|
+
return;
|
|
29
|
+
},
|
|
30
|
+
read(_language, _namespace, callback) {
|
|
31
|
+
callback(null, { [GETTEXT_RESOURCE_KEY]: gettextCatalog });
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const normalizeCount = (count) => {
|
|
35
|
+
if (typeof count === "number") {
|
|
36
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
37
|
+
throw new RangeError("gettext counts must be non-negative safe integers");
|
|
38
|
+
}
|
|
39
|
+
return BigInt(count);
|
|
40
|
+
}
|
|
41
|
+
if (count < 0n) {
|
|
42
|
+
throw new RangeError("gettext counts must be non-negative");
|
|
43
|
+
}
|
|
44
|
+
return count;
|
|
45
|
+
};
|
|
46
|
+
const contextualMsgid = (context, msgid) => `${context}${CONTEXT_SEPARATOR}${msgid}`;
|
|
47
|
+
const isGettextCatalog = (value) => value === gettextCatalog;
|
|
48
|
+
export { GETTEXT_RESOURCE_KEY, gettextBackend, isGettextCatalog };
|
|
49
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AASpD,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAExD,MAAM,cAAc,GAAmB;IACnC,OAAO,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IACD,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IACpF,CAAC;IACD,QAAQ,CAAC,OAAO,EAAE,KAAK;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC;IACD,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK;QACxC,MAAM,kBAAkB,GAAG,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,gBAAgB,GAAG,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAE/D,MAAM,UAAU,GAAG,IAAI,CAAC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uB,CAAC","sourcesContent":["import type { BackendModule } from \"i18next\";\nimport * as GLib from \"@gtkx/gi/glib\";\nimport { applicationId } from \"virtual:gtkx-config\";\n\ntype GettextCatalog = {\n gettext(msgid: string): string;\n ngettext(msgid: string, msgidPlural: string, count: number | bigint): string;\n npgettext(context: string, msgid: string, msgidPlural: string, count: number | bigint): string;\n pgettext(context: string, msgid: string): string;\n};\n\nconst CONTEXT_SEPARATOR = \"\\u{4}\";\nconst GETTEXT_RESOURCE_KEY = \"__gtkx_gettext_catalog__\";\n\nconst gettextCatalog: GettextCatalog = {\n gettext(msgid) {\n return GLib.dgettext(applicationId, msgid);\n },\n ngettext(msgid, msgidPlural, count) {\n return GLib.dngettext(applicationId, msgid, msgidPlural, normalizeCount(count));\n },\n pgettext(context, msgid) {\n return GLib.dpgettext2(applicationId, context, msgid);\n },\n npgettext(context, msgid, msgidPlural, count) {\n const contextualSingular = contextualMsgid(context, msgid);\n const contextualPlural = contextualMsgid(context, msgidPlural);\n\n const translated = GLib.dngettext(\n applicationId,\n contextualSingular,\n contextualPlural,\n normalizeCount(count),\n );\n\n if (translated === contextualSingular) {\n return msgid;\n }\n\n return translated === contextualPlural ? msgidPlural : translated;\n },\n};\n\nconst gettextBackend: BackendModule = {\n type: \"backend\",\n init() {\n return;\n },\n read(_language, _namespace, callback) {\n callback(null, { [GETTEXT_RESOURCE_KEY]: gettextCatalog });\n },\n};\n\nconst normalizeCount = (count: number | bigint): bigint => {\n if (typeof count === \"number\") {\n if (!Number.isSafeInteger(count) || count < 0) {\n throw new RangeError(\"gettext counts must be non-negative safe integers\");\n }\n\n return BigInt(count);\n }\n\n if (count < 0n) {\n throw new RangeError(\"gettext counts must be non-negative\");\n }\n\n return count;\n};\n\nconst contextualMsgid = (context: string, msgid: string): string => `${context}${CONTEXT_SEPARATOR}${msgid}`;\nconst isGettextCatalog = (value: unknown): value is GettextCatalog => value === gettextCatalog;\n\nexport { GETTEXT_RESOURCE_KEY, gettextBackend, isGettextCatalog, type GettextCatalog };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC","sourcesContent":["import \"./i18n.js\";\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Shorthand for {@link gettext}. */
|
|
2
|
+
declare const _: typeof gettext;
|
|
3
|
+
/**
|
|
4
|
+
* Translates a message in the application's gettext domain and interpolates `{{name}}` placeholders.
|
|
5
|
+
* @param msgid The source message stored in the catalog.
|
|
6
|
+
* @param values Values to interpolate into the translated message.
|
|
7
|
+
* @returns The translated and interpolated message, or the source message when no translation exists.
|
|
8
|
+
*/
|
|
9
|
+
declare function gettext(msgid: string, values?: Readonly<Record<string, unknown>>): string;
|
|
10
|
+
/**
|
|
11
|
+
* Translates a singular/plural message pair according to the process locale.
|
|
12
|
+
* @param msgid The singular source message stored in the catalog.
|
|
13
|
+
* @param msgidPlural The plural source message stored in the catalog.
|
|
14
|
+
* @param count The quantity used by the catalog's plural rule and exposed to interpolation as `count`.
|
|
15
|
+
* @param values Additional values to interpolate into the translated message.
|
|
16
|
+
* @returns The translated and interpolated plural form.
|
|
17
|
+
*/
|
|
18
|
+
declare function ngettext(msgid: string, msgidPlural: string, count: number | bigint, values?: Readonly<Record<string, unknown>>): string;
|
|
19
|
+
/**
|
|
20
|
+
* Translates a message disambiguated by gettext context.
|
|
21
|
+
* @param context The catalog context separating this message from identical source text.
|
|
22
|
+
* @param msgid The source message stored in the catalog.
|
|
23
|
+
* @param values Values to interpolate into the translated message.
|
|
24
|
+
* @returns The translated and interpolated message, or the source message when no translation exists.
|
|
25
|
+
*/
|
|
26
|
+
declare function pgettext(context: string, msgid: string, values?: Readonly<Record<string, unknown>>): string;
|
|
27
|
+
/**
|
|
28
|
+
* Translates a singular/plural message pair disambiguated by gettext context.
|
|
29
|
+
* @param context The catalog context separating this message from identical source text.
|
|
30
|
+
* @param msgid The singular source message stored in the catalog.
|
|
31
|
+
* @param msgidPlural The plural source message stored in the catalog.
|
|
32
|
+
* @param count The quantity used by the catalog's plural rule and exposed to interpolation as `count`.
|
|
33
|
+
* @param values Additional values to interpolate into the translated message.
|
|
34
|
+
* @returns The translated and interpolated contextual plural form.
|
|
35
|
+
*/
|
|
36
|
+
declare function npgettext(...[context, msgid, msgidPlural, count, values]: [
|
|
37
|
+
context: string,
|
|
38
|
+
msgid: string,
|
|
39
|
+
msgidPlural: string,
|
|
40
|
+
count: number | bigint,
|
|
41
|
+
values?: Readonly<Record<string, unknown>>
|
|
42
|
+
]): string;
|
|
43
|
+
export { _, gettext, ngettext, npgettext, pgettext };
|
|
44
|
+
//# sourceMappingURL=gettext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gettext.d.ts","sourceRoot":"","sources":["../src/gettext.ts"],"names":[],"mappings":"AAKA,qCAAqC;AACrC,QAAA,MAAM,CAAC,EAAE,OAAO,OAAiB,CAAC;AAKlC;;;;;GAKG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAAG,MAAM,CAEtF;AAED;;;;;;;GAOG;AACH,iBAAS,QAAQ,CACb,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAC/C,MAAM,CAER;AAED;;;;;;GAMG;AACH,iBAAS,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GAAG,MAAM,CAExG;AAED;;;;;;;;GAQG;AACH,iBAAS,SAAS,CACd,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAW,CAAC,EAAE;IAClD,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,MAAM;IACb,WAAW,EAAE,MAAM;IACnB,KAAK,EAAE,MAAM,GAAG,MAAM;IACtB,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C,GACF,MAAM,CAER;AAED,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/gettext.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { i18n } from "./i18n.js";
|
|
2
|
+
import { gettextLookup, ngettextLookup, npgettextLookup, pgettextLookup } from "./lookup.js";
|
|
3
|
+
/** Shorthand for {@link gettext}. */
|
|
4
|
+
const _ = gettext;
|
|
5
|
+
const interpolate = (message, values) => i18n.services.interpolator.interpolate(message, values, i18n.language, {});
|
|
6
|
+
/**
|
|
7
|
+
* Translates a message in the application's gettext domain and interpolates `{{name}}` placeholders.
|
|
8
|
+
* @param msgid The source message stored in the catalog.
|
|
9
|
+
* @param values Values to interpolate into the translated message.
|
|
10
|
+
* @returns The translated and interpolated message, or the source message when no translation exists.
|
|
11
|
+
*/
|
|
12
|
+
function gettext(msgid, values = {}) {
|
|
13
|
+
return interpolate(gettextLookup(msgid), values);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Translates a singular/plural message pair according to the process locale.
|
|
17
|
+
* @param msgid The singular source message stored in the catalog.
|
|
18
|
+
* @param msgidPlural The plural source message stored in the catalog.
|
|
19
|
+
* @param count The quantity used by the catalog's plural rule and exposed to interpolation as `count`.
|
|
20
|
+
* @param values Additional values to interpolate into the translated message.
|
|
21
|
+
* @returns The translated and interpolated plural form.
|
|
22
|
+
*/
|
|
23
|
+
function ngettext(msgid, msgidPlural, count, values = {}) {
|
|
24
|
+
return interpolate(ngettextLookup(msgid, msgidPlural, count), { ...values, count });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Translates a message disambiguated by gettext context.
|
|
28
|
+
* @param context The catalog context separating this message from identical source text.
|
|
29
|
+
* @param msgid The source message stored in the catalog.
|
|
30
|
+
* @param values Values to interpolate into the translated message.
|
|
31
|
+
* @returns The translated and interpolated message, or the source message when no translation exists.
|
|
32
|
+
*/
|
|
33
|
+
function pgettext(context, msgid, values = {}) {
|
|
34
|
+
return interpolate(pgettextLookup(context, msgid), values);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Translates a singular/plural message pair disambiguated by gettext context.
|
|
38
|
+
* @param context The catalog context separating this message from identical source text.
|
|
39
|
+
* @param msgid The singular source message stored in the catalog.
|
|
40
|
+
* @param msgidPlural The plural source message stored in the catalog.
|
|
41
|
+
* @param count The quantity used by the catalog's plural rule and exposed to interpolation as `count`.
|
|
42
|
+
* @param values Additional values to interpolate into the translated message.
|
|
43
|
+
* @returns The translated and interpolated contextual plural form.
|
|
44
|
+
*/
|
|
45
|
+
function npgettext(...[context, msgid, msgidPlural, count, values = {}]) {
|
|
46
|
+
return interpolate(npgettextLookup(context, msgid, msgidPlural, count), { ...values, count });
|
|
47
|
+
}
|
|
48
|
+
export { _, gettext, ngettext, npgettext, pgettext };
|
|
49
|
+
//# sourceMappingURL=gettext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gettext.js","sourceRoot":"","sources":["../src/gettext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7F,qCAAqC;AACrC,MAAM,CAAC,GAAmB,OAAO,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,MAAc,EAAU,EAAE,CAC5D,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,SAAS,OAAO,CAAC,KAAa,EAAE,SAA4C,EAAE;IAC1E,OAAO,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,QAAQ,CACb,KAAa,EACb,WAAmB,EACnB,KAAsB,EACtB,SAA4C,EAAE;IAE9C,OAAO,WAAW,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AACxF,CAAC;AAED;;;;;;GAMG;AACH,SAAS,QAAQ,CAAC,OAAe,EAAE,KAAa,EAAE,SAA4C,EAAE;IAC5F,OAAO,WAAW,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,SAAS,CACd,GAAG,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,EAAE,CAMlD;IAED,OAAO,WAAW,CAAC,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAClG,CAAC;AAED,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC","sourcesContent":["import { i18n } from \"./i18n.js\";\nimport { gettextLookup, ngettextLookup, npgettextLookup, pgettextLookup } from \"./lookup.js\";\n\ntype Values = Readonly<Record<string, unknown>>;\n\n/** Shorthand for {@link gettext}. */\nconst _: typeof gettext = gettext;\n\nconst interpolate = (message: string, values: Values): string =>\n i18n.services.interpolator.interpolate(message, values, i18n.language, {});\n\n/**\n * Translates a message in the application's gettext domain and interpolates `{{name}}` placeholders.\n * @param msgid The source message stored in the catalog.\n * @param values Values to interpolate into the translated message.\n * @returns The translated and interpolated message, or the source message when no translation exists.\n */\nfunction gettext(msgid: string, values: Readonly<Record<string, unknown>> = {}): string {\n return interpolate(gettextLookup(msgid), values);\n}\n\n/**\n * Translates a singular/plural message pair according to the process locale.\n * @param msgid The singular source message stored in the catalog.\n * @param msgidPlural The plural source message stored in the catalog.\n * @param count The quantity used by the catalog's plural rule and exposed to interpolation as `count`.\n * @param values Additional values to interpolate into the translated message.\n * @returns The translated and interpolated plural form.\n */\nfunction ngettext(\n msgid: string,\n msgidPlural: string,\n count: number | bigint,\n values: Readonly<Record<string, unknown>> = {},\n): string {\n return interpolate(ngettextLookup(msgid, msgidPlural, count), { ...values, count });\n}\n\n/**\n * Translates a message disambiguated by gettext context.\n * @param context The catalog context separating this message from identical source text.\n * @param msgid The source message stored in the catalog.\n * @param values Values to interpolate into the translated message.\n * @returns The translated and interpolated message, or the source message when no translation exists.\n */\nfunction pgettext(context: string, msgid: string, values: Readonly<Record<string, unknown>> = {}): string {\n return interpolate(pgettextLookup(context, msgid), values);\n}\n\n/**\n * Translates a singular/plural message pair disambiguated by gettext context.\n * @param context The catalog context separating this message from identical source text.\n * @param msgid The singular source message stored in the catalog.\n * @param msgidPlural The plural source message stored in the catalog.\n * @param count The quantity used by the catalog's plural rule and exposed to interpolation as `count`.\n * @param values Additional values to interpolate into the translated message.\n * @returns The translated and interpolated contextual plural form.\n */\nfunction npgettext(\n ...[context, msgid, msgidPlural, count, values = {}]: [\n context: string,\n msgid: string,\n msgidPlural: string,\n count: number | bigint,\n values?: Readonly<Record<string, unknown>>,\n ]\n): string {\n return interpolate(npgettextLookup(context, msgid, msgidPlural, count), { ...values, count });\n}\n\nexport { _, gettext, ngettext, npgettext, pgettext };\n"]}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":""}
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import i18next from "i18next";
|
|
2
|
+
import { initReactI18next } from "react-i18next";
|
|
3
|
+
import { GETTEXT_RESOURCE_KEY, gettextBackend, isGettextCatalog, } from "./backend.js";
|
|
4
|
+
import { locale } from "./locale.js";
|
|
5
|
+
const gettextFormat = {
|
|
6
|
+
type: "i18nFormat",
|
|
7
|
+
handleAsObject: false,
|
|
8
|
+
addLookupKeys() {
|
|
9
|
+
return;
|
|
10
|
+
},
|
|
11
|
+
getResource(language, namespace, msgid, options) {
|
|
12
|
+
const resource = i18next.getResource(language, namespace, GETTEXT_RESOURCE_KEY, {
|
|
13
|
+
keySeparator: false,
|
|
14
|
+
});
|
|
15
|
+
if (!isGettextCatalog(resource)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return pointLookup(resource, msgid, options);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const getContext = (value) => {
|
|
22
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const context = String(value);
|
|
26
|
+
return context.length === 0 ? undefined : context;
|
|
27
|
+
};
|
|
28
|
+
const pluralLookup = ({ catalog, context, count, msgid, msgidPlural }) => {
|
|
29
|
+
if (context === undefined) {
|
|
30
|
+
return catalog.ngettext(msgid, msgidPlural, count);
|
|
31
|
+
}
|
|
32
|
+
const contextual = catalog.npgettext(context, msgid, msgidPlural, count);
|
|
33
|
+
return contextual === msgid || contextual === msgidPlural
|
|
34
|
+
? catalog.ngettext(msgid, msgidPlural, count)
|
|
35
|
+
: contextual;
|
|
36
|
+
};
|
|
37
|
+
const stringOption = (options, key) => {
|
|
38
|
+
const value = options[key];
|
|
39
|
+
return typeof value === "string" ? value : undefined;
|
|
40
|
+
};
|
|
41
|
+
const assertSupportedPluralOptions = (options) => {
|
|
42
|
+
if (options.ordinal === true || stringOption(options, "defaultValue_zero") !== undefined) {
|
|
43
|
+
throw new RangeError("GNU gettext does not support ordinal or zero-specific plural forms");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const pluralSources = (msgid, options) => {
|
|
47
|
+
assertSupportedPluralOptions(options);
|
|
48
|
+
const defaultValue = stringOption(options, "defaultValue");
|
|
49
|
+
const defaultValueOne = stringOption(options, "defaultValue_one");
|
|
50
|
+
const defaultValueOther = stringOption(options, "defaultValue_other");
|
|
51
|
+
const hasPluralDefaults = defaultValueOne !== undefined || defaultValueOther !== undefined;
|
|
52
|
+
if (!hasPluralDefaults) {
|
|
53
|
+
return { plural: defaultValue ?? msgid, singular: msgid };
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
plural: defaultValueOther ?? defaultValue ?? msgid,
|
|
57
|
+
singular: defaultValueOne ?? defaultValue ?? msgid,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const pluralPointLookup = (catalog, msgid, options, count) => {
|
|
61
|
+
const { plural, singular } = pluralSources(msgid, options);
|
|
62
|
+
return pluralLookup({
|
|
63
|
+
catalog,
|
|
64
|
+
context: getContext(options.context),
|
|
65
|
+
count,
|
|
66
|
+
msgid: singular,
|
|
67
|
+
msgidPlural: plural,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const contextualLookup = (catalog, source, context) => {
|
|
71
|
+
if (context === undefined) {
|
|
72
|
+
return catalog.gettext(source);
|
|
73
|
+
}
|
|
74
|
+
const translated = catalog.pgettext(context, source);
|
|
75
|
+
return translated === source ? catalog.gettext(source) : translated;
|
|
76
|
+
};
|
|
77
|
+
const singularPointLookup = (catalog, msgid, options) => {
|
|
78
|
+
const source = stringOption(options, "defaultValue") ?? msgid;
|
|
79
|
+
const translated = contextualLookup(catalog, source, getContext(options.context));
|
|
80
|
+
return translated === source ? undefined : translated;
|
|
81
|
+
};
|
|
82
|
+
const pointLookup = (catalog, msgid, options) => {
|
|
83
|
+
if (typeof options.count === "number") {
|
|
84
|
+
return pluralPointLookup(catalog, msgid, options, options.count);
|
|
85
|
+
}
|
|
86
|
+
return singularPointLookup(catalog, msgid, options);
|
|
87
|
+
};
|
|
88
|
+
i18next.use(gettextBackend).use(gettextFormat).use(initReactI18next);
|
|
89
|
+
void i18next.init({
|
|
90
|
+
defaultNS: "translation",
|
|
91
|
+
fallbackLng: false,
|
|
92
|
+
initAsync: false,
|
|
93
|
+
interpolation: { escapeValue: false },
|
|
94
|
+
keySeparator: false,
|
|
95
|
+
lng: locale,
|
|
96
|
+
ns: ["translation"],
|
|
97
|
+
nsSeparator: false,
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACH,oBAAoB,EACpB,cAAc,EAEd,gBAAgB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAgBrC,MAAM,aAAa,GAAkB;IACjC,IAAI,EAAE,YAAY;IAClB,cAAc,EAAE,KAAK;IACrB,aAAa;QACT,OAAO;IACX,CAAC;IACD,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO;QAC3C,MAAM,QAAQ,GAAY,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,oBAAoB,EAAE;YACrF,YAAY,EAAE,KAAK;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,gBAAgB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AAC,CAAC;AAErE,KAAK,OAAO,CAAC,IAAI,CAAC;IACd,SAAS,EAAE,aAAa;IACxB,WAAW,EAAE,KAAK;IAClB,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;IACrC,YAAY,EAAE,KAAK;IACnB,GAAG,EAAE,MAAM;IACX,EAAE,EAAE,CAAC,aAAa,CAAC;IACnB,WAAW,EAAE,KAAK;CACrB,CAAC,CAAC","sourcesContent":["import type { I18nFormatModule, TOptions } from \"i18next\";\nimport i18next from \"i18next\";\nimport { initReactI18next } from \"react-i18next\";\nimport {\n GETTEXT_RESOURCE_KEY,\n gettextBackend,\n type GettextCatalog,\n isGettextCatalog,\n} from \"./backend.js\";\nimport { locale } from \"./locale.js\";\n\ntype GettextFormat = I18nFormatModule & {\n addLookupKeys(): void;\n getResource(language: string, namespace: string, msgid: string, options: TOptions): string | undefined;\n handleAsObject: boolean;\n};\n\ntype PluralLookup = {\n catalog: GettextCatalog;\n context: string | undefined;\n count: number;\n msgid: string;\n msgidPlural: string;\n};\n\nconst gettextFormat: GettextFormat = {\n type: \"i18nFormat\",\n handleAsObject: false,\n addLookupKeys() {\n return;\n },\n getResource(language, namespace, msgid, options) {\n const resource: unknown = i18next.getResource(language, namespace, GETTEXT_RESOURCE_KEY, {\n keySeparator: false,\n });\n\n if (!isGettextCatalog(resource)) {\n return;\n }\n\n return pointLookup(resource, msgid, options);\n },\n};\n\nconst getContext = (value: unknown): string | undefined => {\n if (typeof value !== \"string\" && typeof value !== \"number\") {\n return undefined;\n }\n\n const context = String(value);\n\n return context.length === 0 ? undefined : context;\n};\n\nconst pluralLookup = ({ catalog, context, count, msgid, msgidPlural }: PluralLookup): string => {\n if (context === undefined) {\n return catalog.ngettext(msgid, msgidPlural, count);\n }\n\n const contextual = catalog.npgettext(context, msgid, msgidPlural, count);\n\n return contextual === msgid || contextual === msgidPlural\n ? catalog.ngettext(msgid, msgidPlural, count)\n : contextual;\n};\n\nconst stringOption = (options: TOptions, key: string): string | undefined => {\n const value = options[key];\n\n return typeof value === \"string\" ? value : undefined;\n};\n\nconst assertSupportedPluralOptions = (options: TOptions): void => {\n if (options.ordinal === true || stringOption(options, \"defaultValue_zero\") !== undefined) {\n throw new RangeError(\"GNU gettext does not support ordinal or zero-specific plural forms\");\n }\n};\n\nconst pluralSources = (msgid: string, options: TOptions): { plural: string; singular: string } => {\n assertSupportedPluralOptions(options);\n const defaultValue = stringOption(options, \"defaultValue\");\n const defaultValueOne = stringOption(options, \"defaultValue_one\");\n const defaultValueOther = stringOption(options, \"defaultValue_other\");\n const hasPluralDefaults = defaultValueOne !== undefined || defaultValueOther !== undefined;\n\n if (!hasPluralDefaults) {\n return { plural: defaultValue ?? msgid, singular: msgid };\n }\n\n return {\n plural: defaultValueOther ?? defaultValue ?? msgid,\n singular: defaultValueOne ?? defaultValue ?? msgid,\n };\n};\n\nconst pluralPointLookup = (\n catalog: GettextCatalog,\n msgid: string,\n options: TOptions,\n count: number,\n): string => {\n const { plural, singular } = pluralSources(msgid, options);\n\n return pluralLookup({\n catalog,\n context: getContext(options.context),\n count,\n msgid: singular,\n msgidPlural: plural,\n });\n};\n\nconst contextualLookup = (\n catalog: GettextCatalog,\n source: string,\n context: string | undefined,\n): string => {\n if (context === undefined) {\n return catalog.gettext(source);\n }\n\n const translated = catalog.pgettext(context, source);\n\n return translated === source ? catalog.gettext(source) : translated;\n};\n\nconst singularPointLookup = (\n catalog: GettextCatalog,\n msgid: string,\n options: TOptions,\n): string | undefined => {\n const source = stringOption(options, \"defaultValue\") ?? msgid;\n const translated = contextualLookup(catalog, source, getContext(options.context));\n\n return translated === source ? undefined : translated;\n};\n\nconst pointLookup = (catalog: GettextCatalog, msgid: string, options: TOptions): string | undefined => {\n if (typeof options.count === \"number\") {\n return pluralPointLookup(catalog, msgid, options, options.count);\n }\n\n return singularPointLookup(catalog, msgid, options);\n};\n\ni18next.use(gettextBackend).use(gettextFormat).use(initReactI18next);\n\nvoid i18next.init({\n defaultNS: \"translation\",\n fallbackLng: false,\n initAsync: false,\n interpolation: { escapeValue: false },\n keySeparator: false,\n lng: locale,\n ns: [\"translation\"],\n nsSeparator: false,\n});\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "./bootstrap.js";
|
|
2
|
+
import type { GetI18n, IcuTransComponent, IcuTransWithoutContextComponent, Init, TFunction, TransComponent, TranslationComponent, TransWithoutContextComponent, UseTranslation, WithTranslationFactory } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Translation metadata generated from an application's source messages.
|
|
5
|
+
* Applications augment this interface to enable strict translation calls.
|
|
6
|
+
*/
|
|
7
|
+
interface TranslationRegistry extends Record<never, never> {
|
|
8
|
+
}
|
|
9
|
+
/** Translates a message through the configured i18next singleton. */
|
|
10
|
+
declare const t: TFunction;
|
|
11
|
+
/** Initializes the configured i18next singleton. */
|
|
12
|
+
declare const init: Init;
|
|
13
|
+
/** Returns the configured i18next singleton. */
|
|
14
|
+
declare const getI18n: GetI18n;
|
|
15
|
+
/** Returns a translator and the configured i18next instance for React components. */
|
|
16
|
+
declare const useTranslation: UseTranslation;
|
|
17
|
+
/** Injects the configured translator into a React component. */
|
|
18
|
+
declare const withTranslation: WithTranslationFactory;
|
|
19
|
+
/** Supplies the configured translator through a React render prop. */
|
|
20
|
+
declare const Translation: TranslationComponent;
|
|
21
|
+
/** Renders translated React content through the configured i18next singleton. */
|
|
22
|
+
declare const Trans: TransComponent;
|
|
23
|
+
/** Renders translated React content without an inherited gettext context. */
|
|
24
|
+
declare const TransWithoutContext: TransWithoutContextComponent;
|
|
25
|
+
/** Renders ICU-formatted React content through the configured i18next singleton. */
|
|
26
|
+
declare const IcuTrans: IcuTransComponent;
|
|
27
|
+
/** Renders ICU-formatted React content without an inherited gettext context. */
|
|
28
|
+
declare const IcuTransWithoutContext: IcuTransWithoutContextComponent;
|
|
29
|
+
export { IcuTrans, IcuTransWithoutContext, getI18n, init, Trans, TransWithoutContext, Translation, t, type TranslationRegistry, useTranslation, withTranslation, };
|
|
30
|
+
export type { TFunction, TranslationProps, UseTranslationResponse, WithTranslation, } from "./types.js";
|
|
31
|
+
export * from "react-i18next";
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EACR,OAAO,EACP,iBAAiB,EACjB,+BAA+B,EAC/B,IAAI,EACJ,SAAS,EACT,cAAc,EACd,oBAAoB,EACpB,4BAA4B,EAC5B,cAAc,EACd,sBAAsB,EACzB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AAEH,UAAU,mBAAoB,SAAQ,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;CAAG;AAE7D,qEAAqE;AACrE,QAAA,MAAM,CAAC,EAAE,SAAqB,CAAC;AAC/B,oDAAoD;AACpD,QAAA,MAAM,IAAI,EAAE,IAAmB,CAAC;AAChC,gDAAgD;AAChD,QAAA,MAAM,OAAO,EAAE,OAAyB,CAAC;AACzC,qFAAqF;AACrF,QAAA,MAAM,cAAc,EAAE,cAAuC,CAAC;AAC9D,gEAAgE;AAChE,QAAA,MAAM,eAAe,EAAE,sBAAgD,CAAC;AACxE,sEAAsE;AACtE,QAAA,MAAM,WAAW,EAAE,oBAA0C,CAAC;AAC9D,iFAAiF;AACjF,QAAA,MAAM,KAAK,EAAE,cAA8B,CAAC;AAC5C,6EAA6E;AAC7E,QAAA,MAAM,mBAAmB,EAAE,4BAA0D,CAAC;AACtF,oFAAoF;AACpF,QAAA,MAAM,QAAQ,EAAE,iBAAoC,CAAC;AACrD,gFAAgF;AAChF,QAAA,MAAM,sBAAsB,EAAE,+BAAgE,CAAC;AAE/F,OAAO,EACH,QAAQ,EACR,sBAAsB,EACtB,OAAO,EACP,IAAI,EACJ,KAAK,EACL,mBAAmB,EACnB,WAAW,EACX,CAAC,EACD,KAAK,mBAAmB,EACxB,cAAc,EACd,eAAe,GAClB,CAAC;AACF,YAAY,EACR,SAAS,EACT,gBAAgB,EAChB,sBAAsB,EACtB,eAAe,GAClB,MAAM,YAAY,CAAC;AACpB,cAAc,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "./bootstrap.js";
|
|
2
|
+
import { init as upstreamInit, t as upstreamT } from "i18next";
|
|
3
|
+
import { getI18n as upstreamGetI18n, IcuTrans as upstreamIcuTrans, IcuTransWithoutContext as upstreamIcuTransWithoutContext, Trans as upstreamTrans, Translation as upstreamTranslation, TransWithoutContext as upstreamTransWithoutContext, useTranslation as upstreamUseTranslation, withTranslation as upstreamWithTranslation, } from "react-i18next";
|
|
4
|
+
/** Translates a message through the configured i18next singleton. */
|
|
5
|
+
const t = upstreamT;
|
|
6
|
+
/** Initializes the configured i18next singleton. */
|
|
7
|
+
const init = upstreamInit;
|
|
8
|
+
/** Returns the configured i18next singleton. */
|
|
9
|
+
const getI18n = upstreamGetI18n;
|
|
10
|
+
/** Returns a translator and the configured i18next instance for React components. */
|
|
11
|
+
const useTranslation = upstreamUseTranslation;
|
|
12
|
+
/** Injects the configured translator into a React component. */
|
|
13
|
+
const withTranslation = upstreamWithTranslation;
|
|
14
|
+
/** Supplies the configured translator through a React render prop. */
|
|
15
|
+
const Translation = upstreamTranslation;
|
|
16
|
+
/** Renders translated React content through the configured i18next singleton. */
|
|
17
|
+
const Trans = upstreamTrans;
|
|
18
|
+
/** Renders translated React content without an inherited gettext context. */
|
|
19
|
+
const TransWithoutContext = upstreamTransWithoutContext;
|
|
20
|
+
/** Renders ICU-formatted React content through the configured i18next singleton. */
|
|
21
|
+
const IcuTrans = upstreamIcuTrans;
|
|
22
|
+
/** Renders ICU-formatted React content without an inherited gettext context. */
|
|
23
|
+
const IcuTransWithoutContext = upstreamIcuTransWithoutContext;
|
|
24
|
+
export { IcuTrans, IcuTransWithoutContext, getI18n, init, Trans, TransWithoutContext, Translation, t, useTranslation, withTranslation, };
|
|
25
|
+
export * from "react-i18next";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,CAAC,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EACH,OAAO,IAAI,eAAe,EAC1B,QAAQ,IAAI,gBAAgB,EAC5B,sBAAsB,IAAI,8BAA8B,EACxD,KAAK,IAAI,aAAa,EACtB,WAAW,IAAI,mBAAmB,EAClC,mBAAmB,IAAI,2BAA2B,EAClD,cAAc,IAAI,sBAAsB,EACxC,eAAe,IAAI,uBAAuB,GAC7C,MAAM,eAAe,CAAC;AAqBvB,qEAAqE;AACrE,MAAM,CAAC,GAAc,SAAS,CAAC;AAC/B,oDAAoD;AACpD,MAAM,IAAI,GAAS,YAAY,CAAC;AAChC,gDAAgD;AAChD,MAAM,OAAO,GAAY,eAAe,CAAC;AACzC,qFAAqF;AACrF,MAAM,cAAc,GAAmB,sBAAsB,CAAC;AAC9D,gEAAgE;AAChE,MAAM,eAAe,GAA2B,uBAAuB,CAAC;AACxE,sEAAsE;AACtE,MAAM,WAAW,GAAyB,mBAAmB,CAAC;AAC9D,iFAAiF;AACjF,MAAM,KAAK,GAAmB,aAAa,CAAC;AAC5C,6EAA6E;AAC7E,MAAM,mBAAmB,GAAiC,2BAA2B,CAAC;AACtF,oFAAoF;AACpF,MAAM,QAAQ,GAAsB,gBAAgB,CAAC;AACrD,gFAAgF;AAChF,MAAM,sBAAsB,GAAoC,8BAA8B,CAAC;AAE/F,OAAO,EACH,QAAQ,EACR,sBAAsB,EACtB,OAAO,EACP,IAAI,EACJ,KAAK,EACL,mBAAmB,EACnB,WAAW,EACX,CAAC,EAED,cAAc,EACd,eAAe,GAClB,CAAC;AAOF,cAAc,eAAe,CAAC","sourcesContent":["import \"./bootstrap.js\";\nimport { init as upstreamInit, t as upstreamT } from \"i18next\";\nimport {\n getI18n as upstreamGetI18n,\n IcuTrans as upstreamIcuTrans,\n IcuTransWithoutContext as upstreamIcuTransWithoutContext,\n Trans as upstreamTrans,\n Translation as upstreamTranslation,\n TransWithoutContext as upstreamTransWithoutContext,\n useTranslation as upstreamUseTranslation,\n withTranslation as upstreamWithTranslation,\n} from \"react-i18next\";\nimport type {\n GetI18n,\n IcuTransComponent,\n IcuTransWithoutContextComponent,\n Init,\n TFunction,\n TransComponent,\n TranslationComponent,\n TransWithoutContextComponent,\n UseTranslation,\n WithTranslationFactory,\n} from \"./types.js\";\n\n/**\n * Translation metadata generated from an application's source messages.\n * Applications augment this interface to enable strict translation calls.\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- declaration merging requires an interface\ninterface TranslationRegistry extends Record<never, never> {}\n\n/** Translates a message through the configured i18next singleton. */\nconst t: TFunction = upstreamT;\n/** Initializes the configured i18next singleton. */\nconst init: Init = upstreamInit;\n/** Returns the configured i18next singleton. */\nconst getI18n: GetI18n = upstreamGetI18n;\n/** Returns a translator and the configured i18next instance for React components. */\nconst useTranslation: UseTranslation = upstreamUseTranslation;\n/** Injects the configured translator into a React component. */\nconst withTranslation: WithTranslationFactory = upstreamWithTranslation;\n/** Supplies the configured translator through a React render prop. */\nconst Translation: TranslationComponent = upstreamTranslation;\n/** Renders translated React content through the configured i18next singleton. */\nconst Trans: TransComponent = upstreamTrans;\n/** Renders translated React content without an inherited gettext context. */\nconst TransWithoutContext: TransWithoutContextComponent = upstreamTransWithoutContext;\n/** Renders ICU-formatted React content through the configured i18next singleton. */\nconst IcuTrans: IcuTransComponent = upstreamIcuTrans;\n/** Renders ICU-formatted React content without an inherited gettext context. */\nconst IcuTransWithoutContext: IcuTransWithoutContextComponent = upstreamIcuTransWithoutContext;\n\nexport {\n IcuTrans,\n IcuTransWithoutContext,\n getI18n,\n init,\n Trans,\n TransWithoutContext,\n Translation,\n t,\n type TranslationRegistry,\n useTranslation,\n withTranslation,\n};\nexport type {\n TFunction,\n TranslationProps,\n UseTranslationResponse,\n WithTranslation,\n} from \"./types.js\";\nexport * from \"react-i18next\";\n"]}
|
package/dist/locale.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,MAAM,EAAE,MAA2B,CAAC;AAoB1C,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/locale.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t } from "@gtkx/runtime";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { applicationId } from "virtual:gtkx-config";
|
|
4
|
+
const LIBC = "libc.so.6";
|
|
5
|
+
const LC_ALL = 6;
|
|
6
|
+
const GETTEXT_CODESET = ["UTF", "8"].join("-");
|
|
7
|
+
const setLocaleBinding = t.bind(LIBC, "setlocale", [t.int32, t.string()], t.string());
|
|
8
|
+
const bindTextDomainBinding = t.bind(LIBC, "bindtextdomain", [t.string(), t.string()], t.string());
|
|
9
|
+
const bindTextDomainCodesetBinding = t.bind(LIBC, "bind_textdomain_codeset", [t.string(), t.string()], t.string());
|
|
10
|
+
const textDomainBinding = t.bind(LIBC, "textdomain", [t.string()], t.string());
|
|
11
|
+
const locale = initializeLocale();
|
|
12
|
+
function requireStringResult(result) {
|
|
13
|
+
if (typeof result !== "string") {
|
|
14
|
+
throw new TypeError("Unable to initialize the process locale");
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function initializeLocale() {
|
|
19
|
+
const localeDir = process.env.GTKX_LOCALE_DIR ?? fileURLToPath(new URL("locale", import.meta.url));
|
|
20
|
+
const initialized = requireStringResult(setLocaleBinding(LC_ALL, ""));
|
|
21
|
+
requireStringResult(bindTextDomainBinding(applicationId, localeDir));
|
|
22
|
+
requireStringResult(bindTextDomainCodesetBinding(applicationId, GETTEXT_CODESET));
|
|
23
|
+
requireStringResult(textDomainBinding(applicationId));
|
|
24
|
+
return initialized;
|
|
25
|
+
}
|
|
26
|
+
export { locale };
|
|
27
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,IAAI,GAAG,WAAW,CAAC;AACzB,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACtF,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAEnG,MAAM,4BAA4B,GAAG,CAAC,CAAC,IAAI,CACvC,IAAI,EACJ,yBAAyB,EACzB,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EACxB,CAAC,CAAC,MAAM,EAAE,CACb,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AAC/E,MAAM,MAAM,GAAW,gBAAgB,EAAE,CAAC;AAE1C,SAAS,mBAAmB,CAAC,MAAe;IACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB;IACrB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,aAAa,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACnG,MAAM,WAAW,GAAG,mBAAmB,CAAC,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;IACtE,mBAAmB,CAAC,qBAAqB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;IACrE,mBAAmB,CAAC,4BAA4B,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC,CAAC;IAClF,mBAAmB,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC;IAEtD,OAAO,WAAW,CAAC;AACvB,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["import { t } from \"@gtkx/runtime\";\nimport { fileURLToPath } from \"node:url\";\nimport { applicationId } from \"virtual:gtkx-config\";\n\nconst LIBC = \"libc.so.6\";\nconst LC_ALL = 6;\nconst GETTEXT_CODESET = [\"UTF\", \"8\"].join(\"-\");\nconst setLocaleBinding = t.bind(LIBC, \"setlocale\", [t.int32, t.string()], t.string());\nconst bindTextDomainBinding = t.bind(LIBC, \"bindtextdomain\", [t.string(), t.string()], t.string());\n\nconst bindTextDomainCodesetBinding = t.bind(\n LIBC,\n \"bind_textdomain_codeset\",\n [t.string(), t.string()],\n t.string(),\n);\n\nconst textDomainBinding = t.bind(LIBC, \"textdomain\", [t.string()], t.string());\nconst locale: string = initializeLocale();\n\nfunction requireStringResult(result: unknown): string {\n if (typeof result !== \"string\") {\n throw new TypeError(\"Unable to initialize the process locale\");\n }\n\n return result;\n}\n\nfunction initializeLocale(): string {\n const localeDir = process.env.GTKX_LOCALE_DIR ?? fileURLToPath(new URL(\"locale\", import.meta.url));\n const initialized = requireStringResult(setLocaleBinding(LC_ALL, \"\"));\n requireStringResult(bindTextDomainBinding(applicationId, localeDir));\n requireStringResult(bindTextDomainCodesetBinding(applicationId, GETTEXT_CODESET));\n requireStringResult(textDomainBinding(applicationId));\n\n return initialized;\n}\n\nexport { locale };\n"]}
|