@lowdefy/helpers 5.2.0 → 5.4.0
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/dist/builtinMessages.js +80 -0
- package/dist/getLocaleDateFormat.js +61 -0
- package/dist/getLocaleDecimalSeparator.js +24 -0
- package/dist/getLocaleGroupSeparator.js +24 -0
- package/dist/index.js +6 -1
- package/dist/translate.js +42 -0
- package/package.json +3 -2
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ const builtinMessages = {
|
|
16
|
+
'engine.action.loading': 'Loading',
|
|
17
|
+
'engine.action.success': 'Success',
|
|
18
|
+
'engine.validation.fieldRequired': 'This field is required',
|
|
19
|
+
'engine.validation.summary': '{count, plural, one {Your input has # validation error} other {Your input has # validation errors}}',
|
|
20
|
+
'client.popupBlocked': 'A popup blocker may be preventing the application from opening the page. Approve the popup to continue.',
|
|
21
|
+
'client.requestError': 'Request error',
|
|
22
|
+
'client.backAriaLabel': 'back',
|
|
23
|
+
'client.shortcutThen': 'then',
|
|
24
|
+
'errorPage.name': 'Error',
|
|
25
|
+
'errorPage.message': 'An error has occurred.',
|
|
26
|
+
'errorPage.homeLink': 'Return to home page',
|
|
27
|
+
// Agent runtime — surfaces in browser as HTTP error responses / streamed errors
|
|
28
|
+
'agent.runtime.methodNotAllowed': 'Only POST requests are supported.',
|
|
29
|
+
'agent.runtime.invalidPath': 'Invalid agent path',
|
|
30
|
+
'agent.runtime.messagesMustBeArray': 'messages must be an array',
|
|
31
|
+
'agent.runtime.urlQueryMustBeObject': 'urlQuery must be an object',
|
|
32
|
+
'agent.runtime.sharedStateMustBeObject': 'sharedState must be an object',
|
|
33
|
+
'agent.runtime.agentNotFound': 'Agent "{agentId}" does not exist.',
|
|
34
|
+
'agent.runtime.agentTypeNotFound': 'Agent type "{type}" can not be found.',
|
|
35
|
+
'agent.runtime.toolExecutionFailed': 'Endpoint execution failed',
|
|
36
|
+
'agent.runtime.subAgentDepthExceeded': 'Sub-agent nesting exceeds maximum depth of {max}.',
|
|
37
|
+
'agent.runtime.reservedToolName': '{kind} "{name}" uses a reserved platform tool name. Rename it (e.g., to "{name}-app" or "custom-{name}"). Reserved: {reserved}.',
|
|
38
|
+
// AgentChat block UI
|
|
39
|
+
'agent.sender.placeholder': 'Type a message...',
|
|
40
|
+
'agent.toolApproval.approve': 'Approve',
|
|
41
|
+
'agent.toolApproval.reject': 'Reject',
|
|
42
|
+
'agent.message.copy': 'Copy',
|
|
43
|
+
'agent.message.feedback': 'Feedback',
|
|
44
|
+
'agent.message.regenerate': 'Regenerate',
|
|
45
|
+
'agent.message.delete': 'Delete',
|
|
46
|
+
'agent.message.userHeader': 'You',
|
|
47
|
+
'agent.message.assistantHeader': 'Assistant',
|
|
48
|
+
'agent.toolResult.completed': 'Completed',
|
|
49
|
+
'agent.toolResult.completedNoData': 'Completed (no data)',
|
|
50
|
+
'agent.toolResult.empty': 'Empty',
|
|
51
|
+
'agent.toolResult.emptyList': 'Empty list',
|
|
52
|
+
'agent.toolResult.showMore': 'Show more',
|
|
53
|
+
'agent.toolResult.showLess': 'Show less',
|
|
54
|
+
'agent.toolResult.sourcesTitle': 'Sources',
|
|
55
|
+
'agent.toolResult.reasoningTitle': 'Reasoning',
|
|
56
|
+
'agent.toolResult.running': 'Running...',
|
|
57
|
+
'agent.toolResult.processing': 'Processing...',
|
|
58
|
+
'agent.toolResult.failed': 'Tool execution failed',
|
|
59
|
+
'agent.toolResult.rejected': 'Tool execution was rejected',
|
|
60
|
+
'agent.toolResult.returnedCount': '{count, plural, one {Returned # result} other {Returned # results}}',
|
|
61
|
+
'agent.toolResult.returnedKeys': 'Returned: {keys}',
|
|
62
|
+
'agent.toolResult.returnedFields': 'Returned object with {count} fields',
|
|
63
|
+
// Block built-ins — surfaced directly by block components, overridable per-locale.
|
|
64
|
+
'blocks.listSelector.search.placeholder': 'Search…',
|
|
65
|
+
'blocks.listSelector.search.noResults': 'No results',
|
|
66
|
+
'blocks.listSelector.noData': 'No data',
|
|
67
|
+
'blocks.treeSelector.placeholder': 'Select item',
|
|
68
|
+
'blocks.treeSelector.notFound': 'Not found',
|
|
69
|
+
'blocks.treeMultipleSelector.placeholder': 'Select items',
|
|
70
|
+
'blocks.treeMultipleSelector.notFound': 'Not found',
|
|
71
|
+
// antd X built-ins — apps can override per-locale via config.i18n.messages.
|
|
72
|
+
// For en_US and zh_CN, XProvider's pack already covers these natively.
|
|
73
|
+
'agent.antdx.conversations.create': 'New chat',
|
|
74
|
+
'agent.antdx.sender.stopLoading': 'Stop loading',
|
|
75
|
+
'agent.antdx.bubble.editableOk': 'OK',
|
|
76
|
+
'agent.antdx.bubble.editableCancel': 'Cancel',
|
|
77
|
+
'agent.antdx.actions.feedbackLike': 'Like',
|
|
78
|
+
'agent.antdx.actions.feedbackDislike': 'Dislike'
|
|
79
|
+
};
|
|
80
|
+
export default builtinMessages;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ const TYPE_TO_TOKEN = {
|
|
16
|
+
year: 'YYYY',
|
|
17
|
+
month: 'MM',
|
|
18
|
+
day: 'DD',
|
|
19
|
+
hour: 'HH',
|
|
20
|
+
minute: 'mm',
|
|
21
|
+
second: 'ss'
|
|
22
|
+
};
|
|
23
|
+
const OPTIONS = {
|
|
24
|
+
date: {
|
|
25
|
+
year: 'numeric',
|
|
26
|
+
month: '2-digit',
|
|
27
|
+
day: '2-digit'
|
|
28
|
+
},
|
|
29
|
+
datetime: {
|
|
30
|
+
year: 'numeric',
|
|
31
|
+
month: '2-digit',
|
|
32
|
+
day: '2-digit',
|
|
33
|
+
hour: '2-digit',
|
|
34
|
+
minute: '2-digit',
|
|
35
|
+
hour12: false
|
|
36
|
+
},
|
|
37
|
+
time: {
|
|
38
|
+
hour: '2-digit',
|
|
39
|
+
minute: '2-digit',
|
|
40
|
+
hour12: false
|
|
41
|
+
},
|
|
42
|
+
month: {
|
|
43
|
+
year: 'numeric',
|
|
44
|
+
month: '2-digit'
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
// Fixed reference instant — only the locale's literal separators and digit ordering matter,
|
|
48
|
+
// not the values themselves. Using a constant keeps the result deterministic.
|
|
49
|
+
const REFERENCE = new Date(Date.UTC(2024, 0, 2, 15, 30, 45));
|
|
50
|
+
function getLocaleDateFormat(locale, style = 'date') {
|
|
51
|
+
if (typeof locale !== 'string' || locale === '') return null;
|
|
52
|
+
const options = OPTIONS[style];
|
|
53
|
+
if (!options) return null;
|
|
54
|
+
try {
|
|
55
|
+
const parts = new Intl.DateTimeFormat(locale, options).formatToParts(REFERENCE);
|
|
56
|
+
return parts.map((p)=>TYPE_TO_TOKEN[p.type] ?? p.value).join('');
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export default getLocaleDateFormat;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ function getLocaleDecimalSeparator(locale) {
|
|
16
|
+
if (typeof locale !== 'string' || locale === '') return null;
|
|
17
|
+
try {
|
|
18
|
+
const part = new Intl.NumberFormat(locale).formatToParts(1.1).find((p)=>p.type === 'decimal');
|
|
19
|
+
return part?.value ?? null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export default getLocaleDecimalSeparator;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ function getLocaleGroupSeparator(locale) {
|
|
16
|
+
if (typeof locale !== 'string' || locale === '') return null;
|
|
17
|
+
try {
|
|
18
|
+
const part = new Intl.NumberFormat(locale).formatToParts(12345).find((p)=>p.type === 'group');
|
|
19
|
+
return part?.value ?? null;
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export default getLocaleGroupSeparator;
|
package/dist/index.js
CHANGED
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import applyArrayIndices from './applyArrayIndices.js';
|
|
16
|
+
import builtinMessages from './builtinMessages.js';
|
|
16
17
|
import cachedPromises from './cachedPromises.js';
|
|
17
18
|
import extractErrorProps from './extractErrorProps.js';
|
|
18
19
|
import get from './get.js';
|
|
20
|
+
import getLocaleDateFormat from './getLocaleDateFormat.js';
|
|
21
|
+
import getLocaleDecimalSeparator from './getLocaleDecimalSeparator.js';
|
|
22
|
+
import getLocaleGroupSeparator from './getLocaleGroupSeparator.js';
|
|
19
23
|
import LRUCache from './LRUCache.js';
|
|
20
24
|
import mergeObjects from './mergeObjects.js';
|
|
21
25
|
import omit from './omit.js';
|
|
@@ -23,8 +27,9 @@ import serializer from './serializer.js';
|
|
|
23
27
|
import set from './set.js';
|
|
24
28
|
import stableStringify from './stableStringify.js';
|
|
25
29
|
import swap from './swap.js';
|
|
30
|
+
import translate from './translate.js';
|
|
26
31
|
import type from './type.js';
|
|
27
32
|
import unset from './unset.js';
|
|
28
33
|
import urlQuery from './urlQuery.js';
|
|
29
34
|
import wait from './wait.js';
|
|
30
|
-
export { applyArrayIndices, cachedPromises, extractErrorProps, get, LRUCache, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait };
|
|
35
|
+
export { applyArrayIndices, builtinMessages, cachedPromises, extractErrorProps, get, getLocaleDateFormat, getLocaleDecimalSeparator, getLocaleGroupSeparator, LRUCache, mergeObjects, omit, serializer, set, stableStringify, swap, translate, type, unset, urlQuery, wait };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { IntlMessageFormat } from 'intl-messageformat';
|
|
16
|
+
import builtinMessages from './builtinMessages.js';
|
|
17
|
+
import type from './type.js';
|
|
18
|
+
const FALLBACK_LOCALE = 'en-US';
|
|
19
|
+
function resolveMessage({ key, active, messages }) {
|
|
20
|
+
if (active && messages[active]?.[key] != null) return messages[active][key];
|
|
21
|
+
if (messages[FALLBACK_LOCALE]?.[key] != null) return messages[FALLBACK_LOCALE][key];
|
|
22
|
+
if (builtinMessages[key] != null) return builtinMessages[key];
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
25
|
+
function translate({ key, values, locale, i18n }) {
|
|
26
|
+
if (!type.isString(key)) {
|
|
27
|
+
throw new Error('translate requires a string "key".');
|
|
28
|
+
}
|
|
29
|
+
const active = locale ?? i18n?.active ?? i18n?.defaultLocale;
|
|
30
|
+
const messages = i18n?.messages ?? {};
|
|
31
|
+
const message = resolveMessage({
|
|
32
|
+
key,
|
|
33
|
+
active,
|
|
34
|
+
messages
|
|
35
|
+
});
|
|
36
|
+
if (type.isNone(values)) return message;
|
|
37
|
+
if (!type.isObject(values)) {
|
|
38
|
+
throw new Error('translate "values" must be an object.');
|
|
39
|
+
}
|
|
40
|
+
return new IntlMessageFormat(message, active).format(values);
|
|
41
|
+
}
|
|
42
|
+
export default translate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/helpers",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"dist/*"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@lowdefy/errors": "5.
|
|
34
|
+
"@lowdefy/errors": "5.4.0",
|
|
35
|
+
"intl-messageformat": "11.2.7",
|
|
35
36
|
"lodash.merge": "4.6.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|