@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/dist/lookup.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const gettextLookup: (msgid: string) => string;
|
|
2
|
+
declare const ngettextLookup: (msgid: string, msgidPlural: string, count: number | bigint) => string;
|
|
3
|
+
declare const pgettextLookup: (context: string, msgid: string) => string;
|
|
4
|
+
declare const npgettextLookup: (context: string, msgid: string, msgidPlural: string, count: number | bigint) => string;
|
|
5
|
+
export { gettextLookup, ngettextLookup, npgettextLookup, pgettextLookup };
|
|
6
|
+
//# sourceMappingURL=lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../src/lookup.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAA6C,CAAC;AAkBrF,QAAA,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,aAAa,MAAM,EAAE,OAAO,MAAM,GAAG,MAAM,KAAG,MACT,CAAC;AAE7E,QAAA,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,OAAO,MAAM,KAAG,MACP,CAAC;AAInD,QAAA,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,OAAO,MAAM,EAAE,aAAa,MAAM,EAAE,OAAO,MAAM,GAAG,MAAM,KAAG,MAUtG,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/lookup.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as GLib from "@gtkx/gi/glib";
|
|
2
|
+
import { applicationId } from "virtual:gtkx-config";
|
|
3
|
+
const CONTEXT_SEPARATOR = "\u{4}";
|
|
4
|
+
const gettextLookup = (msgid) => GLib.dgettext(applicationId, msgid);
|
|
5
|
+
const normalizeCount = (count) => {
|
|
6
|
+
if (typeof count === "number") {
|
|
7
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
8
|
+
throw new RangeError("gettext counts must be non-negative safe integers");
|
|
9
|
+
}
|
|
10
|
+
return BigInt(count);
|
|
11
|
+
}
|
|
12
|
+
if (count < 0n) {
|
|
13
|
+
throw new RangeError("gettext counts must be non-negative");
|
|
14
|
+
}
|
|
15
|
+
return count;
|
|
16
|
+
};
|
|
17
|
+
const ngettextLookup = (msgid, msgidPlural, count) => GLib.dngettext(applicationId, msgid, msgidPlural, normalizeCount(count));
|
|
18
|
+
const pgettextLookup = (context, msgid) => GLib.dpgettext2(applicationId, context, msgid);
|
|
19
|
+
const contextualMsgid = (context, msgid) => `${context}${CONTEXT_SEPARATOR}${msgid}`;
|
|
20
|
+
const npgettextLookup = (context, msgid, msgidPlural, count) => {
|
|
21
|
+
const contextualSingular = contextualMsgid(context, msgid);
|
|
22
|
+
const contextualPlural = contextualMsgid(context, msgidPlural);
|
|
23
|
+
const translated = ngettextLookup(contextualSingular, contextualPlural, count);
|
|
24
|
+
if (translated === contextualSingular) {
|
|
25
|
+
return msgid;
|
|
26
|
+
}
|
|
27
|
+
return translated === contextualPlural ? msgidPlural : translated;
|
|
28
|
+
};
|
|
29
|
+
export { gettextLookup, ngettextLookup, npgettextLookup, pgettextLookup };
|
|
30
|
+
//# sourceMappingURL=lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../src/lookup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAElC,MAAM,aAAa,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAErF,MAAM,cAAc,GAAG,CAAC,KAAsB,EAAU,EAAE;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,UAAU,CAAC,mDAAmD,CAAC,CAAC;QAC9E,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAAC,qCAAqC,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,WAAmB,EAAE,KAAsB,EAAU,EAAE,CAC1F,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAE7E,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE,CAC9D,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAEnD,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE,CAAC,GAAG,OAAO,GAAG,iBAAiB,GAAG,KAAK,EAAE,CAAC;AAE7G,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,KAAa,EAAE,WAAmB,EAAE,KAAsB,EAAU,EAAE;IAC5G,MAAM,kBAAkB,GAAG,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3D,MAAM,gBAAgB,GAAG,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,cAAc,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;IAE/E,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,UAAU,KAAK,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC;AACtE,CAAC,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import * as GLib from \"@gtkx/gi/glib\";\nimport { applicationId } from \"virtual:gtkx-config\";\n\nconst CONTEXT_SEPARATOR = \"\\u{4}\";\n\nconst gettextLookup = (msgid: string): string => GLib.dgettext(applicationId, msgid);\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 ngettextLookup = (msgid: string, msgidPlural: string, count: number | bigint): string =>\n GLib.dngettext(applicationId, msgid, msgidPlural, normalizeCount(count));\n\nconst pgettextLookup = (context: string, msgid: string): string =>\n GLib.dpgettext2(applicationId, context, msgid);\n\nconst contextualMsgid = (context: string, msgid: string): string => `${context}${CONTEXT_SEPARATOR}${msgid}`;\n\nconst npgettextLookup = (context: string, msgid: string, msgidPlural: string, count: number | bigint): string => {\n const contextualSingular = contextualMsgid(context, msgid);\n const contextualPlural = contextualMsgid(context, msgidPlural);\n const translated = ngettextLookup(contextualSingular, contextualPlural, count);\n\n if (translated === contextualSingular) {\n return msgid;\n }\n\n return translated === contextualPlural ? msgidPlural : translated;\n};\n\nexport { gettextLookup, ngettextLookup, npgettextLookup, pgettextLookup };\n"]}
|