@lingui/core 3.17.0 → 3.17.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/CHANGELOG.md +8 -0
- package/build/cjs/compile.js +25 -34
- package/build/cjs/compile.js.map +1 -1
- package/build/cjs/index.js +213 -370
- package/build/cjs/index.js.map +1 -1
- package/build/esm/compile.js +25 -34
- package/build/esm/compile.js.map +1 -1
- package/build/esm/index.js +213 -370
- package/build/esm/index.js.map +1 -1
- package/build/index.d.ts +16 -16
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.17.1](https://github.com/lingui/js-lingui/compare/v3.17.0...v3.17.1) (2023-02-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @lingui/core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @lingui/core
|
package/build/cjs/compile.js
CHANGED
|
@@ -1,65 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
3
|
var parser = require('@messageformat/parser');
|
|
5
4
|
|
|
6
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
-
|
|
8
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9
|
-
|
|
10
5
|
// [Tokens] -> (CTX -> String)
|
|
11
6
|
function processTokens(tokens, mapText) {
|
|
12
|
-
if (!tokens.filter(
|
|
13
|
-
return token
|
|
14
|
-
}).length) {
|
|
15
|
-
return tokens.map(function (token) {
|
|
16
|
-
return mapText(token.value);
|
|
17
|
-
}).join("");
|
|
7
|
+
if (!tokens.filter(token => token.type !== "content").length) {
|
|
8
|
+
return tokens.map(token => mapText(token.value)).join("");
|
|
18
9
|
}
|
|
10
|
+
return tokens.map(token => {
|
|
11
|
+
if (token.type === "content") {
|
|
12
|
+
return mapText(token.value);
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
if (token.type === 'content') {
|
|
22
|
-
return mapText(token.value); // # in plural case
|
|
14
|
+
// # in plural case
|
|
23
15
|
} else if (token.type === "octothorpe") {
|
|
24
|
-
return "#";
|
|
16
|
+
return "#";
|
|
17
|
+
|
|
18
|
+
// simple argument
|
|
25
19
|
} else if (token.type === "argument") {
|
|
26
|
-
return [token.arg];
|
|
20
|
+
return [token.arg];
|
|
21
|
+
|
|
22
|
+
// argument with custom format (date, number)
|
|
27
23
|
} else if (token.type === "function") {
|
|
28
24
|
var _token$param;
|
|
29
|
-
|
|
30
|
-
var _param = token === null || token === void 0 ? void 0 : (_token$param = token.param) === null || _token$param === void 0 ? void 0 : _token$param[0];
|
|
31
|
-
|
|
25
|
+
const _param = token === null || token === void 0 ? void 0 : (_token$param = token.param) === null || _token$param === void 0 ? void 0 : _token$param[0];
|
|
32
26
|
if (_param) {
|
|
33
27
|
return [token.arg, token.key, _param.value.trim()];
|
|
34
28
|
} else {
|
|
35
29
|
return [token.arg, token.key];
|
|
36
30
|
}
|
|
37
31
|
}
|
|
32
|
+
const offset = token.pluralOffset;
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
token.cases.forEach(function (item) {
|
|
34
|
+
// complex argument with cases
|
|
35
|
+
const formatProps = {};
|
|
36
|
+
token.cases.forEach(item => {
|
|
43
37
|
formatProps[item.key.replace(/^=(.)+/, "$1")] = processTokens(item.tokens, mapText);
|
|
44
38
|
});
|
|
45
|
-
return [token.arg, token.type,
|
|
46
|
-
offset
|
|
47
|
-
|
|
39
|
+
return [token.arg, token.type, {
|
|
40
|
+
offset,
|
|
41
|
+
...formatProps
|
|
42
|
+
}];
|
|
48
43
|
});
|
|
49
|
-
}
|
|
44
|
+
}
|
|
50
45
|
|
|
46
|
+
// Message -> (Params -> String)
|
|
51
47
|
/** @internal */
|
|
52
|
-
|
|
53
|
-
|
|
54
48
|
function compileMessage(message) {
|
|
55
|
-
|
|
56
|
-
return v;
|
|
57
|
-
};
|
|
58
|
-
|
|
49
|
+
let mapText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : v => v;
|
|
59
50
|
try {
|
|
60
51
|
return processTokens(parser.parse(message), mapText);
|
|
61
52
|
} catch (e) {
|
|
62
|
-
console.error(
|
|
53
|
+
console.error(`${e.message} \n\nMessage: ${message}`);
|
|
63
54
|
return message;
|
|
64
55
|
}
|
|
65
56
|
}
|
package/build/cjs/compile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sources":["../../src/compile/compileMessage.ts"],"sourcesContent":["import {Content, parse, Token} from \"@messageformat/parser\"\nimport {CompiledMessage, CompiledMessageToken} from \"../i18n\"\n\ntype MapTextFn =
|
|
1
|
+
{"version":3,"file":"compile.js","sources":["../../src/compile/compileMessage.ts"],"sourcesContent":["import { Content, parse, Token } from \"@messageformat/parser\"\nimport { CompiledMessage, CompiledMessageToken } from \"../i18n\"\n\ntype MapTextFn = (value: string) => string\n\n// [Tokens] -> (CTX -> String)\nfunction processTokens(\n tokens: Array<Token>,\n mapText?: MapTextFn\n): CompiledMessage {\n if (!tokens.filter((token) => token.type !== \"content\").length) {\n return tokens.map((token) => mapText((token as Content).value)).join(\"\")\n }\n\n return tokens.map<CompiledMessageToken>((token) => {\n if (token.type === \"content\") {\n return mapText(token.value)\n\n // # in plural case\n } else if (token.type === \"octothorpe\") {\n return \"#\"\n\n // simple argument\n } else if (token.type === \"argument\") {\n return [token.arg]\n\n // argument with custom format (date, number)\n } else if (token.type === \"function\") {\n const _param = token?.param?.[0] as Content\n\n if (_param) {\n return [token.arg, token.key, _param.value.trim()]\n } else {\n return [token.arg, token.key]\n }\n }\n\n const offset = token.pluralOffset\n\n // complex argument with cases\n const formatProps = {}\n token.cases.forEach((item) => {\n formatProps[item.key.replace(/^=(.)+/, \"$1\")] = processTokens(\n item.tokens,\n mapText\n )\n })\n\n return [\n token.arg,\n token.type,\n {\n offset,\n ...formatProps,\n } as any,\n ] as CompiledMessageToken\n })\n}\n\n// Message -> (Params -> String)\n/** @internal */\nexport function compileMessage(\n message: string,\n mapText: MapTextFn = (v) => v\n): CompiledMessage {\n try {\n return processTokens(parse(message), mapText)\n } catch (e) {\n console.error(`${e.message} \\n\\nMessage: ${message}`)\n return message\n }\n}\n"],"names":["processTokens","tokens","mapText","filter","token","type","length","map","value","join","arg","_param","param","key","trim","offset","pluralOffset","formatProps","cases","forEach","item","replace","compileMessage","message","v","parse","e","console","error"],"mappings":";;;;AAKA;AACA,SAASA,aAAa,CACpBC,MAAoB,EACpBC,OAAmB,EACF;AACjB,EAAA,IAAI,CAACD,MAAM,CAACE,MAAM,CAAEC,KAAK,IAAKA,KAAK,CAACC,IAAI,KAAK,SAAS,CAAC,CAACC,MAAM,EAAE;AAC9D,IAAA,OAAOL,MAAM,CAACM,GAAG,CAAEH,KAAK,IAAKF,OAAO,CAAEE,KAAK,CAAaI,KAAK,CAAC,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC,CA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