@fintatech/fintachart 3.1.0

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 (341) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE.md +63 -0
  3. package/README.md +151 -0
  4. package/THIRD_PARTY_NOTICES.md +38 -0
  5. package/basic-objects.html +165 -0
  6. package/css/FintaChart.min.css +1 -0
  7. package/css/external/jqNumericField.min.css +1 -0
  8. package/css/external/spectrum.min.css +7 -0
  9. package/css/external/toastr.min.css +1 -0
  10. package/custom-indicator.html +209 -0
  11. package/d.ts/FintaChart.d.ts +24313 -0
  12. package/d.ts/frameworks/Intl.d.ts +115 -0
  13. package/d.ts/frameworks/bootstrap.d.ts +128 -0
  14. package/d.ts/frameworks/bootstrap.v3.datetimepicker.d.ts +10 -0
  15. package/d.ts/frameworks/detectizr.d.ts +27 -0
  16. package/d.ts/frameworks/dom-to-image-more.d.ts +17 -0
  17. package/d.ts/frameworks/html2canvas.d.ts +101 -0
  18. package/d.ts/frameworks/i18nextXHRBackend.d.ts +42 -0
  19. package/d.ts/frameworks/jquery-i18next.d.ts +14 -0
  20. package/d.ts/frameworks/jquery-ui.d.ts +1914 -0
  21. package/d.ts/frameworks/jquery.d.ts +3779 -0
  22. package/d.ts/frameworks/jquery.ui.touch-punch.d.ts +12 -0
  23. package/d.ts/frameworks/moment-node.d.ts +485 -0
  24. package/d.ts/frameworks/moment.d.ts +10 -0
  25. package/d.ts/frameworks/tinycolor.d.ts +377 -0
  26. package/d.ts/frameworks-modified/bootstrap-select.d.ts +18 -0
  27. package/d.ts/frameworks-modified/i18next.d.ts +148 -0
  28. package/d.ts/frameworks-modified/jquery.autocolumnlist.d.ts +17 -0
  29. package/d.ts/frameworks-modified/jquery.resizable.d.ts +20 -0
  30. package/d.ts/frameworks-modified/spectrum.d.ts +294 -0
  31. package/d.ts/frameworks-modified/switchery.d.ts +69 -0
  32. package/d.ts/frameworks-modified/toastr.d.ts +224 -0
  33. package/data/offline-market-history/EUR_CAD/Day/1.csv +2001 -0
  34. package/data/offline-market-history/EUR_CAD/Hour/1.csv +1702 -0
  35. package/data/offline-market-history/EUR_CAD/Hour/4.csv +442 -0
  36. package/data/offline-market-history/EUR_CAD/Minute/1.csv +2001 -0
  37. package/data/offline-market-history/EUR_CAD/Minute/15.csv +2001 -0
  38. package/data/offline-market-history/EUR_CAD/Minute/5.csv +2001 -0
  39. package/data/offline-market-history/EUR_CAD/Monthly/1.csv +175 -0
  40. package/data/offline-market-history/EUR_CAD/Weekly/1.csv +752 -0
  41. package/data/offline-market-history/EUR_CAD/Yearly/1.csv +16 -0
  42. package/data/offline-market-history/EUR_GBP/Day/1.csv +2001 -0
  43. package/data/offline-market-history/EUR_GBP/Hour/1.csv +1702 -0
  44. package/data/offline-market-history/EUR_GBP/Hour/4.csv +442 -0
  45. package/data/offline-market-history/EUR_GBP/Minute/1.csv +2001 -0
  46. package/data/offline-market-history/EUR_GBP/Minute/15.csv +2001 -0
  47. package/data/offline-market-history/EUR_GBP/Minute/5.csv +2001 -0
  48. package/data/offline-market-history/EUR_GBP/Monthly/1.csv +199 -0
  49. package/data/offline-market-history/EUR_GBP/Weekly/1.csv +860 -0
  50. package/data/offline-market-history/EUR_GBP/Yearly/1.csv +18 -0
  51. package/data/predefined-templates/EMAAndMACDTemplate.json +100 -0
  52. package/data/predefined-templates/bigTreeTemplate.json +137 -0
  53. package/data/predefined-templates/multiIndicator.json +136 -0
  54. package/data/predefined-templates/renkoTemplate.json +50 -0
  55. package/data/predefined-templates/standartCandleTemplate.json +73 -0
  56. package/fonts/calibri/calibri.svg +3707 -0
  57. package/fonts/calibri/calibri.ttf +0 -0
  58. package/fonts/calibri/calibri.woff +0 -0
  59. package/fonts/courier-new/courier-new.svg +633 -0
  60. package/fonts/courier-new/courier-new.ttf +0 -0
  61. package/fonts/courier-new/courier-new.woff +0 -0
  62. package/fonts/open-sans-cyrillic/open-sans-cyrillic.svg +475 -0
  63. package/fonts/open-sans-cyrillic/open-sans-cyrillic.ttf +0 -0
  64. package/fonts/open-sans-cyrillic/open-sans-cyrillic.woff +0 -0
  65. package/fonts/open-sans-cyrillic-ext/open-sans-cyrillic-ext.svg +567 -0
  66. package/fonts/open-sans-cyrillic-ext/open-sans-cyrillic-ext.ttf +0 -0
  67. package/fonts/open-sans-cyrillic-ext/open-sans-cyrillic-ext.woff +0 -0
  68. package/fonts/open-sans-greek/open-sans-greek.svg +603 -0
  69. package/fonts/open-sans-greek/open-sans-greek.ttf +0 -0
  70. package/fonts/open-sans-greek/open-sans-greek.woff +0 -0
  71. package/fonts/open-sans-greek-ext/open-sans-greek-ext.svg +42 -0
  72. package/fonts/open-sans-greek-ext/open-sans-greek-ext.ttf +0 -0
  73. package/fonts/open-sans-greek-ext/open-sans-greek-ext.woff +0 -0
  74. package/fonts/open-sans-latin/open-sans-latin.svg +1863 -0
  75. package/fonts/open-sans-latin/open-sans-latin.ttf +0 -0
  76. package/fonts/open-sans-latin/open-sans-latin.woff +0 -0
  77. package/fonts/open-sans-latin-ext/open-sans-latin-ext.svg +1686 -0
  78. package/fonts/open-sans-latin-ext/open-sans-latin-ext.ttf +0 -0
  79. package/fonts/open-sans-latin-ext/open-sans-latin-ext.woff +0 -0
  80. package/fonts/open-sans-vietnamese/open-sans-vietnamese.svg +375 -0
  81. package/fonts/open-sans-vietnamese/open-sans-vietnamese.ttf +0 -0
  82. package/fonts/open-sans-vietnamese/open-sans-vietnamese.woff +0 -0
  83. package/fonts/rubik-medium/Rubik-Medium.svg +8831 -0
  84. package/fonts/rubik-medium/Rubik-Medium.ttf +0 -0
  85. package/fonts/rubik-medium/Rubik-Medium.woff +0 -0
  86. package/fonts/rubik-regular/Rubik-Regular.svg +8885 -0
  87. package/fonts/rubik-regular/Rubik-Regular.ttf +0 -0
  88. package/fonts/rubik-regular/Rubik-Regular.woff +0 -0
  89. package/fonts/source-sans-pro-latin/source-sans-pro-latin.svg +2642 -0
  90. package/fonts/source-sans-pro-latin/source-sans-pro-latin.ttf +0 -0
  91. package/fonts/source-sans-pro-latin/source-sans-pro-latin.woff +0 -0
  92. package/fonts/source-sans-pro-latin-ext/source-sans-pro-latin-ext.svg +1572 -0
  93. package/fonts/source-sans-pro-latin-ext/source-sans-pro-latin-ext.ttf +0 -0
  94. package/fonts/source-sans-pro-latin-ext/source-sans-pro-latin-ext.woff +0 -0
  95. package/fonts/source-sans-pro-vietnamese/source-sans-pro-vietnamese.svg +428 -0
  96. package/fonts/source-sans-pro-vietnamese/source-sans-pro-vietnamese.ttf +0 -0
  97. package/fonts/source-sans-pro-vietnamese/source-sans-pro-vietnamese.woff +0 -0
  98. package/htmldialogs/ChartContextMenu.html +3 -0
  99. package/htmldialogs/ChartTypeSettingsDialog.html +231 -0
  100. package/htmldialogs/CheckboxIndicatorParameterControl.html +9 -0
  101. package/htmldialogs/CompareInstrumentSettings.html +61 -0
  102. package/htmldialogs/ComparingContextMenu.html +8 -0
  103. package/htmldialogs/ConfirmDialog.html +28 -0
  104. package/htmldialogs/DemoModePopup.html +24 -0
  105. package/htmldialogs/FillPlotStyleControl.html +28 -0
  106. package/htmldialogs/HotkeysSettings.html +28 -0
  107. package/htmldialogs/IndicatorContextMenu.html +18 -0
  108. package/htmldialogs/IndicatorSettingsDialog.html +38 -0
  109. package/htmldialogs/IndicatorsDialog.html +39 -0
  110. package/htmldialogs/IndicatorsOverview_en.html +1694 -0
  111. package/htmldialogs/IndicatorsOverview_ua.html +9 -0
  112. package/htmldialogs/InstrumentSearchDialog.html +22 -0
  113. package/htmldialogs/LinePlotStyleControl.html +33 -0
  114. package/htmldialogs/MainSettings.html +292 -0
  115. package/htmldialogs/MarketEventPopup.html +27 -0
  116. package/htmldialogs/MarketEventsSettingsDialog.html +22 -0
  117. package/htmldialogs/NumericIndicatorParameter.html +8 -0
  118. package/htmldialogs/OpenChart.html +6 -0
  119. package/htmldialogs/PatternSettingsControl.html +26 -0
  120. package/htmldialogs/PatternsIndicatorSettingsDialog.html +30 -0
  121. package/htmldialogs/PatternsSettingsParameterControl.html +12 -0
  122. package/htmldialogs/PositionShapeContextMenu.html +9 -0
  123. package/htmldialogs/QuantityPopup.html +7 -0
  124. package/htmldialogs/Scrollbar.html +6 -0
  125. package/htmldialogs/SelectableIndicatorParameter.html +9 -0
  126. package/htmldialogs/ShapeContextMenu.html +7 -0
  127. package/htmldialogs/ShapeFibonacciSettingsDialog.html +261 -0
  128. package/htmldialogs/ShapePositionSettingsDialog.html +351 -0
  129. package/htmldialogs/ShapeSettingsDialog.html +521 -0
  130. package/htmldialogs/TimeFrameChangePopup.html +11 -0
  131. package/htmldialogs/TimeIndicatorParameterControl.html +89 -0
  132. package/htmldialogs/Toolbar.html +1710 -0
  133. package/htmldialogs/TooltipView.html +151 -0
  134. package/htmldialogs/TradingContextMenu.html +2 -0
  135. package/img/ContextMenuCheckbox.png +0 -0
  136. package/img/cross-hairs.cur +0 -0
  137. package/img/eu.png +0 -0
  138. package/img/favicon/favicon.ico +0 -0
  139. package/img/fist.cur +0 -0
  140. package/img/point.cur +0 -0
  141. package/img/svg-icons/Illustration-License-b.svg +1 -0
  142. package/img/svg-icons/Illustration-License-w.svg +1 -0
  143. package/img/svg-icons/abcd-label-pattern.svg +1 -0
  144. package/img/svg-icons/abcd-pattern.svg +1 -0
  145. package/img/svg-icons/add.svg +1 -0
  146. package/img/svg-icons/adjust-OHLC.svg +1 -0
  147. package/img/svg-icons/adjust-all.svg +1 -0
  148. package/img/svg-icons/andrews-pitchfork.svg +1 -0
  149. package/img/svg-icons/arrow-down.svg +1 -0
  150. package/img/svg-icons/arrow-left.svg +3 -0
  151. package/img/svg-icons/arrow-right.svg +3 -0
  152. package/img/svg-icons/arrow-type-type.svg +3 -0
  153. package/img/svg-icons/arrow-up.svg +1 -0
  154. package/img/svg-icons/arrow.svg +1 -0
  155. package/img/svg-icons/balloon.svg +1 -0
  156. package/img/svg-icons/brand-x.svg +1 -0
  157. package/img/svg-icons/calculator.svg +15 -0
  158. package/img/svg-icons/chartType-area.svg +1 -0
  159. package/img/svg-icons/chartType-bars.svg +1 -0
  160. package/img/svg-icons/chartType-candles-volume.svg +1 -0
  161. package/img/svg-icons/chartType-candles.svg +1 -0
  162. package/img/svg-icons/chartType-colored-bars.svg +1 -0
  163. package/img/svg-icons/chartType-equi-volume-shadow.svg +1 -0
  164. package/img/svg-icons/chartType-equi-volume.svg +1 -0
  165. package/img/svg-icons/chartType-heikin-ashi.svg +1 -0
  166. package/img/svg-icons/chartType-hollow-candles.svg +1 -0
  167. package/img/svg-icons/chartType-kagi.svg +1 -0
  168. package/img/svg-icons/chartType-line-break.svg +1 -0
  169. package/img/svg-icons/chartType-line.svg +1 -0
  170. package/img/svg-icons/chartType-point-figure.svg +1 -0
  171. package/img/svg-icons/chartType-range-bars.svg +1 -0
  172. package/img/svg-icons/chartType-renko.svg +1 -0
  173. package/img/svg-icons/chevron-right-double.svg +3 -0
  174. package/img/svg-icons/chevron.svg +3 -0
  175. package/img/svg-icons/circle.svg +1 -0
  176. package/img/svg-icons/close-floating-toolbar.svg +1 -0
  177. package/img/svg-icons/close-pane.svg +1 -0
  178. package/img/svg-icons/close-rect.svg +4 -0
  179. package/img/svg-icons/close-windows.svg +1 -0
  180. package/img/svg-icons/close.svg +4 -0
  181. package/img/svg-icons/compare.svg +1 -0
  182. package/img/svg-icons/copy.svg +1 -0
  183. package/img/svg-icons/cursorType-arrow-with-labels.svg +1 -0
  184. package/img/svg-icons/cursorType-arrow.svg +3 -0
  185. package/img/svg-icons/cursorType-crosshairs.svg +1 -0
  186. package/img/svg-icons/cursorType-point.svg +1 -0
  187. package/img/svg-icons/cyclic-lines.svg +1 -0
  188. package/img/svg-icons/default-screen.svg +11 -0
  189. package/img/svg-icons/demo-popup-bg.svg +1 -0
  190. package/img/svg-icons/diamond.svg +1 -0
  191. package/img/svg-icons/dot.svg +1 -0
  192. package/img/svg-icons/drag.svg +1 -0
  193. package/img/svg-icons/elliott-wave-pattern.svg +1 -0
  194. package/img/svg-icons/ellipse.svg +1 -0
  195. package/img/svg-icons/error-channel.svg +1 -0
  196. package/img/svg-icons/export.svg +1 -0
  197. package/img/svg-icons/extended-line.svg +3 -0
  198. package/img/svg-icons/fibonacci-arcs.svg +1 -0
  199. package/img/svg-icons/fibonacci-ellipses.svg +1 -0
  200. package/img/svg-icons/fibonacci-extensions.svg +1 -0
  201. package/img/svg-icons/fibonacci-fan.svg +1 -0
  202. package/img/svg-icons/fibonacci-retracements.svg +1 -0
  203. package/img/svg-icons/fibonacci-time-zones.svg +1 -0
  204. package/img/svg-icons/fintatech.svg +1 -0
  205. package/img/svg-icons/free-hand.svg +1 -0
  206. package/img/svg-icons/full-screen.svg +11 -0
  207. package/img/svg-icons/full-windows.svg +12 -0
  208. package/img/svg-icons/gann-fan.svg +1 -0
  209. package/img/svg-icons/general-delete.svg +3 -0
  210. package/img/svg-icons/head-shoulders-pattern.svg +1 -0
  211. package/img/svg-icons/horizontal-line.svg +1 -0
  212. package/img/svg-icons/horizontal-ray.svg +3 -0
  213. package/img/svg-icons/html-code.svg +1 -0
  214. package/img/svg-icons/image.svg +5 -0
  215. package/img/svg-icons/images.svg +1 -0
  216. package/img/svg-icons/in-shape-mode.svg +1 -0
  217. package/img/svg-icons/insert-indicator.svg +1 -0
  218. package/img/svg-icons/kings-crown-pattern.svg +1 -0
  219. package/img/svg-icons/latest-position.svg +1 -0
  220. package/img/svg-icons/line-segment.svg +1 -0
  221. package/img/svg-icons/link.svg +5 -0
  222. package/img/svg-icons/lock.svg +3 -0
  223. package/img/svg-icons/magnet-mode.svg +1 -0
  224. package/img/svg-icons/measure.svg +1 -0
  225. package/img/svg-icons/multiply-link.svg +5 -0
  226. package/img/svg-icons/note.svg +1 -0
  227. package/img/svg-icons/number-label-pattern.svg +1 -0
  228. package/img/svg-icons/open-OHLC-pane.svg +1 -0
  229. package/img/svg-icons/options.svg +1 -0
  230. package/img/svg-icons/period.svg +1 -0
  231. package/img/svg-icons/polygon.svg +1 -0
  232. package/img/svg-icons/polyline.svg +1 -0
  233. package/img/svg-icons/position-long.svg +90 -0
  234. package/img/svg-icons/position-long_og.svg +81 -0
  235. package/img/svg-icons/position-short.svg +90 -0
  236. package/img/svg-icons/position-short_og.svg +89 -0
  237. package/img/svg-icons/quadrant-lines.svg +1 -0
  238. package/img/svg-icons/raff-regression.svg +1 -0
  239. package/img/svg-icons/ray.svg +3 -0
  240. package/img/svg-icons/rectangle.svg +1 -0
  241. package/img/svg-icons/redo-new.svg +3 -0
  242. package/img/svg-icons/redo.svg +1 -0
  243. package/img/svg-icons/remove-all-indicators.svg +1 -0
  244. package/img/svg-icons/remove-all-shapes.svg +1 -0
  245. package/img/svg-icons/replay-jump.svg +1 -0
  246. package/img/svg-icons/replay-pause.svg +1 -0
  247. package/img/svg-icons/replay-play.svg +1 -0
  248. package/img/svg-icons/replay-skip-end.svg +1 -0
  249. package/img/svg-icons/replay-skip-one.svg +1 -0
  250. package/img/svg-icons/save-as-image.svg +1 -0
  251. package/img/svg-icons/screenshot.svg +5 -0
  252. package/img/svg-icons/scroll-bottom.svg +1 -0
  253. package/img/svg-icons/scroll-left.svg +1 -0
  254. package/img/svg-icons/scroll-right.svg +1 -0
  255. package/img/svg-icons/scroll-top.svg +1 -0
  256. package/img/svg-icons/search.svg +1 -0
  257. package/img/svg-icons/speed-lines.svg +1 -0
  258. package/img/svg-icons/square.svg +1 -0
  259. package/img/svg-icons/star.svg +4 -0
  260. package/img/svg-icons/stash.svg +4 -0
  261. package/img/svg-icons/stick-to-bar.svg +1 -0
  262. package/img/svg-icons/stick-to-close.svg +1 -0
  263. package/img/svg-icons/stick-to-high.svg +1 -0
  264. package/img/svg-icons/stick-to-low.svg +1 -0
  265. package/img/svg-icons/stick-to-open.svg +1 -0
  266. package/img/svg-icons/sticky-mode-off.svg +1 -0
  267. package/img/svg-icons/tcdPane-alert-indicator.svg +1 -0
  268. package/img/svg-icons/tcdPane-close.svg +1 -0
  269. package/img/svg-icons/tcdPane-down.svg +1 -0
  270. package/img/svg-icons/tcdPane-expand-closed.svg +1 -0
  271. package/img/svg-icons/tcdPane-expand.svg +1 -0
  272. package/img/svg-icons/tcdPane-maximize.svg +1 -0
  273. package/img/svg-icons/tcdPane-options.svg +1 -0
  274. package/img/svg-icons/tcdPane-remove-indicator.svg +1 -0
  275. package/img/svg-icons/tcdPane-restore.svg +1 -0
  276. package/img/svg-icons/tcdPane-toggle.svg +1 -0
  277. package/img/svg-icons/tcdPane-up.svg +1 -0
  278. package/img/svg-icons/template-delete.svg +1 -0
  279. package/img/svg-icons/template-edit.svg +1 -0
  280. package/img/svg-icons/template-ok.svg +1 -0
  281. package/img/svg-icons/template.svg +1 -0
  282. package/img/svg-icons/text-editor-b.svg +1 -0
  283. package/img/svg-icons/text-editor-i.svg +1 -0
  284. package/img/svg-icons/text-editor-u.svg +1 -0
  285. package/img/svg-icons/text.svg +1 -0
  286. package/img/svg-icons/tirone-levels.svg +1 -0
  287. package/img/svg-icons/toggle-shapes.svg +1 -0
  288. package/img/svg-icons/trade-manager.svg +1 -0
  289. package/img/svg-icons/trend-angle.svg +1 -0
  290. package/img/svg-icons/trend-channel.svg +1 -0
  291. package/img/svg-icons/triangle-pattern.svg +1 -0
  292. package/img/svg-icons/triangle.svg +1 -0
  293. package/img/svg-icons/undo-new.svg +3 -0
  294. package/img/svg-icons/undo.svg +1 -0
  295. package/img/svg-icons/unlock.svg +3 -0
  296. package/img/svg-icons/vertical-line.svg +1 -0
  297. package/img/svg-icons/visibleProfile.svg +1 -0
  298. package/img/svg-icons/web-link.svg +1 -0
  299. package/img/svg-icons/x.svg +3 -0
  300. package/img/svg-icons/xabcd-pattern.svg +1 -0
  301. package/img/svg-icons/zoom-by-area.svg +1 -0
  302. package/img/svg-icons/zoom.svg +1 -0
  303. package/img/usa.png +0 -0
  304. package/index-dark.html +132 -0
  305. package/index.html +229 -0
  306. package/localization/en.json +1646 -0
  307. package/localization/uk.json +1597 -0
  308. package/multiple-charts.html +162 -0
  309. package/package.json +62 -0
  310. package/scripts/FintaChart.min.js +70 -0
  311. package/scripts/frameworks/Intl.min.js +4 -0
  312. package/scripts/frameworks/bootstrap.v3.datetimepicker.min.js +2605 -0
  313. package/scripts/frameworks/detectizr.min.js +1 -0
  314. package/scripts/frameworks/dom-to-image-more.min.js +3 -0
  315. package/scripts/frameworks/i18nextXHRBackend.min.js +1 -0
  316. package/scripts/frameworks/jquery-i18next.min.js +1 -0
  317. package/scripts/frameworks/jquery-ui.min.js +8 -0
  318. package/scripts/frameworks/jquery.min.js +3 -0
  319. package/scripts/frameworks/jquery.ui.touch-punch.min.js +1 -0
  320. package/scripts/frameworks/moment.min.js +1216 -0
  321. package/scripts/frameworks-modified/bootstrap-select.js +1024 -0
  322. package/scripts/frameworks-modified/i18next.js +2075 -0
  323. package/scripts/frameworks-modified/jquery.autocolumnlist.js +48 -0
  324. package/scripts/frameworks-modified/jquery.resizable.js +229 -0
  325. package/scripts/frameworks-modified/spectrum.js +2279 -0
  326. package/scripts/frameworks-modified/switchery.js +1957 -0
  327. package/scripts/frameworks-modified/toastr.js +414 -0
  328. package/scripts/jsdataadapters/fileDataAdapter.js +129 -0
  329. package/scripts/jsdataadapters/restDataAdapter.js +149 -0
  330. package/scripts/jsdataadapters/webSocketDataAdapter.js +114 -0
  331. package/scripts/miscs/templateFileDataAdapter.js +17 -0
  332. package/scripts/themes/beetTheme.js +2999 -0
  333. package/scripts/themes/darkTheme.js +3004 -0
  334. package/scripts/themes/defaultTheme.js +3095 -0
  335. package/scripts/themes/fintatechDarkTheme.js +3005 -0
  336. package/scripts/themes/grayTheme.js +3004 -0
  337. package/scripts/themes/oliveTheme.js +3004 -0
  338. package/scripts/themes/orangeTheme.js +3004 -0
  339. package/scripts/themes/purpleTheme.js +3004 -0
  340. package/scripts/themes/skyTheme.js +3009 -0
  341. package/scripts/themes/tealTheme.js +3004 -0
@@ -0,0 +1,2075 @@
1
+ 'use strict';
2
+
3
+ var FintaChart;
4
+ (function (FintaChart) {
5
+ var External;
6
+ (function (External) {
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9
+ typeof define === 'function' && define.amd ? define(factory) :
10
+ (global.i18next = factory());
11
+ }(window, (function () {
12
+
13
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
14
+ return typeof obj;
15
+ } : function (obj) {
16
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
17
+ };
18
+
19
+ var classCallCheck = function (instance, Constructor) {
20
+ if (!(instance instanceof Constructor)) {
21
+ throw new TypeError("Cannot call a class as a function");
22
+ }
23
+ };
24
+
25
+ var _extends = Object.assign || function (target) {
26
+ for (var i = 1; i < arguments.length; i++) {
27
+ var source = arguments[i];
28
+
29
+ for (var key in source) {
30
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
31
+ target[key] = source[key];
32
+ }
33
+ }
34
+ }
35
+
36
+ return target;
37
+ };
38
+
39
+ var inherits = function (subClass, superClass) {
40
+ if (typeof superClass !== "function" && superClass !== null) {
41
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
42
+ }
43
+
44
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
45
+ constructor: {
46
+ value: subClass,
47
+ enumerable: false,
48
+ writable: true,
49
+ configurable: true
50
+ }
51
+ });
52
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
53
+ };
54
+
55
+ var possibleConstructorReturn = function (self, call) {
56
+ if (!self) {
57
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
58
+ }
59
+
60
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
61
+ };
62
+
63
+ var slicedToArray = function () {
64
+ function sliceIterator(arr, i) {
65
+ var _arr = [];
66
+ var _n = true;
67
+ var _d = false;
68
+ var _e = undefined;
69
+
70
+ try {
71
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
72
+ _arr.push(_s.value);
73
+
74
+ if (i && _arr.length === i) break;
75
+ }
76
+ } catch (err) {
77
+ _d = true;
78
+ _e = err;
79
+ } finally {
80
+ try {
81
+ if (!_n && _i["return"]) _i["return"]();
82
+ } finally {
83
+ if (_d) throw _e;
84
+ }
85
+ }
86
+
87
+ return _arr;
88
+ }
89
+
90
+ return function (arr, i) {
91
+ if (Array.isArray(arr)) {
92
+ return arr;
93
+ } else if (Symbol.iterator in Object(arr)) {
94
+ return sliceIterator(arr, i);
95
+ } else {
96
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
97
+ }
98
+ };
99
+ }();
100
+
101
+ var consoleLogger = {
102
+ type: 'logger',
103
+
104
+ log: function log(args) {
105
+ this._output('log', args);
106
+ },
107
+ warn: function warn(args) {
108
+ this._output('warn', args);
109
+ },
110
+ error: function error(args) {
111
+ this._output('error', args);
112
+ },
113
+ _output: function _output(type, args) {
114
+ if (console && console[type]) console[type].apply(console, Array.prototype.slice.call(args));
115
+ }
116
+ };
117
+
118
+ var Logger = function () {
119
+ function Logger(concreteLogger) {
120
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
121
+ classCallCheck(this, Logger);
122
+
123
+ this.init(concreteLogger, options);
124
+ }
125
+
126
+ Logger.prototype.init = function init(concreteLogger) {
127
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
128
+
129
+ this.prefix = options.prefix || 'i18next:';
130
+ this.logger = concreteLogger || consoleLogger;
131
+ this.options = options;
132
+ this.debug = options.debug === false ? false : true;
133
+ };
134
+
135
+ Logger.prototype.setDebug = function setDebug(bool) {
136
+ this.debug = bool;
137
+ };
138
+
139
+ Logger.prototype.log = function log() {
140
+ this.forward(arguments, 'log', '', true);
141
+ };
142
+
143
+ Logger.prototype.warn = function warn() {
144
+ this.forward(arguments, 'warn', '', true);
145
+ };
146
+
147
+ Logger.prototype.error = function error() {
148
+ this.forward(arguments, 'error', '');
149
+ };
150
+
151
+ Logger.prototype.deprecate = function deprecate() {
152
+ this.forward(arguments, 'warn', 'WARNING DEPRECATED: ', true);
153
+ };
154
+
155
+ Logger.prototype.forward = function forward(args, lvl, prefix, debugOnly) {
156
+ if (debugOnly && !this.debug) return;
157
+ if (typeof args[0] === 'string') args[0] = prefix + this.prefix + ' ' + args[0];
158
+ this.logger[lvl](args);
159
+ };
160
+
161
+ Logger.prototype.create = function create(moduleName) {
162
+ var sub = new Logger(this.logger, _extends({ prefix: this.prefix + ':' + moduleName + ':' }, this.options));
163
+
164
+ return sub;
165
+ };
166
+
167
+ // createInstance(options = {}) {
168
+ // return new Logger(options, callback);
169
+ // }
170
+
171
+ return Logger;
172
+ }();
173
+
174
+ var baseLogger = new Logger();
175
+
176
+ var EventEmitter = function () {
177
+ function EventEmitter() {
178
+ classCallCheck(this, EventEmitter);
179
+
180
+ this.observers = {};
181
+ }
182
+
183
+ EventEmitter.prototype.on = function on(events, listener) {
184
+ var _this = this;
185
+
186
+ events.split(' ').forEach(function (event) {
187
+ _this.observers[event] = _this.observers[event] || [];
188
+ _this.observers[event].push(listener);
189
+ });
190
+ };
191
+
192
+ EventEmitter.prototype.off = function off(event, listener) {
193
+ var _this2 = this;
194
+
195
+ if (!this.observers[event]) {
196
+ return;
197
+ }
198
+
199
+ this.observers[event].forEach(function () {
200
+ if (!listener) {
201
+ delete _this2.observers[event];
202
+ } else {
203
+ var index = _this2.observers[event].indexOf(listener);
204
+ if (index > -1) {
205
+ _this2.observers[event].splice(index, 1);
206
+ }
207
+ }
208
+ });
209
+ };
210
+
211
+ EventEmitter.prototype.emit = function emit(event) {
212
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
213
+ args[_key - 1] = arguments[_key];
214
+ }
215
+
216
+ if (this.observers[event]) {
217
+ var cloned = [].concat(this.observers[event]);
218
+ cloned.forEach(function (observer) {
219
+ observer.apply(undefined, args);
220
+ });
221
+ }
222
+
223
+ if (this.observers['*']) {
224
+ var _cloned = [].concat(this.observers['*']);
225
+ _cloned.forEach(function (observer) {
226
+ var _ref;
227
+
228
+ observer.apply(observer, (_ref = [event]).concat.apply(_ref, args));
229
+ });
230
+ }
231
+ };
232
+
233
+ return EventEmitter;
234
+ }();
235
+
236
+ function makeString(object) {
237
+ if (object == null) return '';
238
+ return '' + object;
239
+ }
240
+
241
+ function copy(a, s, t) {
242
+ a.forEach(function (m) {
243
+ if (s[m]) t[m] = s[m];
244
+ });
245
+ }
246
+
247
+ function getLastOfPath(object, path, Empty) {
248
+ function cleanKey(key) {
249
+ return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key;
250
+ }
251
+
252
+ var stack = typeof path !== 'string' ? [].concat(path) : path.split('.');
253
+ while (stack.length > 1) {
254
+ if (!object) return {};
255
+
256
+ var key = cleanKey(stack.shift());
257
+ if (!object[key] && Empty) object[key] = new Empty();
258
+ object = object[key];
259
+ }
260
+
261
+ if (!object) return {};
262
+ return {
263
+ obj: object,
264
+ k: cleanKey(stack.shift())
265
+ };
266
+ }
267
+
268
+ function setPath(object, path, newValue) {
269
+ var _getLastOfPath = getLastOfPath(object, path, Object),
270
+ obj = _getLastOfPath.obj,
271
+ k = _getLastOfPath.k;
272
+
273
+ obj[k] = newValue;
274
+ }
275
+
276
+ function pushPath(object, path, newValue, concat) {
277
+ var _getLastOfPath2 = getLastOfPath(object, path, Object),
278
+ obj = _getLastOfPath2.obj,
279
+ k = _getLastOfPath2.k;
280
+
281
+ obj[k] = obj[k] || [];
282
+ if (concat) obj[k] = obj[k].concat(newValue);
283
+ if (!concat) obj[k].push(newValue);
284
+ }
285
+
286
+ function getPath(object, path) {
287
+ var _getLastOfPath3 = getLastOfPath(object, path),
288
+ obj = _getLastOfPath3.obj,
289
+ k = _getLastOfPath3.k;
290
+
291
+ if (!obj) return undefined;
292
+ return obj[k];
293
+ }
294
+
295
+ function deepExtend(target, source, overwrite) {
296
+ for (var prop in source) {
297
+ if (prop in target) {
298
+ // If we reached a leaf string in target or source then replace with source or skip depending on the 'overwrite' switch
299
+ if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) {
300
+ if (overwrite) target[prop] = source[prop];
301
+ } else {
302
+ deepExtend(target[prop], source[prop], overwrite);
303
+ }
304
+ } else {
305
+ target[prop] = source[prop];
306
+ }
307
+ }return target;
308
+ }
309
+
310
+ function regexEscape(str) {
311
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
312
+ }
313
+
314
+ /* eslint-disable */
315
+ var _entityMap = {
316
+ "&": "&amp;",
317
+ "<": "&lt;",
318
+ ">": "&gt;",
319
+ '"': '&quot;',
320
+ "'": '&#39;',
321
+ "/": '&#x2F;'
322
+ };
323
+ /* eslint-enable */
324
+
325
+ function escape(data) {
326
+ if (typeof data === 'string') {
327
+ return data.replace(/[&<>"'\/]/g, function (s) {
328
+ return _entityMap[s];
329
+ });
330
+ } else {
331
+ return data;
332
+ }
333
+ }
334
+
335
+ var ResourceStore = function (_EventEmitter) {
336
+ inherits(ResourceStore, _EventEmitter);
337
+
338
+ function ResourceStore() {
339
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
340
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { ns: ['translation'], defaultNS: 'translation' };
341
+ classCallCheck(this, ResourceStore);
342
+
343
+ var _this = possibleConstructorReturn(this, _EventEmitter.call(this));
344
+
345
+ _this.data = data;
346
+ _this.options = options;
347
+ return _this;
348
+ }
349
+
350
+ ResourceStore.prototype.addNamespaces = function addNamespaces(ns) {
351
+ if (this.options.ns.indexOf(ns) < 0) {
352
+ this.options.ns.push(ns);
353
+ }
354
+ };
355
+
356
+ ResourceStore.prototype.removeNamespaces = function removeNamespaces(ns) {
357
+ var index = this.options.ns.indexOf(ns);
358
+ if (index > -1) {
359
+ this.options.ns.splice(index, 1);
360
+ }
361
+ };
362
+
363
+ ResourceStore.prototype.getResource = function getResource(lng, ns, key) {
364
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
365
+
366
+ var keySeparator = options.keySeparator || this.options.keySeparator;
367
+ if (keySeparator === undefined) keySeparator = '.';
368
+
369
+ var path = [lng, ns];
370
+ if (key && typeof key !== 'string') path = path.concat(key);
371
+ if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key);
372
+
373
+ if (lng.indexOf('.') > -1) {
374
+ path = lng.split('.');
375
+ }
376
+
377
+ return getPath(this.data, path);
378
+ };
379
+
380
+ ResourceStore.prototype.addResource = function addResource(lng, ns, key, value) {
381
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : { silent: false };
382
+
383
+ var keySeparator = this.options.keySeparator;
384
+ if (keySeparator === undefined) keySeparator = '.';
385
+
386
+ var path = [lng, ns];
387
+ if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
388
+
389
+ if (lng.indexOf('.') > -1) {
390
+ path = lng.split('.');
391
+ value = ns;
392
+ ns = path[1];
393
+ }
394
+
395
+ this.addNamespaces(ns);
396
+
397
+ setPath(this.data, path, value);
398
+
399
+ if (!options.silent) this.emit('added', lng, ns, key, value);
400
+ };
401
+
402
+ ResourceStore.prototype.addResources = function addResources(lng, ns, resources) {
403
+ for (var m in resources) {
404
+ if (typeof resources[m] === 'string') this.addResource(lng, ns, m, resources[m], { silent: true });
405
+ }
406
+ this.emit('added', lng, ns, resources);
407
+ };
408
+
409
+ ResourceStore.prototype.addResourceBundle = function addResourceBundle(lng, ns, resources, deep, overwrite) {
410
+ var path = [lng, ns];
411
+ if (lng.indexOf('.') > -1) {
412
+ path = lng.split('.');
413
+ deep = resources;
414
+ resources = ns;
415
+ ns = path[1];
416
+ }
417
+
418
+ this.addNamespaces(ns);
419
+
420
+ var pack = getPath(this.data, path) || {};
421
+
422
+ if (deep) {
423
+ deepExtend(pack, resources, overwrite);
424
+ } else {
425
+ pack = _extends({}, pack, resources);
426
+ }
427
+
428
+ setPath(this.data, path, pack);
429
+
430
+ this.emit('added', lng, ns, resources);
431
+ };
432
+
433
+ ResourceStore.prototype.removeResourceBundle = function removeResourceBundle(lng, ns) {
434
+ if (this.hasResourceBundle(lng, ns)) {
435
+ delete this.data[lng][ns];
436
+ }
437
+ this.removeNamespaces(ns);
438
+
439
+ this.emit('removed', lng, ns);
440
+ };
441
+
442
+ ResourceStore.prototype.hasResourceBundle = function hasResourceBundle(lng, ns) {
443
+ return this.getResource(lng, ns) !== undefined;
444
+ };
445
+
446
+ ResourceStore.prototype.getResourceBundle = function getResourceBundle(lng, ns) {
447
+ if (!ns) ns = this.options.defaultNS;
448
+
449
+ // TODO: COMPATIBILITY remove extend in v2.1.0
450
+ if (this.options.compatibilityAPI === 'v1') return _extends({}, this.getResource(lng, ns));
451
+
452
+ return this.getResource(lng, ns);
453
+ };
454
+
455
+ ResourceStore.prototype.toJSON = function toJSON() {
456
+ return this.data;
457
+ };
458
+
459
+ return ResourceStore;
460
+ }(EventEmitter);
461
+
462
+ var postProcessor = {
463
+
464
+ processors: {},
465
+
466
+ addPostProcessor: function addPostProcessor(module) {
467
+ this.processors[module.name] = module;
468
+ },
469
+ handle: function handle(processors, value, key, options, translator) {
470
+ var _this = this;
471
+
472
+ processors.forEach(function (processor) {
473
+ if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator);
474
+ });
475
+
476
+ return value;
477
+ }
478
+ };
479
+
480
+ function convertInterpolation(options) {
481
+
482
+ options.interpolation = {
483
+ unescapeSuffix: 'HTML'
484
+ };
485
+
486
+ options.interpolation.prefix = options.interpolationPrefix || '__';
487
+ options.interpolation.suffix = options.interpolationSuffix || '__';
488
+ options.interpolation.escapeValue = options.escapeInterpolation || false;
489
+
490
+ options.interpolation.nestingPrefix = options.reusePrefix || '$t(';
491
+ options.interpolation.nestingSuffix = options.reuseSuffix || ')';
492
+
493
+ return options;
494
+ }
495
+
496
+ function convertAPIOptions(options) {
497
+ if (options.resStore) options.resources = options.resStore;
498
+
499
+ if (options.ns && options.ns.defaultNs) {
500
+ options.defaultNS = options.ns.defaultNs;
501
+ options.ns = options.ns.namespaces;
502
+ } else {
503
+ options.defaultNS = options.ns || 'translation';
504
+ }
505
+
506
+ if (options.fallbackToDefaultNS && options.defaultNS) options.fallbackNS = options.defaultNS;
507
+
508
+ options.saveMissing = options.sendMissing;
509
+ options.saveMissingTo = options.sendMissingTo || 'current';
510
+ options.returnNull = options.fallbackOnNull ? false : true;
511
+ options.returnEmptyString = options.fallbackOnEmpty ? false : true;
512
+ options.returnObjects = options.returnObjectTrees;
513
+ options.joinArrays = '\n';
514
+
515
+ options.returnedObjectHandler = options.objectTreeKeyHandler;
516
+ options.parseMissingKeyHandler = options.parseMissingKey;
517
+ options.appendNamespaceToMissingKey = true;
518
+
519
+ options.nsSeparator = options.nsseparator || ':';
520
+ options.keySeparator = options.keyseparator || '.';
521
+
522
+ if (options.shortcutFunction === 'sprintf') {
523
+ options.overloadTranslationOptionHandler = function (args) {
524
+ var values = [];
525
+
526
+ for (var i = 1; i < args.length; i++) {
527
+ values.push(args[i]);
528
+ }
529
+
530
+ return {
531
+ postProcess: 'sprintf',
532
+ sprintf: values
533
+ };
534
+ };
535
+ }
536
+
537
+ options.whitelist = options.lngWhitelist;
538
+ options.preload = options.preload;
539
+ if (options.load === 'current') options.load = 'currentOnly';
540
+ if (options.load === 'unspecific') options.load = 'languageOnly';
541
+
542
+ // backend
543
+ options.backend = options.backend || {};
544
+ options.backend.loadPath = options.resGetPath || 'locales/__lng__/__ns__.json';
545
+ options.backend.addPath = options.resPostPath || 'locales/add/__lng__/__ns__';
546
+ options.backend.allowMultiLoading = options.dynamicLoad;
547
+
548
+ // cache
549
+ options.cache = options.cache || {};
550
+ options.cache.prefix = 'res_';
551
+ options.cache.expirationTime = 7 * 24 * 60 * 60 * 1000;
552
+ options.cache.enabled = options.useLocalStorage ? true : false;
553
+
554
+ options = convertInterpolation(options);
555
+ if (options.defaultVariables) options.interpolation.defaultVariables = options.defaultVariables;
556
+
557
+ // TODO: deprecation
558
+ // if (options.getAsync === false) throw deprecation error
559
+
560
+ return options;
561
+ }
562
+
563
+ function convertJSONOptions(options) {
564
+ options = convertInterpolation(options);
565
+ options.joinArrays = '\n';
566
+
567
+ return options;
568
+ }
569
+
570
+ function convertTOptions(options) {
571
+ if (options.interpolationPrefix || options.interpolationSuffix || options.escapeInterpolation) {
572
+ options = convertInterpolation(options);
573
+ }
574
+
575
+ options.nsSeparator = options.nsseparator;
576
+ options.keySeparator = options.keyseparator;
577
+
578
+ options.returnObjects = options.returnObjectTrees;
579
+
580
+ return options;
581
+ }
582
+
583
+ function appendBackwardsAPI(i18n) {
584
+ i18n.lng = function () {
585
+ baseLogger.deprecate('i18next.lng() can be replaced by i18next.language for detected language or i18next.languages for languages ordered by translation lookup.');
586
+ return i18n.services.languageUtils.toResolveHierarchy(i18n.language)[0];
587
+ };
588
+
589
+ i18n.preload = function (lngs, cb) {
590
+ baseLogger.deprecate('i18next.preload() can be replaced with i18next.loadLanguages()');
591
+ i18n.loadLanguages(lngs, cb);
592
+ };
593
+
594
+ i18n.setLng = function (lng, options, callback) {
595
+ baseLogger.deprecate('i18next.setLng() can be replaced with i18next.changeLanguage() or i18next.getFixedT() to get a translation function with fixed language or namespace.');
596
+ if (typeof options === 'function') {
597
+ callback = options;
598
+ options = {};
599
+ }
600
+ if (!options) options = {};
601
+
602
+ if (options.fixLng === true) {
603
+ if (callback) return callback(null, i18n.getFixedT(lng));
604
+ }
605
+
606
+ i18n.changeLanguage(lng, callback);
607
+ };
608
+
609
+ i18n.addPostProcessor = function (name, fc) {
610
+ baseLogger.deprecate('i18next.addPostProcessor() can be replaced by i18next.use({ type: \'postProcessor\', name: \'name\', process: fc })');
611
+ i18n.use({
612
+ type: 'postProcessor',
613
+ name: name,
614
+ process: fc
615
+ });
616
+ };
617
+ }
618
+
619
+ var Translator = function (_EventEmitter) {
620
+ inherits(Translator, _EventEmitter);
621
+
622
+ function Translator(services) {
623
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
624
+ classCallCheck(this, Translator);
625
+
626
+ var _this = possibleConstructorReturn(this, _EventEmitter.call(this));
627
+
628
+ copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector'], services, _this);
629
+
630
+ _this.options = options;
631
+ _this.logger = baseLogger.create('translator');
632
+ return _this;
633
+ }
634
+
635
+ Translator.prototype.changeLanguage = function changeLanguage(lng) {
636
+ if (lng) this.language = lng;
637
+ };
638
+
639
+ Translator.prototype.exists = function exists(key) {
640
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { interpolation: {} };
641
+
642
+ if (this.options.compatibilityAPI === 'v1') {
643
+ options = convertTOptions(options);
644
+ }
645
+
646
+ return this.resolve(key, options) !== undefined;
647
+ };
648
+
649
+ Translator.prototype.extractFromKey = function extractFromKey(key, options) {
650
+ var nsSeparator = options.nsSeparator || this.options.nsSeparator;
651
+ if (nsSeparator === undefined) nsSeparator = ':';
652
+ var keySeparator = options.keySeparator || this.options.keySeparator || '.';
653
+
654
+ var namespaces = options.ns || this.options.defaultNS;
655
+ if (nsSeparator && key.indexOf(nsSeparator) > -1) {
656
+ var parts = key.split(nsSeparator);
657
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
658
+ key = parts.join(keySeparator);
659
+ }
660
+ if (typeof namespaces === 'string') namespaces = [namespaces];
661
+
662
+ return {
663
+ key: key,
664
+ namespaces: namespaces
665
+ };
666
+ };
667
+
668
+ Translator.prototype.translate = function translate(keys) {
669
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
670
+
671
+ if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') {
672
+ options = this.options.overloadTranslationOptionHandler(arguments);
673
+ } else if (this.options.compatibilityAPI === 'v1') {
674
+ options = convertTOptions(options);
675
+ }
676
+
677
+ // non valid keys handling
678
+ if (keys === undefined || keys === null || keys === '') return '';
679
+ if (typeof keys === 'number') keys = String(keys);
680
+ if (typeof keys === 'string') keys = [keys];
681
+
682
+ // separators
683
+ var keySeparator = options.keySeparator || this.options.keySeparator || '.';
684
+
685
+ // get namespace(s)
686
+
687
+ var _extractFromKey = this.extractFromKey(keys[keys.length - 1], options),
688
+ key = _extractFromKey.key,
689
+ namespaces = _extractFromKey.namespaces;
690
+
691
+ var namespace = namespaces[namespaces.length - 1];
692
+
693
+ // return key on CIMode
694
+ var lng = options.lng || this.language;
695
+ var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
696
+ if (lng && lng.toLowerCase() === 'cimode') {
697
+ if (appendNamespaceToCIMode) {
698
+ var nsSeparator = options.nsSeparator || this.options.nsSeparator;
699
+ return namespace + nsSeparator + key;
700
+ }
701
+
702
+ return key;
703
+ }
704
+
705
+ // resolve from store
706
+ var res = this.resolve(keys, options);
707
+
708
+ var resType = Object.prototype.toString.apply(res);
709
+ var noObject = ['[object Number]', '[object Function]', '[object RegExp]'];
710
+ var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays;
711
+
712
+ // object
713
+ if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) {
714
+ if (!options.returnObjects && !this.options.returnObjects) {
715
+ this.logger.warn('accessing an object - but returnObjects options is not enabled!');
716
+ return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(key, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.';
717
+ }
718
+
719
+ // if we got a separator we loop over children - else we just return object as is
720
+ // as having it set to false means no hierarchy so no lookup for nested values
721
+ if (options.keySeparator || this.options.keySeparator) {
722
+ var copy$$1 = resType === '[object Array]' ? [] : {}; // apply child translation on a copy
723
+
724
+ for (var m in res) {
725
+ copy$$1[m] = this.translate('' + key + keySeparator + m, _extends({}, options, { joinArrays: false, ns: namespaces }));
726
+ }
727
+ res = copy$$1;
728
+ }
729
+ }
730
+ // array special treatment
731
+ else if (joinArrays && resType === '[object Array]') {
732
+ res = res.join(joinArrays);
733
+ if (res) res = this.extendTranslation(res, key, options);
734
+ }
735
+ // string, empty or null
736
+ else {
737
+ var usedDefault = false,
738
+ usedKey = false;
739
+
740
+ // fallback value
741
+ if (!this.isValidLookup(res) && options.defaultValue !== undefined) {
742
+ usedDefault = true;
743
+ res = options.defaultValue;
744
+ }
745
+ if (!this.isValidLookup(res)) {
746
+ usedKey = true;
747
+ res = key;
748
+ }
749
+
750
+ // save missing
751
+ if (usedKey || usedDefault) {
752
+ this.logger.log('missingKey', lng, namespace, key, res);
753
+
754
+ var lngs = [];
755
+ var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
756
+ if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) {
757
+ for (var i = 0; i < fallbackLngs.length; i++) {
758
+ lngs.push(fallbackLngs[i]);
759
+ }
760
+ } else if (this.options.saveMissingTo === 'all') {
761
+ lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
762
+ } else {
763
+ //(this.options.saveMissingTo === 'current' || (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng[0] === false) ) {
764
+ lngs.push(options.lng || this.language);
765
+ }
766
+
767
+ if (this.options.saveMissing) {
768
+ if (this.options.missingKeyHandler) {
769
+ this.options.missingKeyHandler(lngs, namespace, key, res);
770
+ } else if (this.backendConnector && this.backendConnector.saveMissing) {
771
+ this.backendConnector.saveMissing(lngs, namespace, key, res);
772
+ }
773
+ }
774
+
775
+ this.emit('missingKey', lngs, namespace, key, res);
776
+ }
777
+
778
+ // extend
779
+ res = this.extendTranslation(res, key, options);
780
+
781
+ // append namespace if still key
782
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = namespace + ':' + key;
783
+
784
+ // parseMissingKeyHandler
785
+ if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res);
786
+ }
787
+
788
+ // return
789
+ return res;
790
+ };
791
+
792
+ Translator.prototype.extendTranslation = function extendTranslation(res, key, options) {
793
+ var _this2 = this;
794
+
795
+ if (options.interpolation) this.interpolator.init(_extends({}, options, { interpolation: _extends({}, this.options.interpolation, options.interpolation) }));
796
+
797
+ // interpolate
798
+ var data = options.replace && typeof options.replace !== 'string' ? options.replace : options;
799
+ if (this.options.interpolation.defaultVariables) data = _extends({}, this.options.interpolation.defaultVariables, data);
800
+ res = this.interpolator.interpolate(res, data, this.language);
801
+
802
+ // nesting
803
+ res = this.interpolator.nest(res, function () {
804
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
805
+ args[_key] = arguments[_key];
806
+ }
807
+
808
+ return _this2.translate.apply(_this2, args);
809
+ }, options);
810
+
811
+ if (options.interpolation) this.interpolator.reset();
812
+
813
+ // post process
814
+ var postProcess = options.postProcess || this.options.postProcess;
815
+ var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess;
816
+
817
+ if (res !== undefined && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
818
+ res = postProcessor.handle(postProcessorNames, res, key, options, this);
819
+ }
820
+
821
+ return res;
822
+ };
823
+
824
+ Translator.prototype.resolve = function resolve(keys) {
825
+ var _this3 = this;
826
+
827
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
828
+
829
+ var found = void 0;
830
+
831
+ if (typeof keys === 'string') keys = [keys];
832
+
833
+ // forEach possible key
834
+ keys.forEach(function (k) {
835
+ if (_this3.isValidLookup(found)) return;
836
+
837
+ var _extractFromKey2 = _this3.extractFromKey(k, options),
838
+ key = _extractFromKey2.key,
839
+ namespaces = _extractFromKey2.namespaces;
840
+
841
+ if (_this3.options.fallbackNS) namespaces = namespaces.concat(_this3.options.fallbackNS);
842
+
843
+ var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string';
844
+ var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== '';
845
+
846
+ var codes = options.lngs ? options.lngs : _this3.languageUtils.toResolveHierarchy(options.lng || _this3.language);
847
+
848
+ namespaces.forEach(function (ns) {
849
+ if (_this3.isValidLookup(found)) return;
850
+
851
+ codes.forEach(function (code) {
852
+ if (_this3.isValidLookup(found)) return;
853
+
854
+ var finalKey = key;
855
+ var finalKeys = [finalKey];
856
+
857
+ var pluralSuffix = void 0;
858
+ if (needsPluralHandling) pluralSuffix = _this3.pluralResolver.getSuffix(code, options.count);
859
+
860
+ // fallback for plural if context not found
861
+ if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix);
862
+
863
+ // get key for context if needed
864
+ if (needsContextHandling) finalKeys.push(finalKey += '' + _this3.options.contextSeparator + options.context);
865
+
866
+ // get key for plural if needed
867
+ if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix);
868
+
869
+ // iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only
870
+ var possibleKey = void 0;
871
+ while (possibleKey = finalKeys.pop()) {
872
+ if (_this3.isValidLookup(found)) continue;
873
+ found = _this3.getResource(code, ns, possibleKey, options);
874
+ }
875
+ });
876
+ });
877
+ });
878
+
879
+ return found;
880
+ };
881
+
882
+ Translator.prototype.isValidLookup = function isValidLookup(res) {
883
+ return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === '');
884
+ };
885
+
886
+ Translator.prototype.getResource = function getResource(code, ns, key) {
887
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
888
+
889
+ return this.resourceStore.getResource(code, ns, key, options);
890
+ };
891
+
892
+ return Translator;
893
+ }(EventEmitter);
894
+
895
+ function capitalize(string) {
896
+ return string.charAt(0).toUpperCase() + string.slice(1);
897
+ }
898
+
899
+ var LanguageUtil = function () {
900
+ function LanguageUtil(options) {
901
+ classCallCheck(this, LanguageUtil);
902
+
903
+ this.options = options;
904
+
905
+ this.whitelist = this.options.whitelist || false;
906
+ this.logger = baseLogger.create('languageUtils');
907
+ }
908
+
909
+ LanguageUtil.prototype.getScriptPartFromCode = function getScriptPartFromCode(code) {
910
+ if (!code || code.indexOf('-') < 0) return null;
911
+
912
+ var p = code.split('-');
913
+ if (p.length === 2) return null;
914
+ p.pop();
915
+ return this.formatLanguageCode(p.join('-'));
916
+ };
917
+
918
+ LanguageUtil.prototype.getLanguagePartFromCode = function getLanguagePartFromCode(code) {
919
+ if (!code || code.indexOf('-') < 0) return code;
920
+
921
+ var p = code.split('-');
922
+ return this.formatLanguageCode(p[0]);
923
+ };
924
+
925
+ LanguageUtil.prototype.formatLanguageCode = function formatLanguageCode(code) {
926
+ // http://www.iana.org/assignments/language-tags/language-tags.xhtml
927
+ if (typeof code === 'string' && code.indexOf('-') > -1) {
928
+ var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab'];
929
+ var p = code.split('-');
930
+
931
+ if (this.options.lowerCaseLng) {
932
+ p = p.map(function (part) {
933
+ return part.toLowerCase();
934
+ });
935
+ } else if (p.length === 2) {
936
+ p[0] = p[0].toLowerCase();
937
+ p[1] = p[1].toUpperCase();
938
+
939
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
940
+ } else if (p.length === 3) {
941
+ p[0] = p[0].toLowerCase();
942
+
943
+ // if lenght 2 guess it's a country
944
+ if (p[1].length === 2) p[1] = p[1].toUpperCase();
945
+ if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase();
946
+
947
+ if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
948
+ if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
949
+ }
950
+
951
+ return p.join('-');
952
+ } else {
953
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
954
+ }
955
+ };
956
+
957
+ LanguageUtil.prototype.isWhitelisted = function isWhitelisted(code, exactMatch) {
958
+ if (this.options.load === 'languageOnly' || this.options.nonExplicitWhitelist && !exactMatch) {
959
+ code = this.getLanguagePartFromCode(code);
960
+ }
961
+ return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > -1 ? true : false;
962
+ };
963
+
964
+ LanguageUtil.prototype.getFallbackCodes = function getFallbackCodes(fallbacks, code) {
965
+ if (!fallbacks) return [];
966
+ if (typeof fallbacks === 'string') fallbacks = [fallbacks];
967
+ if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
968
+
969
+ if (!code) return fallbacks.default || [];
970
+
971
+ // asume we have an object defining fallbacks
972
+ var found = fallbacks[code];
973
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
974
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
975
+ if (!found) found = fallbacks.default;
976
+
977
+ return found || [];
978
+ };
979
+
980
+ LanguageUtil.prototype.toResolveHierarchy = function toResolveHierarchy(code, fallbackCode) {
981
+ var _this = this;
982
+
983
+ var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
984
+
985
+ var codes = [];
986
+ var addCode = function addCode(code) {
987
+ var exactMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
988
+
989
+ if (!code) return;
990
+ if (_this.isWhitelisted(code, exactMatch)) {
991
+ codes.push(code);
992
+ } else {
993
+ _this.logger.warn('rejecting non-whitelisted language code: ' + code);
994
+ }
995
+ };
996
+
997
+ if (typeof code === 'string' && code.indexOf('-') > -1) {
998
+ if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code), true);
999
+ if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code), true);
1000
+ if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code));
1001
+ } else if (typeof code === 'string') {
1002
+ addCode(this.formatLanguageCode(code));
1003
+ }
1004
+
1005
+ fallbackCodes.forEach(function (fc) {
1006
+ if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc));
1007
+ });
1008
+
1009
+ return codes;
1010
+ };
1011
+
1012
+ return LanguageUtil;
1013
+ }();
1014
+
1015
+ // definition http://translate.sourceforge.net/wiki/l10n/pluralforms
1016
+ /* eslint-disable */
1017
+ var sets = [{ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'tg', 'ti', 'tr', 'uz', 'wa'], nr: [1, 2], fc: 1 }, { lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'es_ar', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'he', 'hi', 'hu', 'hy', 'ia', 'it', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt', 'pt_br', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'], nr: [1, 2], fc: 2 }, { lngs: ['ay', 'bo', 'cgg', 'fa', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'], nr: [1], fc: 3 }, { lngs: ['be', 'bs', 'dz', 'hr', 'ru', 'sr', 'uk'], nr: [1, 2, 5], fc: 4 }, { lngs: ['ar'], nr: [0, 1, 2, 3, 11, 100], fc: 5 }, { lngs: ['cs', 'sk'], nr: [1, 2, 5], fc: 6 }, { lngs: ['csb', 'pl'], nr: [1, 2, 5], fc: 7 }, { lngs: ['cy'], nr: [1, 2, 3, 8], fc: 8 }, { lngs: ['fr'], nr: [1, 2], fc: 9 }, { lngs: ['ga'], nr: [1, 2, 3, 7, 11], fc: 10 }, { lngs: ['gd'], nr: [1, 2, 3, 20], fc: 11 }, { lngs: ['is'], nr: [1, 2], fc: 12 }, { lngs: ['jv'], nr: [0, 1], fc: 13 }, { lngs: ['kw'], nr: [1, 2, 3, 4], fc: 14 }, { lngs: ['lt'], nr: [1, 2, 10], fc: 15 }, { lngs: ['lv'], nr: [1, 2, 0], fc: 16 }, { lngs: ['mk'], nr: [1, 2], fc: 17 }, { lngs: ['mnk'], nr: [0, 1, 2], fc: 18 }, { lngs: ['mt'], nr: [1, 2, 11, 20], fc: 19 }, { lngs: ['or'], nr: [2, 1], fc: 2 }, { lngs: ['ro'], nr: [1, 2, 20], fc: 20 }, { lngs: ['sl'], nr: [5, 1, 2, 3], fc: 21 }];
1018
+
1019
+ var _rulesPluralsTypes = {
1020
+ 1: function _(n) {
1021
+ return Number(n > 1);
1022
+ },
1023
+ 2: function _(n) {
1024
+ return Number(n != 1);
1025
+ },
1026
+ 3: function _(n) {
1027
+ return 0;
1028
+ },
1029
+ 4: function _(n) {
1030
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
1031
+ },
1032
+ 5: function _(n) {
1033
+ return Number(n === 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
1034
+ },
1035
+ 6: function _(n) {
1036
+ return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
1037
+ },
1038
+ 7: function _(n) {
1039
+ return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
1040
+ },
1041
+ 8: function _(n) {
1042
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
1043
+ },
1044
+ 9: function _(n) {
1045
+ return Number(n >= 2);
1046
+ },
1047
+ 10: function _(n) {
1048
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
1049
+ },
1050
+ 11: function _(n) {
1051
+ return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
1052
+ },
1053
+ 12: function _(n) {
1054
+ return Number(n % 10 != 1 || n % 100 == 11);
1055
+ },
1056
+ 13: function _(n) {
1057
+ return Number(n !== 0);
1058
+ },
1059
+ 14: function _(n) {
1060
+ return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
1061
+ },
1062
+ 15: function _(n) {
1063
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
1064
+ },
1065
+ 16: function _(n) {
1066
+ return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
1067
+ },
1068
+ 17: function _(n) {
1069
+ return Number(n == 1 || n % 10 == 1 ? 0 : 1);
1070
+ },
1071
+ 18: function _(n) {
1072
+ return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
1073
+ },
1074
+ 19: function _(n) {
1075
+ return Number(n == 1 ? 0 : n === 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
1076
+ },
1077
+ 20: function _(n) {
1078
+ return Number(n == 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
1079
+ },
1080
+ 21: function _(n) {
1081
+ return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
1082
+ }
1083
+ };
1084
+ /* eslint-enable */
1085
+
1086
+ function createRules() {
1087
+ var l,
1088
+ rules = {};
1089
+ sets.forEach(function (set$$1) {
1090
+ set$$1.lngs.forEach(function (l) {
1091
+ return rules[l] = {
1092
+ numbers: set$$1.nr,
1093
+ plurals: _rulesPluralsTypes[set$$1.fc]
1094
+ };
1095
+ });
1096
+ });
1097
+ return rules;
1098
+ }
1099
+
1100
+ var PluralResolver = function () {
1101
+ function PluralResolver(languageUtils) {
1102
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1103
+ classCallCheck(this, PluralResolver);
1104
+
1105
+ this.languageUtils = languageUtils;
1106
+ this.options = options;
1107
+
1108
+ this.logger = baseLogger.create('pluralResolver');
1109
+
1110
+ this.rules = createRules();
1111
+ }
1112
+
1113
+ PluralResolver.prototype.addRule = function addRule(lng, obj) {
1114
+ this.rules[lng] = obj;
1115
+ };
1116
+
1117
+ PluralResolver.prototype.getRule = function getRule(code) {
1118
+ return this.rules[this.languageUtils.getLanguagePartFromCode(code)];
1119
+ };
1120
+
1121
+ PluralResolver.prototype.needsPlural = function needsPlural(code) {
1122
+ var rule = this.getRule(code);
1123
+
1124
+ return rule && rule.numbers.length <= 1 ? false : true;
1125
+ };
1126
+
1127
+ PluralResolver.prototype.getSuffix = function getSuffix(code, count) {
1128
+ var _this = this;
1129
+
1130
+ var rule = this.getRule(code);
1131
+
1132
+ if (rule) {
1133
+ if (rule.numbers.length === 1) return ''; // only singular
1134
+
1135
+ var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
1136
+ var suffix = rule.numbers[idx];
1137
+
1138
+ // special treatment for lngs only having singular and plural
1139
+ if (rule.numbers.length === 2 && rule.numbers[0] === 1) {
1140
+ if (suffix === 2) {
1141
+ suffix = 'plural';
1142
+ } else if (suffix === 1) {
1143
+ suffix = '';
1144
+ }
1145
+ }
1146
+
1147
+ var returnSuffix = function returnSuffix() {
1148
+ return _this.options.prepend && suffix.toString() ? _this.options.prepend + suffix.toString() : suffix.toString();
1149
+ };
1150
+
1151
+ // COMPATIBILITY JSON
1152
+ // v1
1153
+ if (this.options.compatibilityJSON === 'v1') {
1154
+ if (suffix === 1) return '';
1155
+ if (typeof suffix === 'number') return '_plural_' + suffix.toString();
1156
+ return returnSuffix();
1157
+ }
1158
+ // v2
1159
+ else if (this.options.compatibilityJSON === 'v2' || rule.numbers.length === 2 && rule.numbers[0] === 1) {
1160
+ return returnSuffix();
1161
+ }
1162
+ // v3 - gettext index
1163
+ else if (rule.numbers.length === 2 && rule.numbers[0] === 1) {
1164
+ return returnSuffix();
1165
+ }
1166
+ return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
1167
+ } else {
1168
+ this.logger.warn('no plural rule found for: ' + code);
1169
+ return '';
1170
+ }
1171
+ };
1172
+
1173
+ return PluralResolver;
1174
+ }();
1175
+
1176
+ var Interpolator = function () {
1177
+ function Interpolator() {
1178
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1179
+ classCallCheck(this, Interpolator);
1180
+
1181
+ this.logger = baseLogger.create('interpolator');
1182
+
1183
+ this.init(options, true);
1184
+ }
1185
+
1186
+ Interpolator.prototype.init = function init() {
1187
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1188
+ var reset = arguments[1];
1189
+
1190
+ if (reset) {
1191
+ this.options = options;
1192
+ this.format = options.interpolation && options.interpolation.format || function (value) {
1193
+ return value;
1194
+ };
1195
+ this.escape = options.interpolation && options.interpolation.escape || escape;
1196
+ }
1197
+ if (!options.interpolation) options.interpolation = { escapeValue: true };
1198
+
1199
+ var iOpts = options.interpolation;
1200
+
1201
+ this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true;
1202
+
1203
+ this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{';
1204
+ this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}';
1205
+
1206
+ this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ',';
1207
+
1208
+ this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-';
1209
+ this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || '';
1210
+
1211
+ this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape('$t(');
1212
+ this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(')');
1213
+
1214
+ // the regexp
1215
+ this.resetRegExp();
1216
+ };
1217
+
1218
+ Interpolator.prototype.reset = function reset() {
1219
+ if (this.options) this.init(this.options);
1220
+ };
1221
+
1222
+ Interpolator.prototype.resetRegExp = function resetRegExp() {
1223
+ // the regexp
1224
+ var regexpStr = this.prefix + '(.+?)' + this.suffix;
1225
+ this.regexp = new RegExp(regexpStr, 'g');
1226
+
1227
+ var regexpUnescapeStr = this.prefix + this.unescapePrefix + '(.+?)' + this.unescapeSuffix + this.suffix;
1228
+ this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g');
1229
+
1230
+ var nestingRegexpStr = this.nestingPrefix + '(.+?)' + this.nestingSuffix;
1231
+ this.nestingRegexp = new RegExp(nestingRegexpStr, 'g');
1232
+ };
1233
+
1234
+ Interpolator.prototype.interpolate = function interpolate(str, data, lng) {
1235
+ var _this = this;
1236
+
1237
+ var match = void 0,
1238
+ value = void 0;
1239
+
1240
+ function regexSafe(val) {
1241
+ return val.replace(/\$/g, '$$$$');
1242
+ }
1243
+
1244
+ var handleFormat = function handleFormat(key) {
1245
+ if (key.indexOf(_this.formatSeparator) < 0) return getPath(data, key);
1246
+
1247
+ var p = key.split(_this.formatSeparator);
1248
+ var k = p.shift().trim();
1249
+ var f = p.join(_this.formatSeparator).trim();
1250
+
1251
+ return _this.format(getPath(data, k), f, lng);
1252
+ };
1253
+
1254
+ this.resetRegExp();
1255
+
1256
+ // unescape if has unescapePrefix/Suffix
1257
+ while (match = this.regexpUnescape.exec(str)) {
1258
+ var _value = handleFormat(match[1].trim());
1259
+ str = str.replace(match[0], _value);
1260
+ this.regexpUnescape.lastIndex = 0;
1261
+ }
1262
+
1263
+ // regular escape on demand
1264
+ while (match = this.regexp.exec(str)) {
1265
+ value = handleFormat(match[1].trim());
1266
+ if (typeof value !== 'string') value = makeString(value);
1267
+ if (!value) {
1268
+ this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str);
1269
+ value = '';
1270
+ }
1271
+ value = this.escapeValue ? regexSafe(this.escape(value)) : regexSafe(value);
1272
+ str = str.replace(match[0], value);
1273
+ this.regexp.lastIndex = 0;
1274
+ }
1275
+ return str;
1276
+ };
1277
+
1278
+ Interpolator.prototype.nest = function nest(str, fc) {
1279
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1280
+
1281
+ var match = void 0,
1282
+ value = void 0;
1283
+
1284
+ var clonedOptions = _extends({}, options);
1285
+ clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup
1286
+
1287
+ function handleHasOptions(key) {
1288
+ if (key.indexOf(',') < 0) return key;
1289
+
1290
+ var p = key.split(',');
1291
+ key = p.shift();
1292
+ var optionsString = p.join(',');
1293
+ optionsString = this.interpolate(optionsString, clonedOptions);
1294
+ optionsString = optionsString.replace(/'/g, '"');
1295
+
1296
+ try {
1297
+ clonedOptions = JSON.parse(optionsString);
1298
+ } catch (e) {
1299
+ this.logger.error('failed parsing options string in nesting for key ' + key, e);
1300
+ }
1301
+
1302
+ return key;
1303
+ }
1304
+
1305
+ // regular escape on demand
1306
+ while (match = this.nestingRegexp.exec(str)) {
1307
+ value = fc(handleHasOptions.call(this, match[1].trim()), clonedOptions);
1308
+ if (typeof value !== 'string') value = makeString(value);
1309
+ if (!value) {
1310
+ this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str);
1311
+ value = '';
1312
+ }
1313
+ // Nested keys should not be escaped by default #854
1314
+ // value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value);
1315
+ str = str.replace(match[0], value);
1316
+ this.regexp.lastIndex = 0;
1317
+ }
1318
+ return str;
1319
+ };
1320
+
1321
+ return Interpolator;
1322
+ }();
1323
+
1324
+ function remove(arr, what) {
1325
+ var found = arr.indexOf(what);
1326
+
1327
+ while (found !== -1) {
1328
+ arr.splice(found, 1);
1329
+ found = arr.indexOf(what);
1330
+ }
1331
+ }
1332
+
1333
+ var Connector = function (_EventEmitter) {
1334
+ inherits(Connector, _EventEmitter);
1335
+
1336
+ function Connector(backend, store, services) {
1337
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1338
+ classCallCheck(this, Connector);
1339
+
1340
+ var _this = possibleConstructorReturn(this, _EventEmitter.call(this));
1341
+
1342
+ _this.backend = backend;
1343
+ _this.store = store;
1344
+ _this.services = services;
1345
+ _this.options = options;
1346
+ _this.logger = baseLogger.create('backendConnector');
1347
+
1348
+ _this.state = {};
1349
+ _this.queue = [];
1350
+
1351
+ _this.backend && _this.backend.init && _this.backend.init(services, options.backend, options);
1352
+ return _this;
1353
+ }
1354
+
1355
+ Connector.prototype.queueLoad = function queueLoad(languages, namespaces, callback) {
1356
+ var _this2 = this;
1357
+
1358
+ // find what needs to be loaded
1359
+ var toLoad = [],
1360
+ pending = [],
1361
+ toLoadLanguages = [],
1362
+ toLoadNamespaces = [];
1363
+
1364
+ languages.forEach(function (lng) {
1365
+ var hasAllNamespaces = true;
1366
+
1367
+ namespaces.forEach(function (ns) {
1368
+ var name = lng + '|' + ns;
1369
+
1370
+ if (_this2.store.hasResourceBundle(lng, ns)) {
1371
+ _this2.state[name] = 2; // loaded
1372
+ } else if (_this2.state[name] < 0) {
1373
+ // nothing to do for err
1374
+ } else if (_this2.state[name] === 1) {
1375
+ if (pending.indexOf(name) < 0) pending.push(name);
1376
+ } else {
1377
+ _this2.state[name] = 1; // pending
1378
+
1379
+ hasAllNamespaces = false;
1380
+
1381
+ if (pending.indexOf(name) < 0) pending.push(name);
1382
+ if (toLoad.indexOf(name) < 0) toLoad.push(name);
1383
+ if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns);
1384
+ }
1385
+ });
1386
+
1387
+ if (!hasAllNamespaces) toLoadLanguages.push(lng);
1388
+ });
1389
+
1390
+ if (toLoad.length || pending.length) {
1391
+ this.queue.push({
1392
+ pending: pending,
1393
+ loaded: {},
1394
+ errors: [],
1395
+ callback: callback
1396
+ });
1397
+ }
1398
+
1399
+ return {
1400
+ toLoad: toLoad,
1401
+ pending: pending,
1402
+ toLoadLanguages: toLoadLanguages,
1403
+ toLoadNamespaces: toLoadNamespaces
1404
+ };
1405
+ };
1406
+
1407
+ Connector.prototype.loaded = function loaded(name, err, data) {
1408
+ var _this3 = this;
1409
+
1410
+ var _name$split = name.split('|'),
1411
+ _name$split2 = slicedToArray(_name$split, 2),
1412
+ lng = _name$split2[0],
1413
+ ns = _name$split2[1];
1414
+
1415
+ if (err) this.emit('failedLoading', lng, ns, err);
1416
+
1417
+ if (data) {
1418
+ this.store.addResourceBundle(lng, ns, data);
1419
+ }
1420
+
1421
+ // set loaded
1422
+ this.state[name] = err ? -1 : 2;
1423
+ // callback if ready
1424
+ this.queue.forEach(function (q) {
1425
+ pushPath(q.loaded, [lng], ns);
1426
+ remove(q.pending, name);
1427
+
1428
+ if (err) q.errors.push(err);
1429
+
1430
+ if (q.pending.length === 0 && !q.done) {
1431
+ _this3.emit('loaded', q.loaded);
1432
+ q.errors.length ? q.callback(q.errors) : q.callback();
1433
+ q.done = true;
1434
+ }
1435
+ });
1436
+
1437
+ // remove done load requests
1438
+ this.queue = this.queue.filter(function (q) {
1439
+ return !q.done;
1440
+ });
1441
+ };
1442
+
1443
+ Connector.prototype.read = function read(lng, ns, fcName, tried, wait, callback) {
1444
+ var _this4 = this;
1445
+
1446
+ if (!tried) tried = 0;
1447
+ if (!wait) wait = 250;
1448
+
1449
+ if (!lng.length) return callback(null, {}); // noting to load
1450
+
1451
+ this.backend[fcName](lng, ns, function (err, data) {
1452
+ if (err && data /* = retryFlag */ && tried < 5) {
1453
+ setTimeout(function () {
1454
+ _this4.read.call(_this4, lng, ns, fcName, ++tried, wait * 2, callback);
1455
+ }, wait);
1456
+ return;
1457
+ }
1458
+ callback(err, data);
1459
+ });
1460
+ };
1461
+
1462
+ Connector.prototype.load = function load(languages, namespaces, callback) {
1463
+ var _this5 = this;
1464
+
1465
+ if (!this.backend) {
1466
+ this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1467
+ return callback && callback();
1468
+ }
1469
+ var options = _extends({}, this.backend.options, this.options.backend);
1470
+
1471
+ if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages);
1472
+ if (typeof namespaces === 'string') namespaces = [namespaces];
1473
+
1474
+ var toLoad = this.queueLoad(languages, namespaces, callback);
1475
+ if (!toLoad.toLoad.length) {
1476
+ if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now
1477
+ return; // pendings will trigger callback
1478
+ }
1479
+
1480
+ // load with multi-load
1481
+ if (options.allowMultiLoading && this.backend.readMulti) {
1482
+ this.read(toLoad.toLoadLanguages, toLoad.toLoadNamespaces, 'readMulti', null, null, function (err, data) {
1483
+ if (err) _this5.logger.warn('loading namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading failed', err);
1484
+ if (!err && data) _this5.logger.log('loaded namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading', data);
1485
+
1486
+ toLoad.toLoad.forEach(function (name) {
1487
+ var _name$split3 = name.split('|'),
1488
+ _name$split4 = slicedToArray(_name$split3, 2),
1489
+ l = _name$split4[0],
1490
+ n = _name$split4[1];
1491
+
1492
+ var bundle = getPath(data, [l, n]);
1493
+ if (bundle) {
1494
+ _this5.loaded(name, err, bundle);
1495
+ } else {
1496
+ var _err = 'loading namespace ' + n + ' for language ' + l + ' via multiloading failed';
1497
+ _this5.loaded(name, _err);
1498
+ _this5.logger.error(_err);
1499
+ }
1500
+ });
1501
+ });
1502
+ }
1503
+
1504
+ // load one by one
1505
+ else {
1506
+ var readOne = function readOne(name) {
1507
+ var _this6 = this;
1508
+
1509
+ var _name$split5 = name.split('|'),
1510
+ _name$split6 = slicedToArray(_name$split5, 2),
1511
+ lng = _name$split6[0],
1512
+ ns = _name$split6[1];
1513
+
1514
+ this.read(lng, ns, 'read', null, null, function (err, data) {
1515
+ if (err) _this6.logger.warn('loading namespace ' + ns + ' for language ' + lng + ' failed', err);
1516
+ if (!err && data) _this6.logger.log('loaded namespace ' + ns + ' for language ' + lng, data);
1517
+
1518
+ _this6.loaded(name, err, data);
1519
+ });
1520
+ };
1521
+
1522
+
1523
+
1524
+ toLoad.toLoad.forEach(function (name) {
1525
+ readOne.call(_this5, name);
1526
+ });
1527
+ }
1528
+ };
1529
+
1530
+ Connector.prototype.reload = function reload(languages, namespaces) {
1531
+ var _this7 = this;
1532
+
1533
+ if (!this.backend) {
1534
+ this.logger.warn('No backend was added via i18next.use. Will not load resources.');
1535
+ }
1536
+ var options = _extends({}, this.backend.options, this.options.backend);
1537
+
1538
+ if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages);
1539
+ if (typeof namespaces === 'string') namespaces = [namespaces];
1540
+
1541
+ // load with multi-load
1542
+ if (options.allowMultiLoading && this.backend.readMulti) {
1543
+ this.read(languages, namespaces, 'readMulti', null, null, function (err, data) {
1544
+ if (err) _this7.logger.warn('reloading namespaces ' + namespaces.join(', ') + ' for languages ' + languages.join(', ') + ' via multiloading failed', err);
1545
+ if (!err && data) _this7.logger.log('reloaded namespaces ' + namespaces.join(', ') + ' for languages ' + languages.join(', ') + ' via multiloading', data);
1546
+
1547
+ languages.forEach(function (l) {
1548
+ namespaces.forEach(function (n) {
1549
+ var bundle = getPath(data, [l, n]);
1550
+ if (bundle) {
1551
+ _this7.loaded(l + '|' + n, err, bundle);
1552
+ } else {
1553
+ var _err2 = 'reloading namespace ' + n + ' for language ' + l + ' via multiloading failed';
1554
+ _this7.loaded(l + '|' + n, _err2);
1555
+ _this7.logger.error(_err2);
1556
+ }
1557
+ });
1558
+ });
1559
+ });
1560
+ }
1561
+
1562
+ // load one by one
1563
+ else {
1564
+ var readOne = function readOne(name) {
1565
+ var _this8 = this;
1566
+
1567
+ var _name$split7 = name.split('|'),
1568
+ _name$split8 = slicedToArray(_name$split7, 2),
1569
+ lng = _name$split8[0],
1570
+ ns = _name$split8[1];
1571
+
1572
+ this.read(lng, ns, 'read', null, null, function (err, data) {
1573
+ if (err) _this8.logger.warn('reloading namespace ' + ns + ' for language ' + lng + ' failed', err);
1574
+ if (!err && data) _this8.logger.log('reloaded namespace ' + ns + ' for language ' + lng, data);
1575
+
1576
+ _this8.loaded(name, err, data);
1577
+ });
1578
+ };
1579
+
1580
+
1581
+
1582
+ languages.forEach(function (l) {
1583
+ namespaces.forEach(function (n) {
1584
+ readOne.call(_this7, l + '|' + n);
1585
+ });
1586
+ });
1587
+ }
1588
+ };
1589
+
1590
+ Connector.prototype.saveMissing = function saveMissing(languages, namespace, key, fallbackValue) {
1591
+ if (this.backend && this.backend.create) this.backend.create(languages, namespace, key, fallbackValue);
1592
+
1593
+ // write to store to avoid resending
1594
+ if (!languages || !languages[0]) return;
1595
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
1596
+ };
1597
+
1598
+ return Connector;
1599
+ }(EventEmitter);
1600
+
1601
+ var Connector$1 = function (_EventEmitter) {
1602
+ inherits(Connector, _EventEmitter);
1603
+
1604
+ function Connector(cache, store, services) {
1605
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1606
+ classCallCheck(this, Connector);
1607
+
1608
+ var _this = possibleConstructorReturn(this, _EventEmitter.call(this));
1609
+
1610
+ _this.cache = cache;
1611
+ _this.store = store;
1612
+ _this.services = services;
1613
+ _this.options = options;
1614
+ _this.logger = baseLogger.create('cacheConnector');
1615
+
1616
+ _this.cache && _this.cache.init && _this.cache.init(services, options.cache, options);
1617
+ return _this;
1618
+ }
1619
+
1620
+ Connector.prototype.load = function load(languages, namespaces, callback) {
1621
+ var _this2 = this;
1622
+
1623
+ if (!this.cache) return callback && callback();
1624
+ var options = _extends({}, this.cache.options, this.options.cache);
1625
+
1626
+ if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages);
1627
+ if (typeof namespaces === 'string') namespaces = [namespaces];
1628
+
1629
+ if (options.enabled) {
1630
+ this.cache.load(languages, function (err, data) {
1631
+ if (err) _this2.logger.error('loading languages ' + languages.join(', ') + ' from cache failed', err);
1632
+ if (data) {
1633
+ for (var l in data) {
1634
+ for (var n in data[l]) {
1635
+ if (n === 'i18nStamp') continue;
1636
+ var bundle = data[l][n];
1637
+ if (bundle) _this2.store.addResourceBundle(l, n, bundle);
1638
+ }
1639
+ }
1640
+ }
1641
+ if (callback) callback();
1642
+ });
1643
+ } else {
1644
+ if (callback) callback();
1645
+ }
1646
+ };
1647
+
1648
+ Connector.prototype.save = function save() {
1649
+ if (this.cache && this.options.cache && this.options.cache.enabled) this.cache.save(this.store.data);
1650
+ };
1651
+
1652
+ return Connector;
1653
+ }(EventEmitter);
1654
+
1655
+ function get$1() {
1656
+ return {
1657
+ debug: false,
1658
+ initImmediate: true,
1659
+
1660
+ ns: ['translation'],
1661
+ defaultNS: ['translation'],
1662
+ fallbackLng: ['dev'],
1663
+ fallbackNS: false, // string or array of namespaces
1664
+
1665
+ whitelist: false, // array with whitelisted languages
1666
+ nonExplicitWhitelist: false,
1667
+ load: 'all', // | currentOnly | languageOnly
1668
+ preload: false, // array with preload languages
1669
+
1670
+ keySeparator: '.',
1671
+ nsSeparator: ':',
1672
+ pluralSeparator: '_',
1673
+ contextSeparator: '_',
1674
+
1675
+ saveMissing: false, // enable to send missing values
1676
+ saveMissingTo: 'fallback', // 'current' || 'all'
1677
+ missingKeyHandler: false, // function(lng, ns, key, fallbackValue) -> override if prefer on handling
1678
+
1679
+ postProcess: false, // string or array of postProcessor names
1680
+ returnNull: true, // allows null value as valid translation
1681
+ returnEmptyString: true, // allows empty string value as valid translation
1682
+ returnObjects: false,
1683
+ joinArrays: false, // or string to join array
1684
+ returnedObjectHandler: function returnedObjectHandler() {}, // function(key, value, options) triggered if key returns object but returnObjects is set to false
1685
+ parseMissingKeyHandler: false, // function(key) parsed a key that was not found in t() before returning
1686
+ appendNamespaceToMissingKey: false,
1687
+ appendNamespaceToCIMode: false,
1688
+ overloadTranslationOptionHandler: function overloadTranslationOptionHandler(args) {
1689
+ return { defaultValue: args[1] };
1690
+ },
1691
+
1692
+ interpolation: {
1693
+ escapeValue: true,
1694
+ format: function format(value, _format, lng) {
1695
+ return value;
1696
+ },
1697
+ prefix: '{{',
1698
+ suffix: '}}',
1699
+ formatSeparator: ',',
1700
+ // prefixEscaped: '{{',
1701
+ // suffixEscaped: '}}',
1702
+ // unescapeSuffix: '',
1703
+ unescapePrefix: '-',
1704
+
1705
+ nestingPrefix: '$t(',
1706
+ nestingSuffix: ')',
1707
+ // nestingPrefixEscaped: '$t(',
1708
+ // nestingSuffixEscaped: ')',
1709
+ defaultVariables: undefined // object that can have values to interpolate on - extends passed in interpolation data
1710
+ }
1711
+ };
1712
+ }
1713
+
1714
+ function transformOptions(options) {
1715
+ // create namespace object if namespace is passed in as string
1716
+ if (typeof options.ns === 'string') options.ns = [options.ns];
1717
+ if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng];
1718
+ if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS];
1719
+
1720
+ // extend whitelist with cimode
1721
+ if (options.whitelist && options.whitelist.indexOf('cimode') < 0) options.whitelist.push('cimode');
1722
+
1723
+ return options;
1724
+ }
1725
+
1726
+ function noop() {}
1727
+
1728
+ var I18n = function (_EventEmitter) {
1729
+ inherits(I18n, _EventEmitter);
1730
+
1731
+ function I18n() {
1732
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1733
+ var callback = arguments[1];
1734
+ classCallCheck(this, I18n);
1735
+
1736
+ var _this = possibleConstructorReturn(this, _EventEmitter.call(this));
1737
+
1738
+ _this.options = transformOptions(options);
1739
+ _this.services = {};
1740
+ _this.logger = baseLogger;
1741
+ _this.modules = { external: [] };
1742
+
1743
+ if (callback && !_this.isInitialized && !options.isClone) _this.init(options, callback);
1744
+ return _this;
1745
+ }
1746
+
1747
+ I18n.prototype.init = function init(options, callback) {
1748
+ var _this2 = this;
1749
+
1750
+ if (typeof options === 'function') {
1751
+ callback = options;
1752
+ options = {};
1753
+ }
1754
+ if (!options) options = {};
1755
+
1756
+ if (options.compatibilityAPI === 'v1') {
1757
+ this.options = _extends({}, get$1(), transformOptions(convertAPIOptions(options)), {});
1758
+ } else if (options.compatibilityJSON === 'v1') {
1759
+ this.options = _extends({}, get$1(), transformOptions(convertJSONOptions(options)), {});
1760
+ } else {
1761
+ this.options = _extends({}, get$1(), this.options, transformOptions(options));
1762
+ }
1763
+ if (!callback) callback = noop;
1764
+
1765
+ function createClassOnDemand(ClassOrObject) {
1766
+ if (!ClassOrObject) return;
1767
+ if (typeof ClassOrObject === 'function') return new ClassOrObject();
1768
+ return ClassOrObject;
1769
+ }
1770
+
1771
+ // init services
1772
+ if (!this.options.isClone) {
1773
+ if (this.modules.logger) {
1774
+ baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
1775
+ } else {
1776
+ baseLogger.init(null, this.options);
1777
+ }
1778
+
1779
+ var lu = new LanguageUtil(this.options);
1780
+ this.store = new ResourceStore(this.options.resources, this.options);
1781
+
1782
+ var s = this.services;
1783
+ s.logger = baseLogger;
1784
+ s.resourceStore = this.store;
1785
+ s.resourceStore.on('added removed', function (lng, ns) {
1786
+ s.cacheConnector.save();
1787
+ });
1788
+ s.languageUtils = lu;
1789
+ s.pluralResolver = new PluralResolver(lu, { prepend: this.options.pluralSeparator, compatibilityJSON: this.options.compatibilityJSON });
1790
+ s.interpolator = new Interpolator(this.options);
1791
+
1792
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1793
+ // pipe events from backendConnector
1794
+ s.backendConnector.on('*', function (event) {
1795
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1796
+ args[_key - 1] = arguments[_key];
1797
+ }
1798
+
1799
+ _this2.emit.apply(_this2, [event].concat(args));
1800
+ });
1801
+
1802
+ s.backendConnector.on('loaded', function (loaded) {
1803
+ s.cacheConnector.save();
1804
+ });
1805
+
1806
+ s.cacheConnector = new Connector$1(createClassOnDemand(this.modules.cache), s.resourceStore, s, this.options);
1807
+ // pipe events from backendConnector
1808
+ s.cacheConnector.on('*', function (event) {
1809
+ for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1810
+ args[_key2 - 1] = arguments[_key2];
1811
+ }
1812
+
1813
+ _this2.emit.apply(_this2, [event].concat(args));
1814
+ });
1815
+
1816
+ if (this.modules.languageDetector) {
1817
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
1818
+ s.languageDetector.init(s, this.options.detection, this.options);
1819
+ }
1820
+
1821
+ this.translator = new Translator(this.services, this.options);
1822
+ // pipe events from translator
1823
+ this.translator.on('*', function (event) {
1824
+ for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
1825
+ args[_key3 - 1] = arguments[_key3];
1826
+ }
1827
+
1828
+ _this2.emit.apply(_this2, [event].concat(args));
1829
+ });
1830
+
1831
+ this.modules.external.forEach(function (m) {
1832
+ if (m.init) m.init(_this2);
1833
+ });
1834
+ }
1835
+
1836
+ // append api
1837
+ var storeApi = ['getResource', 'addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle', 'hasResourceBundle', 'getResourceBundle'];
1838
+ storeApi.forEach(function (fcName) {
1839
+ _this2[fcName] = function () {
1840
+ return this.store[fcName].apply(this.store, arguments);
1841
+ };
1842
+ });
1843
+
1844
+ // TODO: COMPATIBILITY remove this
1845
+ if (this.options.compatibilityAPI === 'v1') appendBackwardsAPI(this);
1846
+
1847
+ var load = function load() {
1848
+ _this2.changeLanguage(_this2.options.lng, function (err, t) {
1849
+ _this2.isInitialized = true;
1850
+ _this2.logger.log('initialized', _this2.options);
1851
+ _this2.emit('initialized', _this2.options);
1852
+
1853
+ callback(err, t);
1854
+ });
1855
+ };
1856
+
1857
+ if (this.options.resources || !this.options.initImmediate) {
1858
+ load();
1859
+ } else {
1860
+ setTimeout(load, 0);
1861
+ }
1862
+
1863
+ return this;
1864
+ };
1865
+
1866
+ I18n.prototype.loadResources = function loadResources() {
1867
+ var _this3 = this;
1868
+
1869
+ var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop;
1870
+
1871
+ if (!this.options.resources) {
1872
+ if (this.language && this.language.toLowerCase() === 'cimode') return callback(); // avoid loading resources for cimode
1873
+
1874
+ var toLoad = [];
1875
+
1876
+ var append = function append(lng) {
1877
+ if (!lng) return;
1878
+ var lngs = _this3.services.languageUtils.toResolveHierarchy(lng);
1879
+ lngs.forEach(function (l) {
1880
+ if (toLoad.indexOf(l) < 0) toLoad.push(l);
1881
+ });
1882
+ };
1883
+
1884
+ append(this.language);
1885
+
1886
+ if (this.options.preload) {
1887
+ this.options.preload.forEach(function (l) {
1888
+ append(l);
1889
+ });
1890
+ }
1891
+
1892
+ this.services.cacheConnector.load(toLoad, this.options.ns, function () {
1893
+ _this3.services.backendConnector.load(toLoad, _this3.options.ns, callback);
1894
+ });
1895
+ } else {
1896
+ callback(null);
1897
+ }
1898
+ };
1899
+
1900
+ I18n.prototype.reloadResources = function reloadResources(lngs, ns) {
1901
+ if (!lngs) lngs = this.languages;
1902
+ if (!ns) ns = this.options.ns;
1903
+ this.services.backendConnector.reload(lngs, ns);
1904
+ };
1905
+
1906
+ I18n.prototype.use = function use(module) {
1907
+ if (module.type === 'backend') {
1908
+ this.modules.backend = module;
1909
+ }
1910
+
1911
+ if (module.type === 'cache') {
1912
+ this.modules.cache = module;
1913
+ }
1914
+
1915
+ if (module.type === 'logger' || module.log && module.warn && module.error) {
1916
+ this.modules.logger = module;
1917
+ }
1918
+
1919
+ if (module.type === 'languageDetector') {
1920
+ this.modules.languageDetector = module;
1921
+ }
1922
+
1923
+ if (module.type === 'postProcessor') {
1924
+ postProcessor.addPostProcessor(module);
1925
+ }
1926
+
1927
+ if (module.type === '3rdParty') {
1928
+ this.modules.external.push(module);
1929
+ }
1930
+
1931
+ return this;
1932
+ };
1933
+
1934
+ I18n.prototype.changeLanguage = function changeLanguage(lng, callback) {
1935
+ var _this4 = this;
1936
+
1937
+ var done = function done(err) {
1938
+ if (lng) {
1939
+ _this4.emit('languageChanged', lng);
1940
+ _this4.logger.log('languageChanged', lng);
1941
+ }
1942
+
1943
+ if (callback) callback(err, function () {
1944
+ for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1945
+ args[_key4] = arguments[_key4];
1946
+ }
1947
+
1948
+ return _this4.t.apply(_this4, args);
1949
+ });
1950
+ };
1951
+
1952
+ if (!lng && this.services.languageDetector) lng = this.services.languageDetector.detect();
1953
+
1954
+ if (lng) {
1955
+ this.language = lng;
1956
+ this.languages = this.services.languageUtils.toResolveHierarchy(lng);
1957
+
1958
+ this.translator.changeLanguage(lng);
1959
+
1960
+ if (this.services.languageDetector) this.services.languageDetector.cacheUserLanguage(lng);
1961
+ }
1962
+
1963
+ this.loadResources(function (err) {
1964
+ done(err);
1965
+ });
1966
+ };
1967
+
1968
+ I18n.prototype.getFixedT = function getFixedT(lng, ns) {
1969
+ var _this5 = this;
1970
+
1971
+ var fixedT = function fixedT(key) {
1972
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1973
+
1974
+ var options = _extends({}, opts);
1975
+ options.lng = options.lng || fixedT.lng;
1976
+ options.ns = options.ns || fixedT.ns;
1977
+ return _this5.t(key, options);
1978
+ };
1979
+ fixedT.lng = lng;
1980
+ fixedT.ns = ns;
1981
+ return fixedT;
1982
+ };
1983
+
1984
+ I18n.prototype.t = function t() {
1985
+ return this.translator && this.translator.translate.apply(this.translator, arguments);
1986
+ };
1987
+
1988
+ I18n.prototype.exists = function exists() {
1989
+ return this.translator && this.translator.exists.apply(this.translator, arguments);
1990
+ };
1991
+
1992
+ I18n.prototype.setDefaultNamespace = function setDefaultNamespace(ns) {
1993
+ this.options.defaultNS = ns;
1994
+ };
1995
+
1996
+ I18n.prototype.loadNamespaces = function loadNamespaces(ns, callback) {
1997
+ var _this6 = this;
1998
+
1999
+ if (!this.options.ns) return callback && callback();
2000
+ if (typeof ns === 'string') ns = [ns];
2001
+
2002
+ ns.forEach(function (n) {
2003
+ if (_this6.options.ns.indexOf(n) < 0) _this6.options.ns.push(n);
2004
+ });
2005
+
2006
+ this.loadResources(callback);
2007
+ };
2008
+
2009
+ I18n.prototype.loadLanguages = function loadLanguages(lngs, callback) {
2010
+ if (typeof lngs === 'string') lngs = [lngs];
2011
+ var preloaded = this.options.preload || [];
2012
+
2013
+ var newLngs = lngs.filter(function (lng) {
2014
+ return preloaded.indexOf(lng) < 0;
2015
+ });
2016
+ // Exit early if all given languages are already preloaded
2017
+ if (!newLngs.length) return callback();
2018
+
2019
+ this.options.preload = preloaded.concat(newLngs);
2020
+ this.loadResources(callback);
2021
+ };
2022
+
2023
+ I18n.prototype.dir = function dir(lng) {
2024
+ if (!lng) lng = this.language;
2025
+ if (!lng) return 'rtl';
2026
+
2027
+ var rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam'];
2028
+
2029
+ return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) >= 0 ? 'rtl' : 'ltr';
2030
+ };
2031
+
2032
+ I18n.prototype.createInstance = function createInstance() {
2033
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2034
+ var callback = arguments[1];
2035
+
2036
+ return new I18n(options, callback);
2037
+ };
2038
+
2039
+ I18n.prototype.cloneInstance = function cloneInstance() {
2040
+ var _this7 = this;
2041
+
2042
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2043
+ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
2044
+
2045
+ var mergedOptions = _extends({}, options, this.options, { isClone: true });
2046
+ var clone = new I18n(mergedOptions, callback);
2047
+ var membersToCopy = ['store', 'services', 'language'];
2048
+ membersToCopy.forEach(function (m) {
2049
+ clone[m] = _this7[m];
2050
+ });
2051
+ clone.translator = new Translator(clone.services, clone.options);
2052
+ clone.translator.on('*', function (event) {
2053
+ for (var _len5 = arguments.length, args = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
2054
+ args[_key5 - 1] = arguments[_key5];
2055
+ }
2056
+
2057
+ clone.emit.apply(clone, [event].concat(args));
2058
+ });
2059
+ clone.init(mergedOptions, callback);
2060
+
2061
+ return clone;
2062
+ };
2063
+
2064
+ return I18n;
2065
+ }(EventEmitter);
2066
+
2067
+ var i18next = new I18n();
2068
+
2069
+ return i18next;
2070
+
2071
+ })));
2072
+
2073
+
2074
+ })(External = FintaChart.External || (FintaChart.External = {}));
2075
+ })(FintaChart || (FintaChart = {}));