@magmamath/students-features 1.3.2 → 1.3.3-rc.2

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 (161) hide show
  1. package/dist/commonjs/features/chatbot/helpers.js +1 -5
  2. package/dist/commonjs/features/chatbot/helpers.js.map +1 -1
  3. package/dist/commonjs/features/chatbot/index.js.map +1 -1
  4. package/dist/commonjs/features/chatbot/model/ChatBotModel.js +6 -7
  5. package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
  6. package/dist/commonjs/features/chatbot/model/ChatBoxTextManager.js +1 -2
  7. package/dist/commonjs/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
  8. package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js +4 -2
  9. package/dist/commonjs/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  10. package/dist/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.js +2 -3
  11. package/dist/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -1
  12. package/dist/commonjs/features/exampleSolution/model/ExampleSolutionApi.js +4 -8
  13. package/dist/commonjs/features/exampleSolution/model/ExampleSolutionApi.js.map +1 -1
  14. package/dist/commonjs/index.js +23 -38
  15. package/dist/commonjs/index.js.map +1 -1
  16. package/dist/commonjs/shared/translation/constants.js +2 -17
  17. package/dist/commonjs/shared/translation/constants.js.map +1 -1
  18. package/dist/commonjs/shared/translation/helpers.js +8 -38
  19. package/dist/commonjs/shared/translation/helpers.js.map +1 -1
  20. package/dist/commonjs/shared/translation/hooks.js +7 -15
  21. package/dist/commonjs/shared/translation/hooks.js.map +1 -1
  22. package/dist/commonjs/shared/translation/index.js +0 -25
  23. package/dist/commonjs/shared/translation/index.js.map +1 -1
  24. package/dist/commonjs/shared/translation/react-i18next.d.js +5 -0
  25. package/dist/commonjs/shared/translation/react-i18next.d.js.map +1 -0
  26. package/dist/commonjs/shared/translation/{localization/en.json → schema.json} +43 -38
  27. package/dist/module/features/chatbot/helpers.js +1 -5
  28. package/dist/module/features/chatbot/helpers.js.map +1 -1
  29. package/dist/module/features/chatbot/index.js.map +1 -1
  30. package/dist/module/features/chatbot/model/ChatBotModel.js +6 -7
  31. package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
  32. package/dist/module/features/chatbot/model/ChatBoxTextManager.js +1 -2
  33. package/dist/module/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
  34. package/dist/module/features/chatbot/model/DefaultMessageCreator.js +3 -2
  35. package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  36. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js +3 -4
  37. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -1
  38. package/dist/module/features/exampleSolution/model/ExampleSolutionApi.js +5 -9
  39. package/dist/module/features/exampleSolution/model/ExampleSolutionApi.js.map +1 -1
  40. package/dist/module/index.js +0 -1
  41. package/dist/module/index.js.map +1 -1
  42. package/dist/module/shared/translation/constants.js +1 -15
  43. package/dist/module/shared/translation/constants.js.map +1 -1
  44. package/dist/module/shared/translation/helpers.js +6 -33
  45. package/dist/module/shared/translation/helpers.js.map +1 -1
  46. package/dist/module/shared/translation/hooks.js +7 -14
  47. package/dist/module/shared/translation/hooks.js.map +1 -1
  48. package/dist/module/shared/translation/index.js +2 -3
  49. package/dist/module/shared/translation/index.js.map +1 -1
  50. package/dist/module/shared/translation/react-i18next.d.js +5 -0
  51. package/dist/module/shared/translation/react-i18next.d.js.map +1 -0
  52. package/dist/module/shared/translation/{localization/en.json → schema.json} +43 -38
  53. package/dist/typescript/commonjs/features/chatbot/helpers.d.ts.map +1 -1
  54. package/dist/typescript/commonjs/features/chatbot/index.d.ts +1 -1
  55. package/dist/typescript/commonjs/features/chatbot/index.d.ts.map +1 -1
  56. package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  57. package/dist/typescript/commonjs/features/chatbot/model/ChatBoxTextManager.d.ts +1 -1
  58. package/dist/typescript/commonjs/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
  59. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
  60. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  61. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts +6 -8
  62. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts.map +1 -1
  63. package/dist/typescript/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -1
  64. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolutionApi.d.ts.map +1 -1
  65. package/dist/typescript/commonjs/index.d.ts +0 -1
  66. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  67. package/dist/typescript/commonjs/lib/components/ConditionalWrapper.d.ts +1 -1
  68. package/dist/typescript/commonjs/shared/translation/constants.d.ts +1 -368
  69. package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
  70. package/dist/typescript/commonjs/shared/translation/helpers.d.ts +1 -5
  71. package/dist/typescript/commonjs/shared/translation/helpers.d.ts.map +1 -1
  72. package/dist/typescript/commonjs/shared/translation/hooks.d.ts +1 -3
  73. package/dist/typescript/commonjs/shared/translation/hooks.d.ts.map +1 -1
  74. package/dist/typescript/commonjs/shared/translation/index.d.ts +3 -3
  75. package/dist/typescript/commonjs/shared/translation/index.d.ts.map +1 -1
  76. package/dist/typescript/commonjs/shared/translation/types.d.ts +3 -4
  77. package/dist/typescript/commonjs/shared/translation/types.d.ts.map +1 -1
  78. package/dist/typescript/module/features/chatbot/helpers.d.ts.map +1 -1
  79. package/dist/typescript/module/features/chatbot/index.d.ts +1 -1
  80. package/dist/typescript/module/features/chatbot/index.d.ts.map +1 -1
  81. package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  82. package/dist/typescript/module/features/chatbot/model/ChatBoxTextManager.d.ts +1 -1
  83. package/dist/typescript/module/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
  84. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
  85. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  86. package/dist/typescript/module/features/chatbot/types/api.types.d.ts +6 -8
  87. package/dist/typescript/module/features/chatbot/types/api.types.d.ts.map +1 -1
  88. package/dist/typescript/module/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -1
  89. package/dist/typescript/module/features/exampleSolution/model/ExampleSolutionApi.d.ts.map +1 -1
  90. package/dist/typescript/module/index.d.ts +0 -1
  91. package/dist/typescript/module/index.d.ts.map +1 -1
  92. package/dist/typescript/module/lib/components/ConditionalWrapper.d.ts +1 -1
  93. package/dist/typescript/module/shared/translation/constants.d.ts +1 -368
  94. package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
  95. package/dist/typescript/module/shared/translation/helpers.d.ts +1 -5
  96. package/dist/typescript/module/shared/translation/helpers.d.ts.map +1 -1
  97. package/dist/typescript/module/shared/translation/hooks.d.ts +1 -3
  98. package/dist/typescript/module/shared/translation/hooks.d.ts.map +1 -1
  99. package/dist/typescript/module/shared/translation/index.d.ts +3 -3
  100. package/dist/typescript/module/shared/translation/index.d.ts.map +1 -1
  101. package/dist/typescript/module/shared/translation/types.d.ts +3 -4
  102. package/dist/typescript/module/shared/translation/types.d.ts.map +1 -1
  103. package/package.json +9 -4
  104. package/src/features/chatbot/helpers.ts +0 -2
  105. package/src/features/chatbot/index.ts +1 -9
  106. package/src/features/chatbot/model/ChatBotModel.ts +10 -7
  107. package/src/features/chatbot/model/ChatBoxTextManager.ts +2 -3
  108. package/src/features/chatbot/model/DefaultMessageCreator.ts +3 -3
  109. package/src/features/chatbot/types/api.types.ts +6 -11
  110. package/src/features/exampleSolution/components/ExampleSolutionModalContent.tsx +3 -4
  111. package/src/features/exampleSolution/model/ExampleSolutionApi.ts +5 -9
  112. package/src/index.ts +0 -1
  113. package/src/shared/translation/constants.ts +1 -16
  114. package/src/shared/translation/helpers.ts +5 -45
  115. package/src/shared/translation/hooks.ts +6 -22
  116. package/src/shared/translation/index.ts +3 -3
  117. package/src/shared/translation/react-i18next.d.ts +21 -0
  118. package/src/shared/translation/{localization/en.json → schema.json} +43 -38
  119. package/src/shared/translation/types.ts +3 -19
  120. package/dist/commonjs/lib/types/keys.js +0 -2
  121. package/dist/commonjs/lib/types/keys.js.map +0 -1
  122. package/dist/commonjs/shared/translation/localization/ca.json +0 -61
  123. package/dist/commonjs/shared/translation/localization/de.json +0 -61
  124. package/dist/commonjs/shared/translation/localization/gb.json +0 -61
  125. package/dist/commonjs/shared/translation/localization/sct.json +0 -61
  126. package/dist/commonjs/shared/translation/localization/sw.json +0 -61
  127. package/dist/commonjs/shared/translation/model.js +0 -15
  128. package/dist/commonjs/shared/translation/model.js.map +0 -1
  129. package/dist/commonjs/shared/translation/validation.types.js +0 -6
  130. package/dist/commonjs/shared/translation/validation.types.js.map +0 -1
  131. package/dist/module/lib/types/keys.js +0 -2
  132. package/dist/module/lib/types/keys.js.map +0 -1
  133. package/dist/module/shared/translation/localization/ca.json +0 -61
  134. package/dist/module/shared/translation/localization/de.json +0 -61
  135. package/dist/module/shared/translation/localization/gb.json +0 -61
  136. package/dist/module/shared/translation/localization/sct.json +0 -61
  137. package/dist/module/shared/translation/localization/sw.json +0 -61
  138. package/dist/module/shared/translation/model.js +0 -11
  139. package/dist/module/shared/translation/model.js.map +0 -1
  140. package/dist/module/shared/translation/validation.types.js +0 -4
  141. package/dist/module/shared/translation/validation.types.js.map +0 -1
  142. package/dist/typescript/commonjs/lib/types/keys.d.ts +0 -8
  143. package/dist/typescript/commonjs/lib/types/keys.d.ts.map +0 -1
  144. package/dist/typescript/commonjs/shared/translation/model.d.ts +0 -125
  145. package/dist/typescript/commonjs/shared/translation/model.d.ts.map +0 -1
  146. package/dist/typescript/commonjs/shared/translation/validation.types.d.ts +0 -21
  147. package/dist/typescript/commonjs/shared/translation/validation.types.d.ts.map +0 -1
  148. package/dist/typescript/module/lib/types/keys.d.ts +0 -8
  149. package/dist/typescript/module/lib/types/keys.d.ts.map +0 -1
  150. package/dist/typescript/module/shared/translation/model.d.ts +0 -125
  151. package/dist/typescript/module/shared/translation/model.d.ts.map +0 -1
  152. package/dist/typescript/module/shared/translation/validation.types.d.ts +0 -21
  153. package/dist/typescript/module/shared/translation/validation.types.d.ts.map +0 -1
  154. package/src/lib/types/keys.ts +0 -18
  155. package/src/shared/translation/localization/ca.json +0 -61
  156. package/src/shared/translation/localization/de.json +0 -61
  157. package/src/shared/translation/localization/gb.json +0 -61
  158. package/src/shared/translation/localization/sct.json +0 -61
  159. package/src/shared/translation/localization/sw.json +0 -61
  160. package/src/shared/translation/model.ts +0 -16
  161. package/src/shared/translation/validation.types.ts +0 -34
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/translation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAAE,uBAAuB,EAAE,OAAO,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/translation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,IAAI,CAAC,EAAE,MAAM,WAAW,CAAA;AACxC,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA"}
@@ -1,6 +1,5 @@
1
- import enTranslations from './localization/en.json';
2
- import { RetrieveKeys } from '../../lib/types/keys';
3
- export type Translations = typeof enTranslations;
4
- export type TranslationKeys = RetrieveKeys<Translations>;
1
+ import { TFuncKey } from 'i18next';
2
+ import { NAMESPACE } from './constants';
3
+ export type TranslationKeys = TFuncKey<typeof NAMESPACE>;
5
4
  export type GetText = (key: TranslationKeys, args?: Record<string, string> | null) => string;
6
5
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/shared/translation/types.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,wBAAwB,CAAA;AAOnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAGnD,MAAM,MAAM,YAAY,GAAG,OAAO,cAAc,CAAA;AAChD,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,CAAA;AACxD,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,KAAK,MAAM,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/shared/translation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,SAAS,CAAC,CAAA;AACxD,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,KAAK,MAAM,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magmamath/students-features",
3
- "version": "1.3.2",
3
+ "version": "1.3.3-rc.2",
4
4
  "description": "Magmamath features library",
5
5
  "source": "src/index.ts",
6
6
  "main": "src/index.ts",
@@ -15,7 +15,8 @@
15
15
  "scripts": {
16
16
  "clean": "del-cli dist",
17
17
  "prepare": "bob build",
18
- "release": "release-it"
18
+ "release": "release-it",
19
+ "pull-translations": "node scripts/pullTranslations.mjs"
19
20
  },
20
21
  "peerDependencies": {
21
22
  "@magmamath/frontend-config": "1.1.0",
@@ -32,7 +33,9 @@
32
33
  "expo-audio": "^1.1.1",
33
34
  "expo": ">=52.0.47",
34
35
  "@react-native-masked-view/masked-view": "*",
35
- "react-native-linear-gradient": "*"
36
+ "react-native-linear-gradient": "*",
37
+ "i18next": ">=22",
38
+ "react-i18next": ">=11"
36
39
  },
37
40
  "devDependencies": {
38
41
  "@magmamath/react-native-ui": "0.4.83",
@@ -63,7 +66,9 @@
63
66
  "typescript": "^5.2.2",
64
67
  "axios": "^1.13.5",
65
68
  "@react-native-masked-view/masked-view": "^0.3.2",
66
- "react-native-linear-gradient": "^2.8.3"
69
+ "react-native-linear-gradient": "^2.8.3",
70
+ "i18next": "^22.5.1",
71
+ "react-i18next": "^11.3.4"
67
72
  },
68
73
  "resolutions": {
69
74
  "@types/react": "^18.2.44"
@@ -65,7 +65,6 @@ export function prepareChatRequestPayload(
65
65
  imageAltText,
66
66
  answerOptions,
67
67
  answer,
68
- chatHistory,
69
68
  } = payload
70
69
 
71
70
  if (freeTextMessage) {
@@ -87,7 +86,6 @@ export function prepareChatRequestPayload(
87
86
  language,
88
87
  ...(imageCdnId && { imageCdnId }),
89
88
  ...(imageAltText && { altText: imageAltText }),
90
- ...(chatHistory && { chatHistory }),
91
89
  ...(!!problemStandards?.length && { problemStandards }),
92
90
  ...(!!answerOptions?.length && { answerOptions }),
93
91
  },
@@ -7,15 +7,7 @@ export {
7
7
  type IChatDrawBoardAdapter,
8
8
  } from './types/model.types'
9
9
  export type { RequestOptionalConfig } from '../../lib/effector/createControllerEffect'
10
- export type {
11
- PostMessageResponse,
12
- ChatHintPayload,
13
- ChatHintResponse,
14
- GetAlternativesPayload,
15
- GetAlternativesResponse,
16
- SendMessagePayload,
17
- SendMessageResponse,
18
- } from './types/api.types'
10
+ export type { PostMessageResponse } from './types/api.types'
19
11
  export { DefaultMessagesCreator } from './model/DefaultMessageCreator'
20
12
  export type { ChatAnswer } from './types/units.types'
21
13
  export type { ConversationMessage } from './types/units.types'
@@ -234,6 +234,15 @@ export class ChatbotModel {
234
234
  messages: [messagesHelper.createOwn({ message, translatedMessage })],
235
235
  })
236
236
 
237
+ const chatHistory =
238
+ context.assignmentId && context.problemId
239
+ ? {
240
+ exerciseId: context.assignmentId,
241
+ problemId: context.problemId,
242
+ chatVersion: alternatives?.version,
243
+ }
244
+ : undefined
245
+
237
246
  // Request is overridden by ThreadManager.postMessage (delegates to sendMessage/getHint)
238
247
  const response = await this.api.postMessageFx({
239
248
  answer: context.answer,
@@ -245,14 +254,8 @@ export class ChatbotModel {
245
254
  imageAltText: context.imageDescription,
246
255
  imageCdnId: context.imageCdnId,
247
256
  conversationId: cache[key].conversationId,
257
+ chatHistory,
248
258
  ...(isFreeText && { freeTextMessage: message }),
249
- ...(context.assignmentId && {
250
- chatHistory: {
251
- exerciseId: context.assignmentId,
252
- problemId: context.problemId,
253
- chatVersion: alternatives?.version,
254
- },
255
- }),
256
259
  })
257
260
 
258
261
  const thread = this.threadManager.get(key)
@@ -1,13 +1,12 @@
1
1
  import { DefaultMessagesCreator } from './DefaultMessageCreator'
2
- import { TranslationKeys } from '../../../shared/translation/types'
3
2
  import { getText } from '../../../shared/translation/helpers'
4
3
  import { ChatbotMessages } from '../types/model.types'
5
- import { $localization } from '../../../shared/translation'
4
+ import { TranslationKeys } from '../../../shared/translation'
6
5
 
7
6
  export class ChatBotTextManager {
8
7
  private readonly messagesCreator = new DefaultMessagesCreator<TranslationKeys>({
9
8
  textGetter: getText,
10
- }).bindToLanguageChanged($localization.updates)
9
+ }).bindToLanguageChanged()
11
10
 
12
11
  public readonly messages: ChatbotMessages = {
13
12
  error: this.messagesCreator.createMessage('chat.errorMessage', {
@@ -1,5 +1,5 @@
1
+ import i18next from 'i18next'
1
2
  import { PostMessageResponse } from '../types/api.types'
2
- import { Event } from 'effector'
3
3
  import { ChatAnswer } from '../types/units.types'
4
4
 
5
5
  type ChatMessage = Omit<PostMessageResponse, 'threadId'> & {
@@ -45,8 +45,8 @@ export class DefaultMessagesCreator<K extends string> {
45
45
  return option
46
46
  }
47
47
 
48
- public bindToLanguageChanged(event: Event<unknown>) {
49
- event.watch(() => {
48
+ public bindToLanguageChanged() {
49
+ i18next.on('languageChanged', () => {
50
50
  this.list.forEach((key, chatMessage) => {
51
51
  if ('message' in chatMessage) {
52
52
  chatMessage.message = this.getter(key)
@@ -30,15 +30,14 @@ export type GetAlternativesResponse = {
30
30
  }
31
31
 
32
32
  export type SendMessagePayload = {
33
- message: string
34
33
  problemDescription?: string
35
34
  problemStandards?: ProblemStandard[]
36
35
  correctAnswer?: string | string[]
37
36
  answerOptions?: string[]
38
37
  altText?: string
39
38
  language?: string
39
+ message: string
40
40
  conversationId?: string
41
- chatHistory?: ChatHistory
42
41
  }
43
42
 
44
43
  export type SendMessageResponse = {
@@ -46,12 +45,6 @@ export type SendMessageResponse = {
46
45
  conversationId?: string | null
47
46
  }
48
47
 
49
- export type ChatHistory = {
50
- exerciseId: string
51
- problemId?: string
52
- chatVersion?: string
53
- }
54
-
55
48
  export type PostMessagePayload = {
56
49
  language: string
57
50
  problemAnswer: string[]
@@ -63,7 +56,11 @@ export type PostMessagePayload = {
63
56
  imageCdnId?: string
64
57
  freeTextMessage?: string
65
58
  conversationId?: string | null
66
- chatHistory?: ChatHistory
59
+ chatHistory?: {
60
+ exerciseId: string
61
+ problemId: string
62
+ chatVersion?: string
63
+ }
67
64
  }
68
65
 
69
66
  export type PostMessageResponse = {
@@ -137,7 +134,6 @@ export type ChatHintResponse = {
137
134
  errorCellIds?: string[]
138
135
  errorChars?: ErrorChar[]
139
136
  }
140
-
141
137
  export type ErrorSpottingPayload = {
142
138
  strokes: FullStrokeData[]
143
139
  problemDescription: string
@@ -145,7 +141,6 @@ export type ErrorSpottingPayload = {
145
141
  userAnswer: string | string[]
146
142
  hint: string
147
143
  }
148
-
149
144
  export type ErrorSpottingResponse = {
150
145
  highlightedStrokeIds: string[]
151
146
  }
@@ -1,8 +1,7 @@
1
1
  import { StyleSheet, View } from 'react-native'
2
2
  import React from 'react'
3
3
  import { COLORS, HeadingVariants, IS_WEB, SPACING, Typography } from '@magmamath/react-native-ui'
4
- import { useUnit } from 'effector-react'
5
- import { $localization } from '../../../shared/translation'
4
+ import { useText } from '../../../shared/translation'
6
5
  import { ExampleSolutionModalParams } from '../types'
7
6
  import { QuestionSection } from './QuestionSection'
8
7
  import { SolutionSection } from './SolutionSection'
@@ -18,7 +17,7 @@ export const ExampleSolutionModalContent = ({
18
17
  params: { model, payload, cacheKey },
19
18
  }: ExampleSolutionModalContentProps) => {
20
19
  const { result, status } = useExampleSolution({ model, payload, cacheKey })
21
- const localization = useUnit($localization)
20
+ const t = useText()
22
21
 
23
22
  return (
24
23
  <View
@@ -28,7 +27,7 @@ export const ExampleSolutionModalContent = ({
28
27
  ]}
29
28
  >
30
29
  <Typography align="center" variant={HeadingVariants.H2} style={{ color: COLORS.NEUTRAL_9 }}>
31
- {localization.exampleSolution.exampleSolution}
30
+ {t('exampleSolution.exampleSolution')}
32
31
  </Typography>
33
32
  <View style={styles.content}>
34
33
  <QuestionSection
@@ -1,7 +1,7 @@
1
1
  import { createControllerEffect } from './../../../lib/effector/createControllerEffect'
2
2
  import { ExampleSolutionApiRequests, ExampleSolutionErrorHandler } from '../types'
3
- import { $localization } from '../../../shared/translation'
4
- import { createEffect, sample, attach, StoreValue } from 'effector'
3
+ import { getText } from '../../../shared/translation/helpers'
4
+ import { createEffect, sample } from 'effector'
5
5
 
6
6
  type ExampleSolutionApiProps = {
7
7
  api: ExampleSolutionApiRequests
@@ -12,13 +12,9 @@ export class ExampleSolutionsApi {
12
12
  public readonly generateExampleSolutionFx
13
13
  public readonly errorHandlerFx?: ExampleSolutionErrorHandler
14
14
 
15
- public readonly errorHandlingFx = attach({
16
- source: $localization,
17
- effect: createEffect((localization: StoreValue<typeof $localization>) => {
18
- if (!this.errorHandlerFx) return
19
- const errorMessage = localization.exampleSolution.errorMessage
20
- this.errorHandlerFx(errorMessage)
21
- }),
15
+ public readonly errorHandlingFx = createEffect(() => {
16
+ if (!this.errorHandlerFx) return
17
+ this.errorHandlerFx(getText('exampleSolution.errorMessage'))
22
18
  })
23
19
 
24
20
  constructor({ api, errorHandler }: ExampleSolutionApiProps) {
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { useFeaturesLocalization, setFeaturesLocalization } from './shared/translation'
2
1
  export { generateRandomId } from './lib/helpers/helpers'
3
2
  export * from './features/chatbot'
4
3
  export * from './features/feedback'
@@ -1,16 +1 @@
1
- import { Locale } from '@magmamath/frontend-config'
2
- import EN from './localization/en.json'
3
- import GB from './localization/gb.json'
4
- import SW from './localization/sw.json'
5
- import CA from './localization/ca.json'
6
- import SCT from './localization/sct.json'
7
- import DE from './localization/de.json'
8
-
9
- export const LOCALIZATION_CONFIGS = {
10
- [Locale.US]: EN,
11
- [Locale.GB]: GB,
12
- [Locale.SE]: SW,
13
- [Locale.CA]: CA,
14
- [Locale.SCT]: SCT,
15
- [Locale.DE]: DE,
16
- }
1
+ export const NAMESPACE = 'students-features'
@@ -1,47 +1,7 @@
1
- import { LOCALIZATION_CONFIGS } from './constants'
2
- import { $localization, setLocalization } from './model'
3
- import { GetText, TranslationKeys, Translations } from './types'
1
+ import i18next from 'i18next'
2
+ import { NAMESPACE } from './constants'
3
+ import { GetText } from './types'
4
4
 
5
- export function getTranslation(config: Translations, key: TranslationKeys) {
6
- const rawTranslation = config?.[key as keyof Translations]
7
- if (typeof rawTranslation === 'string' || !key.includes('.')) {
8
- return rawTranslation as string
9
- }
10
- const keys = key.split('.')
11
- let translation = config
12
- for (const k of keys) {
13
- if (translation[k as keyof Translations] === undefined) return key
14
- translation = translation[k as keyof Translations] as any
15
- }
16
- if (typeof translation === 'string') {
17
- return translation
18
- }
19
- return key
20
- }
21
-
22
- export const getSubstitutedString = (str: string, substitutions: Record<string, string> = {}) => {
23
- const substitutionsArray = Object.entries(substitutions)
24
- let result = str
25
-
26
- if (!substitutionsArray.length) return result
27
-
28
- substitutionsArray.forEach(([key, value]) => {
29
- result = result.replace(`{{${key}}}`, value)
30
- })
31
-
32
- return result
33
- }
34
-
35
- export const getText: GetText = (key: TranslationKeys, args = null) => {
36
- const config = $localization.getState()
37
-
38
- const translation = getTranslation(config, key)
39
- if (args) return getSubstitutedString(translation, args)
40
- return translation
41
- }
42
-
43
- export const setFeaturesLocalization = (
44
- generator: ((config: typeof LOCALIZATION_CONFIGS) => Translations) | Translations,
45
- ) => {
46
- setLocalization(generator)
5
+ export const getText: GetText = (key, args = null) => {
6
+ return i18next.t(key, { ns: NAMESPACE, ...(args || {}) }) as string
47
7
  }
@@ -1,25 +1,9 @@
1
- import { useUnit } from 'effector-react'
2
- import { $localization, setLocalization } from './model'
3
- import { GetText, Translations } from './types'
4
- import { useCallback, useEffect } from 'react'
5
- import { LOCALIZATION_CONFIGS } from './constants'
6
- import { getSubstitutedString, getTranslation } from './helpers'
1
+ import { useCallback } from 'react'
2
+ import { useTranslation } from 'react-i18next'
3
+ import { NAMESPACE } from './constants'
4
+ import { GetText } from './types'
7
5
 
8
6
  export const useText = (): GetText => {
9
- const config = useUnit($localization)
10
- return useCallback<GetText>(
11
- (key, args = null) => {
12
- const translation = getTranslation(config, key)
13
- return args ? getSubstitutedString(translation, args) : translation
14
- },
15
- [config],
16
- )
17
- }
18
-
19
- export const useFeaturesLocalization = (
20
- generator: ((config: typeof LOCALIZATION_CONFIGS) => Translations) | Translations,
21
- ) => {
22
- useEffect(() => {
23
- setLocalization(generator)
24
- }, [generator])
7
+ const { t } = useTranslation(NAMESPACE)
8
+ return useCallback<GetText>((key, args = null) => t(key, args ?? undefined) as string, [t])
25
9
  }
@@ -1,3 +1,3 @@
1
- export { useFeaturesLocalization, useText } from './hooks'
2
- export { setFeaturesLocalization, getText as t } from './helpers'
3
- export { $localization, setLocalization } from './model'
1
+ export { useText } from './hooks'
2
+ export { getText as t } from './helpers'
3
+ export type { TranslationKeys, GetText } from './types'
@@ -0,0 +1,21 @@
1
+ import 'i18next'
2
+ import 'react-i18next'
3
+ import schema from './schema.json'
4
+
5
+ declare module 'i18next' {
6
+ interface CustomTypeOptions {
7
+ defaultNS: 'students-features'
8
+ resources: {
9
+ ['students-features']: typeof schema
10
+ }
11
+ }
12
+ }
13
+
14
+ declare module 'react-i18next' {
15
+ interface CustomTypeOptions {
16
+ defaultNS: 'students-features'
17
+ resources: {
18
+ ['students-features']: typeof schema
19
+ }
20
+ }
21
+ }
@@ -1,61 +1,66 @@
1
1
  {
2
- "locale": "en-SE",
3
- "teacherFeedback.noComments": "No comments yet",
4
- "time.justNow": "just now",
5
- "time.minuteAgo": "minute ago",
6
- "time.minutesAgo": "{{count}} minutes ago",
7
- "time.hourAgo": "hour ago",
8
- "time.hoursAgo": "{{count}} hours ago",
9
- "time.dayAgo": "day ago",
10
- "time.daysAgo": "{{count}} days ago",
11
- "time.monthAgo": "month ago",
12
- "time.monthsAgo": "{{count}} months ago",
13
- "time.yearAgo": "year ago",
14
- "time.yearsAgo": "{{count}} years ago",
15
2
  "chat": {
16
3
  "anotherHint": "Give me another hint",
17
- "getHint": "Get a hint",
18
- "needHint": "I need a hint",
19
- "giveHintOpenChat": "I need a hint",
20
4
  "answerAgain": "Answer again to get another hint!",
21
5
  "errorMessage": "Something went wrong! Try again",
6
+ "getHint": "Get a hint",
7
+ "giveHint": "I need a hint",
8
+ "giveHintOpenChat": "I need a hint",
22
9
  "howCanIHelp": "Hi! Do you want help?",
23
- "showError": "Show error",
24
- "inputPlaceholder": "Type..."
25
- },
26
- "gifCelebrations": {
27
- "greatStart": "Great start!",
28
- "onTheWay": "On the way!",
29
- "almostThere": "Almost there"
10
+ "inputPlaceholder": "Type...",
11
+ "needHint": "I need a hint",
12
+ "showError": "Show error"
30
13
  },
31
14
  "exampleSolution": {
32
- "exampleSolution": "Example solution",
33
- "letMeThink": "Let me think...",
34
15
  "aha": "Aha!",
35
- "errorMessage": "Something went wrong with generating an example solution"
16
+ "errorMessage": "Something went wrong with generating an example solution",
17
+ "exampleSolution": "Example solution",
18
+ "letMeThink": "Let me think..."
19
+ },
20
+ "gifCelebrations": {
21
+ "almostThere": "Almost there",
22
+ "greatStart": "Great start!",
23
+ "onTheWay": "On the way!"
36
24
  },
37
25
  "keyboard": {
38
- "length": "Length",
39
26
  "area": "Area",
27
+ "length": "Length",
28
+ "time": "Time",
40
29
  "volume": "Volume",
41
- "weight": "Weight",
42
- "time": "Time"
30
+ "weight": "Weight"
31
+ },
32
+ "locale": "en-SE",
33
+ "teacherFeedback": {
34
+ "noComments": "No comments yet"
35
+ },
36
+ "time": {
37
+ "dayAgo": "day ago",
38
+ "daysAgo": "{{count}} days ago",
39
+ "hourAgo": "hour ago",
40
+ "hoursAgo": "{{count}} hours ago",
41
+ "justNow": "just now",
42
+ "minuteAgo": "minute ago",
43
+ "minutesAgo": "{{count}} minutes ago",
44
+ "monthAgo": "month ago",
45
+ "monthsAgo": "{{count}} months ago",
46
+ "yearAgo": "year ago",
47
+ "yearsAgo": "{{count}} years ago"
43
48
  },
44
49
  "voice": {
45
- "deleteRecording": "Delete recording?",
46
- "youWontBeAbleToRecover": "You won't be able to recover this file once it's gone.",
47
- "recordingDeleted": "Recording successfully deleted.",
48
- "delete": "Delete",
50
+ "attempt": "Attempt '{{'number'}}'",
49
51
  "cancel": "Cancel",
52
+ "delete": "Delete",
53
+ "deleteRecording": "Delete recording?",
50
54
  "noMicrophoneAccess": "No microphone access.",
51
55
  "noMicrophoneAccessBySystem": "Microphone access denied by system settings.",
52
56
  "noMicrophoneFound": "No microphone found.",
53
- "uploadFailed": "Upload failed. Please try again.",
54
- "redoRecording": "Redo recording?",
57
+ "recordingDeleted": "Recording successfully deleted.",
55
58
  "redo": "Redo",
59
+ "redoRecording": "Redo recording?",
56
60
  "thisWillRemoveRecording": "This will remove your previous recording.",
57
61
  "transcriptions": "Transcriptions",
58
- "attempt": "Attempt {{number}}",
59
- "transcriptNotAvailable": "Transcript not available"
62
+ "transcriptNotAvailable": "Transcript not available",
63
+ "uploadFailed": "Upload failed. Please try again.",
64
+ "youWontBeAbleToRecover": "You won't be able to recover this file once it's gone."
60
65
  }
61
- }
66
+ }
@@ -1,21 +1,5 @@
1
- import enTranslations from './localization/en.json'
2
- import swTranslations from './localization/sw.json'
3
- import gbTranslations from './localization/gb.json'
4
- import caTranslations from './localization/ca.json'
5
- import sctTranslations from './localization/sct.json'
6
- import deTranslations from './localization/de.json'
1
+ import { TFuncKey } from 'i18next'
2
+ import { NAMESPACE } from './constants'
7
3
 
8
- import { RetrieveKeys } from '../../lib/types/keys'
9
- import { ISValidTranslation } from './validation.types'
10
-
11
- export type Translations = typeof enTranslations
12
- export type TranslationKeys = RetrieveKeys<Translations>
4
+ export type TranslationKeys = TFuncKey<typeof NAMESPACE>
13
5
  export type GetText = (key: TranslationKeys, args?: Record<string, string> | null) => string
14
-
15
- // Validation of translations, do not remove
16
- type ISValidEN = ISValidTranslation<Translations>
17
- type ISValidSW = ISValidTranslation<typeof swTranslations>
18
- type ISValidGB = ISValidTranslation<typeof gbTranslations>
19
- type ISValidCA = ISValidTranslation<typeof caTranslations>
20
- type ISValidSCT = ISValidTranslation<typeof sctTranslations>
21
- type ISValidDE = ISValidTranslation<typeof deTranslations>
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=keys.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["lib/types/keys.ts"],"mappings":"","ignoreList":[]}
@@ -1,61 +0,0 @@
1
- {
2
- "locale": "en-CA",
3
- "teacherFeedback.noComments": "No comments yet",
4
- "time.justNow": "just now",
5
- "time.minuteAgo": "minute ago",
6
- "time.minutesAgo": "{{count}} minutes ago",
7
- "time.hourAgo": "hour ago",
8
- "time.hoursAgo": "{{count}} hours ago",
9
- "time.dayAgo": "day ago",
10
- "time.daysAgo": "{{count}} days ago",
11
- "time.monthAgo": "month ago",
12
- "time.monthsAgo": "{{count}} months ago",
13
- "time.yearAgo": "year ago",
14
- "time.yearsAgo": "{{count}} years ago",
15
- "chat": {
16
- "anotherHint": "Give me another hint",
17
- "getHint": "Get a hint",
18
- "needHint": "I need a hint",
19
- "giveHintOpenChat": "I need a hint",
20
- "answerAgain": "Answer again to get another hint!",
21
- "errorMessage": "Something went wrong! Try again",
22
- "howCanIHelp": "Hi! Do you want help?",
23
- "showError": "Show error",
24
- "inputPlaceholder": "Type..."
25
- },
26
- "gifCelebrations": {
27
- "greatStart": "Great start!",
28
- "onTheWay": "On the way!",
29
- "almostThere": "Almost there"
30
- },
31
- "exampleSolution": {
32
- "exampleSolution": "Example solution",
33
- "letMeThink": "Let me think...",
34
- "aha": "Aha!",
35
- "errorMessage": "Something went wrong with generating an example solution"
36
- },
37
- "keyboard": {
38
- "length": "Length",
39
- "area": "Area",
40
- "volume": "Volume",
41
- "weight": "Weight",
42
- "time": "Time"
43
- },
44
- "voice": {
45
- "deleteRecording": "Delete recording?",
46
- "youWontBeAbleToRecover": "You won't be able to recover this file once it's gone.",
47
- "recordingDeleted": "Recording successfully deleted.",
48
- "delete": "Delete",
49
- "cancel": "Cancel",
50
- "noMicrophoneAccess": "No microphone access.",
51
- "noMicrophoneAccessBySystem": "Microphone access denied by system settings.",
52
- "noMicrophoneFound": "No microphone found.",
53
- "uploadFailed": "Upload failed. Please try again.",
54
- "redoRecording": "Redo recording?",
55
- "redo": "Redo",
56
- "thisWillRemoveRecording": "This will remove your previous recording.",
57
- "transcriptions": "Transcriptions",
58
- "attempt": "Attempt {{number}}",
59
- "transcriptNotAvailable": "Transcript not available"
60
- }
61
- }