@gtkx/i18n 2.0.0-beta.10 → 2.0.0-beta.11
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 +8 -168
- package/dist/backend.d.ts +3 -3
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +7 -14
- package/dist/backend.js.map +1 -1
- package/dist/i18n.js +3 -7
- package/dist/i18n.js.map +1 -1
- package/dist/locale.js +2 -2
- package/dist/locale.js.map +1 -1
- package/package.json +11 -10
- package/src/backend.ts +12 -21
- package/src/i18n.ts +3 -9
- package/src/locale.ts +2 -2
package/README.md
CHANGED
|
@@ -1,177 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="https://raw.githubusercontent.com/gtkx-org/gtkx/main/logo.svg" alt="GTKX" width="100" />
|
|
3
|
-
</p>
|
|
1
|
+
# @gtkx/i18n
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Gettext localization for GTKX through react-i18next.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
The React framework for Linux.<br />
|
|
9
|
-
Write native GNOME applications with React and TypeScript.
|
|
10
|
-
Real Adwaita and GTK4 widgets with standard web tooling.
|
|
11
|
-
</p>
|
|
5
|
+
Translate React content with `useTranslation` and `Trans`. The CLI extracts messages and compiles gettext catalogs; application bootstrap loads the catalog for the current locale.
|
|
12
6
|
|
|
13
|
-
|
|
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%A526.7-339933?logo=node.js&logoColor=white" alt="Node >= 26.7" />
|
|
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
|
-
This app starts with an Adwaita application shell, renders native GTK4 widgets inside it, and uses ordinary React hooks and events:
|
|
42
|
-
|
|
43
|
-
```tsx
|
|
44
|
-
import * as Gtk from "@gtkx/gi/gtk";
|
|
45
|
-
import { AdwApplication, AdwApplicationWindow, AdwHeaderBar, AdwToolbarView } from "@gtkx/jsx/adw";
|
|
46
|
-
import { GtkBox, GtkButton, GtkLabel } from "@gtkx/jsx/gtk";
|
|
47
|
-
import { createRoot, quit } from "@gtkx/react";
|
|
48
|
-
import { useState } from "react";
|
|
49
|
-
|
|
50
|
-
const Counter = () => {
|
|
51
|
-
const [count, setCount] = useState(0);
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<AdwApplicationWindow
|
|
55
|
-
title="Hello GTKX"
|
|
56
|
-
defaultWidth={400}
|
|
57
|
-
defaultHeight={300}
|
|
58
|
-
onCloseRequest={quit}
|
|
59
|
-
>
|
|
60
|
-
<AdwToolbarView topBar={<AdwHeaderBar />}>
|
|
61
|
-
<GtkBox
|
|
62
|
-
orientation={Gtk.Orientation.VERTICAL}
|
|
63
|
-
spacing={20}
|
|
64
|
-
marginTop={40}
|
|
65
|
-
marginBottom={40}
|
|
66
|
-
marginStart={40}
|
|
67
|
-
marginEnd={40}
|
|
68
|
-
valign={Gtk.Align.CENTER}
|
|
69
|
-
halign={Gtk.Align.CENTER}
|
|
70
|
-
>
|
|
71
|
-
<GtkLabel cssClasses={["title-1"]}>Welcome to GTKX!</GtkLabel>
|
|
72
|
-
<GtkLabel cssClasses={["title-2"]}>{`Count: ${String(count)}`}</GtkLabel>
|
|
73
|
-
<GtkButton
|
|
74
|
-
label="Increment"
|
|
75
|
-
onClicked={() => setCount((c) => c + 1)}
|
|
76
|
-
cssClasses={["suggested-action", "pill"]}
|
|
77
|
-
/>
|
|
78
|
-
</GtkBox>
|
|
79
|
-
</AdwToolbarView>
|
|
80
|
-
</AdwApplicationWindow>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const App = () => (
|
|
85
|
-
<AdwApplication>
|
|
86
|
-
<Counter />
|
|
87
|
-
</AdwApplication>
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
createRoot().render(<App />);
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
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.
|
|
94
|
-
|
|
95
|
-
## Why GTKX
|
|
96
|
-
|
|
97
|
-
### Adwaita-first application development
|
|
98
|
-
|
|
99
|
-
GTKX uses Adwaita as the foundation for applications, windows, navigation, dialogs, and adaptive layouts, with the complete GTK4 toolkit underneath. It adds a declarative React layer and an integrated TypeScript toolchain to the GNOME platform:
|
|
100
|
-
|
|
101
|
-
- a React reconciler that exposes every GObject as a JSX element,
|
|
102
|
-
- a CLI for scaffolding, development, and production builds,
|
|
103
|
-
- a dev server with Fast Refresh that patches your running UI in place,
|
|
104
|
-
- CSS-in-JS styling, React Hook Form-powered Adwaita controls, gettext-backed react-i18next localization, React Spring animations, React Navigation stack, tab, drawer, and split view navigators, and high-level list, grid, and dialog components,
|
|
105
|
-
- a Testing Library-style API for querying and driving your widgets in tests,
|
|
106
|
-
- and a Model Context Protocol (MCP) server that exposes your live app to AI agents.
|
|
107
|
-
|
|
108
|
-
### Native GNOME widgets, without a compatibility layer
|
|
109
|
-
|
|
110
|
-
React Native and similar frameworks hide the native toolkit so one API can run everywhere. GTKX renders real Adwaita and GTK4 widgets and exposes any other GObject-Introspection library on your system. It is GNOME-native and Linux-only by design.
|
|
111
|
-
|
|
112
|
-
### Why Node.js, and why generated bindings
|
|
113
|
-
|
|
114
|
-
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.
|
|
115
|
-
|
|
116
|
-
GTKX generates the TypeScript types and native FFI calls from the same GObject-Introspection data, so the types cannot drift from the calls they back. `Adw-1` is the sole default GIR root; its GIR include pulls in `Gtk-4.0`, so codegen covers both complete API surfaces. Neither belongs in a GTKX 2 `libraries` list.
|
|
117
|
-
|
|
118
|
-
At runtime, the native Rust core calls straight into the system Adwaita, GTK4, and GLib libraries through libffi, without loading libgirepository at all.
|
|
119
|
-
|
|
120
|
-
## Quick start
|
|
121
|
-
|
|
122
|
-
GTKX is Linux-only and needs Node.js 26.7 or later. See [Requirements](#requirements).
|
|
123
|
-
|
|
124
|
-
Scaffold a new app with the `create-gtkx` initializer:
|
|
7
|
+
In an existing GTKX 2.0 beta app:
|
|
125
8
|
|
|
126
9
|
```sh
|
|
127
|
-
npm
|
|
10
|
+
npm install @gtkx/i18n@beta
|
|
128
11
|
```
|
|
129
12
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
Then run your new app:
|
|
133
|
-
|
|
134
|
-
```sh
|
|
135
|
-
cd my-app
|
|
136
|
-
npm run dev
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
To go further, follow the [tutorial](https://gtkx.dev/tutorial/).
|
|
140
|
-
|
|
141
|
-
## Documentation
|
|
142
|
-
|
|
143
|
-
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.
|
|
144
|
-
|
|
145
|
-
**[Read the docs →](https://gtkx.dev/guide/why-gtkx)**
|
|
146
|
-
|
|
147
|
-
## Requirements
|
|
148
|
-
|
|
149
|
-
GTKX is Linux-only. You need:
|
|
150
|
-
|
|
151
|
-
- Linux with the Adwaita (1.8 or later), GTK4 (4.20 or later), and GLib development libraries
|
|
152
|
-
- Node.js 26.7 or later
|
|
153
|
-
|
|
154
|
-
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.
|
|
155
|
-
|
|
156
|
-
## Examples
|
|
157
|
-
|
|
158
|
-
Explore the [example apps](https://github.com/gtkx-org/gtkx/tree/main/examples):
|
|
159
|
-
|
|
160
|
-
- [`hello-world`](https://github.com/gtkx-org/gtkx/tree/main/examples/hello-world): the Adwaita counter above.
|
|
161
|
-
- [`gtk-demo`](https://github.com/gtkx-org/gtkx/tree/main/examples/gtk-demo): the official GTK4 widget showcase in an Adwaita application shell, covering lists, dialogs, gestures, CSS, and OpenGL.
|
|
162
|
-
- [`browser`](https://github.com/gtkx-org/gtkx/tree/main/examples/browser): an Adwaita browser built around `WebKitWebView`.
|
|
163
|
-
- [`animations`](https://github.com/gtkx-org/gtkx/tree/main/examples/animations): an Adwaita showcase for `@gtkx/animated`, with React Spring animations driven by the GTK frame clock.
|
|
164
|
-
- [`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.
|
|
165
|
-
- [`tutorial`](https://github.com/gtkx-org/gtkx/tree/main/examples/tutorial): the Tasks app the documentation builds.
|
|
166
|
-
|
|
167
|
-
## Status
|
|
168
|
-
|
|
169
|
-
GTKX is stable and ready for production use.
|
|
170
|
-
|
|
171
|
-
## Contributing
|
|
172
|
-
|
|
173
|
-
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 26.7 or later, pnpm, and a Rust toolchain.
|
|
13
|
+
[Guide](https://gtkx.dev/v2/guide/internationalization) · [API reference](https://gtkx.dev/v2/reference/@gtkx/i18n/) · [GTKX](https://gtkx.dev)
|
|
174
14
|
|
|
175
|
-
|
|
15
|
+
GTKX runs on Linux with Node.js and system native libraries. See [Getting Started](https://gtkx.dev/v2/guide/getting-started) for supported versions and installation. This README describes the 2.0 beta.
|
|
176
16
|
|
|
177
|
-
|
|
17
|
+
[MPL-2.0](https://github.com/gtkx-org/gtkx/blob/main/LICENSE).
|
package/dist/backend.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { BackendModule } from "i18next";
|
|
2
2
|
type GettextCatalog = {
|
|
3
3
|
gettext(msgid: string): string;
|
|
4
|
-
ngettext(msgid: string, msgidPlural: string, count: number
|
|
5
|
-
npgettext(context: string, msgid: string, msgidPlural: string, count: number
|
|
6
|
-
pgettext(context: string, msgid: string): string;
|
|
4
|
+
ngettext(msgid: string, msgidPlural: string, count: number): string;
|
|
5
|
+
npgettext(context: string, msgid: string, msgidPlural: string, count: number): string | undefined;
|
|
6
|
+
pgettext(context: string, msgid: string): string | undefined;
|
|
7
7
|
};
|
|
8
8
|
declare const GETTEXT_RESOURCE_KEY = "__gtkx_gettext_catalog__";
|
|
9
9
|
declare const gettextBackend: BackendModule;
|
package/dist/backend.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,CAAC;IACpE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAClG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAChE,CAAC;AAGF,QAAA,MAAM,oBAAoB,6BAA6B,CAAC;AA8BxD,QAAA,MAAM,cAAc,EAAE,aAQrB,CAAC;AAWF,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
CHANGED
|
@@ -10,16 +10,15 @@ const gettextCatalog = {
|
|
|
10
10
|
return GLib.dngettext(applicationId, msgid, msgidPlural, normalizeCount(count));
|
|
11
11
|
},
|
|
12
12
|
pgettext(context, msgid) {
|
|
13
|
-
|
|
13
|
+
const contextual = contextualMsgid(context, msgid);
|
|
14
|
+
const translated = GLib.dgettext(applicationId, contextual);
|
|
15
|
+
return translated === contextual ? undefined : translated;
|
|
14
16
|
},
|
|
15
17
|
npgettext(context, msgid, msgidPlural, count) {
|
|
16
18
|
const contextualSingular = contextualMsgid(context, msgid);
|
|
17
19
|
const contextualPlural = contextualMsgid(context, msgidPlural);
|
|
18
20
|
const translated = GLib.dngettext(applicationId, contextualSingular, contextualPlural, normalizeCount(count));
|
|
19
|
-
|
|
20
|
-
return msgid;
|
|
21
|
-
}
|
|
22
|
-
return translated === contextualPlural ? msgidPlural : translated;
|
|
21
|
+
return translated === contextualSingular || translated === contextualPlural ? undefined : translated;
|
|
23
22
|
},
|
|
24
23
|
};
|
|
25
24
|
const gettextBackend = {
|
|
@@ -32,16 +31,10 @@ const gettextBackend = {
|
|
|
32
31
|
},
|
|
33
32
|
};
|
|
34
33
|
const normalizeCount = (count) => {
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
throw new RangeError("gettext counts must be non-negative safe integers");
|
|
38
|
-
}
|
|
39
|
-
return BigInt(count);
|
|
34
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
35
|
+
throw new RangeError("gettext counts must be non-negative safe integers");
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
throw new RangeError("gettext counts must be non-negative");
|
|
43
|
-
}
|
|
44
|
-
return count;
|
|
37
|
+
return BigInt(count);
|
|
45
38
|
};
|
|
46
39
|
const contextualMsgid = (context, msgid) => `${context}${CONTEXT_SEPARATOR}${msgid}`;
|
|
47
40
|
const isGettextCatalog = (value) => value === gettextCatalog;
|
package/dist/backend.js.map
CHANGED
|
@@ -1 +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,
|
|
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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M,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,UAAU,CAAC,mDAAmD,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE,CAAC,GAAG,OAAO,GAAG,iBAAiB,GAAG,KAAK,EAAE,CAAC;AAC7G,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA2B,EAAE,CAAC,KAAK,KAAK,cAAc,CAAC;AAE/F,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,EAAuB,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): string;\n npgettext(context: string, msgid: string, msgidPlural: string, count: number): string | undefined;\n pgettext(context: string, msgid: string): string | undefined;\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 const contextual = contextualMsgid(context, msgid);\n const translated = GLib.dgettext(applicationId, contextual);\n\n return translated === contextual ? undefined : translated;\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 return translated === contextualSingular || translated === contextualPlural ? undefined : 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 => {\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\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"]}
|
package/dist/i18n.js
CHANGED
|
@@ -29,10 +29,7 @@ const pluralLookup = ({ catalog, context, count, msgid, msgidPlural }) => {
|
|
|
29
29
|
if (context === undefined) {
|
|
30
30
|
return catalog.ngettext(msgid, msgidPlural, count);
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
return contextual === msgid || contextual === msgidPlural
|
|
34
|
-
? catalog.ngettext(msgid, msgidPlural, count)
|
|
35
|
-
: contextual;
|
|
32
|
+
return catalog.npgettext(context, msgid, msgidPlural, count) ?? catalog.ngettext(msgid, msgidPlural, count);
|
|
36
33
|
};
|
|
37
34
|
const stringOption = (options, key) => {
|
|
38
35
|
const value = options[key];
|
|
@@ -71,8 +68,7 @@ const contextualLookup = (catalog, source, context) => {
|
|
|
71
68
|
if (context === undefined) {
|
|
72
69
|
return catalog.gettext(source);
|
|
73
70
|
}
|
|
74
|
-
|
|
75
|
-
return translated === source ? catalog.gettext(source) : translated;
|
|
71
|
+
return catalog.pgettext(context, source) ?? catalog.gettext(source);
|
|
76
72
|
};
|
|
77
73
|
const singularPointLookup = (catalog, msgid, options) => {
|
|
78
74
|
const source = stringOption(options, "defaultValue") ?? msgid;
|
|
@@ -80,7 +76,7 @@ const singularPointLookup = (catalog, msgid, options) => {
|
|
|
80
76
|
return translated === source ? undefined : translated;
|
|
81
77
|
};
|
|
82
78
|
const pointLookup = (catalog, msgid, options) => {
|
|
83
|
-
if (
|
|
79
|
+
if (options.count !== undefined) {
|
|
84
80
|
return pluralPointLookup(catalog, msgid, options, options.count);
|
|
85
81
|
}
|
|
86
82
|
return singularPointLookup(catalog, msgid, options);
|
package/dist/i18n.js.map
CHANGED
|
@@ -1 +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,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9B,OAAO;QACX,CAAC;QAED,OAAO,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;CACJ,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,KAAc,EAAsB,EAAE;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACzD,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE9B,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC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,OAAiB,EACC,EAAE;IACpB,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,KAAK,CAAC;IAC9D,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAElF,OAAO,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;AAC1D,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,OAAuB,EAAE,KAAa,EAAE,OAAiB,EAAsB,EAAE;IAClG,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,mBAAmB,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,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,gBAAgB,EAAE,OAAO;IACzB,YAAY,EAAE,GAAG;IACjB,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 return catalog.npgettext(context, msgid, msgidPlural, count) ?? catalog.ngettext(msgid, msgidPlural, count);\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 return catalog.pgettext(context, source) ?? catalog.gettext(source);\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 (options.count !== undefined) {\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 contextSeparator: \"\\u{4}\",\n keySeparator: \".\",\n lng: locale,\n ns: [\"translation\"],\n nsSeparator: false,\n});\n"]}
|
package/dist/locale.js
CHANGED
|
@@ -17,11 +17,11 @@ function requireStringResult(result) {
|
|
|
17
17
|
}
|
|
18
18
|
function initializeLocale() {
|
|
19
19
|
const localeDir = process.env.GTKX_LOCALE_DIR ?? fileURLToPath(new URL("locale", import.meta.url));
|
|
20
|
-
|
|
20
|
+
requireStringResult(setLocaleBinding(LC_ALL, ""));
|
|
21
21
|
requireStringResult(bindTextDomainBinding(applicationId, localeDir));
|
|
22
22
|
requireStringResult(bindTextDomainCodesetBinding(applicationId, GETTEXT_CODESET));
|
|
23
23
|
requireStringResult(textDomainBinding(applicationId));
|
|
24
|
-
return
|
|
24
|
+
return new Intl.NumberFormat().resolvedOptions().locale;
|
|
25
25
|
}
|
|
26
26
|
export { locale };
|
|
27
27
|
//# sourceMappingURL=locale.js.map
|
package/dist/locale.js.map
CHANGED
|
@@ -1 +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,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B,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,mBAAmB,CAAC,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;IAClD,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,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC;AAC5D,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 requireStringResult(setLocaleBinding(LC_ALL, \"\"));\n requireStringResult(bindTextDomainBinding(applicationId, localeDir));\n requireStringResult(bindTextDomainCodesetBinding(applicationId, GETTEXT_CODESET));\n requireStringResult(textDomainBinding(applicationId));\n\n return new Intl.NumberFormat().resolvedOptions().locale;\n}\n\nexport { locale };\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/i18n",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0-beta.11",
|
|
4
|
+
"description": "Gettext localization for GTKX through react-i18next.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtkx",
|
|
7
7
|
"gtk",
|
|
@@ -70,19 +70,20 @@
|
|
|
70
70
|
"node": ">=26.7.0"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@gtkx/runtime": "2.0.0-beta.
|
|
73
|
+
"@gtkx/runtime": "2.0.0-beta.11",
|
|
74
74
|
"i18next": "^26.4.2",
|
|
75
|
-
"react-i18next": "^17.0.
|
|
75
|
+
"react-i18next": "^17.0.15"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"react": "^19.
|
|
78
|
+
"@types/react": "^19.3",
|
|
79
|
+
"react": "^19.3"
|
|
79
80
|
},
|
|
80
81
|
"devDependencies": {
|
|
81
|
-
"@gtkx/config": "2.0.0-beta.
|
|
82
|
-
"@gtkx/testing": "2.0.0-beta.
|
|
83
|
-
"@gtkx/vitest": "2.0.0-beta.
|
|
84
|
-
"@types/react": "^19.
|
|
85
|
-
"vitest": "^5.0.
|
|
82
|
+
"@gtkx/config": "2.0.0-beta.11",
|
|
83
|
+
"@gtkx/testing": "2.0.0-beta.11",
|
|
84
|
+
"@gtkx/vitest": "2.0.0-beta.11",
|
|
85
|
+
"@types/react": "^19.3.0",
|
|
86
|
+
"vitest": "^5.0.1"
|
|
86
87
|
},
|
|
87
88
|
"scripts": {
|
|
88
89
|
"release": "tsx ../../scripts/release-package.ts"
|
package/src/backend.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { applicationId } from "virtual:gtkx-config";
|
|
|
4
4
|
|
|
5
5
|
type GettextCatalog = {
|
|
6
6
|
gettext(msgid: string): string;
|
|
7
|
-
ngettext(msgid: string, msgidPlural: string, count: number
|
|
8
|
-
npgettext(context: string, msgid: string, msgidPlural: string, count: number
|
|
9
|
-
pgettext(context: string, msgid: string): string;
|
|
7
|
+
ngettext(msgid: string, msgidPlural: string, count: number): string;
|
|
8
|
+
npgettext(context: string, msgid: string, msgidPlural: string, count: number): string | undefined;
|
|
9
|
+
pgettext(context: string, msgid: string): string | undefined;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
const CONTEXT_SEPARATOR = "\u{4}";
|
|
@@ -20,7 +20,10 @@ const gettextCatalog: GettextCatalog = {
|
|
|
20
20
|
return GLib.dngettext(applicationId, msgid, msgidPlural, normalizeCount(count));
|
|
21
21
|
},
|
|
22
22
|
pgettext(context, msgid) {
|
|
23
|
-
|
|
23
|
+
const contextual = contextualMsgid(context, msgid);
|
|
24
|
+
const translated = GLib.dgettext(applicationId, contextual);
|
|
25
|
+
|
|
26
|
+
return translated === contextual ? undefined : translated;
|
|
24
27
|
},
|
|
25
28
|
npgettext(context, msgid, msgidPlural, count) {
|
|
26
29
|
const contextualSingular = contextualMsgid(context, msgid);
|
|
@@ -33,11 +36,7 @@ const gettextCatalog: GettextCatalog = {
|
|
|
33
36
|
normalizeCount(count),
|
|
34
37
|
);
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
return msgid;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return translated === contextualPlural ? msgidPlural : translated;
|
|
39
|
+
return translated === contextualSingular || translated === contextualPlural ? undefined : translated;
|
|
41
40
|
},
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -51,20 +50,12 @@ const gettextBackend: BackendModule = {
|
|
|
51
50
|
},
|
|
52
51
|
};
|
|
53
52
|
|
|
54
|
-
const normalizeCount = (count: number
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
throw new RangeError("gettext counts must be non-negative safe integers");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return BigInt(count);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (count < 0n) {
|
|
64
|
-
throw new RangeError("gettext counts must be non-negative");
|
|
53
|
+
const normalizeCount = (count: number): bigint => {
|
|
54
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
55
|
+
throw new RangeError("gettext counts must be non-negative safe integers");
|
|
65
56
|
}
|
|
66
57
|
|
|
67
|
-
return count;
|
|
58
|
+
return BigInt(count);
|
|
68
59
|
};
|
|
69
60
|
|
|
70
61
|
const contextualMsgid = (context: string, msgid: string): string => `${context}${CONTEXT_SEPARATOR}${msgid}`;
|
package/src/i18n.ts
CHANGED
|
@@ -57,11 +57,7 @@ const pluralLookup = ({ catalog, context, count, msgid, msgidPlural }: PluralLoo
|
|
|
57
57
|
return catalog.ngettext(msgid, msgidPlural, count);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return contextual === msgid || contextual === msgidPlural
|
|
63
|
-
? catalog.ngettext(msgid, msgidPlural, count)
|
|
64
|
-
: contextual;
|
|
60
|
+
return catalog.npgettext(context, msgid, msgidPlural, count) ?? catalog.ngettext(msgid, msgidPlural, count);
|
|
65
61
|
};
|
|
66
62
|
|
|
67
63
|
const stringOption = (options: TOptions, key: string): string | undefined => {
|
|
@@ -119,9 +115,7 @@ const contextualLookup = (
|
|
|
119
115
|
return catalog.gettext(source);
|
|
120
116
|
}
|
|
121
117
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return translated === source ? catalog.gettext(source) : translated;
|
|
118
|
+
return catalog.pgettext(context, source) ?? catalog.gettext(source);
|
|
125
119
|
};
|
|
126
120
|
|
|
127
121
|
const singularPointLookup = (
|
|
@@ -136,7 +130,7 @@ const singularPointLookup = (
|
|
|
136
130
|
};
|
|
137
131
|
|
|
138
132
|
const pointLookup = (catalog: GettextCatalog, msgid: string, options: TOptions): string | undefined => {
|
|
139
|
-
if (
|
|
133
|
+
if (options.count !== undefined) {
|
|
140
134
|
return pluralPointLookup(catalog, msgid, options, options.count);
|
|
141
135
|
}
|
|
142
136
|
|
package/src/locale.ts
CHANGED
|
@@ -28,12 +28,12 @@ function requireStringResult(result: unknown): string {
|
|
|
28
28
|
|
|
29
29
|
function initializeLocale(): string {
|
|
30
30
|
const localeDir = process.env.GTKX_LOCALE_DIR ?? fileURLToPath(new URL("locale", import.meta.url));
|
|
31
|
-
|
|
31
|
+
requireStringResult(setLocaleBinding(LC_ALL, ""));
|
|
32
32
|
requireStringResult(bindTextDomainBinding(applicationId, localeDir));
|
|
33
33
|
requireStringResult(bindTextDomainCodesetBinding(applicationId, GETTEXT_CODESET));
|
|
34
34
|
requireStringResult(textDomainBinding(applicationId));
|
|
35
35
|
|
|
36
|
-
return
|
|
36
|
+
return new Intl.NumberFormat().resolvedOptions().locale;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export { locale };
|