@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.
Files changed (139) hide show
  1. package/AccessForbidden/AccessForbidden.js +10 -2
  2. package/AccessForbidden/polyglot/index.d.ts +2 -0
  3. package/AccessForbidden/polyglot/index.js +10 -0
  4. package/AccessForbidden/polyglot/messages_en.d.ts +3 -0
  5. package/AccessForbidden/polyglot/messages_en.js +4 -0
  6. package/AccessForbidden/polyglot/messages_ru.d.ts +3 -0
  7. package/AccessForbidden/polyglot/messages_ru.js +4 -0
  8. package/AccessForbidden/polyglot/types.d.ts +5 -0
  9. package/AccessForbidden/polyglot/types.js +1 -0
  10. package/Calendar/CalendarDropdown/CalendarDropdown.js +15 -3
  11. package/Calendar/CalendarSuperForm/components/CalendarTimeAndTimezoneSection/CalendarTimeAndTimezoneSection.js +14 -4
  12. package/Calendar/polyglot/index.d.ts +2 -0
  13. package/Calendar/polyglot/index.js +10 -0
  14. package/Calendar/polyglot/messages_en.d.ts +3 -0
  15. package/Calendar/polyglot/messages_en.js +11 -0
  16. package/Calendar/polyglot/messages_ru.d.ts +3 -0
  17. package/Calendar/polyglot/messages_ru.js +11 -0
  18. package/Calendar/polyglot/types.d.ts +14 -0
  19. package/Calendar/polyglot/types.js +1 -0
  20. package/CrashScreen/CrashScreen.js +6 -1
  21. package/CrashScreen/polyglot/index.d.ts +2 -0
  22. package/CrashScreen/polyglot/index.js +10 -0
  23. package/CrashScreen/polyglot/messages_en.d.ts +3 -0
  24. package/CrashScreen/polyglot/messages_en.js +4 -0
  25. package/CrashScreen/polyglot/messages_ru.d.ts +3 -0
  26. package/CrashScreen/polyglot/messages_ru.js +4 -0
  27. package/CrashScreen/polyglot/types.d.ts +5 -0
  28. package/CrashScreen/polyglot/types.js +1 -0
  29. package/DateTimePicker/components/DatePickerField/DatePickerField.js +4 -1
  30. package/DateTimePicker/components/DateTimePickerField/DateTimePickerField.js +4 -1
  31. package/DateTimePicker/components/Month/Month.js +16 -1
  32. package/DateTimePicker/polyglot/index.d.ts +2 -0
  33. package/DateTimePicker/polyglot/index.js +9 -0
  34. package/DateTimePicker/polyglot/messages_en.d.ts +3 -0
  35. package/DateTimePicker/polyglot/messages_en.js +11 -0
  36. package/DateTimePicker/polyglot/messages_ru.d.ts +3 -0
  37. package/DateTimePicker/polyglot/messages_ru.js +11 -0
  38. package/DateTimePicker/polyglot/types.d.ts +12 -0
  39. package/DateTimePicker/polyglot/types.js +1 -0
  40. package/Drawer/components/DrawerDocs/DrawerDocs.js +9 -3
  41. package/Drawer/polyglot/index.d.ts +2 -0
  42. package/Drawer/polyglot/index.js +10 -0
  43. package/Drawer/polyglot/messages_en.d.ts +3 -0
  44. package/Drawer/polyglot/messages_en.js +4 -0
  45. package/Drawer/polyglot/messages_ru.d.ts +3 -0
  46. package/Drawer/polyglot/messages_ru.js +4 -0
  47. package/Drawer/polyglot/types.d.ts +5 -0
  48. package/Drawer/polyglot/types.js +1 -0
  49. package/EditableField/EditableField.js +7 -2
  50. package/EditableField/polyglot/index.d.ts +2 -0
  51. package/EditableField/polyglot/index.js +9 -0
  52. package/EditableField/polyglot/messages_en.d.ts +3 -0
  53. package/EditableField/polyglot/messages_en.js +4 -0
  54. package/EditableField/polyglot/messages_ru.d.ts +3 -0
  55. package/EditableField/polyglot/messages_ru.js +4 -0
  56. package/EditableField/polyglot/types.d.ts +5 -0
  57. package/EditableField/polyglot/types.js +1 -0
  58. package/EmailTemplatePreview/components/NoEmailTemplatePreview/NoEmailTemplatePreview.js +11 -3
  59. package/EmailTemplatePreview/polyglot/index.d.ts +2 -0
  60. package/EmailTemplatePreview/polyglot/index.js +10 -0
  61. package/EmailTemplatePreview/polyglot/messages_en.d.ts +3 -0
  62. package/EmailTemplatePreview/polyglot/messages_en.js +5 -0
  63. package/EmailTemplatePreview/polyglot/messages_ru.d.ts +3 -0
  64. package/EmailTemplatePreview/polyglot/messages_ru.js +5 -0
  65. package/EmailTemplatePreview/polyglot/types.d.ts +6 -0
  66. package/EmailTemplatePreview/polyglot/types.js +1 -0
  67. package/FrequencyCapping/FrequencyCappingEdit.js +7 -2
  68. package/FrequencyCapping/FrequencyCappingInApps.js +7 -2
  69. package/FrequencyCapping/FrequencyCappingReadonly.js +5 -2
  70. package/FrequencyCapping/components/Description/index.js +3 -1
  71. package/FrequencyCapping/components/Settings/EditCappingSettings.js +10 -3
  72. package/FrequencyCapping/components/Settings/EditInAppCappingSettings.js +25 -8
  73. package/FrequencyCapping/helpers/getCappingChipText.d.ts +2 -1
  74. package/FrequencyCapping/helpers/getCappingChipText.js +13 -15
  75. package/FrequencyCapping/helpers/getDescriptionMessages.d.ts +2 -1
  76. package/FrequencyCapping/helpers/getDescriptionMessages.js +42 -22
  77. package/FrequencyCapping/helpers/getGlobalCappingLinkText.d.ts +2 -0
  78. package/FrequencyCapping/helpers/getGlobalCappingLinkText.js +7 -0
  79. package/FrequencyCapping/helpers/getReadonlyCappingHelpers.d.ts +2 -1
  80. package/FrequencyCapping/helpers/getReadonlyCappingHelpers.js +27 -15
  81. package/FrequencyCapping/polyglot/index.d.ts +4 -0
  82. package/FrequencyCapping/polyglot/index.js +10 -0
  83. package/FrequencyCapping/polyglot/messages_en.d.ts +3 -0
  84. package/FrequencyCapping/polyglot/messages_en.js +33 -0
  85. package/FrequencyCapping/polyglot/messages_ru.d.ts +3 -0
  86. package/FrequencyCapping/polyglot/messages_ru.js +33 -0
  87. package/FrequencyCapping/polyglot/types.d.ts +46 -0
  88. package/FrequencyCapping/polyglot/types.js +1 -0
  89. package/Modal/components/ModalConfirm/ModalConfirm.js +21 -8
  90. package/Modal/components/ModalConfirm/types.d.ts +1 -1
  91. package/Modal/polyglot/index.d.ts +2 -0
  92. package/Modal/polyglot/index.js +9 -0
  93. package/Modal/polyglot/messages_en.d.ts +3 -0
  94. package/Modal/polyglot/messages_en.js +6 -0
  95. package/Modal/polyglot/messages_ru.d.ts +3 -0
  96. package/Modal/polyglot/messages_ru.js +6 -0
  97. package/Modal/polyglot/types.d.ts +7 -0
  98. package/Modal/polyglot/types.js +1 -0
  99. package/NotificationInbox/NotificationBell.js +7 -1
  100. package/NotificationInbox/NotificationInbox.js +19 -5
  101. package/NotificationInbox/polyglot/index.d.ts +2 -0
  102. package/NotificationInbox/polyglot/index.js +10 -0
  103. package/NotificationInbox/polyglot/messages_en.d.ts +3 -0
  104. package/NotificationInbox/polyglot/messages_en.js +8 -0
  105. package/NotificationInbox/polyglot/messages_ru.d.ts +3 -0
  106. package/NotificationInbox/polyglot/messages_ru.js +8 -0
  107. package/NotificationInbox/polyglot/types.d.ts +11 -0
  108. package/NotificationInbox/polyglot/types.js +1 -0
  109. package/PushPreview/components/MissedContentPreview/MissedContentPreview.js +7 -2
  110. package/PushPreview/polyglot/index.d.ts +2 -0
  111. package/PushPreview/polyglot/index.js +9 -0
  112. package/PushPreview/polyglot/messages_en.d.ts +3 -0
  113. package/PushPreview/polyglot/messages_en.js +4 -0
  114. package/PushPreview/polyglot/messages_ru.d.ts +3 -0
  115. package/PushPreview/polyglot/messages_ru.js +4 -0
  116. package/PushPreview/polyglot/types.d.ts +5 -0
  117. package/PushPreview/polyglot/types.js +1 -0
  118. package/SendRate/SendRateEdit.js +7 -2
  119. package/SendRate/SendRateReadonly.js +5 -2
  120. package/SendRate/components/Condition/index.js +8 -1
  121. package/SendRate/components/Description/index.js +20 -6
  122. package/SendRate/components/Settings/index.js +7 -2
  123. package/SendRate/helpers/getGlobalSendRateLinkText.d.ts +2 -0
  124. package/SendRate/helpers/getGlobalSendRateLinkText.js +7 -0
  125. package/SendRate/helpers/getReadonlySendRateHelpers.d.ts +2 -1
  126. package/SendRate/helpers/getReadonlySendRateHelpers.js +20 -11
  127. package/SendRate/polyglot/index.d.ts +4 -0
  128. package/SendRate/polyglot/index.js +10 -0
  129. package/SendRate/polyglot/messages_en.d.ts +3 -0
  130. package/SendRate/polyglot/messages_en.js +20 -0
  131. package/SendRate/polyglot/messages_ru.d.ts +3 -0
  132. package/SendRate/polyglot/messages_ru.js +20 -0
  133. package/SendRate/polyglot/types.d.ts +23 -0
  134. package/SendRate/polyglot/types.js +1 -0
  135. package/package.json +1 -1
  136. package/polyglot/index.d.ts +1 -1
  137. package/polyglot/index.js +1 -1
  138. package/polyglot/react.d.ts +12 -2
  139. 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, "Custom send rate for this message:", React.createElement(ChipSendRate, {
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
- }, "Send messages without global send rate", React.createElement(Tooltip, {
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, "Global send rate:", React.createElement(ChipSendRate, {
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
- }), "because limit isn\u2019t set") : React.createElement(React.Fragment, null, "Global send rate:", React.createElement(ChipSendRate, {
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 'Messages will be sent without rate limits, if possible, because no send rate is applied to this message';
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,10 @@
1
+ import { messages as en } from './messages_en';
2
+ import { messages as ru } from './messages_ru';
3
+ import { createLang } from '../../polyglot';
4
+ export const {
5
+ Lang,
6
+ useLang
7
+ } = createLang({
8
+ en,
9
+ ru
10
+ });
@@ -0,0 +1,3 @@
1
+ import { type SendRateMessages } from './types';
2
+ import type { LangMessages } from '../../polyglot';
3
+ export declare const messages: LangMessages<SendRateMessages>;
@@ -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,3 @@
1
+ import { type SendRateMessages } from './types';
2
+ import type { LangMessages } from '../../polyglot';
3
+ export declare const messages: LangMessages<SendRateMessages>;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.133",
3
+ "version": "1.1.135",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -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';
@@ -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: Record<string, LangMessages<any>>;
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 LangContext = createContext(null);
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 langMessages = languages[language];
13
- const asts = Object.fromEntries(Object.entries(langMessages).map(([k, v]) => {
14
- try {
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
+ });