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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/locales/schema.json +1 -0
  17. package/dist/commonjs/shared/translation/constants.js +2 -17
  18. package/dist/commonjs/shared/translation/constants.js.map +1 -1
  19. package/dist/commonjs/shared/translation/helpers.js +8 -38
  20. package/dist/commonjs/shared/translation/helpers.js.map +1 -1
  21. package/dist/commonjs/shared/translation/hooks.js +7 -15
  22. package/dist/commonjs/shared/translation/hooks.js.map +1 -1
  23. package/dist/commonjs/shared/translation/index.js +0 -25
  24. package/dist/commonjs/shared/translation/index.js.map +1 -1
  25. package/dist/commonjs/shared/translation/types.js +0 -4
  26. package/dist/module/features/chatbot/helpers.js +1 -5
  27. package/dist/module/features/chatbot/helpers.js.map +1 -1
  28. package/dist/module/features/chatbot/index.js.map +1 -1
  29. package/dist/module/features/chatbot/model/ChatBotModel.js +6 -7
  30. package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
  31. package/dist/module/features/chatbot/model/ChatBoxTextManager.js +1 -2
  32. package/dist/module/features/chatbot/model/ChatBoxTextManager.js.map +1 -1
  33. package/dist/module/features/chatbot/model/DefaultMessageCreator.js +3 -2
  34. package/dist/module/features/chatbot/model/DefaultMessageCreator.js.map +1 -1
  35. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js +3 -4
  36. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -1
  37. package/dist/module/features/exampleSolution/model/ExampleSolutionApi.js +5 -9
  38. package/dist/module/features/exampleSolution/model/ExampleSolutionApi.js.map +1 -1
  39. package/dist/module/index.js +0 -1
  40. package/dist/module/index.js.map +1 -1
  41. package/dist/module/locales/schema.json +1 -0
  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/types.js +0 -2
  51. package/dist/typescript/commonjs/features/chatbot/helpers.d.ts.map +1 -1
  52. package/dist/typescript/commonjs/features/chatbot/index.d.ts +1 -1
  53. package/dist/typescript/commonjs/features/chatbot/index.d.ts.map +1 -1
  54. package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  55. package/dist/typescript/commonjs/features/chatbot/model/ChatBoxTextManager.d.ts +1 -2
  56. package/dist/typescript/commonjs/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
  57. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
  58. package/dist/typescript/commonjs/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  59. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts +6 -8
  60. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts.map +1 -1
  61. package/dist/typescript/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -1
  62. package/dist/typescript/commonjs/features/exampleSolution/model/ExampleSolutionApi.d.ts.map +1 -1
  63. package/dist/typescript/commonjs/index.d.ts +0 -1
  64. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  65. package/dist/typescript/commonjs/lib/components/ConditionalWrapper.d.ts +1 -1
  66. package/dist/typescript/commonjs/shared/translation/constants.d.ts +1 -368
  67. package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
  68. package/dist/typescript/commonjs/shared/translation/helpers.d.ts +1 -5
  69. package/dist/typescript/commonjs/shared/translation/helpers.d.ts.map +1 -1
  70. package/dist/typescript/commonjs/shared/translation/hooks.d.ts +1 -3
  71. package/dist/typescript/commonjs/shared/translation/hooks.d.ts.map +1 -1
  72. package/dist/typescript/commonjs/shared/translation/index.d.ts +3 -3
  73. package/dist/typescript/commonjs/shared/translation/index.d.ts.map +1 -1
  74. package/dist/typescript/commonjs/shared/translation/types.d.ts +1 -4
  75. package/dist/typescript/commonjs/shared/translation/types.d.ts.map +1 -1
  76. package/dist/typescript/module/features/chatbot/helpers.d.ts.map +1 -1
  77. package/dist/typescript/module/features/chatbot/index.d.ts +1 -1
  78. package/dist/typescript/module/features/chatbot/index.d.ts.map +1 -1
  79. package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  80. package/dist/typescript/module/features/chatbot/model/ChatBoxTextManager.d.ts +1 -2
  81. package/dist/typescript/module/features/chatbot/model/ChatBoxTextManager.d.ts.map +1 -1
  82. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts +1 -2
  83. package/dist/typescript/module/features/chatbot/model/DefaultMessageCreator.d.ts.map +1 -1
  84. package/dist/typescript/module/features/chatbot/types/api.types.d.ts +6 -8
  85. package/dist/typescript/module/features/chatbot/types/api.types.d.ts.map +1 -1
  86. package/dist/typescript/module/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -1
  87. package/dist/typescript/module/features/exampleSolution/model/ExampleSolutionApi.d.ts.map +1 -1
  88. package/dist/typescript/module/index.d.ts +0 -1
  89. package/dist/typescript/module/index.d.ts.map +1 -1
  90. package/dist/typescript/module/lib/components/ConditionalWrapper.d.ts +1 -1
  91. package/dist/typescript/module/shared/translation/constants.d.ts +1 -368
  92. package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
  93. package/dist/typescript/module/shared/translation/helpers.d.ts +1 -5
  94. package/dist/typescript/module/shared/translation/helpers.d.ts.map +1 -1
  95. package/dist/typescript/module/shared/translation/hooks.d.ts +1 -3
  96. package/dist/typescript/module/shared/translation/hooks.d.ts.map +1 -1
  97. package/dist/typescript/module/shared/translation/index.d.ts +3 -3
  98. package/dist/typescript/module/shared/translation/index.d.ts.map +1 -1
  99. package/dist/typescript/module/shared/translation/types.d.ts +1 -4
  100. package/dist/typescript/module/shared/translation/types.d.ts.map +1 -1
  101. package/package.json +18 -13
  102. package/src/features/chatbot/helpers.ts +0 -2
  103. package/src/features/chatbot/index.ts +1 -9
  104. package/src/features/chatbot/model/ChatBotModel.ts +10 -7
  105. package/src/features/chatbot/model/ChatBoxTextManager.ts +3 -5
  106. package/src/features/chatbot/model/DefaultMessageCreator.ts +3 -3
  107. package/src/features/chatbot/types/api.types.ts +6 -11
  108. package/src/features/exampleSolution/components/ExampleSolutionModalContent.tsx +3 -4
  109. package/src/features/exampleSolution/model/ExampleSolutionApi.ts +5 -9
  110. package/src/index.ts +0 -1
  111. package/src/locales/schema.json +1 -0
  112. package/src/shared/translation/constants.ts +1 -16
  113. package/src/shared/translation/helpers.ts +5 -45
  114. package/src/shared/translation/hooks.ts +6 -22
  115. package/src/shared/translation/index.ts +3 -3
  116. package/src/shared/translation/types.ts +1 -20
  117. package/dist/commonjs/lib/types/keys.js +0 -2
  118. package/dist/commonjs/lib/types/keys.js.map +0 -1
  119. package/dist/commonjs/shared/translation/localization/ca.json +0 -61
  120. package/dist/commonjs/shared/translation/localization/de.json +0 -61
  121. package/dist/commonjs/shared/translation/localization/en.json +0 -61
  122. package/dist/commonjs/shared/translation/localization/gb.json +0 -61
  123. package/dist/commonjs/shared/translation/localization/sct.json +0 -61
  124. package/dist/commonjs/shared/translation/localization/sw.json +0 -61
  125. package/dist/commonjs/shared/translation/model.js +0 -15
  126. package/dist/commonjs/shared/translation/model.js.map +0 -1
  127. package/dist/commonjs/shared/translation/validation.types.js +0 -6
  128. package/dist/commonjs/shared/translation/validation.types.js.map +0 -1
  129. package/dist/module/lib/types/keys.js +0 -2
  130. package/dist/module/lib/types/keys.js.map +0 -1
  131. package/dist/module/shared/translation/localization/ca.json +0 -61
  132. package/dist/module/shared/translation/localization/de.json +0 -61
  133. package/dist/module/shared/translation/localization/en.json +0 -61
  134. package/dist/module/shared/translation/localization/gb.json +0 -61
  135. package/dist/module/shared/translation/localization/sct.json +0 -61
  136. package/dist/module/shared/translation/localization/sw.json +0 -61
  137. package/dist/module/shared/translation/model.js +0 -11
  138. package/dist/module/shared/translation/model.js.map +0 -1
  139. package/dist/module/shared/translation/validation.types.js +0 -4
  140. package/dist/module/shared/translation/validation.types.js.map +0 -1
  141. package/dist/typescript/commonjs/lib/types/keys.d.ts +0 -8
  142. package/dist/typescript/commonjs/lib/types/keys.d.ts.map +0 -1
  143. package/dist/typescript/commonjs/shared/translation/model.d.ts +0 -125
  144. package/dist/typescript/commonjs/shared/translation/model.d.ts.map +0 -1
  145. package/dist/typescript/commonjs/shared/translation/validation.types.d.ts +0 -21
  146. package/dist/typescript/commonjs/shared/translation/validation.types.d.ts.map +0 -1
  147. package/dist/typescript/module/lib/types/keys.d.ts +0 -8
  148. package/dist/typescript/module/lib/types/keys.d.ts.map +0 -1
  149. package/dist/typescript/module/shared/translation/model.d.ts +0 -125
  150. package/dist/typescript/module/shared/translation/model.d.ts.map +0 -1
  151. package/dist/typescript/module/shared/translation/validation.types.d.ts +0 -21
  152. package/dist/typescript/module/shared/translation/validation.types.d.ts.map +0 -1
  153. package/src/lib/types/keys.ts +0 -18
  154. package/src/shared/translation/localization/ca.json +0 -61
  155. package/src/shared/translation/localization/de.json +0 -61
  156. package/src/shared/translation/localization/en.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
@@ -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,11 @@
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'
6
4
 
7
5
  export class ChatBotTextManager {
8
- private readonly messagesCreator = new DefaultMessagesCreator<TranslationKeys>({
6
+ private readonly messagesCreator = new DefaultMessagesCreator<string>({
9
7
  textGetter: getText,
10
- }).bindToLanguageChanged($localization.updates)
8
+ }).bindToLanguageChanged()
11
9
 
12
10
  public readonly messages: ChatbotMessages = {
13
11
  error: this.messagesCreator.createMessage('chat.errorMessage', {
@@ -21,7 +19,7 @@ export class ChatBotTextManager {
21
19
  private readonly defaultMessages = { ...this.messages }
22
20
 
23
21
  public update(
24
- cb: (manager: DefaultMessagesCreator<TranslationKeys>) => Partial<ChatbotMessages>,
22
+ cb: (manager: DefaultMessagesCreator<string>) => Partial<ChatbotMessages>,
25
23
  ) {
26
24
  Object.assign(this.messages, cb(this.messagesCreator))
27
25
  }
@@ -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'
@@ -0,0 +1 @@
1
+ {}
@@ -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 || {}) })
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), [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'
@@ -1,21 +1,2 @@
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'
7
-
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>
1
+ export type TranslationKeys = string
13
2
  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
- }
@@ -1,61 +0,0 @@
1
- {
2
- "locale": "de-DE",
3
- "teacherFeedback.noComments": "Noch keine Kommentare",
4
- "time.justNow": "gerade eben",
5
- "time.minuteAgo": "vor einer Minute",
6
- "time.minutesAgo": "vor {{count}} Minuten",
7
- "time.hourAgo": "vor einer Stunde",
8
- "time.hoursAgo": "vor {{count}} Stunden",
9
- "time.dayAgo": "vor einem Tag",
10
- "time.daysAgo": "vor {{count}} Tagen",
11
- "time.monthAgo": "vor einem Monat",
12
- "time.monthsAgo": "vor {{count}} Monaten",
13
- "time.yearAgo": "vor einem Jahr",
14
- "time.yearsAgo": "vor {{count}} Jahren",
15
- "chat": {
16
- "anotherHint": "Gib mir noch einen Hinweis",
17
- "getHint": "Einen Hinweis erhalten",
18
- "needHint": "Ich brauche einen Hinweis",
19
- "giveHintOpenChat": "Ich brauche einen Hinweis",
20
- "answerAgain": "Noch einmal antworten, um einen weiteren Hinweis zu bekommen!",
21
- "errorMessage": "Etwas ist schiefgelaufen! Versuch es erneut",
22
- "howCanIHelp": "Hi! Möchtest du Hilfe?",
23
- "showError": "Fehler anzeigen",
24
- "inputPlaceholder": "Tippe..."
25
- },
26
- "gifCelebrations": {
27
- "greatStart": "Toller Start!",
28
- "onTheWay": "Auf dem Weg!",
29
- "almostThere": "Fast geschafft"
30
- },
31
- "exampleSolution": {
32
- "exampleSolution": "Beispiellösung",
33
- "letMeThink": "Lass mich nachdenken...",
34
- "aha": "Aha!",
35
- "errorMessage": "Beim Erstellen einer Beispiellösung ist etwas schiefgelaufen"
36
- },
37
- "keyboard": {
38
- "length": "Länge",
39
- "area": "Fläche",
40
- "volume": "Volumen",
41
- "weight": "Gewicht",
42
- "time": "Zeit"
43
- },
44
- "voice": {
45
- "deleteRecording": "Aufnahme löschen?",
46
- "youWontBeAbleToRecover": "Du kannst die Datei nicht wiederherstellen, wenn sie einmal gelöscht ist.",
47
- "recordingDeleted": "Aufnahme gelöscht.",
48
- "delete": "Löschen",
49
- "cancel": "Abbrechen",
50
- "noMicrophoneAccess": "Kein Mikrofon-Zugriff.",
51
- "noMicrophoneAccessBySystem": "Mikrofonzugriff durch Systemeinstellungen verweigert.",
52
- "noMicrophoneFound": "Kein Mikrofon gefunden.",
53
- "uploadFailed": "Hochladen fehlgeschlagen. Bitte versuche es erneut.",
54
- "redoRecording": "Aufnahme erneut aufnehmen?",
55
- "redo": "Wiederholen",
56
- "thisWillRemoveRecording": "Dadurch wird die Aufnahme entfernt.",
57
- "transcriptions": "Transkriptionen",
58
- "attempt": "Versuch {{number}}",
59
- "transcriptNotAvailable": "Transkript nicht verfügbar"
60
- }
61
- }
@@ -1,61 +0,0 @@
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
- "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
- }
@@ -1,61 +0,0 @@
1
- {
2
- "locale": "en-GB",
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
- }
@@ -1,61 +0,0 @@
1
- {
2
- "locale": "en-SCT",
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
- }