@magmamath/students-features 1.3.23-rc.2 → 1.3.23-rc.21

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 (306) hide show
  1. package/dist/commonjs/features/translation/constants.js +11 -0
  2. package/dist/commonjs/features/translation/constants.js.map +1 -0
  3. package/dist/commonjs/features/translation/helpers.js +60 -0
  4. package/dist/commonjs/features/translation/helpers.js.map +1 -0
  5. package/dist/commonjs/features/translation/index.js +105 -0
  6. package/dist/commonjs/features/translation/index.js.map +1 -0
  7. package/dist/commonjs/features/translation/model/TranslationModel.js +122 -0
  8. package/dist/commonjs/features/translation/model/TranslationModel.js.map +1 -0
  9. package/dist/commonjs/features/translation/model/TranslationPreprocessor.js +142 -0
  10. package/dist/commonjs/features/translation/model/TranslationPreprocessor.js.map +1 -0
  11. package/dist/commonjs/features/translation/model/TranslationService.js +112 -0
  12. package/dist/commonjs/features/translation/model/TranslationService.js.map +1 -0
  13. package/dist/commonjs/features/translation/preserve/wordsToPreserve.js +314 -0
  14. package/dist/commonjs/features/translation/preserve/wordsToPreserve.js.map +1 -0
  15. package/dist/commonjs/features/translation/providers/google/GoogleTranslationProvider.js +50 -0
  16. package/dist/commonjs/features/translation/providers/google/GoogleTranslationProvider.js.map +1 -0
  17. package/dist/commonjs/features/translation/providers/google/supportedLanguages.js +230 -0
  18. package/dist/commonjs/features/translation/providers/google/supportedLanguages.js.map +1 -0
  19. package/dist/commonjs/features/translation/providers/google.types.js +2 -0
  20. package/dist/commonjs/features/translation/providers/google.types.js.map +1 -0
  21. package/dist/commonjs/features/translation/providers/translation.interface.js +49 -0
  22. package/dist/commonjs/features/translation/providers/translation.interface.js.map +1 -0
  23. package/dist/commonjs/features/translation/types.js +2 -0
  24. package/dist/commonjs/features/translation/types.js.map +1 -0
  25. package/dist/commonjs/features/voice/index.js +4 -4
  26. package/dist/commonjs/features/voice/index.js.map +1 -1
  27. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptContent.js +44 -0
  28. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptContent.js.map +1 -0
  29. package/dist/commonjs/features/voice/playing/components/VoiceTranscription.js +107 -0
  30. package/dist/commonjs/features/voice/playing/components/VoiceTranscription.js.map +1 -0
  31. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.js +66 -0
  32. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.js.map +1 -0
  33. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.js +58 -0
  34. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.js.map +1 -0
  35. package/dist/commonjs/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.js → useDropdownAnimation.js} +8 -7
  36. package/dist/commonjs/features/voice/playing/hooks/useDropdownAnimation.js.map +1 -0
  37. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.js +128 -0
  38. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.js.map +1 -0
  39. package/dist/commonjs/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.js → Dropdown.model.js} +4 -4
  40. package/dist/commonjs/features/voice/playing/model/Dropdown.model.js.map +1 -0
  41. package/dist/commonjs/features/voice/playing/model/PlaybackController.js +183 -0
  42. package/dist/commonjs/features/voice/playing/model/PlaybackController.js.map +1 -0
  43. package/dist/commonjs/features/voice/playing/model/Player.model.js +24 -1
  44. package/dist/commonjs/features/voice/playing/model/Player.model.js.map +1 -1
  45. package/dist/commonjs/features/voice/playing/model/{VoiceTranscriptionsCollection.js → TranscriptionsCollection.js} +4 -4
  46. package/dist/commonjs/features/voice/playing/model/TranscriptionsCollection.js.map +1 -0
  47. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.js +82 -0
  48. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.js.map +1 -0
  49. package/dist/commonjs/features/voice/playing/model/Translation.model.js +62 -0
  50. package/dist/commonjs/features/voice/playing/model/Translation.model.js.map +1 -0
  51. package/dist/commonjs/features/voice/playing/model/VoiceFileDownloader.model.js +2 -2
  52. package/dist/commonjs/features/voice/playing/model/VoiceFileDownloader.model.js.map +1 -1
  53. package/dist/commonjs/features/voice/playing/model/VoicePlayer.model.js +46 -172
  54. package/dist/commonjs/features/voice/playing/model/VoicePlayer.model.js.map +1 -1
  55. package/dist/commonjs/features/voice/types.js.map +1 -1
  56. package/dist/commonjs/index.js +12 -0
  57. package/dist/commonjs/index.js.map +1 -1
  58. package/dist/module/features/translation/constants.js +7 -0
  59. package/dist/module/features/translation/constants.js.map +1 -0
  60. package/dist/module/features/translation/helpers.js +53 -0
  61. package/dist/module/features/translation/helpers.js.map +1 -0
  62. package/dist/module/features/translation/index.js +12 -0
  63. package/dist/module/features/translation/index.js.map +1 -0
  64. package/dist/module/features/translation/model/TranslationModel.js +117 -0
  65. package/dist/module/features/translation/model/TranslationModel.js.map +1 -0
  66. package/dist/module/features/translation/model/TranslationPreprocessor.js +137 -0
  67. package/dist/module/features/translation/model/TranslationPreprocessor.js.map +1 -0
  68. package/dist/module/features/translation/model/TranslationService.js +107 -0
  69. package/dist/module/features/translation/model/TranslationService.js.map +1 -0
  70. package/dist/module/features/translation/preserve/wordsToPreserve.js +310 -0
  71. package/dist/module/features/translation/preserve/wordsToPreserve.js.map +1 -0
  72. package/dist/module/features/translation/providers/google/GoogleTranslationProvider.js +45 -0
  73. package/dist/module/features/translation/providers/google/GoogleTranslationProvider.js.map +1 -0
  74. package/dist/module/features/translation/providers/google/supportedLanguages.js +225 -0
  75. package/dist/module/features/translation/providers/google/supportedLanguages.js.map +1 -0
  76. package/dist/module/features/translation/providers/google.types.js +2 -0
  77. package/dist/module/features/translation/providers/google.types.js.map +1 -0
  78. package/dist/module/features/translation/providers/translation.interface.js +44 -0
  79. package/dist/module/features/translation/providers/translation.interface.js.map +1 -0
  80. package/dist/module/features/translation/types.js +2 -0
  81. package/dist/module/features/translation/types.js.map +1 -0
  82. package/dist/module/features/voice/index.js +1 -1
  83. package/dist/module/features/voice/index.js.map +1 -1
  84. package/dist/module/features/voice/playing/components/VoiceTranscriptContent.js +38 -0
  85. package/dist/module/features/voice/playing/components/VoiceTranscriptContent.js.map +1 -0
  86. package/dist/module/features/voice/playing/components/VoiceTranscription.js +101 -0
  87. package/dist/module/features/voice/playing/components/VoiceTranscription.js.map +1 -0
  88. package/dist/module/features/voice/playing/components/VoiceTranscriptionCollapsible.js +58 -0
  89. package/dist/module/features/voice/playing/components/VoiceTranscriptionCollapsible.js.map +1 -0
  90. package/dist/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.js +52 -0
  91. package/dist/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.js.map +1 -0
  92. package/dist/module/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.js → useDropdownAnimation.js} +6 -5
  93. package/dist/module/features/voice/playing/hooks/useDropdownAnimation.js.map +1 -0
  94. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionController.js +123 -0
  95. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionController.js.map +1 -0
  96. package/dist/module/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.js → Dropdown.model.js} +2 -2
  97. package/dist/module/features/voice/playing/model/Dropdown.model.js.map +1 -0
  98. package/dist/module/features/voice/playing/model/PlaybackController.js +178 -0
  99. package/dist/module/features/voice/playing/model/PlaybackController.js.map +1 -0
  100. package/dist/module/features/voice/playing/model/Player.model.js +24 -1
  101. package/dist/module/features/voice/playing/model/Player.model.js.map +1 -1
  102. package/dist/module/features/voice/playing/model/{VoiceTranscriptionsCollection.js → TranscriptionsCollection.js} +2 -2
  103. package/dist/module/features/voice/playing/model/TranscriptionsCollection.js.map +1 -0
  104. package/dist/module/features/voice/playing/model/TranscriptionsDownloader.model.js +77 -0
  105. package/dist/module/features/voice/playing/model/TranscriptionsDownloader.model.js.map +1 -0
  106. package/dist/module/features/voice/playing/model/Translation.model.js +57 -0
  107. package/dist/module/features/voice/playing/model/Translation.model.js.map +1 -0
  108. package/dist/module/features/voice/playing/model/VoiceFileDownloader.model.js +2 -2
  109. package/dist/module/features/voice/playing/model/VoiceFileDownloader.model.js.map +1 -1
  110. package/dist/module/features/voice/playing/model/VoicePlayer.model.js +48 -174
  111. package/dist/module/features/voice/playing/model/VoicePlayer.model.js.map +1 -1
  112. package/dist/module/features/voice/types.js.map +1 -1
  113. package/dist/module/index.js +1 -0
  114. package/dist/module/index.js.map +1 -1
  115. package/dist/typescript/commonjs/features/translation/constants.d.ts +5 -0
  116. package/dist/typescript/commonjs/features/translation/constants.d.ts.map +1 -0
  117. package/dist/typescript/commonjs/features/translation/helpers.d.ts +9 -0
  118. package/dist/typescript/commonjs/features/translation/helpers.d.ts.map +1 -0
  119. package/dist/typescript/commonjs/features/translation/index.d.ts +12 -0
  120. package/dist/typescript/commonjs/features/translation/index.d.ts.map +1 -0
  121. package/dist/typescript/commonjs/features/translation/model/TranslationModel.d.ts +33 -0
  122. package/dist/typescript/commonjs/features/translation/model/TranslationModel.d.ts.map +1 -0
  123. package/dist/typescript/commonjs/features/translation/model/TranslationPreprocessor.d.ts +34 -0
  124. package/dist/typescript/commonjs/features/translation/model/TranslationPreprocessor.d.ts.map +1 -0
  125. package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts +40 -0
  126. package/dist/typescript/commonjs/features/translation/model/TranslationService.d.ts.map +1 -0
  127. package/dist/typescript/commonjs/features/translation/preserve/wordsToPreserve.d.ts +3 -0
  128. package/dist/typescript/commonjs/features/translation/preserve/wordsToPreserve.d.ts.map +1 -0
  129. package/dist/typescript/commonjs/features/translation/providers/google/GoogleTranslationProvider.d.ts +17 -0
  130. package/dist/typescript/commonjs/features/translation/providers/google/GoogleTranslationProvider.d.ts.map +1 -0
  131. package/dist/typescript/commonjs/features/translation/providers/google/supportedLanguages.d.ts +209 -0
  132. package/dist/typescript/commonjs/features/translation/providers/google/supportedLanguages.d.ts.map +1 -0
  133. package/dist/typescript/commonjs/features/translation/providers/google.types.d.ts +15 -0
  134. package/dist/typescript/commonjs/features/translation/providers/google.types.d.ts.map +1 -0
  135. package/dist/typescript/commonjs/features/translation/providers/translation.interface.d.ts +30 -0
  136. package/dist/typescript/commonjs/features/translation/providers/translation.interface.d.ts.map +1 -0
  137. package/dist/typescript/commonjs/features/translation/types.d.ts +27 -0
  138. package/dist/typescript/commonjs/features/translation/types.d.ts.map +1 -0
  139. package/dist/typescript/commonjs/features/voice/index.d.ts +2 -1
  140. package/dist/typescript/commonjs/features/voice/index.d.ts.map +1 -1
  141. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptContent.d.ts +8 -0
  142. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptContent.d.ts.map +1 -0
  143. package/dist/typescript/{module/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts → commonjs/features/voice/playing/components/VoiceTranscription.d.ts} +3 -4
  144. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscription.d.ts.map +1 -0
  145. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts +10 -0
  146. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts.map +1 -0
  147. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts +12 -0
  148. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts.map +1 -0
  149. package/dist/typescript/{module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts → commonjs/features/voice/playing/hooks/useDropdownAnimation.d.ts} +3 -3
  150. package/dist/typescript/commonjs/features/voice/playing/hooks/useDropdownAnimation.d.ts.map +1 -0
  151. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts +30 -0
  152. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts.map +1 -0
  153. package/dist/typescript/{module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts → commonjs/features/voice/playing/model/Dropdown.model.d.ts} +2 -2
  154. package/dist/typescript/commonjs/features/voice/playing/model/Dropdown.model.d.ts.map +1 -0
  155. package/dist/typescript/commonjs/features/voice/playing/model/PlaybackController.d.ts +28 -0
  156. package/dist/typescript/commonjs/features/voice/playing/model/PlaybackController.d.ts.map +1 -0
  157. package/dist/typescript/commonjs/features/voice/playing/model/Player.model.d.ts +3 -0
  158. package/dist/typescript/commonjs/features/voice/playing/model/Player.model.d.ts.map +1 -1
  159. package/dist/typescript/{module/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts → commonjs/features/voice/playing/model/TranscriptionsCollection.d.ts} +2 -2
  160. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsCollection.d.ts.map +1 -0
  161. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.d.ts +19 -0
  162. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloader.model.d.ts.map +1 -0
  163. package/dist/typescript/commonjs/features/voice/playing/model/Translation.model.d.ts +25 -0
  164. package/dist/typescript/commonjs/features/voice/playing/model/Translation.model.d.ts.map +1 -0
  165. package/dist/typescript/commonjs/features/voice/playing/model/VoiceFileDownloader.model.d.ts +2 -2
  166. package/dist/typescript/commonjs/features/voice/playing/model/VoiceFileDownloader.model.d.ts.map +1 -1
  167. package/dist/typescript/commonjs/features/voice/playing/model/VoicePlayer.model.d.ts +18 -18
  168. package/dist/typescript/commonjs/features/voice/playing/model/VoicePlayer.model.d.ts.map +1 -1
  169. package/dist/typescript/commonjs/features/voice/types.d.ts +5 -1
  170. package/dist/typescript/commonjs/features/voice/types.d.ts.map +1 -1
  171. package/dist/typescript/commonjs/index.d.ts +1 -0
  172. package/dist/typescript/commonjs/index.d.ts.map +1 -1
  173. package/dist/typescript/module/features/translation/constants.d.ts +5 -0
  174. package/dist/typescript/module/features/translation/constants.d.ts.map +1 -0
  175. package/dist/typescript/module/features/translation/helpers.d.ts +9 -0
  176. package/dist/typescript/module/features/translation/helpers.d.ts.map +1 -0
  177. package/dist/typescript/module/features/translation/index.d.ts +12 -0
  178. package/dist/typescript/module/features/translation/index.d.ts.map +1 -0
  179. package/dist/typescript/module/features/translation/model/TranslationModel.d.ts +33 -0
  180. package/dist/typescript/module/features/translation/model/TranslationModel.d.ts.map +1 -0
  181. package/dist/typescript/module/features/translation/model/TranslationPreprocessor.d.ts +34 -0
  182. package/dist/typescript/module/features/translation/model/TranslationPreprocessor.d.ts.map +1 -0
  183. package/dist/typescript/module/features/translation/model/TranslationService.d.ts +40 -0
  184. package/dist/typescript/module/features/translation/model/TranslationService.d.ts.map +1 -0
  185. package/dist/typescript/module/features/translation/preserve/wordsToPreserve.d.ts +3 -0
  186. package/dist/typescript/module/features/translation/preserve/wordsToPreserve.d.ts.map +1 -0
  187. package/dist/typescript/module/features/translation/providers/google/GoogleTranslationProvider.d.ts +17 -0
  188. package/dist/typescript/module/features/translation/providers/google/GoogleTranslationProvider.d.ts.map +1 -0
  189. package/dist/typescript/module/features/translation/providers/google/supportedLanguages.d.ts +209 -0
  190. package/dist/typescript/module/features/translation/providers/google/supportedLanguages.d.ts.map +1 -0
  191. package/dist/typescript/module/features/translation/providers/google.types.d.ts +15 -0
  192. package/dist/typescript/module/features/translation/providers/google.types.d.ts.map +1 -0
  193. package/dist/typescript/module/features/translation/providers/translation.interface.d.ts +30 -0
  194. package/dist/typescript/module/features/translation/providers/translation.interface.d.ts.map +1 -0
  195. package/dist/typescript/module/features/translation/types.d.ts +27 -0
  196. package/dist/typescript/module/features/translation/types.d.ts.map +1 -0
  197. package/dist/typescript/module/features/voice/index.d.ts +2 -1
  198. package/dist/typescript/module/features/voice/index.d.ts.map +1 -1
  199. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptContent.d.ts +8 -0
  200. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptContent.d.ts.map +1 -0
  201. package/dist/typescript/{commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts → module/features/voice/playing/components/VoiceTranscription.d.ts} +3 -4
  202. package/dist/typescript/module/features/voice/playing/components/VoiceTranscription.d.ts.map +1 -0
  203. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts +10 -0
  204. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionCollapsible.d.ts.map +1 -0
  205. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts +12 -0
  206. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionHeaderActions.d.ts.map +1 -0
  207. package/dist/typescript/{commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts → module/features/voice/playing/hooks/useDropdownAnimation.d.ts} +3 -3
  208. package/dist/typescript/module/features/voice/playing/hooks/useDropdownAnimation.d.ts.map +1 -0
  209. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts +30 -0
  210. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionController.d.ts.map +1 -0
  211. package/dist/typescript/{commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts → module/features/voice/playing/model/Dropdown.model.d.ts} +2 -2
  212. package/dist/typescript/module/features/voice/playing/model/Dropdown.model.d.ts.map +1 -0
  213. package/dist/typescript/module/features/voice/playing/model/PlaybackController.d.ts +28 -0
  214. package/dist/typescript/module/features/voice/playing/model/PlaybackController.d.ts.map +1 -0
  215. package/dist/typescript/module/features/voice/playing/model/Player.model.d.ts +3 -0
  216. package/dist/typescript/module/features/voice/playing/model/Player.model.d.ts.map +1 -1
  217. package/dist/typescript/{commonjs/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts → module/features/voice/playing/model/TranscriptionsCollection.d.ts} +2 -2
  218. package/dist/typescript/module/features/voice/playing/model/TranscriptionsCollection.d.ts.map +1 -0
  219. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloader.model.d.ts +19 -0
  220. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloader.model.d.ts.map +1 -0
  221. package/dist/typescript/module/features/voice/playing/model/Translation.model.d.ts +25 -0
  222. package/dist/typescript/module/features/voice/playing/model/Translation.model.d.ts.map +1 -0
  223. package/dist/typescript/module/features/voice/playing/model/VoiceFileDownloader.model.d.ts +2 -2
  224. package/dist/typescript/module/features/voice/playing/model/VoiceFileDownloader.model.d.ts.map +1 -1
  225. package/dist/typescript/module/features/voice/playing/model/VoicePlayer.model.d.ts +18 -18
  226. package/dist/typescript/module/features/voice/playing/model/VoicePlayer.model.d.ts.map +1 -1
  227. package/dist/typescript/module/features/voice/types.d.ts +5 -1
  228. package/dist/typescript/module/features/voice/types.d.ts.map +1 -1
  229. package/dist/typescript/module/index.d.ts +1 -0
  230. package/dist/typescript/module/index.d.ts.map +1 -1
  231. package/package.json +28 -1
  232. package/src/features/translation/constants.ts +4 -0
  233. package/src/features/translation/helpers.ts +63 -0
  234. package/src/features/translation/index.ts +30 -0
  235. package/src/features/translation/model/TranslationModel.ts +174 -0
  236. package/src/features/translation/model/TranslationPreprocessor.ts +171 -0
  237. package/src/features/translation/model/TranslationService.ts +148 -0
  238. package/src/features/translation/preserve/wordsToPreserve.ts +87 -0
  239. package/src/features/translation/providers/google/GoogleTranslationProvider.ts +50 -0
  240. package/src/features/translation/providers/google/supportedLanguages.ts +229 -0
  241. package/src/features/translation/providers/google.types.ts +16 -0
  242. package/src/features/translation/providers/translation.interface.ts +63 -0
  243. package/src/features/translation/types.ts +30 -0
  244. package/src/features/voice/index.ts +2 -1
  245. package/src/features/voice/playing/components/VoiceTranscriptContent.tsx +37 -0
  246. package/src/features/voice/playing/components/VoiceTranscription.tsx +117 -0
  247. package/src/features/voice/playing/components/VoiceTranscriptionCollapsible.tsx +59 -0
  248. package/src/features/voice/playing/components/VoiceTranscriptionHeaderActions.tsx +61 -0
  249. package/src/features/voice/playing/hooks/{useVoiceTranscriptionsDropdown.ts → useDropdownAnimation.ts} +5 -5
  250. package/src/features/voice/playing/hooks/useVoiceTranscriptionController.ts +171 -0
  251. package/src/features/voice/playing/model/{VoiceTranscriptionsDropdown.model.ts → Dropdown.model.ts} +2 -2
  252. package/src/features/voice/playing/model/PlaybackController.ts +213 -0
  253. package/src/features/voice/playing/model/Player.model.ts +26 -1
  254. package/src/features/voice/playing/model/{VoiceTranscriptionsCollection.ts → TranscriptionsCollection.ts} +1 -1
  255. package/src/features/voice/playing/model/TranscriptionsDownloader.model.ts +88 -0
  256. package/src/features/voice/playing/model/Translation.model.ts +75 -0
  257. package/src/features/voice/playing/model/VoiceFileDownloader.model.ts +2 -2
  258. package/src/features/voice/playing/model/VoicePlayer.model.ts +57 -194
  259. package/src/features/voice/types.ts +10 -0
  260. package/src/index.ts +1 -0
  261. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.js +0 -251
  262. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.js.map +0 -1
  263. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js +0 -109
  264. package/dist/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js.map +0 -1
  265. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.js.map +0 -1
  266. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js +0 -34
  267. package/dist/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js.map +0 -1
  268. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.js +0 -66
  269. package/dist/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.js.map +0 -1
  270. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionsCollection.js.map +0 -1
  271. package/dist/commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.js.map +0 -1
  272. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdown.js +0 -244
  273. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdown.js.map +0 -1
  274. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js +0 -103
  275. package/dist/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.js.map +0 -1
  276. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.js.map +0 -1
  277. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js +0 -29
  278. package/dist/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.js.map +0 -1
  279. package/dist/module/features/voice/playing/model/TranscriptionsDownloaderModel.js +0 -61
  280. package/dist/module/features/voice/playing/model/TranscriptionsDownloaderModel.js.map +0 -1
  281. package/dist/module/features/voice/playing/model/VoiceTranscriptionsCollection.js.map +0 -1
  282. package/dist/module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.js.map +0 -1
  283. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts.map +0 -1
  284. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts +0 -12
  285. package/dist/typescript/commonjs/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts.map +0 -1
  286. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts.map +0 -1
  287. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts +0 -11
  288. package/dist/typescript/commonjs/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts.map +0 -1
  289. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts +0 -15
  290. package/dist/typescript/commonjs/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts.map +0 -1
  291. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts.map +0 -1
  292. package/dist/typescript/commonjs/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts.map +0 -1
  293. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdown.d.ts.map +0 -1
  294. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts +0 -12
  295. package/dist/typescript/module/features/voice/playing/components/VoiceTranscriptionsDropdownItem.d.ts.map +0 -1
  296. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdown.d.ts.map +0 -1
  297. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts +0 -11
  298. package/dist/typescript/module/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.d.ts.map +0 -1
  299. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts +0 -15
  300. package/dist/typescript/module/features/voice/playing/model/TranscriptionsDownloaderModel.d.ts.map +0 -1
  301. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionsCollection.d.ts.map +0 -1
  302. package/dist/typescript/module/features/voice/playing/model/VoiceTranscriptionsDropdown.model.d.ts.map +0 -1
  303. package/src/features/voice/playing/components/VoiceTranscriptionsDropdown.tsx +0 -302
  304. package/src/features/voice/playing/components/VoiceTranscriptionsDropdownItem.tsx +0 -128
  305. package/src/features/voice/playing/hooks/useVoiceTranscriptionsDropdownItemAnimation.ts +0 -40
  306. package/src/features/voice/playing/model/TranscriptionsDownloaderModel.ts +0 -80
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+
3
+ import { maskSegment, replaceMappedTokens } from "../helpers.js";
4
+ const KATEX_REGEX = /\$(.+?)\$/g;
5
+ const NEWLINE_REGEX = /\n/g;
6
+ const QUOTE_REGEX = /\\(['"])/g;
7
+ const DOLLAR_REGEX = /\\\$/gm;
8
+ const COMMA_REGEX = /,/gm;
9
+ const DOT_REGEX = /\./gm;
10
+ const wrapNoTranslate = content => `<span translate="no">${content}</span>`;
11
+ const KATEX_PLACEHOLDER = wrapNoTranslate('{{@}}');
12
+ const NEWLINE__PLACEHOLDER = wrapNoTranslate('{{#}}');
13
+ const QUOTE_PLACEHOLDER = wrapNoTranslate('{{""}}');
14
+ const DOLLAR_PLACEHOLDER = wrapNoTranslate('{{!}}');
15
+ const COMMA_PLACEHOLDER = wrapNoTranslate('{{,}}');
16
+ const DOT_PLACEHOLDER = wrapNoTranslate('{{.}}');
17
+ const defaultOrderedReplacersMap = [[DOLLAR_REGEX, DOLLAR_PLACEHOLDER], [KATEX_REGEX, KATEX_PLACEHOLDER], [NEWLINE_REGEX, NEWLINE__PLACEHOLDER], [QUOTE_REGEX, QUOTE_PLACEHOLDER], [COMMA_REGEX, COMMA_PLACEHOLDER], [DOT_REGEX, DOT_PLACEHOLDER]];
18
+ export class TranslationKatexPreprocessor {
19
+ static plaintextConverter = text => text;
20
+ static setPlaintextConverter(converter) {
21
+ this.plaintextConverter = converter;
22
+ }
23
+ static shouldSkipTranslation(text = '') {
24
+ if (Array.isArray(text)) {
25
+ return text.every(t => this.isMathExpressionOnly(t) || this.isSingleLetter(t) || this.isMathSymbolsOnly(t));
26
+ }
27
+ return this.isMathExpressionOnly(text) || this.isSingleLetter(text) || this.isMathSymbolsOnly(text);
28
+ }
29
+ static isMathExpressionOnly(text) {
30
+ return /^[\d\s+\-*/^=().\\><%!|]+$/.test(text.trim());
31
+ }
32
+ static isSingleLetter(text) {
33
+ return /^[a-zA-Z]$/.test(text);
34
+ }
35
+ static isMathSymbolsOnly(text) {
36
+ const plainText = this.plaintextConverter(text);
37
+ const cleanedUp = plainText.replace(/(\\\\|\\|\$|\−|\+|\=|\*|kr|pln|€|£|x|y|\{|\}|\÷)/gi, '');
38
+ const mathOnlyRegex = /^(?=.*\d)[0-9+\-×÷*/^().\s]+$/u;
39
+ return cleanedUp.length > 0 && mathOnlyRegex.test(cleanedUp);
40
+ }
41
+ globalTargetLanguage = null;
42
+ preserveWordsMap = {};
43
+ preserveWordsReplacers = [];
44
+ normalizePlaceholderSpacing(text) {
45
+ return text.replace(/\s+(<span[^>]*translate="no"[^>]*>)/g, '$1').replace(/(<\/span>)\s+/g, '$1');
46
+ }
47
+ sanitize(text) {
48
+ const language = this.globalTargetLanguage ?? '';
49
+ const replacements = [];
50
+ let sanitizedText = text;
51
+ defaultOrderedReplacersMap.forEach(([regex, placeholder]) => {
52
+ sanitizedText = maskSegment({
53
+ text: sanitizedText,
54
+ regex,
55
+ placeholder,
56
+ replacements
57
+ });
58
+ });
59
+ this.preserveWordsReplacers.forEach(([regex, placeholder]) => {
60
+ const preserveWordsMapTarget = this.preserveWordsMap[language];
61
+ sanitizedText = maskSegment({
62
+ text: sanitizedText,
63
+ regex,
64
+ placeholder,
65
+ replacements,
66
+ shouldSkip: match => this.skipCustomReplacerSanitizeWithoutGlossary(match, preserveWordsMapTarget)
67
+ });
68
+ });
69
+ return {
70
+ sanitized: sanitizedText,
71
+ replacements
72
+ };
73
+ }
74
+ restore(text, replacements) {
75
+ let restored = this.normalizePlaceholderSpacing(text);
76
+ replacements.forEach(({
77
+ placeholder,
78
+ original,
79
+ leftPad,
80
+ rightPad
81
+ }) => {
82
+ const wrapped = `${leftPad ? ' ' : ''}${original}${rightPad ? ' ' : ''}`;
83
+ restored = restored.replace(placeholder, wrapped);
84
+ });
85
+ return this.applyPreserved(restored);
86
+ }
87
+ sanitizeBatch(texts) {
88
+ const sanitized = [];
89
+ const replacements = [];
90
+ texts.forEach(t => {
91
+ const {
92
+ sanitized: s,
93
+ replacements: r
94
+ } = this.sanitize(t);
95
+ sanitized.push(s);
96
+ replacements.push(r);
97
+ });
98
+ return {
99
+ sanitized,
100
+ replacements
101
+ };
102
+ }
103
+ restoreBatch(texts, replacementsArray) {
104
+ return texts.map((t, i) => {
105
+ const restored = this.restore(t, replacementsArray[i]);
106
+ return this.applyPreserved(restored);
107
+ });
108
+ }
109
+
110
+ // Glossaries apply after translation response and do not remove words from payload.
111
+ // This replaces words from the string before sending request to API to completely avoid
112
+ // translating it. We use it to avoid "context localization" e.g. Google API changes numbers
113
+ // when units are passed and target language is from a different region. We must preserve
114
+ // words like "miles" and the exact number in this case.
115
+ setupPreservable({
116
+ glossaryToPreserve,
117
+ preserveWordsReplacers
118
+ }) {
119
+ this.preserveWordsMap = glossaryToPreserve;
120
+ this.preserveWordsReplacers = preserveWordsReplacers;
121
+ }
122
+ setupTarget(language) {
123
+ this.globalTargetLanguage = language;
124
+ }
125
+ skipCustomReplacerSanitizeWithoutGlossary(match, preserveWordsMapTarget) {
126
+ if (!preserveWordsMapTarget) return true;
127
+ const normalized = match.toLowerCase();
128
+ const glossaryKeys = Object.keys(preserveWordsMapTarget).map(key => key.toLowerCase());
129
+ return !glossaryKeys.includes(normalized);
130
+ }
131
+ applyPreserved(restored) {
132
+ const language = this.globalTargetLanguage ?? '';
133
+ const preservedMap = this.preserveWordsMap[language];
134
+ return preservedMap ? replaceMappedTokens(restored, preservedMap) : restored;
135
+ }
136
+ }
137
+ //# sourceMappingURL=TranslationPreprocessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["maskSegment","replaceMappedTokens","KATEX_REGEX","NEWLINE_REGEX","QUOTE_REGEX","DOLLAR_REGEX","COMMA_REGEX","DOT_REGEX","wrapNoTranslate","content","KATEX_PLACEHOLDER","NEWLINE__PLACEHOLDER","QUOTE_PLACEHOLDER","DOLLAR_PLACEHOLDER","COMMA_PLACEHOLDER","DOT_PLACEHOLDER","defaultOrderedReplacersMap","TranslationKatexPreprocessor","plaintextConverter","text","setPlaintextConverter","converter","shouldSkipTranslation","Array","isArray","every","t","isMathExpressionOnly","isSingleLetter","isMathSymbolsOnly","test","trim","plainText","cleanedUp","replace","mathOnlyRegex","length","globalTargetLanguage","preserveWordsMap","preserveWordsReplacers","normalizePlaceholderSpacing","sanitize","language","replacements","sanitizedText","forEach","regex","placeholder","preserveWordsMapTarget","shouldSkip","match","skipCustomReplacerSanitizeWithoutGlossary","sanitized","restore","restored","original","leftPad","rightPad","wrapped","applyPreserved","sanitizeBatch","texts","s","r","push","restoreBatch","replacementsArray","map","i","setupPreservable","glossaryToPreserve","setupTarget","normalized","toLowerCase","glossaryKeys","Object","keys","key","includes","preservedMap"],"sourceRoot":"../../../../../src","sources":["features/translation/model/TranslationPreprocessor.ts"],"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AC;EAC3C;EAEQb,cAAcA,CAACL,QAAgB,EAAE;IACvC,MAAMZ,QAAQ,GAAG,IAAI,CAACL,oBAAoB,IAAI,EAAE;IAChD,MAAM0C,YAAY,GAAG,IAAI,CAACzC,gBAAgB,CAACI,QAAQ,CAAC;IAEpD,OAAOqC,YAAY,GAAG9E,mBAAmB,CAACqD,QAAQ,EAAEyB,YAAY,CAAC,GAAGzB,QAAQ;EAC9E;AACF","ignoreList":[]}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ import { TranslationKatexPreprocessor } from "./TranslationPreprocessor.js";
4
+ export class TranslationService {
5
+ preprocessor = new TranslationKatexPreprocessor();
6
+ cache = new Map();
7
+ providers = [];
8
+ globalTargetLanguage = null;
9
+ sourceLanguage = null;
10
+ customCacheKeyFn = null;
11
+ constructor({
12
+ providers,
13
+ preserve,
14
+ onError
15
+ }) {
16
+ this.providers = providers;
17
+ this.onError = onError;
18
+ if (preserve) {
19
+ this.preprocessor.setupPreservable({
20
+ glossaryToPreserve: preserve.map,
21
+ preserveWordsReplacers: preserve.replacers
22
+ });
23
+ }
24
+ }
25
+ getTargetLanguage(targetLang) {
26
+ const target = targetLang || this.globalTargetLanguage;
27
+ if (!target) {
28
+ throw new Error('Target language is missing, either provide in arguments or use .bindTargetLanguage()');
29
+ }
30
+ return target;
31
+ }
32
+ getProvider(target) {
33
+ const provider = this.providers.find(svc => svc.isTargetSupported(target));
34
+ if (!provider) throw new Error(`This target language: "${target}" is not supported.`);
35
+ return provider;
36
+ }
37
+ createCacheKey(text, target, suffix) {
38
+ let baseKey;
39
+ if (this.customCacheKeyFn) {
40
+ baseKey = this.customCacheKeyFn(text, target);
41
+ } else {
42
+ baseKey = Array.isArray(text) ? `${JSON.stringify(text)}::${target}` : `${text}::${target}`;
43
+ }
44
+ return suffix ? `${baseKey}${suffix}` : baseKey;
45
+ }
46
+ translate = async (text = '', config) => {
47
+ const isArrayInput = Array.isArray(text);
48
+ const target = this.getTargetLanguage(config?.targetLang) ?? '';
49
+ if (!text.length || TranslationKatexPreprocessor.shouldSkipTranslation(text)) {
50
+ const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix);
51
+ if (this.cache.has(key)) return this.cache.get(key);
52
+ return text;
53
+ }
54
+ const source = config?.sourceLang ?? this.sourceLanguage ?? undefined;
55
+ const provider = this.getProvider(target);
56
+ const key = config?.cacheKey ?? this.createCacheKey(text, target, config?.cacheKeySuffix);
57
+ if (this.cache.has(key)) return this.cache.get(key);
58
+ let translated;
59
+ if (isArrayInput) {
60
+ const {
61
+ sanitized,
62
+ replacements
63
+ } = this.preprocessor.sanitizeBatch(text);
64
+ const response = await provider.requestBatch(sanitized, target, source);
65
+ translated = this.preprocessor.restoreBatch(response, replacements);
66
+ } else {
67
+ const {
68
+ sanitized,
69
+ replacements
70
+ } = this.preprocessor.sanitize(text);
71
+ const response = await provider.request(sanitized, target, source);
72
+ translated = this.preprocessor.restore(response, replacements);
73
+ }
74
+ this.cache.set(key, translated);
75
+ return translated;
76
+ };
77
+ bindTargetLanguage(store, callback) {
78
+ store.watch(t => {
79
+ const value = callback ? callback(t) : t;
80
+ this.globalTargetLanguage = value;
81
+ this.preprocessor.setupTarget(value);
82
+ });
83
+ return this;
84
+ }
85
+ bindSourceLanguage(store) {
86
+ store.watch(value => {
87
+ this.sourceLanguage = value;
88
+ });
89
+ return this;
90
+ }
91
+ bindCustomCacheKey(store, callback) {
92
+ store.watch(t => {
93
+ this.customCacheKeyFn = (text, target) => callback(t, {
94
+ text,
95
+ target
96
+ });
97
+ });
98
+ return this;
99
+ }
100
+ getCached(key) {
101
+ return this.cache.get(key);
102
+ }
103
+ reset() {
104
+ this.cache.clear();
105
+ }
106
+ }
107
+ //# sourceMappingURL=TranslationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TranslationKatexPreprocessor","TranslationService","preprocessor","cache","Map","providers","globalTargetLanguage","sourceLanguage","customCacheKeyFn","constructor","preserve","onError","setupPreservable","glossaryToPreserve","map","preserveWordsReplacers","replacers","getTargetLanguage","targetLang","target","Error","getProvider","provider","find","svc","isTargetSupported","createCacheKey","text","suffix","baseKey","Array","isArray","JSON","stringify","translate","config","isArrayInput","length","shouldSkipTranslation","key","cacheKey","cacheKeySuffix","has","get","source","sourceLang","undefined","translated","sanitized","replacements","sanitizeBatch","response","requestBatch","restoreBatch","sanitize","request","restore","set","bindTargetLanguage","store","callback","watch","t","value","setupTarget","bindSourceLanguage","bindCustomCacheKey","getCached","reset","clear"],"sourceRoot":"../../../../../src","sources":["features/translation/model/TranslationService.ts"],"mappings":";;AACA,SAASA,4BAA4B,QAAQ,8BAA2B;AAmBxE,OAAO,MAAMC,kBAAkB,CAAC;EACbC,YAAY,GAAG,IAAIF,4BAA4B,CAAC,CAAC;EACjDG,KAAK,GAAG,IAAIC,GAAG,CAA4B,CAAC;EAC5CC,SAAS,GAA0B,EAAE;EAG9CC,oBAAoB,GAAkB,IAAI;EAC1CC,cAAc,GAAkB,IAAI;EACpCC,gBAAgB,GAAiE,IAAI;EAE7FC,WAAWA,CAAC;IAAEJ,SAAS;IAAEK,QAAQ;IAAEC;EAAiC,CAAC,EAAE;IACrE,IAAI,CAACN,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACM,OAAO,GAAGA,OAAO;IAEtB,IAAID,QAAQ,EAAE;MACZ,IAAI,CAACR,YAAY,CAACU,gBAAgB,CAAC;QACjCC,kBAAkB,EAAEH,QAAQ,CAACI,GAAG;QAChCC,sBAAsB,EAAEL,QAAQ,CAACM;MACnC,CAAC,CAAC;IACJ;EACF;EAEQC,iBAAiBA,CAACC,UAAmB,EAAE;IAC7C,MAAMC,MAAM,GAAGD,UAAU,IAAI,IAAI,CAACZ,oBAAoB;IACtD,IAAI,CAACa,MAAM,EAAE;MACX,MAAM,IAAIC,KAAK,CACb,sFACF,CAAC;IACH;IACA,OAAOD,MAAM;EACf;EAEQE,WAAWA,CAACF,MAAc,EAAE;IAClC,MAAMG,QAAQ,GAAG,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kBA,CACvBC,KAAe,EACfC,QAA+B,EACzB;IACND,KAAK,CAACE,KAAK,CAAEC,CAAC,IAAK;MACjB,MAAMC,KAAK,GAAGH,QAAQ,GAAGA,QAAQ,CAACE,CAAC,CAAC,GAAGA,CAAC;MACxC,IAAI,CAACxD,oBAAoB,GAAGyD,KAAK;MACjC,IAAI,CAAC7D,YAAY,CAAC8D,WAAW,CAACD,KAAK,CAAC;IACtC,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOE,kBAAkBA,CAAmBN,KAAe,EAAQ;IACjEA,KAAK,CAACE,KAAK,CAAEE,KAAK,IAAK;MACrB,IAAI,CAACxD,cAAc,GAAGwD,KAAK;IAC7B,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOG,kBAAkBA,CACvBP,KAAe,EACfC,QAAkF,EAC5E;IACND,KAAK,CAACE,KAAK,CAAEC,CAAC,IAAK;MACjB,IAAI,CAACtD,gBAAgB,GAAG,CAACmB,IAAuB,EAAER,MAAc,KAC9DyC,QAAQ,CAACE,CAAC,EAAE;QAAEnC,IAAI;QAAER;MAAO,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,OAAO,IAAI;EACb;EAEOgD,SAASA,CAA8B5B,GAAW,EAAiB;IACxE,OAAO,IAAI,CAACpC,KAAK,CAACwC,GAAG,CAACJ,GAAG,CAAC;EAC5B;EAEO6B,KAAKA,CAAA,EAAG;IACb,IAAI,CAACjE,KAAK,CAACkE,KAAK,CAAC,CAAC;EACpB;AACF","ignoreList":[]}
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+
3
+ export const wordsToPreserve = {
4
+ es: {
5
+ mile: 'milla',
6
+ miles: 'millas'
7
+ },
8
+ hy: {
9
+ mile: 'մղոն',
10
+ miles: 'մղոններ'
11
+ },
12
+ fr: {
13
+ mile: 'mille',
14
+ miles: 'milles'
15
+ },
16
+ ru: {
17
+ mile: 'миля',
18
+ miles: 'мили'
19
+ },
20
+ ar: {
21
+ mile: 'ميل',
22
+ miles: 'أميال'
23
+ },
24
+ is: {
25
+ mile: 'míla',
26
+ miles: 'mílur'
27
+ },
28
+ ja: {
29
+ mile: 'マイル',
30
+ miles: 'マイル'
31
+ },
32
+ 'zh-Hans': {
33
+ mile: '英里',
34
+ miles: '英里'
35
+ },
36
+ af: {
37
+ mile: 'myl',
38
+ miles: 'myls'
39
+ },
40
+ ko: {
41
+ mile: '마일',
42
+ miles: '마일'
43
+ },
44
+ de: {
45
+ mile: 'Meile',
46
+ miles: 'Meilen'
47
+ },
48
+ zu: {
49
+ mile: 'ileyili',
50
+ miles: 'amayela'
51
+ },
52
+ 'zh-Hant': {
53
+ mile: '英里',
54
+ miles: '英里'
55
+ },
56
+ it: {
57
+ mile: 'miglio',
58
+ miles: 'miglia'
59
+ },
60
+ ht: {
61
+ mile: 'miy',
62
+ miles: 'miy'
63
+ },
64
+ hi: {
65
+ mile: 'मील',
66
+ miles: 'मील'
67
+ },
68
+ pt: {
69
+ mile: 'milha',
70
+ miles: 'milhas'
71
+ },
72
+ sq: {
73
+ mile: 'milje',
74
+ miles: 'milje'
75
+ },
76
+ el: {
77
+ mile: 'μίλι',
78
+ miles: 'μίλια'
79
+ },
80
+ pl: {
81
+ mile: 'mila',
82
+ miles: 'mile'
83
+ },
84
+ te: {
85
+ mile: 'మైలు',
86
+ miles: 'మైలు‌లు'
87
+ },
88
+ am: {
89
+ mile: 'ማይል',
90
+ miles: 'ማይሎች'
91
+ },
92
+ ta: {
93
+ mile: 'மைல்',
94
+ miles: 'மைல்கள்'
95
+ },
96
+ vi: {
97
+ mile: 'dặm',
98
+ miles: 'dặm'
99
+ },
100
+ uk: {
101
+ mile: 'миля',
102
+ miles: 'милі'
103
+ },
104
+ haw: {
105
+ mile: 'maila',
106
+ miles: 'maila'
107
+ },
108
+ sv: {
109
+ mile: 'mile',
110
+ miles: 'miles'
111
+ },
112
+ bn: {
113
+ mile: 'মাইল',
114
+ miles: 'মাইল'
115
+ },
116
+ tl: {
117
+ mile: 'milya',
118
+ miles: 'milya'
119
+ },
120
+ ga: {
121
+ mile: 'míle',
122
+ miles: 'míleanna'
123
+ },
124
+ nl: {
125
+ mile: 'mijl',
126
+ miles: 'mijlen'
127
+ },
128
+ ur: {
129
+ mile: 'میل',
130
+ miles: 'میل'
131
+ },
132
+ ee: {
133
+ mile: 'maili',
134
+ miles: 'maili'
135
+ },
136
+ en: {
137
+ mile: 'mile',
138
+ miles: 'miles'
139
+ },
140
+ az: {
141
+ mile: 'mil',
142
+ miles: 'mil'
143
+ },
144
+ gu: {
145
+ mile: 'માઈલ',
146
+ miles: 'માઈલ્સ'
147
+ },
148
+ ml: {
149
+ mile: 'മൈൽ',
150
+ miles: 'മൈലുകൾ'
151
+ },
152
+ pa: {
153
+ mile: 'ਮਾਈਲ',
154
+ miles: 'ਮਾਈਲਾਂ'
155
+ },
156
+ as: {
157
+ mile: 'মাইল',
158
+ miles: 'মাইল'
159
+ },
160
+ bm: {
161
+ mile: 'maili',
162
+ miles: 'maili'
163
+ },
164
+ he: {
165
+ mile: 'מייל',
166
+ miles: 'מיילים'
167
+ },
168
+ fa: {
169
+ mile: 'مایل',
170
+ miles: 'مایل‌ها'
171
+ },
172
+ fi: {
173
+ mile: 'maili',
174
+ miles: 'mailia'
175
+ },
176
+ tr: {
177
+ mile: 'mil',
178
+ miles: 'mil'
179
+ },
180
+ da: {
181
+ mile: 'mil',
182
+ miles: 'mil'
183
+ },
184
+ bg: {
185
+ mile: 'миля',
186
+ miles: 'мили'
187
+ },
188
+ xh: {
189
+ mile: 'imayile',
190
+ miles: 'iimayile'
191
+ },
192
+ yi: {
193
+ mile: 'מייל',
194
+ miles: 'מיילן'
195
+ },
196
+ ps: {
197
+ mile: 'مایل',
198
+ miles: 'مایلونه'
199
+ },
200
+ mr: {
201
+ mile: 'मैल',
202
+ miles: 'मैले'
203
+ },
204
+ eu: {
205
+ mile: 'mila',
206
+ miles: 'milak'
207
+ },
208
+ bs: {
209
+ mile: 'milja',
210
+ miles: 'milje'
211
+ },
212
+ cs: {
213
+ mile: 'míle',
214
+ miles: 'míle'
215
+ },
216
+ yo: {
217
+ mile: 'maili',
218
+ miles: 'maili'
219
+ },
220
+ ak: {
221
+ mile: 'maili',
222
+ miles: 'maili'
223
+ },
224
+ ro: {
225
+ mile: 'milă',
226
+ miles: 'mile'
227
+ },
228
+ mn: {
229
+ mile: 'миль',
230
+ miles: 'миль'
231
+ },
232
+ bho: {
233
+ mile: 'माइल',
234
+ miles: 'माइल्स'
235
+ },
236
+ ka: {
237
+ mile: 'მილი',
238
+ miles: 'მილი'
239
+ },
240
+ ca: {
241
+ mile: 'milla',
242
+ miles: 'milles'
243
+ },
244
+ be: {
245
+ mile: 'міля',
246
+ miles: 'мілі'
247
+ },
248
+ sw: {
249
+ mile: 'maili',
250
+ miles: 'maili'
251
+ },
252
+ eo: {
253
+ mile: 'mejlo',
254
+ miles: 'mejloj'
255
+ },
256
+ th: {
257
+ mile: 'ไมล์',
258
+ miles: 'ไมล์'
259
+ },
260
+ ay: {
261
+ mile: 'maili',
262
+ miles: 'maili'
263
+ },
264
+ doi: {
265
+ mile: 'माइल',
266
+ miles: 'माइल्स'
267
+ },
268
+ hr: {
269
+ mile: 'milja',
270
+ miles: 'milje'
271
+ },
272
+ sm: {
273
+ mile: 'maila',
274
+ miles: 'maila'
275
+ },
276
+ kn: {
277
+ mile: 'ಮೈಲು',
278
+ miles: 'ಮೈಲುಗಳು'
279
+ },
280
+ et: {
281
+ mile: 'miil',
282
+ miles: 'miilid'
283
+ },
284
+ ceb: {
285
+ mile: 'milya',
286
+ miles: 'milya'
287
+ },
288
+ ig: {
289
+ mile: 'maịlụ',
290
+ miles: 'maịlụ'
291
+ },
292
+ ne: {
293
+ mile: 'माइल',
294
+ miles: 'माइलहरू'
295
+ },
296
+ uz: {
297
+ mile: 'mil',
298
+ miles: 'mil'
299
+ },
300
+ cy: {
301
+ mile: 'filltir',
302
+ miles: 'mili'
303
+ }
304
+ };
305
+ const MILE_REGEX = /mile/gm;
306
+ const MILE_PLACEHOLDER = '__!{21_37_70}!__';
307
+ const MILES_REGEX = /miles/gm;
308
+ const MILES_PLACEHOLDER = '__!{21_37_69}!__';
309
+ export const preservedWordsReplacers = [[MILES_REGEX, MILES_PLACEHOLDER], [MILE_REGEX, MILE_PLACEHOLDER]];
310
+ //# sourceMappingURL=wordsToPreserve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["wordsToPreserve","es","mile","miles","hy","fr","ru","ar","is","ja","af","ko","de","zu","it","ht","hi","pt","sq","el","pl","te","am","ta","vi","uk","haw","sv","bn","tl","ga","nl","ur","ee","en","az","gu","ml","pa","as","bm","he","fa","fi","tr","da","bg","xh","yi","ps","mr","eu","bs","cs","yo","ak","ro","mn","bho","ka","ca","be","sw","eo","th","ay","doi","hr","sm","kn","et","ceb","ig","ne","uz","cy","MILE_REGEX","MILE_PLACEHOLDER","MILES_REGEX","MILES_PLACEHOLDER","preservedWordsReplacers"],"sourceRoot":"../../../../../src","sources":["features/translation/preserve/wordsToPreserve.ts"],"mappings":";;AAAA,OAAO,MAAMA,eAAuD,GAAG;EACrEC,EAAE,EAAE;IAAEC,IAAI,EAAE,OAAO;IAAEC,KAAK,EAAE;EAAS,CAAC;EACtCC,EAAE,EAAE;IAAEF,IAAI,EAAE,MAAM;IAAEC,KAAK,EAAE;EAAU,CAAC;EACtCE,EAAE,EAAE;IAAEH,IAAI,EAAE,OAAO;IAAEC,KAAK,EAAE;EAAS,CAAC;EACtCG,EAAE,EAAE;IAAEJ,IAAI,EAAE,MAAM;IAAEC,KAAK,EAAE;EAAO,CAAC;EACnCI,EAAE,EAAE;IAAEL,IAAI,EAAE,KAAK;IAAEC,KAAK,EAAE;EAAQ,CAAC;EACnCK,EAAE,EAAE;IAAEN,IAAI,EAAE,MAAM;IAAEC,KAAK,EAAE;EAAQ,CAAC;EACpCM,EAAE,EAAE;IAAEP,IAAI,EAAE,KAAK;IAAEC,KAAK,EAAE;EAAM,CAAC;EACjC,SAAS,EAAE;I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,OAAO;IAAEC,KAAK,EAAE;EAAQ,CAAC;EACtCqE,EAAE,EAAE;IAAEtE,IAAI,EAAE,OAAO;IAAEC,KAAK,EAAE;EAAQ,CAAC;EACrCsE,EAAE,EAAE;IAAEvE,IAAI,EAAE,MAAM;IAAEC,KAAK,EAAE;EAAU,CAAC;EACtCuE,EAAE,EAAE;IAAExE,IAAI,EAAE,KAAK;IAAEC,KAAK,EAAE;EAAM,CAAC;EACjCwE,EAAE,EAAE;IAAEzE,IAAI,EAAE,SAAS;IAAEC,KAAK,EAAE;EAAO;AACvC,CAAC;AAED,MAAMyE,UAAU,GAAG,QAAQ;AAC3B,MAAMC,gBAAgB,GAAG,kBAAkB;AAC3C,MAAMC,WAAW,GAAG,SAAS;AAC7B,MAAMC,iBAAiB,GAAG,kBAAkB;AAE5C,OAAO,MAAMC,uBAA2C,GAAG,CACzD,CAACF,WAAW,EAAEC,iBAAiB,CAAC,EAChC,CAACH,UAAU,EAAEC,gBAAgB,CAAC,CAC/B","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ import { createEffect } from 'effector';
4
+ import { TranslationProvider } from "../translation.interface.js";
5
+ import { GoogleTranslateLanguage, resolveGoogleLanguageCode } from "./supportedLanguages.js";
6
+ import { decodeHtmlEntities } from "../../helpers.js";
7
+ export class GoogleTranslationProvider extends TranslationProvider {
8
+ constructor({
9
+ api,
10
+ glossaries
11
+ }) {
12
+ super({
13
+ supportedLanguages: Object.values(GoogleTranslateLanguage),
14
+ glossaries
15
+ });
16
+ this.getTranslationFx = createEffect(api.translateRequest);
17
+ }
18
+ resolveLanguage(language) {
19
+ return resolveGoogleLanguageCode(language);
20
+ }
21
+ async request(text, targetLanguage, sourceLanguage) {
22
+ const resolvedTarget = this.resolveLanguage(targetLanguage) ?? targetLanguage;
23
+ const resolvedSource = sourceLanguage ? this.resolveLanguage(sourceLanguage) ?? undefined : undefined;
24
+ const response = await this.getTranslationFx({
25
+ text: [text],
26
+ targetLanguage: resolvedTarget,
27
+ sourceLanguage: resolvedSource
28
+ });
29
+ const translated = response.data.translations[0]?.translatedText ?? '';
30
+ return this.applyGlossary(decodeHtmlEntities(translated), resolvedTarget);
31
+ }
32
+ async requestBatch(text, targetLanguage, sourceLanguage) {
33
+ const resolvedTarget = this.resolveLanguage(targetLanguage) ?? targetLanguage;
34
+ const resolvedSource = sourceLanguage ? this.resolveLanguage(sourceLanguage) ?? undefined : undefined;
35
+ const response = await this.getTranslationFx({
36
+ text,
37
+ targetLanguage: resolvedTarget,
38
+ sourceLanguage: resolvedSource
39
+ });
40
+ return response.data.translations.map(({
41
+ translatedText
42
+ }) => this.applyGlossary(decodeHtmlEntities(translatedText), resolvedTarget));
43
+ }
44
+ }
45
+ //# sourceMappingURL=GoogleTranslationProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createEffect","TranslationProvider","GoogleTranslateLanguage","resolveGoogleLanguageCode","decodeHtmlEntities","GoogleTranslationProvider","constructor","api","glossaries","supportedLanguages","Object","values","getTranslationFx","translateRequest","resolveLanguage","language","request","text","targetLanguage","sourceLanguage","resolvedTarget","resolvedSource","undefined","response","translated","data","translations","translatedText","applyGlossary","requestBatch","map"],"sourceRoot":"../../../../../../src","sources":["features/translation/providers/google/GoogleTranslationProvider.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAgB,UAAU;AAC/C,SAA2BC,mBAAmB,QAAQ,6BAA0B;AAChF,SAASC,uBAAuB,EAAEC,yBAAyB,QAAQ,yBAAsB;AAEzF,SAASC,kBAAkB,QAAQ,kBAAe;AASlD,OAAO,MAAMC,yBAAyB,SAASJ,mBAAmB,CAAC;EAGjEK,WAAWA,CAAC;IAAEC,GAAG;IAAEC;EAA2C,CAAC,EAAE;IAC/D,KAAK,CAAC;MAAEC,kBAAkB,EAAEC,MAAM,CAACC,MAAM,CAACT,uBAAuB,CAAC;MAAEM;IAAW,CAAC,CAAC;IACjF,IAAI,CAACI,gBAAgB,GAAGZ,YAAY,CAACO,GAA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