smartloc 2.0.2 → 2.0.4
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/adapters/adapter-base.d.ts +12 -0
- package/adapters/adapter-base.js +56 -0
- package/adapters/adapter-base.js.map +1 -0
- package/adapters/index.d.ts +4 -0
- package/adapters/index.js +32 -0
- package/adapters/index.js.map +1 -0
- package/adapters/json.d.ts +6 -0
- package/adapters/json.js +23 -0
- package/adapters/json.js.map +1 -0
- package/adapters/xliff.d.ts +6 -0
- package/adapters/xliff.js +35 -0
- package/adapters/xliff.js.map +1 -0
- package/cli/cli.d.ts +2 -0
- package/cli/cli.js +129 -0
- package/cli/cli.js.map +1 -0
- package/cli/collect.d.ts +14 -0
- package/{src/cli/collect.ts → cli/collect.js} +59 -75
- package/cli/collect.js.map +1 -0
- package/cli/interfaces.js +3 -0
- package/cli/interfaces.js.map +1 -0
- package/cli/reconciliate.d.ts +6 -0
- package/{src/cli/reconciliate.ts → cli/reconciliate.js} +35 -40
- package/cli/reconciliate.js.map +1 -0
- package/cli/utils.d.ts +6 -0
- package/{src/cli/utils.ts → cli/utils.js} +16 -12
- package/cli/utils.js.map +1 -0
- package/core/default-locale.d.ts +10 -0
- package/{src/core/default-locale.tsx → core/default-locale.js} +23 -28
- package/core/default-locale.js.map +1 -0
- package/{src/core/interfaces.ts → core/interfaces.d.ts} +15 -20
- package/core/interfaces.js +3 -0
- package/core/interfaces.js.map +1 -0
- package/core/json-utils.d.ts +19 -0
- package/{src/core/json-utils.ts → core/json-utils.js} +27 -33
- package/core/json-utils.js.map +1 -0
- package/core/literal.d.ts +13 -0
- package/{src/core/literal.ts → core/literal.js} +20 -19
- package/core/literal.js.map +1 -0
- package/core/load.d.ts +32 -0
- package/core/load.js +50 -0
- package/core/load.js.map +1 -0
- package/core/locale-list.d.ts +27 -0
- package/{src/core/locale-list.ts → core/locale-list.js} +35 -38
- package/core/locale-list.js.map +1 -0
- package/core/locale.d.ts +15 -0
- package/{src/core/locale.tsx → core/locale.js} +29 -28
- package/core/locale.js.map +1 -0
- package/core/smartloc.d.ts +39 -0
- package/{src/core/smartloc.tsx → core/smartloc.js} +104 -122
- package/core/smartloc.js.map +1 -0
- package/core/tag.d.ts +13 -0
- package/core/tag.js +26 -0
- package/core/tag.js.map +1 -0
- package/core/utils.d.ts +4 -0
- package/core/utils.js +30 -0
- package/core/utils.js.map +1 -0
- package/express.d.ts +12 -0
- package/{src/express.ts → express.js} +33 -41
- package/express.js.map +1 -0
- package/graphql.d.ts +13 -0
- package/{src/graphql.ts → graphql.js} +62 -74
- package/graphql.js.map +1 -0
- package/index.js +30 -1
- package/index.js.map +1 -0
- package/node/index.d.ts +1 -0
- package/node/index.js +18 -0
- package/node/index.js.map +1 -0
- package/node/load.d.ts +12 -0
- package/node/load.js +37 -0
- package/node/load.js.map +1 -0
- package/package.json +3 -22
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
- package/.vscode/launch.json +0 -65
- package/.vscode/settings.json +0 -14
- package/.vscode/tasks.json +0 -27
- package/build/README.md +0 -225
- package/build/package.json +0 -60
- package/bun.lock +0 -310
- package/samples/express/main.ts +0 -37
- package/samples/express/package.json +0 -10
- package/samples/graphql/main.ts +0 -73
- package/samples/graphql/package.json +0 -15
- package/src/adapters/adapter-base.ts +0 -58
- package/src/adapters/index.ts +0 -31
- package/src/adapters/json.ts +0 -18
- package/src/adapters/xliff.ts +0 -30
- package/src/cli/cli.ts +0 -137
- package/src/core/load.ts +0 -82
- package/src/core/tag.ts +0 -48
- package/src/core/utils.tsx +0 -24
- package/src/node/index.ts +0 -1
- package/src/node/load.ts +0 -32
- package/test/collect.spec.ts +0 -45
- package/test/reconciliation.spec.ts +0 -132
- package/test/serialization.spec.ts +0 -162
- package/test/translation.spec.ts +0 -61
- package/tsconfig.json +0 -37
- package/tslint.json +0 -103
- /package/{src/cli/interfaces.ts → cli/interfaces.d.ts} +0 -0
- /package/{src/index.ts → index.d.ts} +0 -0
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = default_1;
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const accept_language_parser_1 = __importDefault(require("accept-language-parser"));
|
|
4
9
|
const supportedMethods = [
|
|
5
10
|
{ key: 'json', },
|
|
6
11
|
{ key: 'jsonp', },
|
|
7
|
-
{ key: 'send', fn: (v
|
|
12
|
+
{ key: 'send', fn: (v) => (0, _1.isLocStr)(v) ? v.toString() : v },
|
|
8
13
|
];
|
|
9
|
-
|
|
10
|
-
export interface SmartlocExpressOptions {
|
|
11
|
-
/** (optional) Waits for this promise before performing a translation. This might be for instance the promise that waits all locales to be declared via addLocale() loaded */
|
|
12
|
-
waitFor?: Promise<any>;
|
|
13
|
-
/** Custom resolution (will fall back on accept-language if this function does not return anything) */
|
|
14
|
-
customLocaleResolver?: (req: any) => string | string[] | null | undefined | Promise<string | string[] | null | undefined>;
|
|
15
|
-
/** Error logger (gives a chance to log resolution errors) */
|
|
16
|
-
errorLogger?: (err: any) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
14
|
/**
|
|
20
15
|
* Express middleware that will translate calls to .send(), .json() (etc...) based on the Accept-Language request header.
|
|
21
16
|
*/
|
|
22
|
-
|
|
17
|
+
function default_1(options) {
|
|
23
18
|
const { errorLogger, customLocaleResolver, waitFor } = options ?? {};
|
|
24
|
-
let waiter
|
|
25
|
-
return function (req
|
|
26
|
-
|
|
27
|
-
let locales: string[];
|
|
28
|
-
|
|
19
|
+
let waiter = waitFor;
|
|
20
|
+
return function (req, res, next) {
|
|
21
|
+
let locales;
|
|
29
22
|
function serve() {
|
|
30
23
|
waiter = null;
|
|
31
24
|
try {
|
|
@@ -34,9 +27,11 @@ export default function (options?: SmartlocExpressOptions) {
|
|
|
34
27
|
const cust = customLocaleResolver?.(req);
|
|
35
28
|
if (typeof cust === 'string') {
|
|
36
29
|
locales = [cust];
|
|
37
|
-
}
|
|
30
|
+
}
|
|
31
|
+
else if (cust instanceof Array) {
|
|
38
32
|
locales = cust;
|
|
39
|
-
}
|
|
33
|
+
}
|
|
34
|
+
else if (cust) {
|
|
40
35
|
cust.then(resCust => {
|
|
41
36
|
if (typeof resCust === 'string') {
|
|
42
37
|
resCust = [resCust];
|
|
@@ -46,11 +41,10 @@ export default function (options?: SmartlocExpressOptions) {
|
|
|
46
41
|
}, e => {
|
|
47
42
|
errorLogger?.(e);
|
|
48
43
|
serve();
|
|
49
|
-
})
|
|
44
|
+
});
|
|
50
45
|
return; // defered => method will be called again later.
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
// === resolve locales from headers
|
|
55
49
|
if (!locales || !locales.length) {
|
|
56
50
|
const lh = req?.headers?.['accept-language'];
|
|
@@ -58,36 +52,34 @@ export default function (options?: SmartlocExpressOptions) {
|
|
|
58
52
|
next();
|
|
59
53
|
return; // => no locale... just serve without patching
|
|
60
54
|
}
|
|
61
|
-
locales =
|
|
55
|
+
locales = accept_language_parser_1.default.parse(lh)
|
|
62
56
|
?.map(x => x.region ? `${x.code}-${x.region}` : x.code);
|
|
63
57
|
}
|
|
64
|
-
|
|
65
58
|
// === override methods that sends potentially translatable content
|
|
66
59
|
for (const { key, fn } of supportedMethods) {
|
|
67
|
-
const orig
|
|
68
|
-
res[key] = function (fst
|
|
69
|
-
return withLocales(locales, () => {
|
|
70
|
-
return orig.call(this
|
|
71
|
-
|
|
72
|
-
, ...args);
|
|
73
|
-
})
|
|
60
|
+
const orig = res[key];
|
|
61
|
+
res[key] = function (fst, ...args) {
|
|
62
|
+
return (0, _1.withLocales)(locales, () => {
|
|
63
|
+
return orig.call(this, fn ? fn(fst) : fst, ...args);
|
|
64
|
+
});
|
|
74
65
|
};
|
|
75
66
|
}
|
|
76
67
|
next();
|
|
77
68
|
return;
|
|
78
|
-
}
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
79
71
|
errorLogger?.(e);
|
|
80
72
|
next();
|
|
81
73
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
}
|
|
75
|
+
;
|
|
85
76
|
// === serve if nothing to wait
|
|
86
77
|
if (!waiter) {
|
|
87
78
|
serve();
|
|
88
|
-
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
89
81
|
waiter.then(serve, serve);
|
|
90
82
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=express.js.map
|
package/express.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":";;;;;AAqBA,4BAuEC;AA5FD,wBAA0C;AAC1C,oFAA4C;AAE5C,MAAM,gBAAgB,GAAG;IACrB,EAAE,GAAG,EAAE,MAAM,GAAG;IAChB,EAAE,GAAG,EAAE,OAAO,GAAG;IACjB,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAM,EAAE,EAAE,CAAC,IAAA,WAAQ,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;CAClE,CAAC;AAWF;;GAEG;AACH,mBAAyB,OAAgC;IACrD,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACrE,IAAI,MAAM,GAAQ,OAAO,CAAC;IAC1B,OAAO,UAAU,GAAQ,EAAE,GAAQ,EAAE,IAAS;QAE1C,IAAI,OAAiB,CAAC;QAEtB,SAAS,KAAK;YACV,MAAM,GAAG,IAAI,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AAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAChE,CAAC;gBAED,mEAAmE;gBACnE,KAAK,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,gBAAgB,EAAE,CAAC;oBACzC,MAAM,IAAI,GAAa,GAAG,CAAC,GAAG,CAAC,CAAC;oBAChC,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,GAAQ,EAAE,GAAG,IAAW;wBACzC,OAAO,IAAA,cAAW,EAAC,OAAO,EAAE,GAAG,EAAE;4BAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EACf,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAClB,GAAG,IAAI,CAAC,CAAC;wBACnB,CAAC,CAAC,CAAA;oBACN,CAAC,CAAC;gBACN,CAAC;gBACD,IAAI,EAAE,CAAC;gBACP,OAAO;YACX,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;gBACjB,IAAI,EAAE,CAAC;YACX,CAAC;QACL,CAAC;QAAA,CAAC;QAGF,+BAA+B;QAC/B,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,KAAK,EAAE,CAAC;QACZ,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;IAEL,CAAC,CAAA;AACL,CAAC"}
|
package/graphql.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { GraphQLScalarType } from 'graphql';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
export declare const GLocString: GraphQLScalarType;
|
|
5
|
+
export declare function localizeSchema(schema: GraphQLSchema): GraphQLSchema;
|
|
6
|
+
export interface ExpressContext {
|
|
7
|
+
req: express.Request;
|
|
8
|
+
res: express.Response;
|
|
9
|
+
}
|
|
10
|
+
export type Context<T = object> = T;
|
|
11
|
+
export type ContextFunction<FunctionParams = any, ProducedContext = object> = (context: FunctionParams) => Context<ProducedContext> | Promise<Context<ProducedContext>>;
|
|
12
|
+
export declare function localizedContext(context: ContextFunction<ExpressContext, Context>): ContextFunction<ExpressContext, Context>;
|
|
13
|
+
export declare function localizedContextObject<T>(ctx: T, locales: string[]): T;
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GLocString = void 0;
|
|
7
|
+
exports.localizeSchema = localizeSchema;
|
|
8
|
+
exports.localizedContext = localizedContext;
|
|
9
|
+
exports.localizedContextObject = localizedContextObject;
|
|
10
|
+
const graphql_1 = require("graphql");
|
|
11
|
+
const graphql_2 = require("graphql");
|
|
12
|
+
const _1 = require(".");
|
|
13
|
+
const accept_language_parser_1 = __importDefault(require("accept-language-parser"));
|
|
14
|
+
const smartloc_1 = require("./core/smartloc");
|
|
15
|
+
const json_utils_1 = require("./core/json-utils");
|
|
16
|
+
const language_1 = require("graphql/language");
|
|
10
17
|
const INVALID_MSG = `Invalid localizable string input. Expecting either a string in the default locale, or an object like {"en": "English translation", "fr": "Traduction française"}`;
|
|
11
|
-
function parseValue(value
|
|
18
|
+
function parseValue(value) {
|
|
12
19
|
if (!value) {
|
|
13
20
|
return null;
|
|
14
21
|
}
|
|
15
22
|
if (typeof value === 'string') {
|
|
16
|
-
return singleLoc(value);
|
|
23
|
+
return (0, smartloc_1.singleLoc)(value);
|
|
17
24
|
}
|
|
18
25
|
if (typeof value === 'object') {
|
|
19
26
|
for (const v of Object.values(value)) {
|
|
@@ -21,21 +28,20 @@ function parseValue(value: any) {
|
|
|
21
28
|
throw new TypeError(INVALID_MSG);
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
|
-
return multiLoc(value);
|
|
31
|
+
return (0, smartloc_1.multiLoc)(value);
|
|
25
32
|
}
|
|
26
33
|
throw new TypeError(INVALID_MSG);
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
function parseObject(ast: any, variables: any) {
|
|
35
|
+
function parseObject(ast, variables) {
|
|
30
36
|
const value = Object.create(null);
|
|
31
37
|
let hasValue = false;
|
|
32
|
-
ast.fields.forEach((field
|
|
33
|
-
let val
|
|
38
|
+
ast.fields.forEach((field) => {
|
|
39
|
+
let val;
|
|
34
40
|
switch (field.value.kind) {
|
|
35
|
-
case Kind.STRING:
|
|
41
|
+
case language_1.Kind.STRING:
|
|
36
42
|
val = field.value.value;
|
|
37
43
|
break;
|
|
38
|
-
case Kind.VARIABLE: {
|
|
44
|
+
case language_1.Kind.VARIABLE: {
|
|
39
45
|
val = variables?.[field.value.name.value];
|
|
40
46
|
break;
|
|
41
47
|
}
|
|
@@ -54,18 +60,17 @@ function parseObject(ast: any, variables: any) {
|
|
|
54
60
|
if (!hasValue) {
|
|
55
61
|
return null;
|
|
56
62
|
}
|
|
57
|
-
return multiLoc(value);
|
|
63
|
+
return (0, smartloc_1.multiLoc)(value);
|
|
58
64
|
}
|
|
59
|
-
|
|
60
|
-
function parseLiteral(ast: any, variables: any) {
|
|
65
|
+
function parseLiteral(ast, variables) {
|
|
61
66
|
switch (ast.kind) {
|
|
62
|
-
case Kind.STRING:
|
|
63
|
-
return singleLoc(ast.value);
|
|
64
|
-
case Kind.OBJECT:
|
|
67
|
+
case language_1.Kind.STRING:
|
|
68
|
+
return (0, smartloc_1.singleLoc)(ast.value);
|
|
69
|
+
case language_1.Kind.OBJECT:
|
|
65
70
|
return parseObject(ast, variables);
|
|
66
|
-
case Kind.NULL:
|
|
71
|
+
case language_1.Kind.NULL:
|
|
67
72
|
return null;
|
|
68
|
-
case Kind.VARIABLE: {
|
|
73
|
+
case language_1.Kind.VARIABLE: {
|
|
69
74
|
const name = ast.name.value;
|
|
70
75
|
return variables ? parseValue(variables[name]) : undefined;
|
|
71
76
|
}
|
|
@@ -73,32 +78,27 @@ function parseLiteral(ast: any, variables: any) {
|
|
|
73
78
|
throw new TypeError(`Invalid localizable string input (${ast.kind}). Expecting either a string in the default locale, or an object like {"en": "English translation", "fr": "Traduction française"}`);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
|
-
|
|
77
81
|
const localeTag = Symbol('_smartloc_locale');
|
|
78
|
-
|
|
82
|
+
exports.GLocString = new graphql_2.GraphQLScalarType({
|
|
79
83
|
name: 'LocalizedString',
|
|
80
84
|
description: 'A string which value depends on Accept-Language request headers.',
|
|
81
85
|
serialize(value) {
|
|
82
|
-
if (isLocStr(value)) {
|
|
86
|
+
if ((0, _1.isLocStr)(value)) {
|
|
83
87
|
throw new TypeError(`You must apply the localizeSchema() patch to fix your schema when using LocalizedString`);
|
|
84
88
|
}
|
|
85
|
-
|
|
86
89
|
if (value === null || value === undefined || typeof value === 'string') {
|
|
87
90
|
return value;
|
|
88
91
|
}
|
|
89
|
-
|
|
90
92
|
throw new TypeError(`Graphql field of type LocalizedString expecting a localizable string`);
|
|
91
93
|
},
|
|
92
94
|
parseValue,
|
|
93
95
|
parseLiteral,
|
|
94
96
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
97
|
const patchedTag = Symbol('_smartloc_patched');
|
|
98
|
-
|
|
98
|
+
function localizeSchema(schema) {
|
|
99
99
|
const patched = new Set();
|
|
100
|
-
function patchObject(type
|
|
101
|
-
if (!(type instanceof GraphQLObjectType)) {
|
|
100
|
+
function patchObject(type) {
|
|
101
|
+
if (!(type instanceof graphql_1.GraphQLObjectType)) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
const fields = type.getFields();
|
|
@@ -107,44 +107,45 @@ export function localizeSchema(schema: GraphQLSchema) {
|
|
|
107
107
|
}
|
|
108
108
|
patched.add(type);
|
|
109
109
|
for (const [id, field] of Object.entries(fields)) {
|
|
110
|
-
let ft =
|
|
110
|
+
let ft = field.type;
|
|
111
111
|
if (!ft) {
|
|
112
112
|
continue;
|
|
113
113
|
}
|
|
114
|
-
|
|
115
114
|
while (true) {
|
|
116
|
-
if (ft instanceof GraphQLList || ft instanceof GraphQLNonNull) {
|
|
115
|
+
if (ft instanceof graphql_2.GraphQLList || ft instanceof graphql_2.GraphQLNonNull) {
|
|
117
116
|
ft = ft.ofType;
|
|
118
|
-
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
119
|
break;
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
if (ft instanceof GraphQLUnionType) {
|
|
122
|
+
if (ft instanceof graphql_2.GraphQLUnionType) {
|
|
123
123
|
for (const t of ft.getTypes()) {
|
|
124
124
|
patchObject(t);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
if (ft instanceof GraphQLInterfaceType) {
|
|
127
|
+
if (ft instanceof graphql_2.GraphQLInterfaceType) {
|
|
128
128
|
for (const t of schema.getPossibleTypes(ft)) {
|
|
129
129
|
patchObject(t);
|
|
130
130
|
}
|
|
131
|
-
}
|
|
131
|
+
}
|
|
132
|
+
else if (ft instanceof graphql_1.GraphQLObjectType) {
|
|
132
133
|
patchObject(ft);
|
|
133
|
-
}
|
|
134
|
+
}
|
|
135
|
+
else if (ft === exports.GLocString) {
|
|
134
136
|
patchField(id, field);
|
|
135
|
-
}
|
|
137
|
+
}
|
|
138
|
+
else if (ft instanceof graphql_2.GraphQLScalarType && (ft.name === 'JSON' || ft.name === 'JSONObject')) {
|
|
136
139
|
patchField(id, field);
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
|
-
|
|
141
|
-
patchObject(schema.
|
|
142
|
-
patchObject(schema.getMutationType() as GraphQLObjectType);
|
|
143
|
+
patchObject(schema.getQueryType());
|
|
144
|
+
patchObject(schema.getMutationType());
|
|
143
145
|
return schema;
|
|
144
146
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if ((field.resolve as any)?.[patchedTag]) {
|
|
147
|
+
function patchField(id, field) {
|
|
148
|
+
if (field.resolve?.[patchedTag]) {
|
|
148
149
|
return;
|
|
149
150
|
}
|
|
150
151
|
const or = field.resolve;
|
|
@@ -155,41 +156,27 @@ function patchField(id: string, field: GraphQLField<any, any>) {
|
|
|
155
156
|
const locales = ctx && typeof ctx === 'object'
|
|
156
157
|
? ctx?.[localeTag]
|
|
157
158
|
: null;
|
|
158
|
-
return withLocales(locales, () => translateInContext(value));
|
|
159
|
+
return (0, smartloc_1.withLocales)(locales, () => (0, json_utils_1.translateInContext)(value));
|
|
159
160
|
};
|
|
160
|
-
|
|
161
|
+
field.resolve[patchedTag] = true;
|
|
161
162
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
export interface ExpressContext {
|
|
166
|
-
req: express.Request;
|
|
167
|
-
res: express.Response;
|
|
168
|
-
}
|
|
169
|
-
export type Context<T = object> = T;
|
|
170
|
-
export type ContextFunction<FunctionParams = any, ProducedContext = object> = (
|
|
171
|
-
context: FunctionParams,
|
|
172
|
-
) => Context<ProducedContext> | Promise<Context<ProducedContext>>;
|
|
173
|
-
|
|
174
|
-
export function localizedContext(context: ContextFunction<ExpressContext, Context>): ContextFunction<ExpressContext, Context> {
|
|
163
|
+
function localizedContext(context) {
|
|
175
164
|
return app => {
|
|
176
165
|
const ctx = context(app);
|
|
177
166
|
if ('then' in ctx && typeof ctx.then === 'function') {
|
|
178
167
|
return ctx.then(x => patchContextObj(app.req, x));
|
|
179
168
|
}
|
|
180
169
|
return patchContextObj(app.req, ctx);
|
|
181
|
-
}
|
|
170
|
+
};
|
|
182
171
|
}
|
|
183
|
-
|
|
184
|
-
export function localizedContextObject<T>(ctx: T, locales: string[]): T {
|
|
172
|
+
function localizedContextObject(ctx, locales) {
|
|
185
173
|
if (!ctx || typeof ctx !== 'object') {
|
|
186
174
|
return ctx;
|
|
187
175
|
}
|
|
188
|
-
|
|
176
|
+
ctx[localeTag] = locales;
|
|
189
177
|
return ctx;
|
|
190
178
|
}
|
|
191
|
-
|
|
192
|
-
function patchContextObj(req: express.Request, ctx: any) {
|
|
179
|
+
function patchContextObj(req, ctx) {
|
|
193
180
|
if (!ctx || typeof ctx !== 'object') {
|
|
194
181
|
return ctx;
|
|
195
182
|
}
|
|
@@ -200,7 +187,8 @@ function patchContextObj(req: express.Request, ctx: any) {
|
|
|
200
187
|
if (!lh) {
|
|
201
188
|
return ctx;
|
|
202
189
|
}
|
|
203
|
-
ctx[localeTag] =
|
|
190
|
+
ctx[localeTag] = accept_language_parser_1.default.parse(lh)
|
|
204
191
|
?.map(x => x.region ? `${x.code}-${x.region}` : x.code);
|
|
205
192
|
return ctx;
|
|
206
|
-
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=graphql.js.map
|
package/graphql.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../src/graphql.ts"],"names":[],"mappings":";;;;;;AAiGA,wCA8CC;AA8BD,4CAQC;AAED,wDAMC;AA7LD,qCAA2D;AAC3D,qCAAgI;AAEhI,wBAA6B;AAC7B,oFAA4C;AAC5C,8CAAmE;AACnE,kDAAuD;AACvD,+CAAwC;AAExC,MAAM,WAAW,GAAG,kKAAkK,CAAC;AACvL,SAAS,UAAU,CAAC,KAAU;IAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,IAAA,oBAAS,EAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK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,CAAC,GAAG,gCAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/index.js
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadJsonLocale = exports.toLocalizable = exports.translateObject = exports.toJsonStorable = exports.jsonParseLocalized = exports.translateInContext = exports.isLocStr = exports.useAsString = exports.withSerializationContext = exports.joinArray = exports.multiLoc = exports.singleLoc = exports.withLocales = exports.loc = exports.getDefaultLocale = exports.setDefaultLocale = exports.removeLocale = exports.clearLocales = exports.addLocale = exports.changeLocale = void 0;
|
|
4
|
+
var locale_list_1 = require("./core/locale-list");
|
|
5
|
+
Object.defineProperty(exports, "changeLocale", { enumerable: true, get: function () { return locale_list_1.changeLocale; } });
|
|
6
|
+
Object.defineProperty(exports, "addLocale", { enumerable: true, get: function () { return locale_list_1.addLocale; } });
|
|
7
|
+
Object.defineProperty(exports, "clearLocales", { enumerable: true, get: function () { return locale_list_1.clearLocales; } });
|
|
8
|
+
Object.defineProperty(exports, "removeLocale", { enumerable: true, get: function () { return locale_list_1.removeLocale; } });
|
|
9
|
+
Object.defineProperty(exports, "setDefaultLocale", { enumerable: true, get: function () { return locale_list_1.setDefaultLocale; } });
|
|
10
|
+
Object.defineProperty(exports, "getDefaultLocale", { enumerable: true, get: function () { return locale_list_1.getDefaultLocale; } });
|
|
11
|
+
var tag_1 = require("./core/tag");
|
|
12
|
+
Object.defineProperty(exports, "loc", { enumerable: true, get: function () { return tag_1.loc; } });
|
|
13
|
+
var smartloc_1 = require("./core/smartloc");
|
|
14
|
+
Object.defineProperty(exports, "withLocales", { enumerable: true, get: function () { return smartloc_1.withLocales; } });
|
|
15
|
+
Object.defineProperty(exports, "singleLoc", { enumerable: true, get: function () { return smartloc_1.singleLoc; } });
|
|
16
|
+
Object.defineProperty(exports, "multiLoc", { enumerable: true, get: function () { return smartloc_1.multiLoc; } });
|
|
17
|
+
Object.defineProperty(exports, "joinArray", { enumerable: true, get: function () { return smartloc_1.joinArray; } });
|
|
18
|
+
Object.defineProperty(exports, "withSerializationContext", { enumerable: true, get: function () { return smartloc_1.withSerializationContext; } });
|
|
19
|
+
Object.defineProperty(exports, "useAsString", { enumerable: true, get: function () { return smartloc_1.useAsString; } });
|
|
20
|
+
var literal_1 = require("./core/literal");
|
|
21
|
+
Object.defineProperty(exports, "isLocStr", { enumerable: true, get: function () { return literal_1.isLocStr; } });
|
|
22
|
+
var json_utils_1 = require("./core/json-utils");
|
|
23
|
+
Object.defineProperty(exports, "translateInContext", { enumerable: true, get: function () { return json_utils_1.translateInContext; } });
|
|
24
|
+
Object.defineProperty(exports, "jsonParseLocalized", { enumerable: true, get: function () { return json_utils_1.jsonParseLocalized; } });
|
|
25
|
+
Object.defineProperty(exports, "toJsonStorable", { enumerable: true, get: function () { return json_utils_1.toJsonStorable; } });
|
|
26
|
+
Object.defineProperty(exports, "translateObject", { enumerable: true, get: function () { return json_utils_1.translateObject; } });
|
|
27
|
+
Object.defineProperty(exports, "toLocalizable", { enumerable: true, get: function () { return json_utils_1.toLocalizable; } });
|
|
28
|
+
var load_1 = require("./core/load");
|
|
29
|
+
Object.defineProperty(exports, "loadJsonLocale", { enumerable: true, get: function () { return load_1.loadJsonLocale; } });
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,kDAA6H;AAApH,2GAAA,YAAY,OAAA;AAAE,wGAAA,SAAS,OAAA;AAAE,2GAAA,YAAY,OAAA;AAAE,2GAAA,YAAY,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAAE,+GAAA,gBAAgB,OAAA;AAChG,kCAAiC;AAAxB,0FAAA,GAAG,OAAA;AACZ,4CAAqH;AAA5G,uGAAA,WAAW,OAAA;AAAE,qGAAA,SAAS,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAAE,qGAAA,SAAS,OAAA;AAAE,oHAAA,wBAAwB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAC3F,0CAA0C;AAAjC,mGAAA,QAAQ,OAAA;AAEjB,gDAA2H;AAAlH,gHAAA,kBAAkB,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,6GAAA,eAAe,OAAA;AAAE,2GAAA,aAAa,OAAA;AAC/F,oCAA6C;AAApC,sGAAA,cAAc,OAAA"}
|
package/node/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './load';
|
package/node/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./load"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB"}
|
package/node/load.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads all locales generated from CLI
|
|
3
|
+
* @param dirPath The file directory where to look for translation
|
|
4
|
+
* @param merge If true, then the translations will be merged with already existing translations.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadAllLocales(dirPath: string, merge?: boolean): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Loads a locale generated from CLI
|
|
9
|
+
* @param filePath The file path to load
|
|
10
|
+
* @param merge If true, then the translations will be merged with already existing translations.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadLocale(filePath: string, merge?: boolean): Promise<boolean>;
|
package/node/load.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadAllLocales = loadAllLocales;
|
|
7
|
+
exports.loadLocale = loadLocale;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const adapters_1 = require("../adapters");
|
|
11
|
+
const locale_list_1 = require("../core/locale-list");
|
|
12
|
+
const load_1 = require("src/core/load");
|
|
13
|
+
/**
|
|
14
|
+
* Loads all locales generated from CLI
|
|
15
|
+
* @param dirPath The file directory where to look for translation
|
|
16
|
+
* @param merge If true, then the translations will be merged with already existing translations.
|
|
17
|
+
*/
|
|
18
|
+
async function loadAllLocales(dirPath, merge) {
|
|
19
|
+
for (const f of await fs_extra_1.default.readdir(dirPath)) {
|
|
20
|
+
await loadLocale(path_1.default.join(dirPath, f), merge);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Loads a locale generated from CLI
|
|
25
|
+
* @param filePath The file path to load
|
|
26
|
+
* @param merge If true, then the translations will be merged with already existing translations.
|
|
27
|
+
*/
|
|
28
|
+
async function loadLocale(filePath, merge) {
|
|
29
|
+
const locale = await (0, adapters_1.loadLocaleFrom)(filePath);
|
|
30
|
+
if (!locale) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const transformed = (0, load_1.convertLocale)(locale);
|
|
34
|
+
(0, locale_list_1.addLocale)(locale.targetLanguage, transformed, merge);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=load.js.map
|
package/node/load.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/node/load.ts"],"names":[],"mappings":";;;;;AAWA,wCAIC;AAQD,gCAQC;AA/BD,gDAAwB;AACxB,wDAA0B;AAC1B,0CAA6C;AAC7C,qDAAgD;AAChD,wCAA8C;AAE9C;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,KAAe;IACjE,KAAK,MAAM,CAAC,IAAI,MAAM,kBAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;AACL,CAAC;AAGD;;;;GAIG;AACI,KAAK,UAAU,UAAU,CAAC,QAAgB,EAAE,KAAe;IAC9D,MAAM,MAAM,GAAG,MAAM,IAAA,yBAAc,EAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,WAAW,GAAG,IAAA,oBAAa,EAAC,MAAM,CAAC,CAAC;IAC1C,IAAA,uBAAS,EAAC,MAAM,CAAC,cAAc,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smartloc",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "A i18n toolset for nodejs apis leveraging tagged strings",
|
|
5
|
-
"main": "
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "tsc && cp package.json bin/package.json && cp README.md build",
|
|
8
|
-
"release": "npm publish",
|
|
9
|
-
"t": "tsc --project tsconfig.json --noEmit"
|
|
10
|
-
},
|
|
5
|
+
"main": "index.js",
|
|
11
6
|
"bin": {
|
|
12
|
-
"smartloc": "
|
|
7
|
+
"smartloc": "cli/cli.js"
|
|
13
8
|
},
|
|
14
9
|
"repository": "https://github.com/oguimbal/smartloc",
|
|
15
10
|
"keywords": [
|
|
@@ -27,7 +22,6 @@
|
|
|
27
22
|
"author": "Olivier Guimbal",
|
|
28
23
|
"license": "MIT",
|
|
29
24
|
"dependencies": {
|
|
30
|
-
"@types/gitignore-parser": "^0.0.3",
|
|
31
25
|
"accept-language-parser": "~1.5.0",
|
|
32
26
|
"diacritics": "^1.3.0",
|
|
33
27
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -43,18 +37,5 @@
|
|
|
43
37
|
"express": "~4.17.1",
|
|
44
38
|
"graphql": "0.13.2",
|
|
45
39
|
"react": "^19"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@types/accept-language-parser": "^1.5.1",
|
|
49
|
-
"@types/bun": "latest",
|
|
50
|
-
"@types/diacritics": "^1.3.1",
|
|
51
|
-
"@types/express": "^4.17.2",
|
|
52
|
-
"@types/fs-extra": "^8.0.1",
|
|
53
|
-
"@types/graphql": "0.13.2",
|
|
54
|
-
"@types/js-levenshtein": "^1.1.3",
|
|
55
|
-
"@types/node": "^13.1.8",
|
|
56
|
-
"@types/react": "^19.2.7",
|
|
57
|
-
"@types/yargs": "^15.0.0",
|
|
58
|
-
"typescript": "^5.9.3"
|
|
59
40
|
}
|
|
60
41
|
}
|