@magmamath/students-features 1.4.6 → 1.5.0-rc.10

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 (412) hide show
  1. package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.js +1 -6
  2. package/dist/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.js.map +1 -1
  3. package/dist/commonjs/features/fluency/components/Fluency.js +6 -12
  4. package/dist/commonjs/features/fluency/components/Fluency.js.map +1 -1
  5. package/dist/commonjs/features/fluency/components/select-math-operator/SelectMathOperator.js +5 -13
  6. package/dist/commonjs/features/fluency/components/select-math-operator/SelectMathOperator.js.map +1 -1
  7. package/dist/commonjs/features/fluency/model/FluencyModel.js +0 -21
  8. package/dist/commonjs/features/fluency/model/FluencyModel.js.map +1 -1
  9. package/dist/commonjs/features/fluency/shared/fluency.constants.js +1 -6
  10. package/dist/commonjs/features/fluency/shared/fluency.constants.js.map +1 -1
  11. package/dist/commonjs/features/fluency/shared/fluency.helpers.js +1 -3
  12. package/dist/commonjs/features/fluency/shared/fluency.helpers.js.map +1 -1
  13. package/dist/commonjs/features/pmProgress/model/PmProgressModel.js +1 -7
  14. package/dist/commonjs/features/pmProgress/model/PmProgressModel.js.map +1 -1
  15. package/dist/commonjs/features/pmProgress/model/PmRecommendationsModel.js +4 -20
  16. package/dist/commonjs/features/pmProgress/model/PmRecommendationsModel.js.map +1 -1
  17. package/dist/commonjs/features/pmProgress/shared/pmProgress.helpers.js +1 -22
  18. package/dist/commonjs/features/pmProgress/shared/pmProgress.helpers.js.map +1 -1
  19. package/dist/commonjs/features/translation/constants.js +11 -0
  20. package/dist/commonjs/features/translation/constants.js.map +1 -0
  21. package/dist/commonjs/features/translation/helpers.js +60 -0
  22. package/dist/commonjs/features/translation/helpers.js.map +1 -0
  23. package/dist/commonjs/features/translation/index.js +105 -0
  24. package/dist/commonjs/features/translation/index.js.map +1 -0
  25. package/dist/commonjs/features/translation/model/TranslationModel.js +122 -0
  26. package/dist/commonjs/features/translation/model/TranslationModel.js.map +1 -0
  27. package/dist/commonjs/features/translation/model/TranslationPreprocessor.js +142 -0
  28. package/dist/commonjs/features/translation/model/TranslationPreprocessor.js.map +1 -0
  29. package/dist/commonjs/features/translation/model/TranslationService.js +112 -0
  30. package/dist/commonjs/features/translation/model/TranslationService.js.map +1 -0
  31. package/dist/commonjs/features/translation/preserve/wordsToPreserve.js +314 -0
  32. package/dist/commonjs/features/translation/preserve/wordsToPreserve.js.map +1 -0
  33. package/dist/commonjs/features/translation/providers/google/GoogleTranslationProvider.js +50 -0
  34. package/dist/commonjs/features/translation/providers/google/GoogleTranslationProvider.js.map +1 -0
  35. package/dist/commonjs/features/translation/providers/google/supportedLanguages.js +230 -0
  36. package/dist/commonjs/features/translation/providers/google/supportedLanguages.js.map +1 -0
  37. package/dist/commonjs/features/translation/providers/google.types.js +2 -0
  38. package/dist/commonjs/features/translation/providers/google.types.js.map +1 -0
  39. package/dist/commonjs/features/translation/providers/translation.interface.js +49 -0
  40. package/dist/commonjs/features/translation/providers/translation.interface.js.map +1 -0
  41. package/dist/commonjs/features/translation/types.js +2 -0
  42. package/dist/commonjs/features/translation/types.js.map +1 -0
  43. package/dist/commonjs/features/voice/index.js +15 -4
  44. package/dist/commonjs/features/voice/index.js.map +1 -1
  45. package/dist/commonjs/features/voice/playing/components/VoiceIcon.js +1 -1
  46. package/dist/commonjs/features/voice/playing/components/VoiceIcon.js.map +1 -1
  47. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptContent.js +44 -0
  48. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptContent.js.map +1 -0
  49. package/dist/commonjs/features/voice/playing/components/VoiceTranscription.js +107 -0
  50. package/dist/commonjs/features/voice/playing/components/VoiceTranscription.js.map +1 -0
  51. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.js +66 -0
  52. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.js.map +1 -0
  53. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.js +58 -0
  54. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.js.map +1 -0
  55. package/dist/commonjs/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.js → useDropdownAnimation.js} +8 -7
  56. package/dist/commonjs/features/voice/playing/hooks/useDropdownAnimation.js.map +1 -0
  57. package/dist/commonjs/features/voice/playing/hooks/useVoicePlayerLifecycle.js +53 -0
  58. package/dist/commonjs/features/voice/playing/hooks/useVoicePlayerLifecycle.js.map +1 -0
  59. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.js +111 -0
  60. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.js.map +1 -0
  61. package/dist/commonjs/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.js → Dropdown.model.js} +4 -4
  62. package/dist/commonjs/features/voice/playing/model/Dropdown.model.js.map +1 -0
  63. package/dist/commonjs/features/voice/playing/model/PlaybackController.js +192 -0
  64. package/dist/commonjs/features/voice/playing/model/PlaybackController.js.map +1 -0
  65. package/dist/commonjs/features/voice/playing/model/Player.model.js +50 -5
  66. package/dist/commonjs/features/voice/playing/model/Player.model.js.map +1 -1
  67. package/dist/commonjs/features/voice/playing/model/{VoiceTranscriptionsCollection.js → TranscriptionsCollection.js} +4 -4
  68. package/dist/commonjs/features/voice/playing/model/TranscriptionsCollection.js.map +1 -0
  69. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.js +83 -0
  70. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.js.map +1 -0
  71. package/dist/commonjs/features/voice/playing/model/Translation.model.js +62 -0
  72. package/dist/commonjs/features/voice/playing/model/Translation.model.js.map +1 -0
  73. package/dist/commonjs/features/voice/playing/model/VoiceFileDownloader.model.js +2 -2
  74. package/dist/commonjs/features/voice/playing/model/VoiceFileDownloader.model.js.map +1 -1
  75. package/dist/commonjs/features/voice/playing/model/VoicePlayer.model.js +58 -172
  76. package/dist/commonjs/features/voice/playing/model/VoicePlayer.model.js.map +1 -1
  77. package/dist/commonjs/features/voice/recording/components/VoiceRecordDivider.js +1 -1
  78. package/dist/commonjs/features/voice/recording/components/VoiceRecordDivider.js.map +1 -1
  79. package/dist/commonjs/features/voice/types.js +12 -1
  80. package/dist/commonjs/features/voice/types.js.map +1 -1
  81. package/dist/commonjs/index.js +12 -0
  82. package/dist/commonjs/index.js.map +1 -1
  83. package/dist/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.js +2 -7
  84. package/dist/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.js.map +1 -1
  85. package/dist/module/features/fluency/components/Fluency.js +8 -14
  86. package/dist/module/features/fluency/components/Fluency.js.map +1 -1
  87. package/dist/module/features/fluency/components/select-math-operator/SelectMathOperator.js +5 -13
  88. package/dist/module/features/fluency/components/select-math-operator/SelectMathOperator.js.map +1 -1
  89. package/dist/module/features/fluency/model/FluencyModel.js +1 -22
  90. package/dist/module/features/fluency/model/FluencyModel.js.map +1 -1
  91. package/dist/module/features/fluency/shared/fluency.constants.js +0 -5
  92. package/dist/module/features/fluency/shared/fluency.constants.js.map +1 -1
  93. package/dist/module/features/fluency/shared/fluency.helpers.js +0 -1
  94. package/dist/module/features/fluency/shared/fluency.helpers.js.map +1 -1
  95. package/dist/module/features/pmProgress/model/PmProgressModel.js +1 -7
  96. package/dist/module/features/pmProgress/model/PmProgressModel.js.map +1 -1
  97. package/dist/module/features/pmProgress/model/PmRecommendationsModel.js +4 -20
  98. package/dist/module/features/pmProgress/model/PmRecommendationsModel.js.map +1 -1
  99. package/dist/module/features/pmProgress/shared/pmProgress.helpers.js +0 -20
  100. package/dist/module/features/pmProgress/shared/pmProgress.helpers.js.map +1 -1
  101. package/dist/module/features/translation/constants.js +7 -0
  102. package/dist/module/features/translation/constants.js.map +1 -0
  103. package/dist/module/features/translation/helpers.js +53 -0
  104. package/dist/module/features/translation/helpers.js.map +1 -0
  105. package/dist/module/features/translation/index.js +12 -0
  106. package/dist/module/features/translation/index.js.map +1 -0
  107. package/dist/module/features/translation/model/TranslationModel.js +117 -0
  108. package/dist/module/features/translation/model/TranslationModel.js.map +1 -0
  109. package/dist/module/features/translation/model/TranslationPreprocessor.js +137 -0
  110. package/dist/module/features/translation/model/TranslationPreprocessor.js.map +1 -0
  111. package/dist/module/features/translation/model/TranslationService.js +107 -0
  112. package/dist/module/features/translation/model/TranslationService.js.map +1 -0
  113. package/dist/module/features/translation/preserve/wordsToPreserve.js +310 -0
  114. package/dist/module/features/translation/preserve/wordsToPreserve.js.map +1 -0
  115. package/dist/module/features/translation/providers/google/GoogleTranslationProvider.js +45 -0
  116. package/dist/module/features/translation/providers/google/GoogleTranslationProvider.js.map +1 -0
  117. package/dist/module/features/translation/providers/google/supportedLanguages.js +225 -0
  118. package/dist/module/features/translation/providers/google/supportedLanguages.js.map +1 -0
  119. package/dist/module/features/translation/providers/google.types.js +2 -0
  120. package/dist/module/features/translation/providers/google.types.js.map +1 -0
  121. package/dist/module/features/translation/providers/translation.interface.js +44 -0
  122. package/dist/module/features/translation/providers/translation.interface.js.map +1 -0
  123. package/dist/module/features/translation/types.js +2 -0
  124. package/dist/module/features/translation/types.js.map +1 -0
  125. package/dist/module/features/voice/index.js +2 -1
  126. package/dist/module/features/voice/index.js.map +1 -1
  127. package/dist/module/features/voice/playing/components/VoiceIcon.js +2 -2
  128. package/dist/module/features/voice/playing/components/VoiceIcon.js.map +1 -1
  129. package/dist/module/features/voice/playing/components/VoiceTranscriptContent.js +38 -0
  130. package/dist/module/features/voice/playing/components/VoiceTranscriptContent.js.map +1 -0
  131. package/dist/module/features/voice/playing/components/VoiceTranscription.js +101 -0
  132. package/dist/module/features/voice/playing/components/VoiceTranscription.js.map +1 -0
  133. package/dist/module/features/voice/playing/components/VoiceTranscriptionCollapsible.js +58 -0
  134. package/dist/module/features/voice/playing/components/VoiceTranscriptionCollapsible.js.map +1 -0
  135. package/dist/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.js +52 -0
  136. package/dist/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.js.map +1 -0
  137. package/dist/module/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.js → useDropdownAnimation.js} +6 -5
  138. package/dist/module/features/voice/playing/hooks/useDropdownAnimation.js.map +1 -0
  139. package/dist/module/features/voice/playing/hooks/useVoicePlayerLifecycle.js +48 -0
  140. package/dist/module/features/voice/playing/hooks/useVoicePlayerLifecycle.js.map +1 -0
  141. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionController.js +106 -0
  142. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionController.js.map +1 -0
  143. package/dist/module/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.js → Dropdown.model.js} +2 -2
  144. package/dist/module/features/voice/playing/model/Dropdown.model.js.map +1 -0
  145. package/dist/module/features/voice/playing/model/PlaybackController.js +187 -0
  146. package/dist/module/features/voice/playing/model/PlaybackController.js.map +1 -0
  147. package/dist/module/features/voice/playing/model/Player.model.js +51 -4
  148. package/dist/module/features/voice/playing/model/Player.model.js.map +1 -1
  149. package/dist/module/features/voice/playing/model/{VoiceTranscriptionsCollection.js → TranscriptionsCollection.js} +2 -2
  150. package/dist/module/features/voice/playing/model/TranscriptionsCollection.js.map +1 -0
  151. package/dist/module/features/voice/playing/model/TranscriptionsDownloader.model.js +78 -0
  152. package/dist/module/features/voice/playing/model/TranscriptionsDownloader.model.js.map +1 -0
  153. package/dist/module/features/voice/playing/model/Translation.model.js +57 -0
  154. package/dist/module/features/voice/playing/model/Translation.model.js.map +1 -0
  155. package/dist/module/features/voice/playing/model/VoiceFileDownloader.model.js +2 -2
  156. package/dist/module/features/voice/playing/model/VoiceFileDownloader.model.js.map +1 -1
  157. package/dist/module/features/voice/playing/model/VoicePlayer.model.js +60 -174
  158. package/dist/module/features/voice/playing/model/VoicePlayer.model.js.map +1 -1
  159. package/dist/module/features/voice/recording/components/VoiceRecordDivider.js +2 -2
  160. package/dist/module/features/voice/recording/components/VoiceRecordDivider.js.map +1 -1
  161. package/dist/module/features/voice/types.js +11 -0
  162. package/dist/module/features/voice/types.js.map +1 -1
  163. package/dist/module/index.js +1 -0
  164. package/dist/module/index.js.map +1 -1
  165. package/dist/typescript/commonjs/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.d.ts.map +1 -1
  166. package/dist/typescript/commonjs/features/fluency/components/Fluency.d.ts.map +1 -1
  167. package/dist/typescript/commonjs/features/fluency/components/select-math-operator/SelectMathOperator.d.ts.map +1 -1
  168. package/dist/typescript/commonjs/features/fluency/model/FluencyModel.d.ts +0 -3
  169. package/dist/typescript/commonjs/features/fluency/model/FluencyModel.d.ts.map +1 -1
  170. package/dist/typescript/commonjs/features/fluency/shared/fluency.constants.d.ts +0 -4
  171. package/dist/typescript/commonjs/features/fluency/shared/fluency.constants.d.ts.map +1 -1
  172. package/dist/typescript/commonjs/features/fluency/shared/fluency.helpers.d.ts +0 -1
  173. package/dist/typescript/commonjs/features/fluency/shared/fluency.helpers.d.ts.map +1 -1
  174. package/dist/typescript/commonjs/features/pmProgress/model/PmProgressModel.d.ts.map +1 -1
  175. package/dist/typescript/commonjs/features/pmProgress/model/PmRecommendationsModel.d.ts +38 -9
  176. package/dist/typescript/commonjs/features/pmProgress/model/PmRecommendationsModel.d.ts.map +1 -1
  177. package/dist/typescript/commonjs/features/pmProgress/shared/pmProgress.helpers.d.ts +0 -1
  178. package/dist/typescript/commonjs/features/pmProgress/shared/pmProgress.helpers.d.ts.map +1 -1
  179. package/dist/typescript/commonjs/features/translation/constants.d.ts +5 -0
  180. package/dist/typescript/commonjs/features/translation/constants.d.ts.map +1 -0
  181. package/dist/typescript/commonjs/features/translation/helpers.d.ts +9 -0
  182. package/dist/typescript/commonjs/features/translation/helpers.d.ts.map +1 -0
  183. package/dist/typescript/commonjs/features/translation/index.d.ts +12 -0
  184. package/dist/typescript/commonjs/features/translation/index.d.ts.map +1 -0
  185. package/dist/typescript/commonjs/features/translation/model/TranslationModel.d.ts +33 -0
  186. package/dist/typescript/commonjs/features/translation/model/TranslationModel.d.ts.map +1 -0
  187. package/dist/typescript/commonjs/features/translation/model/TranslationPreprocessor.d.ts +34 -0
  188. package/dist/typescript/commonjs/features/translation/model/TranslationPreprocessor.d.ts.map +1 -0
  189. package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts +40 -0
  190. package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts.map +1 -0
  191. package/dist/typescript/commonjs/features/translation/preserve/wordsToPreserve.d.ts +3 -0
  192. package/dist/typescript/commonjs/features/translation/preserve/wordsToPreserve.d.ts.map +1 -0
  193. package/dist/typescript/commonjs/features/translation/providers/google/GoogleTranslationProvider.d.ts +17 -0
  194. package/dist/typescript/commonjs/features/translation/providers/google/GoogleTranslationProvider.d.ts.map +1 -0
  195. package/dist/typescript/commonjs/features/translation/providers/google/supportedLanguages.d.ts +209 -0
  196. package/dist/typescript/commonjs/features/translation/providers/google/supportedLanguages.d.ts.map +1 -0
  197. package/dist/typescript/commonjs/features/translation/providers/google.types.d.ts +15 -0
  198. package/dist/typescript/commonjs/features/translation/providers/google.types.d.ts.map +1 -0
  199. package/dist/typescript/commonjs/features/translation/providers/translation.interface.d.ts +30 -0
  200. package/dist/typescript/commonjs/features/translation/providers/translation.interface.d.ts.map +1 -0
  201. package/dist/typescript/commonjs/features/translation/types.d.ts +27 -0
  202. package/dist/typescript/commonjs/features/translation/types.d.ts.map +1 -0
  203. package/dist/typescript/commonjs/features/voice/index.d.ts +3 -1
  204. package/dist/typescript/commonjs/features/voice/index.d.ts.map +1 -1
  205. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptContent.d.ts +8 -0
  206. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptContent.d.ts.map +1 -0
  207. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscription.d.ts +16 -0
  208. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscription.d.ts.map +1 -0
  209. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts +10 -0
  210. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts.map +1 -0
  211. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts +12 -0
  212. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts.map +1 -0
  213. package/dist/typescript/commonjs/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.d.ts → useDropdownAnimation.d.ts} +3 -3
  214. package/dist/typescript/commonjs/features/voice/playing/hooks/useDropdownAnimation.d.ts.map +1 -0
  215. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoicePlayerLifecycle.d.ts +15 -0
  216. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoicePlayerLifecycle.d.ts.map +1 -0
  217. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts +30 -0
  218. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts.map +1 -0
  219. package/dist/typescript/{module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts → commonjs/features/voice/playing/model/Dropdown.model.d.ts} +2 -2
  220. package/dist/typescript/commonjs/features/voice/playing/model/Dropdown.model.d.ts.map +1 -0
  221. package/dist/typescript/commonjs/features/voice/playing/model/PlaybackController.d.ts +28 -0
  222. package/dist/typescript/commonjs/features/voice/playing/model/PlaybackController.d.ts.map +1 -0
  223. package/dist/typescript/commonjs/features/voice/playing/model/Player.model.d.ts +4 -0
  224. package/dist/typescript/commonjs/features/voice/playing/model/Player.model.d.ts.map +1 -1
  225. package/dist/typescript/{module/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts → commonjs/features/voice/playing/model/TranscriptionsCollection.d.ts} +2 -2
  226. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsCollection.d.ts.map +1 -0
  227. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.d.ts +19 -0
  228. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.d.ts.map +1 -0
  229. package/dist/typescript/commonjs/features/voice/playing/model/Translation.model.d.ts +25 -0
  230. package/dist/typescript/commonjs/features/voice/playing/model/Translation.model.d.ts.map +1 -0
  231. package/dist/typescript/commonjs/features/voice/playing/model/VoiceFileDownloader.model.d.ts +2 -2
  232. package/dist/typescript/commonjs/features/voice/playing/model/VoiceFileDownloader.model.d.ts.map +1 -1
  233. package/dist/typescript/commonjs/features/voice/playing/model/VoicePlayer.model.d.ts +19 -18
  234. package/dist/typescript/commonjs/features/voice/playing/model/VoicePlayer.model.d.ts.map +1 -1
  235. package/dist/typescript/commonjs/features/voice/types.d.ts +14 -2
  236. package/dist/typescript/commonjs/features/voice/types.d.ts.map +1 -1
  237. package/dist/typescript/commonjs/index.d.ts +1 -0
  238. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  239. package/dist/typescript/module/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.d.ts.map +1 -1
  240. package/dist/typescript/module/features/fluency/components/Fluency.d.ts.map +1 -1
  241. package/dist/typescript/module/features/fluency/components/select-math-operator/SelectMathOperator.d.ts.map +1 -1
  242. package/dist/typescript/module/features/fluency/model/FluencyModel.d.ts +0 -3
  243. package/dist/typescript/module/features/fluency/model/FluencyModel.d.ts.map +1 -1
  244. package/dist/typescript/module/features/fluency/shared/fluency.constants.d.ts +0 -4
  245. package/dist/typescript/module/features/fluency/shared/fluency.constants.d.ts.map +1 -1
  246. package/dist/typescript/module/features/fluency/shared/fluency.helpers.d.ts +0 -1
  247. package/dist/typescript/module/features/fluency/shared/fluency.helpers.d.ts.map +1 -1
  248. package/dist/typescript/module/features/pmProgress/model/PmProgressModel.d.ts.map +1 -1
  249. package/dist/typescript/module/features/pmProgress/model/PmRecommendationsModel.d.ts +38 -9
  250. package/dist/typescript/module/features/pmProgress/model/PmRecommendationsModel.d.ts.map +1 -1
  251. package/dist/typescript/module/features/pmProgress/shared/pmProgress.helpers.d.ts +0 -1
  252. package/dist/typescript/module/features/pmProgress/shared/pmProgress.helpers.d.ts.map +1 -1
  253. package/dist/typescript/module/features/translation/constants.d.ts +5 -0
  254. package/dist/typescript/module/features/translation/constants.d.ts.map +1 -0
  255. package/dist/typescript/module/features/translation/helpers.d.ts +9 -0
  256. package/dist/typescript/module/features/translation/helpers.d.ts.map +1 -0
  257. package/dist/typescript/module/features/translation/index.d.ts +12 -0
  258. package/dist/typescript/module/features/translation/index.d.ts.map +1 -0
  259. package/dist/typescript/module/features/translation/model/TranslationModel.d.ts +33 -0
  260. package/dist/typescript/module/features/translation/model/TranslationModel.d.ts.map +1 -0
  261. package/dist/typescript/module/features/translation/model/TranslationPreprocessor.d.ts +34 -0
  262. package/dist/typescript/module/features/translation/model/TranslationPreprocessor.d.ts.map +1 -0
  263. package/dist/typescript/module/features/translation/model/TranslationService.d.ts +40 -0
  264. package/dist/typescript/module/features/translation/model/TranslationService.d.ts.map +1 -0
  265. package/dist/typescript/module/features/translation/preserve/wordsToPreserve.d.ts +3 -0
  266. package/dist/typescript/module/features/translation/preserve/wordsToPreserve.d.ts.map +1 -0
  267. package/dist/typescript/module/features/translation/providers/google/GoogleTranslationProvider.d.ts +17 -0
  268. package/dist/typescript/module/features/translation/providers/google/GoogleTranslationProvider.d.ts.map +1 -0
  269. package/dist/typescript/module/features/translation/providers/google/supportedLanguages.d.ts +209 -0
  270. package/dist/typescript/module/features/translation/providers/google/supportedLanguages.d.ts.map +1 -0
  271. package/dist/typescript/module/features/translation/providers/google.types.d.ts +15 -0
  272. package/dist/typescript/module/features/translation/providers/google.types.d.ts.map +1 -0
  273. package/dist/typescript/module/features/translation/providers/translation.interface.d.ts +30 -0
  274. package/dist/typescript/module/features/translation/providers/translation.interface.d.ts.map +1 -0
  275. package/dist/typescript/module/features/translation/types.d.ts +27 -0
  276. package/dist/typescript/module/features/translation/types.d.ts.map +1 -0
  277. package/dist/typescript/module/features/voice/index.d.ts +3 -1
  278. package/dist/typescript/module/features/voice/index.d.ts.map +1 -1
  279. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptContent.d.ts +8 -0
  280. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptContent.d.ts.map +1 -0
  281. package/dist/typescript/module/features/voice/playing/components/VoiceTranscription.d.ts +16 -0
  282. package/dist/typescript/module/features/voice/playing/components/VoiceTranscription.d.ts.map +1 -0
  283. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts +10 -0
  284. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts.map +1 -0
  285. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts +12 -0
  286. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts.map +1 -0
  287. package/dist/typescript/module/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.d.ts → useDropdownAnimation.d.ts} +3 -3
  288. package/dist/typescript/module/features/voice/playing/hooks/useDropdownAnimation.d.ts.map +1 -0
  289. package/dist/typescript/module/features/voice/playing/hooks/useVoicePlayerLifecycle.d.ts +15 -0
  290. package/dist/typescript/module/features/voice/playing/hooks/useVoicePlayerLifecycle.d.ts.map +1 -0
  291. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts +30 -0
  292. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts.map +1 -0
  293. package/dist/typescript/{commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts → module/features/voice/playing/model/Dropdown.model.d.ts} +2 -2
  294. package/dist/typescript/module/features/voice/playing/model/Dropdown.model.d.ts.map +1 -0
  295. package/dist/typescript/module/features/voice/playing/model/PlaybackController.d.ts +28 -0
  296. package/dist/typescript/module/features/voice/playing/model/PlaybackController.d.ts.map +1 -0
  297. package/dist/typescript/module/features/voice/playing/model/Player.model.d.ts +4 -0
  298. package/dist/typescript/module/features/voice/playing/model/Player.model.d.ts.map +1 -1
  299. package/dist/typescript/{commonjs/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts → module/features/voice/playing/model/TranscriptionsCollection.d.ts} +2 -2
  300. package/dist/typescript/module/features/voice/playing/model/TranscriptionsCollection.d.ts.map +1 -0
  301. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloader.model.d.ts +19 -0
  302. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloader.model.d.ts.map +1 -0
  303. package/dist/typescript/module/features/voice/playing/model/Translation.model.d.ts +25 -0
  304. package/dist/typescript/module/features/voice/playing/model/Translation.model.d.ts.map +1 -0
  305. package/dist/typescript/module/features/voice/playing/model/VoiceFileDownloader.model.d.ts +2 -2
  306. package/dist/typescript/module/features/voice/playing/model/VoiceFileDownloader.model.d.ts.map +1 -1
  307. package/dist/typescript/module/features/voice/playing/model/VoicePlayer.model.d.ts +19 -18
  308. package/dist/typescript/module/features/voice/playing/model/VoicePlayer.model.d.ts.map +1 -1
  309. package/dist/typescript/module/features/voice/types.d.ts +14 -2
  310. package/dist/typescript/module/features/voice/types.d.ts.map +1 -1
  311. package/dist/typescript/module/index.d.ts +1 -0
  312. package/dist/typescript/module/index.d.ts.map +1 -1
  313. package/package.json +37 -10
  314. package/src/features/endOfAssignment/components/CorrectAnswer/CorrectAnswer.tsx +2 -9
  315. package/src/features/fluency/components/Fluency.tsx +9 -17
  316. package/src/features/fluency/components/select-math-operator/SelectMathOperator.tsx +5 -13
  317. package/src/features/fluency/model/FluencyModel.ts +1 -25
  318. package/src/features/fluency/shared/fluency.constants.ts +0 -5
  319. package/src/features/fluency/shared/fluency.helpers.ts +0 -3
  320. package/src/features/pmProgress/model/PmProgressModel.ts +1 -4
  321. package/src/features/pmProgress/model/PmRecommendationsModel.ts +6 -22
  322. package/src/features/pmProgress/shared/pmProgress.helpers.ts +0 -33
  323. package/src/features/translation/constants.ts +4 -0
  324. package/src/features/translation/helpers.ts +63 -0
  325. package/src/features/translation/index.ts +30 -0
  326. package/src/features/translation/model/TranslationModel.ts +174 -0
  327. package/src/features/translation/model/TranslationPreprocessor.ts +171 -0
  328. package/src/features/translation/model/TranslationService.ts +148 -0
  329. package/src/features/translation/preserve/wordsToPreserve.ts +87 -0
  330. package/src/features/translation/providers/google/GoogleTranslationProvider.ts +50 -0
  331. package/src/features/translation/providers/google/supportedLanguages.ts +229 -0
  332. package/src/features/translation/providers/google.types.ts +16 -0
  333. package/src/features/translation/providers/translation.interface.ts +63 -0
  334. package/src/features/translation/types.ts +30 -0
  335. package/src/features/voice/index.ts +3 -1
  336. package/src/features/voice/playing/components/VoiceIcon.tsx +2 -2
  337. package/src/features/voice/playing/components/VoiceTranscriptContent.tsx +44 -0
  338. package/src/features/voice/playing/components/VoiceTranscription.tsx +117 -0
  339. package/src/features/voice/playing/components/VoiceTranscriptionCollapsible.tsx +59 -0
  340. package/src/features/voice/playing/components/VoiceTranscriptionHeaderActions.tsx +61 -0
  341. package/src/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.ts → useDropdownAnimation.ts} +5 -5
  342. package/src/features/voice/playing/hooks/useVoicePlayerLifecycle.ts +64 -0
  343. package/src/features/voice/playing/hooks/useVoiceTranscriptionController.ts +148 -0
  344. package/src/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.ts → Dropdown.model.ts} +2 -2
  345. package/src/features/voice/playing/model/PlaybackController.ts +221 -0
  346. package/src/features/voice/playing/model/Player.model.ts +52 -4
  347. package/src/features/voice/playing/model/{VoiceTranscriptionsCollection.ts → TranscriptionsCollection.ts} +1 -1
  348. package/src/features/voice/playing/model/TranscriptionsDownloader.model.ts +88 -0
  349. package/src/features/voice/playing/model/Translation.model.ts +75 -0
  350. package/src/features/voice/playing/model/VoiceFileDownloader.model.ts +2 -2
  351. package/src/features/voice/playing/model/VoicePlayer.model.ts +68 -192
  352. package/src/features/voice/recording/components/VoiceRecordDivider.tsx +2 -2
  353. package/src/features/voice/types.ts +21 -1
  354. package/src/i18n/.generated/schema.json +3 -7
  355. package/src/index.ts +1 -0
  356. package/dist/commonjs/features/fluency/components/FluencyStatusOverlay.js +0 -101
  357. package/dist/commonjs/features/fluency/components/FluencyStatusOverlay.js.map +0 -1
  358. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.js +0 -245
  359. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.js.map +0 -1
  360. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js +0 -109
  361. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js.map +0 -1
  362. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.js.map +0 -1
  363. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js +0 -34
  364. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js.map +0 -1
  365. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.js +0 -66
  366. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.js.map +0 -1
  367. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionsCollection.js.map +0 -1
  368. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.js.map +0 -1
  369. package/dist/module/features/fluency/components/FluencyStatusOverlay.js +0 -95
  370. package/dist/module/features/fluency/components/FluencyStatusOverlay.js.map +0 -1
  371. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdown.js +0 -238
  372. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdown.js.map +0 -1
  373. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js +0 -103
  374. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js.map +0 -1
  375. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.js.map +0 -1
  376. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js +0 -29
  377. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js.map +0 -1
  378. package/dist/module/features/voice/playing/model/TranscriptionsDownloaderModel.js +0 -61
  379. package/dist/module/features/voice/playing/model/TranscriptionsDownloaderModel.js.map +0 -1
  380. package/dist/module/features/voice/playing/model/VoiceTranscriptionsCollection.js.map +0 -1
  381. package/dist/module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.js.map +0 -1
  382. package/dist/typescript/commonjs/features/fluency/components/FluencyStatusOverlay.d.ts +0 -8
  383. package/dist/typescript/commonjs/features/fluency/components/FluencyStatusOverlay.d.ts.map +0 -1
  384. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts +0 -16
  385. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts.map +0 -1
  386. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts +0 -12
  387. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts.map +0 -1
  388. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts.map +0 -1
  389. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts +0 -11
  390. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts.map +0 -1
  391. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts +0 -15
  392. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts.map +0 -1
  393. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts.map +0 -1
  394. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts.map +0 -1
  395. package/dist/typescript/module/features/fluency/components/FluencyStatusOverlay.d.ts +0 -8
  396. package/dist/typescript/module/features/fluency/components/FluencyStatusOverlay.d.ts.map +0 -1
  397. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts +0 -16
  398. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts.map +0 -1
  399. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts +0 -12
  400. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts.map +0 -1
  401. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts.map +0 -1
  402. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts +0 -11
  403. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts.map +0 -1
  404. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts +0 -15
  405. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts.map +0 -1
  406. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts.map +0 -1
  407. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts.map +0 -1
  408. package/src/features/fluency/components/FluencyStatusOverlay.tsx +0 -101
  409. package/src/features/voice/playing/components/VoiceTranscriptionsDropdown.tsx +0 -296
  410. package/src/features/voice/playing/components/VoiceTranscriptionsDropdownItem.tsx +0 -128
  411. package/src/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.ts +0 -40
  412. package/src/features/voice/playing/model/TranscriptionsDownloaderModel.ts +0 -80
@@ -0,0 +1,171 @@
1
+ import { LanguageGlossary } from '../providers/translation.interface'
2
+ import { maskSegment, replaceMappedTokens } from '../helpers'
3
+ import { Replacement } from '../types'
4
+
5
+ const KATEX_REGEX = /\$(.+?)\$/g
6
+ const NEWLINE_REGEX = /\n/g
7
+ const QUOTE_REGEX = /\\(['"])/g
8
+ const DOLLAR_REGEX = /\\\$/gm
9
+ const COMMA_REGEX = /,/gm
10
+ const DOT_REGEX = /\./gm
11
+
12
+ const wrapNoTranslate = (content: string) => `<span translate="no">${content}</span>`
13
+
14
+ const KATEX_PLACEHOLDER = wrapNoTranslate('{{@}}')
15
+ const NEWLINE__PLACEHOLDER = wrapNoTranslate('{{#}}')
16
+ const QUOTE_PLACEHOLDER = wrapNoTranslate('{{""}}')
17
+ const DOLLAR_PLACEHOLDER = wrapNoTranslate('{{!}}')
18
+ const COMMA_PLACEHOLDER = wrapNoTranslate('{{,}}')
19
+ const DOT_PLACEHOLDER = wrapNoTranslate('{{.}}')
20
+
21
+ const defaultOrderedReplacersMap = [
22
+ [DOLLAR_REGEX, DOLLAR_PLACEHOLDER],
23
+ [KATEX_REGEX, KATEX_PLACEHOLDER],
24
+ [NEWLINE_REGEX, NEWLINE__PLACEHOLDER],
25
+ [QUOTE_REGEX, QUOTE_PLACEHOLDER],
26
+ [COMMA_REGEX, COMMA_PLACEHOLDER],
27
+ [DOT_REGEX, DOT_PLACEHOLDER],
28
+ ] as const
29
+
30
+ type SetupPreservableProps = {
31
+ glossaryToPreserve: LanguageGlossary
32
+ preserveWordsReplacers: [RegExp, string][]
33
+ }
34
+
35
+ export class TranslationKatexPreprocessor {
36
+ private static plaintextConverter: (text: string) => string = (text) => text
37
+
38
+ public static setPlaintextConverter(converter: (text: string) => string) {
39
+ this.plaintextConverter = converter
40
+ }
41
+
42
+ public static shouldSkipTranslation(text: string | string[] = '') {
43
+ if (Array.isArray(text)) {
44
+ return text.every(
45
+ (t) => this.isMathExpressionOnly(t) || this.isSingleLetter(t) || this.isMathSymbolsOnly(t),
46
+ )
47
+ }
48
+
49
+ return (
50
+ this.isMathExpressionOnly(text) || this.isSingleLetter(text) || this.isMathSymbolsOnly(text)
51
+ )
52
+ }
53
+
54
+ public static isMathExpressionOnly(text: string) {
55
+ return /^[\d\s+\-*/^=().\\><%!|]+$/.test(text.trim())
56
+ }
57
+
58
+ public static isSingleLetter(text: string) {
59
+ return /^[a-zA-Z]$/.test(text)
60
+ }
61
+
62
+ public static isMathSymbolsOnly(text: string) {
63
+ const plainText = this.plaintextConverter(text)
64
+ const cleanedUp = plainText.replace(/(\\\\|\\|\$|\−|\+|\=|\*|kr|pln|€|£|x|y|\{|\}|\÷)/gi, '')
65
+ const mathOnlyRegex = /^(?=.*\d)[0-9+\-×÷*/^().\s]+$/u
66
+ return cleanedUp.length > 0 && mathOnlyRegex.test(cleanedUp)
67
+ }
68
+
69
+ private globalTargetLanguage: string | null = null
70
+ private preserveWordsMap: LanguageGlossary = {}
71
+ private preserveWordsReplacers: [RegExp, string][] = []
72
+
73
+ private normalizePlaceholderSpacing(text: string) {
74
+ return text
75
+ .replace(/\s+(<span[^>]*translate="no"[^>]*>)/g, '$1')
76
+ .replace(/(<\/span>)\s+/g, '$1')
77
+ }
78
+
79
+ public sanitize(text: string): { sanitized: string; replacements: Replacement[] } {
80
+ const language = this.globalTargetLanguage ?? ''
81
+ const replacements: Replacement[] = []
82
+ let sanitizedText = text
83
+
84
+ defaultOrderedReplacersMap.forEach(([regex, placeholder]) => {
85
+ sanitizedText = maskSegment({
86
+ text: sanitizedText,
87
+ regex,
88
+ placeholder,
89
+ replacements,
90
+ })
91
+ })
92
+
93
+ this.preserveWordsReplacers.forEach(([regex, placeholder]) => {
94
+ const preserveWordsMapTarget = this.preserveWordsMap[language]
95
+
96
+ sanitizedText = maskSegment({
97
+ text: sanitizedText,
98
+ regex,
99
+ placeholder,
100
+ replacements,
101
+ shouldSkip: (match) =>
102
+ this.skipCustomReplacerSanitizeWithoutGlossary(match, preserveWordsMapTarget),
103
+ })
104
+ })
105
+
106
+ return { sanitized: sanitizedText, replacements }
107
+ }
108
+
109
+ public restore(text: string, replacements: Replacement[]) {
110
+ let restored = this.normalizePlaceholderSpacing(text)
111
+ replacements.forEach(({ placeholder, original, leftPad, rightPad }) => {
112
+ const wrapped = `${leftPad ? ' ' : ''}${original}${rightPad ? ' ' : ''}`
113
+ restored = restored.replace(placeholder, wrapped)
114
+ })
115
+
116
+ return this.applyPreserved(restored)
117
+ }
118
+
119
+ public sanitizeBatch(texts: string[]): { sanitized: string[]; replacements: Replacement[][] } {
120
+ const sanitized: string[] = []
121
+ const replacements: Replacement[][] = []
122
+
123
+ texts.forEach((t) => {
124
+ const { sanitized: s, replacements: r } = this.sanitize(t)
125
+ sanitized.push(s)
126
+ replacements.push(r)
127
+ })
128
+
129
+ return { sanitized, replacements }
130
+ }
131
+
132
+ public restoreBatch(texts: string[], replacementsArray: Replacement[][]) {
133
+ return texts.map((t, i) => {
134
+ const restored = this.restore(t, replacementsArray[i])
135
+ return this.applyPreserved(restored)
136
+ })
137
+ }
138
+
139
+ // Glossaries apply after translation response and do not remove words from payload.
140
+ // This replaces words from the string before sending request to API to completely avoid
141
+ // translating it. We use it to avoid "context localization" e.g. Google API changes numbers
142
+ // when units are passed and target language is from a different region. We must preserve
143
+ // words like "miles" and the exact number in this case.
144
+ public setupPreservable({ glossaryToPreserve, preserveWordsReplacers }: SetupPreservableProps) {
145
+ this.preserveWordsMap = glossaryToPreserve
146
+ this.preserveWordsReplacers = preserveWordsReplacers
147
+ }
148
+
149
+ public setupTarget(language: string) {
150
+ this.globalTargetLanguage = language
151
+ }
152
+
153
+ private skipCustomReplacerSanitizeWithoutGlossary(
154
+ match: string,
155
+ preserveWordsMapTarget?: Record<string, string>,
156
+ ) {
157
+ if (!preserveWordsMapTarget) return true
158
+
159
+ const normalized = match.toLowerCase()
160
+ const glossaryKeys = Object.keys(preserveWordsMapTarget).map((key) => key.toLowerCase())
161
+
162
+ return !glossaryKeys.includes(normalized)
163
+ }
164
+
165
+ private applyPreserved(restored: string) {
166
+ const language = this.globalTargetLanguage ?? ''
167
+ const preservedMap = this.preserveWordsMap[language]
168
+
169
+ return preservedMap ? replaceMappedTokens(restored, preservedMap) : restored
170
+ }
171
+ }
@@ -0,0 +1,148 @@
1
+ import { Store } from 'effector'
2
+ import { TranslationKatexPreprocessor } from './TranslationPreprocessor'
3
+ import { LanguageGlossary, TranslationProvider } from '../providers/translation.interface'
4
+
5
+ type TranslationServiceProps = {
6
+ providers: TranslationProvider[]
7
+ preserve?: {
8
+ map: LanguageGlossary
9
+ replacers: [RegExp, string][]
10
+ }
11
+ onError?: () => void
12
+ }
13
+
14
+ export type TranslateConfigProps = {
15
+ targetLang?: string
16
+ sourceLang?: string
17
+ cacheKeySuffix?: string
18
+ cacheKey?: string
19
+ }
20
+
21
+ export class TranslationService {
22
+ private readonly preprocessor = new TranslationKatexPreprocessor()
23
+ private readonly cache = new Map<string, string | string[]>()
24
+ private readonly providers: TranslationProvider[] = []
25
+ private readonly onError
26
+
27
+ private globalTargetLanguage: string | null = null
28
+ private sourceLanguage: string | null = null
29
+ private customCacheKeyFn: ((text: string | string[], target: string) => string) | null = null
30
+
31
+ constructor({ providers, preserve, onError }: TranslationServiceProps) {
32
+ this.providers = providers
33
+ this.onError = onError
34
+
35
+ if (preserve) {
36
+ this.preprocessor.setupPreservable({
37
+ glossaryToPreserve: preserve.map,
38
+ preserveWordsReplacers: preserve.replacers,
39
+ })
40
+ }
41
+ }
42
+
43
+ private getTargetLanguage(targetLang?: string) {
44
+ const target = targetLang || this.globalTargetLanguage
45
+ if (!target) {
46
+ throw new Error(
47
+ 'Target language is missing, either provide in arguments or use .bindTargetLanguage()',
48
+ )
49
+ }
50
+ return target
51
+ }
52
+
53
+ private getProvider(target: string) {
54
+ const provider = this.providers.find((svc) => svc.isTargetSupported(target))
55
+ if (!provider) throw new Error(`This target language: "${target}" is not supported.`)
56
+ return provider
57
+ }
58
+
59
+ private createCacheKey(text: string | string[], target: string, suffix?: string) {
60
+ let baseKey: string
61
+
62
+ if (this.customCacheKeyFn) {
63
+ baseKey = this.customCacheKeyFn(text, target)
64
+ } else {
65
+ baseKey = Array.isArray(text) ? `${JSON.stringify(text)}::${target}` : `${text}::${target}`
66
+ }
67
+
68
+ return suffix ? `${baseKey}${suffix}` : baseKey
69
+ }
70
+
71
+ public translate = async <T extends string | string[]>(
72
+ text: T = '' as T,
73
+ config?: TranslateConfigProps,
74
+ ): Promise<T> => {
75
+ const isArrayInput = Array.isArray(text)
76
+ const target = this.getTargetLanguage(config?.targetLang) ?? ''
77
+
78
+ if (!text.length || TranslationKatexPreprocessor.shouldSkipTranslation(text)) {
79
+ const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix)
80
+ if (this.cache.has(key)) return this.cache.get(key) as T
81
+
82
+ return text
83
+ }
84
+
85
+ const source = config?.sourceLang ?? this.sourceLanguage ?? undefined
86
+ const provider = this.getProvider(target)
87
+ const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix)
88
+
89
+ if (this.cache.has(key)) return this.cache.get(key) as T
90
+
91
+ let translated: string | string[]
92
+
93
+ if (isArrayInput) {
94
+ const { sanitized, replacements } = this.preprocessor.sanitizeBatch(text)
95
+ const response = await provider.requestBatch(sanitized, target, source)
96
+ translated = this.preprocessor.restoreBatch(response, replacements)
97
+ } else {
98
+ const { sanitized, replacements } = this.preprocessor.sanitize(text)
99
+ const response = await provider.request(sanitized, target, source)
100
+ translated = this.preprocessor.restore(response, replacements)
101
+ }
102
+
103
+ this.cache.set(key, translated)
104
+
105
+ return translated as T
106
+ }
107
+
108
+ public bindTargetLanguage<T extends string>(
109
+ store: Store<T>,
110
+ callback?: (value: T) => string,
111
+ ): this {
112
+ store.watch((t) => {
113
+ const value = callback ? callback(t) : t
114
+ this.globalTargetLanguage = value
115
+ this.preprocessor.setupTarget(value)
116
+ })
117
+
118
+ return this
119
+ }
120
+
121
+ public bindSourceLanguage<T extends string>(store: Store<T>): this {
122
+ store.watch((value) => {
123
+ this.sourceLanguage = value
124
+ })
125
+
126
+ return this
127
+ }
128
+
129
+ public bindCustomCacheKey<T extends string>(
130
+ store: Store<T>,
131
+ callback: (value: T, input: { text: string | string[]; target: string }) => string,
132
+ ): this {
133
+ store.watch((t) => {
134
+ this.customCacheKeyFn = (text: string | string[], target: string) =>
135
+ callback(t, { text, target })
136
+ })
137
+
138
+ return this
139
+ }
140
+
141
+ public getCached<T extends string | string[]>(key: string): T | undefined {
142
+ return this.cache.get(key) as T | undefined
143
+ }
144
+
145
+ public reset() {
146
+ this.cache.clear()
147
+ }
148
+ }
@@ -0,0 +1,87 @@
1
+ export const wordsToPreserve: Record<string, Record<string, string>> = {
2
+ es: { mile: 'milla', miles: 'millas' },
3
+ hy: { mile: 'մղոն', miles: 'մղոններ' },
4
+ fr: { mile: 'mille', miles: 'milles' },
5
+ ru: { mile: 'миля', miles: 'мили' },
6
+ ar: { mile: 'ميل', miles: 'أميال' },
7
+ is: { mile: 'míla', miles: 'mílur' },
8
+ ja: { mile: 'マイル', miles: 'マイル' },
9
+ 'zh-Hans': { mile: '英里', miles: '英里' },
10
+ af: { mile: 'myl', miles: 'myls' },
11
+ ko: { mile: '마일', miles: '마일' },
12
+ de: { mile: 'Meile', miles: 'Meilen' },
13
+ zu: { mile: 'ileyili', miles: 'amayela' },
14
+ 'zh-Hant': { mile: '英里', miles: '英里' },
15
+ it: { mile: 'miglio', miles: 'miglia' },
16
+ ht: { mile: 'miy', miles: 'miy' },
17
+ hi: { mile: 'मील', miles: 'मील' },
18
+ pt: { mile: 'milha', miles: 'milhas' },
19
+ sq: { mile: 'milje', miles: 'milje' },
20
+ el: { mile: 'μίλι', miles: 'μίλια' },
21
+ pl: { mile: 'mila', miles: 'mile' },
22
+ te: { mile: 'మైలు', miles: 'మైలు‌లు' },
23
+ am: { mile: 'ማይል', miles: 'ማይሎች' },
24
+ ta: { mile: 'மைல்', miles: 'மைல்கள்' },
25
+ vi: { mile: 'dặm', miles: 'dặm' },
26
+ uk: { mile: 'миля', miles: 'милі' },
27
+ haw: { mile: 'maila', miles: 'maila' },
28
+ sv: { mile: 'mile', miles: 'miles' },
29
+ bn: { mile: 'মাইল', miles: 'মাইল' },
30
+ tl: { mile: 'milya', miles: 'milya' },
31
+ ga: { mile: 'míle', miles: 'míleanna' },
32
+ nl: { mile: 'mijl', miles: 'mijlen' },
33
+ ur: { mile: 'میل', miles: 'میل' },
34
+ ee: { mile: 'maili', miles: 'maili' },
35
+ en: { mile: 'mile', miles: 'miles' },
36
+ az: { mile: 'mil', miles: 'mil' },
37
+ gu: { mile: 'માઈલ', miles: 'માઈલ્સ' },
38
+ ml: { mile: 'മൈൽ', miles: 'മൈലുകൾ' },
39
+ pa: { mile: 'ਮਾਈਲ', miles: 'ਮਾਈਲਾਂ' },
40
+ as: { mile: 'মাইল', miles: 'মাইল' },
41
+ bm: { mile: 'maili', miles: 'maili' },
42
+ he: { mile: 'מייל', miles: 'מיילים' },
43
+ fa: { mile: 'مایل', miles: 'مایل‌ها' },
44
+ fi: { mile: 'maili', miles: 'mailia' },
45
+ tr: { mile: 'mil', miles: 'mil' },
46
+ da: { mile: 'mil', miles: 'mil' },
47
+ bg: { mile: 'миля', miles: 'мили' },
48
+ xh: { mile: 'imayile', miles: 'iimayile' },
49
+ yi: { mile: 'מייל', miles: 'מיילן' },
50
+ ps: { mile: 'مایل', miles: 'مایلونه' },
51
+ mr: { mile: 'मैल', miles: 'मैले' },
52
+ eu: { mile: 'mila', miles: 'milak' },
53
+ bs: { mile: 'milja', miles: 'milje' },
54
+ cs: { mile: 'míle', miles: 'míle' },
55
+ yo: { mile: 'maili', miles: 'maili' },
56
+ ak: { mile: 'maili', miles: 'maili' },
57
+ ro: { mile: 'milă', miles: 'mile' },
58
+ mn: { mile: 'миль', miles: 'миль' },
59
+ bho: { mile: 'माइल', miles: 'माइल्स' },
60
+ ka: { mile: 'მილი', miles: 'მილი' },
61
+ ca: { mile: 'milla', miles: 'milles' },
62
+ be: { mile: 'міля', miles: 'мілі' },
63
+ sw: { mile: 'maili', miles: 'maili' },
64
+ eo: { mile: 'mejlo', miles: 'mejloj' },
65
+ th: { mile: 'ไมล์', miles: 'ไมล์' },
66
+ ay: { mile: 'maili', miles: 'maili' },
67
+ doi: { mile: 'माइल', miles: 'माइल्स' },
68
+ hr: { mile: 'milja', miles: 'milje' },
69
+ sm: { mile: 'maila', miles: 'maila' },
70
+ kn: { mile: 'ಮೈಲು', miles: 'ಮೈಲುಗಳು' },
71
+ et: { mile: 'miil', miles: 'miilid' },
72
+ ceb: { mile: 'milya', miles: 'milya' },
73
+ ig: { mile: 'maịlụ', miles: 'maịlụ' },
74
+ ne: { mile: 'माइल', miles: 'माइलहरू' },
75
+ uz: { mile: 'mil', miles: 'mil' },
76
+ cy: { mile: 'filltir', miles: 'mili' },
77
+ }
78
+
79
+ const MILE_REGEX = /mile/gm
80
+ const MILE_PLACEHOLDER = '__!{21_37_70}!__'
81
+ const MILES_REGEX = /miles/gm
82
+ const MILES_PLACEHOLDER = '__!{21_37_69}!__'
83
+
84
+ export const preservedWordsReplacers: [RegExp, string][] = [
85
+ [MILES_REGEX, MILES_PLACEHOLDER],
86
+ [MILE_REGEX, MILE_PLACEHOLDER],
87
+ ]
@@ -0,0 +1,50 @@
1
+ import { createEffect, Effect } from 'effector'
2
+ import { LanguageGlossary, TranslationProvider } from '../translation.interface'
3
+ import { GoogleTranslateLanguage, resolveGoogleLanguageCode } from './supportedLanguages'
4
+ import { GoogleTranslateProps, GoogleTranslateResponse } from '../google.types'
5
+ import { decodeHtmlEntities } from '../../helpers'
6
+
7
+ type GoogleTranslationProviderProps = {
8
+ api: {
9
+ translateRequest: (payload: GoogleTranslateProps) => Promise<GoogleTranslateResponse>
10
+ }
11
+ glossaries?: LanguageGlossary
12
+ }
13
+
14
+ export class GoogleTranslationProvider extends TranslationProvider {
15
+ private readonly getTranslationFx: Effect<GoogleTranslateProps, GoogleTranslateResponse>
16
+
17
+ constructor({ api, glossaries }: GoogleTranslationProviderProps) {
18
+ super({ supportedLanguages: Object.values(GoogleTranslateLanguage), glossaries })
19
+ this.getTranslationFx = createEffect(api.translateRequest)
20
+ }
21
+
22
+ public resolveLanguage(language: string): string | null {
23
+ return resolveGoogleLanguageCode(language)
24
+ }
25
+
26
+ public async request(text: string, targetLanguage: string, sourceLanguage?: string) {
27
+ const resolvedTarget = this.resolveLanguage(targetLanguage) ?? targetLanguage
28
+ const resolvedSource = sourceLanguage ? this.resolveLanguage(sourceLanguage) ?? undefined : undefined
29
+ const response = await this.getTranslationFx({
30
+ text: [text],
31
+ targetLanguage: resolvedTarget,
32
+ sourceLanguage: resolvedSource,
33
+ })
34
+ const translated = response.data.translations[0]?.translatedText ?? ''
35
+ return this.applyGlossary(decodeHtmlEntities(translated), resolvedTarget)
36
+ }
37
+
38
+ public async requestBatch(text: string[], targetLanguage: string, sourceLanguage?: string) {
39
+ const resolvedTarget = this.resolveLanguage(targetLanguage) ?? targetLanguage
40
+ const resolvedSource = sourceLanguage ? this.resolveLanguage(sourceLanguage) ?? undefined : undefined
41
+ const response = await this.getTranslationFx({
42
+ text,
43
+ targetLanguage: resolvedTarget,
44
+ sourceLanguage: resolvedSource,
45
+ })
46
+ return response.data.translations.map(({ translatedText }) =>
47
+ this.applyGlossary(decodeHtmlEntities(translatedText), resolvedTarget),
48
+ )
49
+ }
50
+ }
@@ -0,0 +1,229 @@
1
+ const SUPPORTED_CODES = new Set<string>()
2
+ const NAME_TO_CODE: Record<string, string> = {}
3
+
4
+ const normalizeLanguageName = (language: string): string =>
5
+ language
6
+ .trim()
7
+ .toUpperCase()
8
+ .replace(/[\s()-]+/g, '_')
9
+
10
+ /**
11
+ * Resolves an arbitrary language input (ISO code, locale, or English name) to the
12
+ * Google Translate ISO code. Returns null when the language is not supported.
13
+ *
14
+ * Examples:
15
+ * "en" → "en"
16
+ * "en-SE" → "en" (base fallback)
17
+ * "zh-CN" → "zh-CN" (exact match)
18
+ * "Spanish" → "es" (name lookup)
19
+ * "Chinese Simplified" → "zh-CN"
20
+ */
21
+ export const resolveGoogleLanguageCode = (language?: string | null): string | null => {
22
+ if (!language) return null
23
+ if (SUPPORTED_CODES.has(language)) return language
24
+ const base = language.split('-')[0]
25
+ if (base !== language && SUPPORTED_CODES.has(base)) return base
26
+ return NAME_TO_CODE[normalizeLanguageName(language)] ?? null
27
+ }
28
+
29
+ export const GoogleTranslateLanguage = {
30
+ ABKHAZ: 'ab',
31
+ ACEHNESE: 'ace',
32
+ ACHOLI: 'ach',
33
+ AFRIKAANS: 'af',
34
+ ALBANIAN: 'sq',
35
+ ALUR: 'alz',
36
+ AMHARIC: 'am',
37
+ ARABIC: 'ar',
38
+ ARMENIAN: 'hy',
39
+ ASSAMESE: 'as',
40
+ AWADHI: 'awa',
41
+ AYMARA: 'ay',
42
+ AZERBAIJANI: 'az',
43
+ BALINESE: 'ban',
44
+ BAMBARA: 'bm',
45
+ BASHKIR: 'ba',
46
+ BASQUE: 'eu',
47
+ BATAK_KARO: 'btx',
48
+ BATAK_SIMALUNGUN: 'bts',
49
+ BATAK_TOBA: 'bbc',
50
+ BELARUSIAN: 'be',
51
+ BEMBA: 'bem',
52
+ BENGALI: 'bn',
53
+ BETAWI: 'bew',
54
+ BHOJPURI: 'bho',
55
+ BIKOL: 'bik',
56
+ BOSNIAN: 'bs',
57
+ BRETON: 'br',
58
+ BULGARIAN: 'bg',
59
+ BURMESE: 'my',
60
+ BURYAT: 'bua',
61
+ CANTONESE: 'yue',
62
+ CATALAN: 'ca',
63
+ CEBUANO: 'ceb',
64
+ CHICHEWA_NYANJA: 'ny',
65
+ CHINESE_SIMPLIFIED: 'zh-CN',
66
+ CHINESE_TRADITIONAL: 'zh-TW',
67
+ CHUVASH: 'cv',
68
+ CORSICAN: 'co',
69
+ CRIMEAN_TATAR: 'crh',
70
+ CROATIAN: 'hr',
71
+ CZECH: 'cs',
72
+ DANISH: 'da',
73
+ DINKA: 'din',
74
+ DIVEHI: 'dv',
75
+ DOGRI: 'doi',
76
+ DOMBE: 'dov',
77
+ DUTCH: 'nl',
78
+ DZONGKHA: 'dz',
79
+ ENGLISH: 'en',
80
+ ESPERANTO: 'eo',
81
+ ESTONIAN: 'et',
82
+ EWE: 'ee',
83
+ FIJIAN: 'fj',
84
+ FILIPINO_TAGALOG: 'fil',
85
+ FINNISH: 'fi',
86
+ FRENCH: 'fr',
87
+ FRENCH_CANADA: 'fr-CA',
88
+ FRENCH_FRANCE: 'fr-FR',
89
+ FRISIAN: 'fy',
90
+ FULFULDE: 'ff',
91
+ GA: 'gaa',
92
+ GALICIAN: 'gl',
93
+ GANDA_LUGANDA: 'lg',
94
+ GEORGIAN: 'ka',
95
+ GERMAN: 'de',
96
+ GREEK: 'el',
97
+ GUARANI: 'gn',
98
+ GUJARATI: 'gu',
99
+ HAITIAN_CREOLE: 'ht',
100
+ HAKHA_CHIN: 'cnh',
101
+ HAUSA: 'ha',
102
+ HAWAIIAN: 'haw',
103
+ HEBREW: 'he',
104
+ HILIGAYNON: 'hil',
105
+ HINDI: 'hi',
106
+ HMONG: 'hmn',
107
+ HUNGARIAN: 'hu',
108
+ HUNSRIK: 'hrx',
109
+ ICELANDIC: 'is',
110
+ IGBO: 'ig',
111
+ ILOKO: 'ilo',
112
+ INDONESIAN: 'id',
113
+ IRISH: 'ga',
114
+ ITALIAN: 'it',
115
+ JAPANESE: 'ja',
116
+ JAVANESE: 'jw',
117
+ KANNADA: 'kn',
118
+ KAPAMPANGAN: 'pam',
119
+ KAZAKH: 'kk',
120
+ KHMER: 'km',
121
+ KIGA: 'cgg',
122
+ KINYARWANDA: 'rw',
123
+ KITUBA: 'ktu',
124
+ KONKANI: 'gom',
125
+ KOREAN: 'ko',
126
+ KRIO: 'kri',
127
+ KURMANJI: 'ku',
128
+ KYRGYZ: 'ky',
129
+ LAO: 'lo',
130
+ LATGALIAN: 'ltg',
131
+ LATIN: 'la',
132
+ LATVIAN: 'lv',
133
+ LIGURIAN: 'lij',
134
+ LIMBURGAN: 'li',
135
+ LINGALA: 'ln',
136
+ LITHUANIAN: 'lt',
137
+ LOMBARD: 'lmo',
138
+ LUO: 'luo',
139
+ LUXEMBOURGISH: 'lb',
140
+ MACEDONIAN: 'mk',
141
+ MAITHILI: 'mai',
142
+ MAKASSAR: 'mak',
143
+ MALAGASY: 'mg',
144
+ MALAY: 'ms',
145
+ MALAYALAM: 'ml',
146
+ MALAY_JAWI: 'ms-Arab',
147
+ MALTESE: 'mt',
148
+ MAORI: 'mi',
149
+ MARATHI: 'mr',
150
+ MEADOW_MARI: 'chm',
151
+ MEITEILON_MANIPURI: 'mni-Mtei',
152
+ MINANG: 'min',
153
+ MIZO: 'lus',
154
+ MONGOLIAN: 'mn',
155
+ NDEBELE_SOUTH: 'nr',
156
+ NEPALBHASA_NEWARI: 'new',
157
+ NEPALI: 'ne',
158
+ NORTHERN_SOTHO: 'nso',
159
+ NORWEGIAN: 'no',
160
+ NUER: 'nus',
161
+ OCCITAN: 'oc',
162
+ ODIA: 'or',
163
+ OROMO: 'om',
164
+ PANGASINAN: 'pag',
165
+ PAPIAMENTO: 'pap',
166
+ PASHTO: 'ps',
167
+ PERSIAN: 'fa',
168
+ POLISH: 'pl',
169
+ PORTUGUESE: 'pt',
170
+ PORTUGUESE_BRAZIL: 'pt-BR',
171
+ PORTUGUESE_PORTUGAL: 'pt-PT',
172
+ PUNJABI: 'pa',
173
+ PUNJABI_SHAHMUKHI: 'pa-Arab',
174
+ QUECHUA: 'qu',
175
+ ROMANI: 'rom',
176
+ ROMANIAN: 'ro',
177
+ RUNDI: 'rn',
178
+ RUSSIAN: 'ru',
179
+ SAMOAN: 'sm',
180
+ SANGO: 'sg',
181
+ SANSKRIT: 'sa',
182
+ SCOTS_GAELIC: 'gd',
183
+ SERBIAN: 'sr',
184
+ SESOTHO: 'st',
185
+ SEYCHELLOIS_CREOLE: 'crs',
186
+ SHAN: 'shn',
187
+ SHONA: 'sn',
188
+ SICILIAN: 'scn',
189
+ SILESIAN: 'szl',
190
+ SINDHI: 'sd',
191
+ SINHALA: 'si',
192
+ SLOVAK: 'sk',
193
+ SLOVENIAN: 'sl',
194
+ SOMALI: 'so',
195
+ SORANI: 'ckb',
196
+ SPANISH: 'es',
197
+ SUNDANESE: 'su',
198
+ SWAHILI: 'sw',
199
+ SWATI: 'ss',
200
+ SWEDISH: 'sv',
201
+ TAJIK: 'tg',
202
+ TAMIL: 'ta',
203
+ TATAR: 'tt',
204
+ TELUGU: 'te',
205
+ TETUM: 'tet',
206
+ THAI: 'th',
207
+ TIGRINYA: 'ti',
208
+ TSONGA: 'ts',
209
+ TSWANA: 'tn',
210
+ TURKISH: 'tr',
211
+ TURKMEN: 'tk',
212
+ TWI_AKAN: 'ak',
213
+ UKRAINIAN: 'uk',
214
+ URDU: 'ur',
215
+ UYGHUR: 'ug',
216
+ UZBEK: 'uz',
217
+ VIETNAMESE: 'vi',
218
+ WELSH: 'cy',
219
+ XHOSA: 'xh',
220
+ YIDDISH: 'yi',
221
+ YORUBA: 'yo',
222
+ YUCATEC_MAYA: 'yua',
223
+ ZULU: 'zu',
224
+ }
225
+
226
+ Object.entries(GoogleTranslateLanguage).forEach(([name, code]) => {
227
+ SUPPORTED_CODES.add(code)
228
+ NAME_TO_CODE[name] = code
229
+ })
@@ -0,0 +1,16 @@
1
+ export type GoogleTranslateProps = {
2
+ text: string[]
3
+ targetLanguage: string
4
+ sourceLanguage?: string
5
+ }
6
+
7
+ export type GoogleTranslation = {
8
+ translatedText: string
9
+ detectedSourceLanguage: string
10
+ }
11
+
12
+ export type GoogleTranslateResponse = {
13
+ data: {
14
+ translations: GoogleTranslation[]
15
+ }
16
+ }