@pushwoosh/dumb-components 1.1.133 → 1.1.135
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/AccessForbidden/AccessForbidden.js +10 -2
- package/AccessForbidden/polyglot/index.d.ts +2 -0
- package/AccessForbidden/polyglot/index.js +10 -0
- package/AccessForbidden/polyglot/messages_en.d.ts +3 -0
- package/AccessForbidden/polyglot/messages_en.js +4 -0
- package/AccessForbidden/polyglot/messages_ru.d.ts +3 -0
- package/AccessForbidden/polyglot/messages_ru.js +4 -0
- package/AccessForbidden/polyglot/types.d.ts +5 -0
- package/AccessForbidden/polyglot/types.js +1 -0
- package/Calendar/CalendarDropdown/CalendarDropdown.js +15 -3
- package/Calendar/CalendarSuperForm/components/CalendarTimeAndTimezoneSection/CalendarTimeAndTimezoneSection.js +14 -4
- package/Calendar/polyglot/index.d.ts +2 -0
- package/Calendar/polyglot/index.js +10 -0
- package/Calendar/polyglot/messages_en.d.ts +3 -0
- package/Calendar/polyglot/messages_en.js +11 -0
- package/Calendar/polyglot/messages_ru.d.ts +3 -0
- package/Calendar/polyglot/messages_ru.js +11 -0
- package/Calendar/polyglot/types.d.ts +14 -0
- package/Calendar/polyglot/types.js +1 -0
- package/CrashScreen/CrashScreen.js +6 -1
- package/CrashScreen/polyglot/index.d.ts +2 -0
- package/CrashScreen/polyglot/index.js +10 -0
- package/CrashScreen/polyglot/messages_en.d.ts +3 -0
- package/CrashScreen/polyglot/messages_en.js +4 -0
- package/CrashScreen/polyglot/messages_ru.d.ts +3 -0
- package/CrashScreen/polyglot/messages_ru.js +4 -0
- package/CrashScreen/polyglot/types.d.ts +5 -0
- package/CrashScreen/polyglot/types.js +1 -0
- package/DateTimePicker/components/DatePickerField/DatePickerField.js +4 -1
- package/DateTimePicker/components/DateTimePickerField/DateTimePickerField.js +4 -1
- package/DateTimePicker/components/Month/Month.js +16 -1
- package/DateTimePicker/polyglot/index.d.ts +2 -0
- package/DateTimePicker/polyglot/index.js +9 -0
- package/DateTimePicker/polyglot/messages_en.d.ts +3 -0
- package/DateTimePicker/polyglot/messages_en.js +11 -0
- package/DateTimePicker/polyglot/messages_ru.d.ts +3 -0
- package/DateTimePicker/polyglot/messages_ru.js +11 -0
- package/DateTimePicker/polyglot/types.d.ts +12 -0
- package/DateTimePicker/polyglot/types.js +1 -0
- package/Drawer/components/DrawerDocs/DrawerDocs.js +9 -3
- package/Drawer/polyglot/index.d.ts +2 -0
- package/Drawer/polyglot/index.js +10 -0
- package/Drawer/polyglot/messages_en.d.ts +3 -0
- package/Drawer/polyglot/messages_en.js +4 -0
- package/Drawer/polyglot/messages_ru.d.ts +3 -0
- package/Drawer/polyglot/messages_ru.js +4 -0
- package/Drawer/polyglot/types.d.ts +5 -0
- package/Drawer/polyglot/types.js +1 -0
- package/EditableField/EditableField.js +7 -2
- package/EditableField/polyglot/index.d.ts +2 -0
- package/EditableField/polyglot/index.js +9 -0
- package/EditableField/polyglot/messages_en.d.ts +3 -0
- package/EditableField/polyglot/messages_en.js +4 -0
- package/EditableField/polyglot/messages_ru.d.ts +3 -0
- package/EditableField/polyglot/messages_ru.js +4 -0
- package/EditableField/polyglot/types.d.ts +5 -0
- package/EditableField/polyglot/types.js +1 -0
- package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.js +11 -3
- package/EmailTemplatePreview/polyglot/index.d.ts +2 -0
- package/EmailTemplatePreview/polyglot/index.js +10 -0
- package/EmailTemplatePreview/polyglot/messages_en.d.ts +3 -0
- package/EmailTemplatePreview/polyglot/messages_en.js +5 -0
- package/EmailTemplatePreview/polyglot/messages_ru.d.ts +3 -0
- package/EmailTemplatePreview/polyglot/messages_ru.js +5 -0
- package/EmailTemplatePreview/polyglot/types.d.ts +6 -0
- package/EmailTemplatePreview/polyglot/types.js +1 -0
- package/FrequencyCapping/FrequencyCappingEdit.js +7 -2
- package/FrequencyCapping/FrequencyCappingInApps.js +7 -2
- package/FrequencyCapping/FrequencyCappingReadonly.js +5 -2
- package/FrequencyCapping/components/Description/index.js +3 -1
- package/FrequencyCapping/components/Settings/EditCappingSettings.js +10 -3
- package/FrequencyCapping/components/Settings/EditInAppCappingSettings.js +25 -8
- package/FrequencyCapping/helpers/getCappingChipText.d.ts +2 -1
- package/FrequencyCapping/helpers/getCappingChipText.js +13 -15
- package/FrequencyCapping/helpers/getDescriptionMessages.d.ts +2 -1
- package/FrequencyCapping/helpers/getDescriptionMessages.js +42 -22
- package/FrequencyCapping/helpers/getGlobalCappingLinkText.d.ts +2 -0
- package/FrequencyCapping/helpers/getGlobalCappingLinkText.js +7 -0
- package/FrequencyCapping/helpers/getReadonlyCappingHelpers.d.ts +2 -1
- package/FrequencyCapping/helpers/getReadonlyCappingHelpers.js +27 -15
- package/FrequencyCapping/polyglot/index.d.ts +4 -0
- package/FrequencyCapping/polyglot/index.js +10 -0
- package/FrequencyCapping/polyglot/messages_en.d.ts +3 -0
- package/FrequencyCapping/polyglot/messages_en.js +33 -0
- package/FrequencyCapping/polyglot/messages_ru.d.ts +3 -0
- package/FrequencyCapping/polyglot/messages_ru.js +33 -0
- package/FrequencyCapping/polyglot/types.d.ts +46 -0
- package/FrequencyCapping/polyglot/types.js +1 -0
- package/Modal/components/ModalConfirm/ModalConfirm.js +21 -8
- package/Modal/components/ModalConfirm/types.d.ts +1 -1
- package/Modal/polyglot/index.d.ts +2 -0
- package/Modal/polyglot/index.js +9 -0
- package/Modal/polyglot/messages_en.d.ts +3 -0
- package/Modal/polyglot/messages_en.js +6 -0
- package/Modal/polyglot/messages_ru.d.ts +3 -0
- package/Modal/polyglot/messages_ru.js +6 -0
- package/Modal/polyglot/types.d.ts +7 -0
- package/Modal/polyglot/types.js +1 -0
- package/NotificationInbox/NotificationBell.js +7 -1
- package/NotificationInbox/NotificationInbox.js +19 -5
- package/NotificationInbox/polyglot/index.d.ts +2 -0
- package/NotificationInbox/polyglot/index.js +10 -0
- package/NotificationInbox/polyglot/messages_en.d.ts +3 -0
- package/NotificationInbox/polyglot/messages_en.js +8 -0
- package/NotificationInbox/polyglot/messages_ru.d.ts +3 -0
- package/NotificationInbox/polyglot/messages_ru.js +8 -0
- package/NotificationInbox/polyglot/types.d.ts +11 -0
- package/NotificationInbox/polyglot/types.js +1 -0
- package/PushPreview/components/MissedContentPreview/MissedContentPreview.js +7 -2
- package/PushPreview/polyglot/index.d.ts +2 -0
- package/PushPreview/polyglot/index.js +9 -0
- package/PushPreview/polyglot/messages_en.d.ts +3 -0
- package/PushPreview/polyglot/messages_en.js +4 -0
- package/PushPreview/polyglot/messages_ru.d.ts +3 -0
- package/PushPreview/polyglot/messages_ru.js +4 -0
- package/PushPreview/polyglot/types.d.ts +5 -0
- package/PushPreview/polyglot/types.js +1 -0
- package/SendRate/SendRateEdit.js +7 -2
- package/SendRate/SendRateReadonly.js +5 -2
- package/SendRate/components/Condition/index.js +8 -1
- package/SendRate/components/Description/index.js +20 -6
- package/SendRate/components/Settings/index.js +7 -2
- package/SendRate/helpers/getGlobalSendRateLinkText.d.ts +2 -0
- package/SendRate/helpers/getGlobalSendRateLinkText.js +7 -0
- package/SendRate/helpers/getReadonlySendRateHelpers.d.ts +2 -1
- package/SendRate/helpers/getReadonlySendRateHelpers.js +20 -11
- package/SendRate/polyglot/index.d.ts +4 -0
- package/SendRate/polyglot/index.js +10 -0
- package/SendRate/polyglot/messages_en.d.ts +3 -0
- package/SendRate/polyglot/messages_en.js +20 -0
- package/SendRate/polyglot/messages_ru.d.ts +3 -0
- package/SendRate/polyglot/messages_ru.js +20 -0
- package/SendRate/polyglot/types.d.ts +23 -0
- package/SendRate/polyglot/types.js +1 -0
- package/package.json +1 -1
- package/polyglot/index.d.ts +1 -1
- package/polyglot/index.js +1 -1
- package/polyglot/react.d.ts +12 -2
- package/polyglot/react.js +80 -45
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type SendRateLang } from '../polyglot';
|
|
2
3
|
import { type SendRateBase } from '../types';
|
|
3
4
|
export declare function getReadonlySendRateLabel<T extends SendRateBase>(sendRateOption: T, isGlobalSendRateDisabled: boolean, globalSendRate: {
|
|
4
5
|
count: number;
|
|
5
6
|
seconds: number;
|
|
6
|
-
}): React.JSX.Element;
|
|
7
|
+
}, lang: SendRateLang): React.JSX.Element;
|
|
@@ -4,14 +4,16 @@ import { HelpRoundIcon } from '@pushwoosh/kit-icons';
|
|
|
4
4
|
import { Tooltip } from '../../Tooltip';
|
|
5
5
|
import { ChipSendRate } from '../components/Condition';
|
|
6
6
|
import { IconWrapper } from '../styles';
|
|
7
|
-
export function getReadonlySendRateLabel(sendRateOption, isGlobalSendRateDisabled, globalSendRate) {
|
|
7
|
+
export function getReadonlySendRateLabel(sendRateOption, isGlobalSendRateDisabled, globalSendRate, lang) {
|
|
8
8
|
const {
|
|
9
9
|
policy,
|
|
10
10
|
sendRate
|
|
11
11
|
} = sendRateOption;
|
|
12
|
-
const tooltip = getReadonlyTooltip(policy);
|
|
12
|
+
const tooltip = getReadonlyTooltip(policy, lang);
|
|
13
13
|
if (policy === 'CUSTOM') {
|
|
14
|
-
return React.createElement(React.Fragment, null,
|
|
14
|
+
return React.createElement(React.Fragment, null, lang({
|
|
15
|
+
message: 'DUMB.SEND_RATE.RO.CUSTOM_LABEL'
|
|
16
|
+
}), React.createElement(ChipSendRate, {
|
|
15
17
|
messages: sendRate
|
|
16
18
|
}));
|
|
17
19
|
}
|
|
@@ -20,7 +22,9 @@ export function getReadonlySendRateLabel(sendRateOption, isGlobalSendRateDisable
|
|
|
20
22
|
"$alignItems": "center",
|
|
21
23
|
"$gap": 4,
|
|
22
24
|
"$justifyContent": "start"
|
|
23
|
-
},
|
|
25
|
+
}, lang({
|
|
26
|
+
message: 'DUMB.SEND_RATE.RO.IGNORE_LABEL'
|
|
27
|
+
}), React.createElement(Tooltip, {
|
|
24
28
|
content: tooltip,
|
|
25
29
|
position: "top-middle"
|
|
26
30
|
}, React.createElement(IconWrapper, {
|
|
@@ -30,18 +34,23 @@ export function getReadonlySendRateLabel(sendRateOption, isGlobalSendRateDisable
|
|
|
30
34
|
view: "lined"
|
|
31
35
|
}))));
|
|
32
36
|
}
|
|
33
|
-
return isGlobalSendRateDisabled ? React.createElement(React.Fragment, null,
|
|
37
|
+
return isGlobalSendRateDisabled ? React.createElement(React.Fragment, null, lang({
|
|
38
|
+
message: 'DUMB.SEND_RATE.RO.GLOBAL_LABEL'
|
|
39
|
+
}), React.createElement(ChipSendRate, {
|
|
34
40
|
messages: 0
|
|
35
|
-
}),
|
|
41
|
+
}), lang({
|
|
42
|
+
message: 'DUMB.SEND_RATE.RO.BECAUSE_UNSET'
|
|
43
|
+
})) : React.createElement(React.Fragment, null, lang({
|
|
44
|
+
message: 'DUMB.SEND_RATE.RO.GLOBAL_LABEL'
|
|
45
|
+
}), React.createElement(ChipSendRate, {
|
|
36
46
|
messages: globalSendRate.count
|
|
37
47
|
}));
|
|
38
48
|
}
|
|
39
|
-
function getReadonlyTooltip(sendRateOption) {
|
|
40
|
-
if (sendRateOption === 'CUSTOM') {
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
49
|
+
function getReadonlyTooltip(sendRateOption, lang) {
|
|
43
50
|
if (sendRateOption === 'IGNORE') {
|
|
44
|
-
return
|
|
51
|
+
return lang({
|
|
52
|
+
message: 'DUMB.SEND_RATE.RO.TOOLTIP_IGNORE'
|
|
53
|
+
});
|
|
45
54
|
}
|
|
46
55
|
return '';
|
|
47
56
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SendRateMessages } from './types';
|
|
2
|
+
import { type LangProps } from '../../polyglot';
|
|
3
|
+
export declare const Lang: import("react").FC<LangProps<SendRateMessages>>, useLang: () => (props: LangProps<SendRateMessages>) => string;
|
|
4
|
+
export type SendRateLang = (props: LangProps<SendRateMessages>) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const messages = {
|
|
2
|
+
'DUMB.SEND_RATE.FIELD_TITLE': 'Send rate',
|
|
3
|
+
'DUMB.SEND_RATE.LINK.SET_UP': 'Set up',
|
|
4
|
+
'DUMB.SEND_RATE.LINK.SETTINGS': 'Settings',
|
|
5
|
+
'DUMB.SEND_RATE.SETTINGS.LIMIT_TO_MAX': 'Limit to a maximum of',
|
|
6
|
+
'DUMB.SEND_RATE.SETTINGS.MESSAGES_PER_SEC': 'messages per 1 sec',
|
|
7
|
+
'DUMB.SEND_RATE.CHIP.UNLIMITED': 'unlimited',
|
|
8
|
+
'DUMB.SEND_RATE.CHIP.RATE': '{{messages}} messages per 1 sec',
|
|
9
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_UNSET_PREFIX': 'This message will use an',
|
|
10
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_UNSET_SUFFIX': 'global send rate because limit isn’t set.',
|
|
11
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_SET_PREFIX': 'This message will use the Global send rate limit of',
|
|
12
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_SET_SUFFIX': 'to help reduce backend load.',
|
|
13
|
+
'DUMB.SEND_RATE.DESC.CUSTOM': 'Instead of using the Global send rate, a custom delivery speed will be applied. Messages will be sent at the rate defined below.',
|
|
14
|
+
'DUMB.SEND_RATE.DESC.IGNORE': 'This message will be sent as fast as possible, regardless of any Global send rate limits. Use with caution to avoid overloading your backend or creating delivery spikes.',
|
|
15
|
+
'DUMB.SEND_RATE.RO.CUSTOM_LABEL': 'Custom send rate for this message:',
|
|
16
|
+
'DUMB.SEND_RATE.RO.IGNORE_LABEL': 'Send messages without global send rate',
|
|
17
|
+
'DUMB.SEND_RATE.RO.GLOBAL_LABEL': 'Global send rate:',
|
|
18
|
+
'DUMB.SEND_RATE.RO.BECAUSE_UNSET': 'because limit isn’t set',
|
|
19
|
+
'DUMB.SEND_RATE.RO.TOOLTIP_IGNORE': 'Messages will be sent without rate limits, if possible, because no send rate is applied to this message'
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const messages = {
|
|
2
|
+
'DUMB.SEND_RATE.FIELD_TITLE': 'Скорость отправки',
|
|
3
|
+
'DUMB.SEND_RATE.LINK.SET_UP': 'Настроить',
|
|
4
|
+
'DUMB.SEND_RATE.LINK.SETTINGS': 'Настройки',
|
|
5
|
+
'DUMB.SEND_RATE.SETTINGS.LIMIT_TO_MAX': 'Не более',
|
|
6
|
+
'DUMB.SEND_RATE.SETTINGS.MESSAGES_PER_SEC': 'сообщений в секунду',
|
|
7
|
+
'DUMB.SEND_RATE.CHIP.UNLIMITED': 'без ограничений',
|
|
8
|
+
'DUMB.SEND_RATE.CHIP.RATE': '{{messages}} {{messages | pluralize: "сообщение", "сообщения", "сообщений"}} в секунду',
|
|
9
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_UNSET_PREFIX': 'Это сообщение будет использовать',
|
|
10
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_UNSET_SUFFIX': 'глобальную скорость отправки, так как лимит не задан.',
|
|
11
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_SET_PREFIX': 'Это сообщение будет использовать глобальный лимит скорости отправки',
|
|
12
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_SET_SUFFIX': 'чтобы снизить нагрузку на бэкенд.',
|
|
13
|
+
'DUMB.SEND_RATE.DESC.CUSTOM': 'Вместо глобальной скорости отправки будет применена пользовательская скорость доставки. Сообщения будут отправляться со скоростью, заданной ниже.',
|
|
14
|
+
'DUMB.SEND_RATE.DESC.IGNORE': 'Это сообщение будет отправлено максимально быстро, без учёта глобальных лимитов скорости отправки. Используйте с осторожностью, чтобы не перегрузить бэкенд и не создавать всплески доставки.',
|
|
15
|
+
'DUMB.SEND_RATE.RO.CUSTOM_LABEL': 'Пользовательская скорость отправки для этого сообщения:',
|
|
16
|
+
'DUMB.SEND_RATE.RO.IGNORE_LABEL': 'Отправлять сообщения без глобальной скорости отправки',
|
|
17
|
+
'DUMB.SEND_RATE.RO.GLOBAL_LABEL': 'Глобальная скорость отправки:',
|
|
18
|
+
'DUMB.SEND_RATE.RO.BECAUSE_UNSET': 'так как лимит не задан',
|
|
19
|
+
'DUMB.SEND_RATE.RO.TOOLTIP_IGNORE': 'Сообщения будут отправлены без ограничений скорости, по возможности, так как к этому сообщению не применяется скорость отправки'
|
|
20
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { NoParams } from '../../polyglot';
|
|
2
|
+
export type SendRateMessages = {
|
|
3
|
+
'DUMB.SEND_RATE.FIELD_TITLE': NoParams;
|
|
4
|
+
'DUMB.SEND_RATE.LINK.SET_UP': NoParams;
|
|
5
|
+
'DUMB.SEND_RATE.LINK.SETTINGS': NoParams;
|
|
6
|
+
'DUMB.SEND_RATE.SETTINGS.LIMIT_TO_MAX': NoParams;
|
|
7
|
+
'DUMB.SEND_RATE.SETTINGS.MESSAGES_PER_SEC': NoParams;
|
|
8
|
+
'DUMB.SEND_RATE.CHIP.UNLIMITED': NoParams;
|
|
9
|
+
'DUMB.SEND_RATE.CHIP.RATE': {
|
|
10
|
+
messages: number;
|
|
11
|
+
};
|
|
12
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_UNSET_PREFIX': NoParams;
|
|
13
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_UNSET_SUFFIX': NoParams;
|
|
14
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_SET_PREFIX': NoParams;
|
|
15
|
+
'DUMB.SEND_RATE.DESC.GLOBAL_SET_SUFFIX': NoParams;
|
|
16
|
+
'DUMB.SEND_RATE.DESC.CUSTOM': NoParams;
|
|
17
|
+
'DUMB.SEND_RATE.DESC.IGNORE': NoParams;
|
|
18
|
+
'DUMB.SEND_RATE.RO.CUSTOM_LABEL': NoParams;
|
|
19
|
+
'DUMB.SEND_RATE.RO.IGNORE_LABEL': NoParams;
|
|
20
|
+
'DUMB.SEND_RATE.RO.GLOBAL_LABEL': NoParams;
|
|
21
|
+
'DUMB.SEND_RATE.RO.BECAUSE_UNSET': NoParams;
|
|
22
|
+
'DUMB.SEND_RATE.RO.TOOLTIP_IGNORE': NoParams;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
package/polyglot/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { LangMessages, LangProps, UseLangHook, NoParams } from './types';
|
|
2
|
-
export { LangProvider, LangBase, useLangBase } from './react';
|
|
2
|
+
export { LangProvider, LangBase, useLangBase, LangLib, useLangLib, createLang, } from './react';
|
package/polyglot/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { LangProvider, LangBase, useLangBase } from './react';
|
|
1
|
+
export { LangProvider, LangBase, useLangBase, LangLib, useLangLib, createLang } from './react';
|
package/polyglot/react.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { type FC, type PropsWithChildren } from 'react';
|
|
2
|
-
import { type LangMessages } from './types';
|
|
2
|
+
import { type LangMessages, type LangProps } from './types';
|
|
3
|
+
type LanguagesMap = Record<string, LangMessages<any>>;
|
|
3
4
|
type LangProviderProps = {
|
|
4
5
|
timezone: string;
|
|
5
6
|
language: string;
|
|
6
|
-
languages:
|
|
7
|
+
languages: LanguagesMap;
|
|
7
8
|
};
|
|
8
9
|
export declare const LangProvider: FC<PropsWithChildren<LangProviderProps>>;
|
|
9
10
|
export declare const LangBase: FC;
|
|
10
11
|
export declare const useLangBase: () => (allProps: any) => string;
|
|
12
|
+
type LangLibProps = {
|
|
13
|
+
$languages: LanguagesMap;
|
|
14
|
+
} & Record<string, any>;
|
|
15
|
+
export declare const LangLib: FC<LangLibProps>;
|
|
16
|
+
export declare const useLangLib: (languages: LanguagesMap) => (allProps: any) => string;
|
|
17
|
+
export declare const createLang: <M>(languages: Record<string, LangMessages<M>>) => {
|
|
18
|
+
Lang: FC<LangProps<M>>;
|
|
19
|
+
useLang: () => (props: LangProps<M>) => string;
|
|
20
|
+
};
|
|
11
21
|
export {};
|
package/polyglot/react.js
CHANGED
|
@@ -1,7 +1,62 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
2
|
import { stringToAst } from './liquid/parser';
|
|
3
3
|
import { renderToReact, renderToString } from './liquid/render';
|
|
4
|
-
const
|
|
4
|
+
const createLangPack = (language, timezone) => {
|
|
5
|
+
const astCache = {};
|
|
6
|
+
const register = languages => {
|
|
7
|
+
const langMessages = languages[language] ?? languages.en;
|
|
8
|
+
if (!langMessages) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
Object.entries(langMessages).forEach(([key, message]) => {
|
|
12
|
+
if (key in astCache) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
astCache[key] = stringToAst(message);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.error(key, message, e);
|
|
19
|
+
astCache[key] = [];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const getAst = message => {
|
|
24
|
+
const ast = astCache[message];
|
|
25
|
+
if (!ast) {
|
|
26
|
+
console.error('no message', message);
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return ast;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
language,
|
|
33
|
+
timezone,
|
|
34
|
+
register,
|
|
35
|
+
lang: allProps => {
|
|
36
|
+
const {
|
|
37
|
+
message,
|
|
38
|
+
...values
|
|
39
|
+
} = allProps;
|
|
40
|
+
return renderToString(getAst(message), {
|
|
41
|
+
values,
|
|
42
|
+
language,
|
|
43
|
+
timezone
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
langReact: allProps => {
|
|
47
|
+
const {
|
|
48
|
+
message,
|
|
49
|
+
...values
|
|
50
|
+
} = allProps;
|
|
51
|
+
return renderToReact(getAst(message), {
|
|
52
|
+
values,
|
|
53
|
+
language,
|
|
54
|
+
timezone
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const LangContext = createContext(createLangPack('en', 'UTC'));
|
|
5
60
|
export const LangProvider = ({
|
|
6
61
|
timezone,
|
|
7
62
|
language,
|
|
@@ -9,49 +64,9 @@ export const LangProvider = ({
|
|
|
9
64
|
children
|
|
10
65
|
}) => {
|
|
11
66
|
const langFnPack = useMemo(() => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return [k, stringToAst(v)];
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.error(k, v, e);
|
|
18
|
-
return [k, []];
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
const getAst = message => {
|
|
22
|
-
const ast = asts[message];
|
|
23
|
-
if (!ast) {
|
|
24
|
-
console.error('no message', message);
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
return ast;
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
lang: allProps => {
|
|
31
|
-
const {
|
|
32
|
-
message,
|
|
33
|
-
...values
|
|
34
|
-
} = allProps;
|
|
35
|
-
const ast = getAst(message);
|
|
36
|
-
return renderToString(ast, {
|
|
37
|
-
values,
|
|
38
|
-
language,
|
|
39
|
-
timezone
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
langReact: allProps => {
|
|
43
|
-
const {
|
|
44
|
-
message,
|
|
45
|
-
...values
|
|
46
|
-
} = allProps;
|
|
47
|
-
const ast = getAst(message);
|
|
48
|
-
return renderToReact(ast, {
|
|
49
|
-
values,
|
|
50
|
-
language,
|
|
51
|
-
timezone
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
67
|
+
const pack = createLangPack(language, timezone);
|
|
68
|
+
pack.register(languages);
|
|
69
|
+
return pack;
|
|
55
70
|
}, [languages, language, timezone]);
|
|
56
71
|
return React.createElement(LangContext.Provider, {
|
|
57
72
|
value: langFnPack
|
|
@@ -60,4 +75,24 @@ export const LangProvider = ({
|
|
|
60
75
|
export const LangBase = props => {
|
|
61
76
|
return useContext(LangContext).langReact(props);
|
|
62
77
|
};
|
|
63
|
-
export const useLangBase = () => useContext(LangContext).lang;
|
|
78
|
+
export const useLangBase = () => useContext(LangContext).lang;
|
|
79
|
+
export const LangLib = ({
|
|
80
|
+
$languages,
|
|
81
|
+
...props
|
|
82
|
+
}) => {
|
|
83
|
+
const ctx = useContext(LangContext);
|
|
84
|
+
useMemo(() => ctx.register($languages), [ctx, $languages]);
|
|
85
|
+
return ctx.langReact(props);
|
|
86
|
+
};
|
|
87
|
+
export const useLangLib = languages => {
|
|
88
|
+
const ctx = useContext(LangContext);
|
|
89
|
+
useMemo(() => ctx.register(languages), [ctx, languages]);
|
|
90
|
+
return ctx.lang;
|
|
91
|
+
};
|
|
92
|
+
export const createLang = languages => ({
|
|
93
|
+
Lang: props => React.createElement(LangLib, {
|
|
94
|
+
"$languages": languages,
|
|
95
|
+
...props
|
|
96
|
+
}),
|
|
97
|
+
useLang: () => useLangLib(languages)
|
|
98
|
+
});
|