trepur_components 2.3.2 → 2.3.4
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.
- package/.eslintrc.cjs +43 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.json +22 -0
- package/archive/Breadcrumbs/Breadcrumbs.stories.tsx +46 -0
- package/archive/Breadcrumbs/index.tsx +42 -0
- package/archive/BreadcrumbsBordered/BreadcrumbsBordered.stories.tsx +52 -0
- package/archive/BreadcrumbsBordered/index.tsx +44 -0
- package/archive/BreadcrumbsItem/BreadcrumbsItem.stories.tsx +40 -0
- package/archive/BreadcrumbsItem/index.tsx +149 -0
- package/archive/Button/Button.stories.tsx +150 -0
- package/archive/Button/index.tsx +111 -0
- package/archive/Button/style.module.css +76 -0
- package/archive/Calendar/Calendar.stories.tsx +82 -0
- package/archive/Calendar/index.tsx +76 -0
- package/archive/Calendar/style.css +233 -0
- package/archive/Card/Card.stories.tsx +75 -0
- package/archive/Card/index.tsx +102 -0
- package/archive/Card/style.module.css +75 -0
- package/archive/CardWithTopImage/CardWithTopImage.stories.tsx +50 -0
- package/archive/CardWithTopImage/index.tsx +39 -0
- package/archive/CardWithTopImage/style.module.css +11 -0
- package/archive/Carousel/Carousel.stories.tsx +451 -0
- package/archive/Carousel/index.tsx +388 -0
- package/archive/Carousel/style.module.css +99 -0
- package/archive/CarouselThumbnail/CarouselThumbnail.stories.tsx +350 -0
- package/archive/CarouselThumbnail/index.tsx +302 -0
- package/archive/CarouselThumbnail/style.module.css +67 -0
- package/archive/Checkbox/Checkbox.mdx +33 -0
- package/archive/Checkbox/Checkbox.stories.tsx +34 -0
- package/archive/Checkbox/index.tsx +51 -0
- package/archive/Checkbox/style.module.css +15 -0
- package/archive/Collapsible/Collapsible.stories.tsx +67 -0
- package/archive/Collapsible/index.tsx +116 -0
- package/archive/Collapsible/style.module.css +47 -0
- package/archive/Column/Column.stories.tsx +89 -0
- package/archive/Column/index.tsx +119 -0
- package/archive/Column/style.module.css +151 -0
- package/archive/ComponentWrapper/ComponentWrapper.stories.tsx +40 -0
- package/archive/ComponentWrapper/index.tsx +55 -0
- package/archive/ComponentWrapper/style.module.css +40 -0
- package/archive/Container/Container.stories.tsx +40 -0
- package/archive/Container/index.tsx +24 -0
- package/archive/Container/style.module.css +4 -0
- package/archive/Counter/Counter.stories.tsx +19 -0
- package/archive/Counter/index.tsx +66 -0
- package/archive/Counter/style.module.css +19 -0
- package/archive/DetailUpdater/DetailUpdater.stories.tsx +96 -0
- package/archive/DetailUpdater/index.tsx +112 -0
- package/archive/DetailUpdater/style.module.css +31 -0
- package/archive/Dialog/Dialog.stories.tsx +131 -0
- package/archive/Dialog/index.tsx +91 -0
- package/archive/Dialog/style.module.css +44 -0
- package/archive/DropdownMenu/DropdownMenu.stories.tsx +59 -0
- package/archive/DropdownMenu/index.tsx +51 -0
- package/archive/DropdownMenu/style.module.css +38 -0
- package/archive/DynamicTextSection/DynamicTextSection.stories.tsx +74 -0
- package/archive/DynamicTextSection/index.tsx +36 -0
- package/archive/DynamicTextSection/style.module.css +0 -0
- package/archive/FileUploader/FilePreview.tsx +48 -0
- package/archive/FileUploader/FileUploader.stories.tsx +28 -0
- package/archive/FileUploader/index.tsx +135 -0
- package/archive/FileUploader/style.module.css +54 -0
- package/archive/FilterItem/FilterItem.stories.tsx +33 -0
- package/archive/FilterItem/index.tsx +101 -0
- package/archive/FilterItem/style.module.css +27 -0
- package/archive/Footer/Footer.stories.tsx +59 -0
- package/archive/Footer/index.tsx +50 -0
- package/archive/Footer/style.module.css +19 -0
- package/archive/FooterNav/FooterNav.stories.tsx +125 -0
- package/archive/FooterNav/index.tsx +57 -0
- package/archive/FooterNav/style.module.css +32 -0
- package/archive/FooterNavItem/FooterNavItem.stories.tsx +53 -0
- package/archive/FooterNavItem/index.tsx +80 -0
- package/archive/FooterNavItem/style.module.css +139 -0
- package/archive/Form/Form.stories.tsx +86 -0
- package/archive/Form/index.tsx +61 -0
- package/archive/Form/style.module.css +0 -0
- package/archive/FyreCard/FyreCard.stories.tsx +31 -0
- package/archive/FyreCard/index.tsx +52 -0
- package/archive/FyreCard/style.module.css +19 -0
- package/archive/Greeting/Greeting.stories.tsx +41 -0
- package/archive/Greeting/index.tsx +32 -0
- package/archive/HamburgerIcon/HamburgerIcon.stories.tsx +32 -0
- package/archive/HamburgerIcon/index.tsx +103 -0
- package/archive/HamburgerIcon/style.module.css +85 -0
- package/archive/HorizontalLine/HorizontalLine.stories.tsx +54 -0
- package/archive/HorizontalLine/index.tsx +40 -0
- package/archive/HorizontalLine/style.module.css +55 -0
- package/archive/Icon/Icon.stories.tsx +164 -0
- package/archive/Icon/index.tsx +115 -0
- package/archive/Icon/style.module.css +253 -0
- package/archive/IconCard/IconCard.stories.tsx +46 -0
- package/archive/IconCard/index.tsx +57 -0
- package/archive/IconCard/style.module.css +18 -0
- package/archive/Image/Image.stories.tsx +87 -0
- package/archive/Image/index.tsx +132 -0
- package/archive/Image/style.module.css +109 -0
- package/archive/ImageInfo/ImageInfo.stories.tsx +39 -0
- package/archive/ImageInfo/index.tsx +95 -0
- package/archive/ImageInfo/style.module.css +47 -0
- package/archive/ImageLink/ImageLink.stories.tsx +37 -0
- package/archive/ImageLink/index.tsx +49 -0
- package/archive/ImageLink/style.module.css +23 -0
- package/archive/ImageLinkList/ImageLinkList.stories.tsx +34 -0
- package/archive/ImageLinkList/index.tsx +33 -0
- package/archive/ImageLinkList/style.module.css +3 -0
- package/archive/InformationIcon/InformationIcon.stories.tsx +83 -0
- package/archive/InformationIcon/index.tsx +128 -0
- package/archive/InformationIcon/style.module.css +71 -0
- package/archive/InformationIconBlock/InformationIconBlock.stories.tsx +32 -0
- package/archive/InformationIconBlock/index.tsx +63 -0
- package/archive/InformationIconBlock/style.module.css +7 -0
- package/archive/Input/Input.stories.tsx +84 -0
- package/archive/Input/index.tsx +131 -0
- package/archive/Input/style.module.css +60 -0
- package/archive/Jumbotron/Jumbotron.stories.tsx +21 -0
- package/archive/Jumbotron/index.tsx +31 -0
- package/archive/Jumbotron/style.module.css +8 -0
- package/archive/MenuButton/MenuButton.stories.tsx +46 -0
- package/archive/MenuButton/index.tsx +82 -0
- package/archive/MenuButton/style.module.css +45 -0
- package/archive/Modal/Modal.stories.tsx +86 -0
- package/archive/Modal/index.tsx +74 -0
- package/archive/Modal/style.module.css +35 -0
- package/archive/NavItem/NavItem.stories.tsx +90 -0
- package/archive/NavItem/index.tsx +65 -0
- package/archive/NavItem/style.module.css +71 -0
- package/archive/NavOld/NavOld.stories.tsx +193 -0
- package/archive/NavOld/StickyNav.tsx +191 -0
- package/archive/NavOld/index.tsx +273 -0
- package/archive/NavOld/style.module.css +156 -0
- package/archive/NavTwo/Dropdown.tsx +35 -0
- package/archive/NavTwo/Nav.stories.tsx +38 -0
- package/archive/NavTwo/Sidebar.tsx +34 -0
- package/archive/NavTwo/StickyNav.tsx +34 -0
- package/archive/NavTwo/index.tsx +45 -0
- package/archive/NavTwo/style.module.css +35 -0
- package/archive/NewsCard/NewsCard.stories.tsx +72 -0
- package/archive/NewsCard/index.tsx +57 -0
- package/archive/NewsCard/style.module.css +15 -0
- package/archive/Pill/Pill.stories.tsx +44 -0
- package/archive/Pill/index.tsx +64 -0
- package/archive/Pill/style.module.css +32 -0
- package/archive/ProductCard/ProductCard.stories.tsx +61 -0
- package/archive/ProductCard/index.tsx +111 -0
- package/archive/ProductCard/style.module.css +53 -0
- package/archive/ProductCardV2/ProductCardV2.stories.tsx +50 -0
- package/archive/ProductCardV2/index.tsx +119 -0
- package/archive/ProductCardV2/style.module.css +59 -0
- package/archive/Proficiencies/Proficiencies.stories.tsx +50 -0
- package/archive/Proficiencies/index.tsx +63 -0
- package/archive/Proficiencies/style.module.css +31 -0
- package/archive/Profile/Profile.stories.tsx +49 -0
- package/archive/Profile/index.tsx +103 -0
- package/archive/Profile/style.module.css +47 -0
- package/archive/Row/Row.stories.tsx +53 -0
- package/archive/Row/index.tsx +23 -0
- package/archive/Row/style.module.css +3 -0
- package/archive/Search/Search.stories.tsx +63 -0
- package/archive/Search/index.tsx +68 -0
- package/archive/Search/style.module.css +23 -0
- package/archive/Select/Select.stories.tsx +56 -0
- package/archive/Select/index.tsx +106 -0
- package/archive/Select/style.module.css +52 -0
- package/archive/Showcase/Showcase.stories.tsx +30 -0
- package/archive/Showcase/index.tsx +75 -0
- package/archive/Showcase/style.module.css +47 -0
- package/archive/SideNav/SideNav.stories.tsx +50 -0
- package/archive/SideNav/index.tsx +46 -0
- package/archive/SideNav/style.module.css +43 -0
- package/archive/SocialBlock/SocialBlock.stories.tsx +58 -0
- package/archive/SocialBlock/index.tsx +63 -0
- package/archive/SocialButton/SocialButton.stories.tsx +88 -0
- package/archive/SocialButton/index.tsx +71 -0
- package/archive/SocialButton/style.module.css +77 -0
- package/archive/StarRating/StarRating.stories.tsx +23 -0
- package/archive/StarRating/index.tsx +71 -0
- package/archive/Testimonial/Testimonial.stories.tsx +110 -0
- package/archive/Testimonial/index.tsx +61 -0
- package/archive/Testimonial/style.module.css +27 -0
- package/archive/TextAndTitle/TextAndTitle.stories.tsx +70 -0
- package/archive/TextAndTitle/index.tsx +123 -0
- package/archive/TextAndTitle/style.module.css +75 -0
- package/archive/TextArea/TextArea.stories.tsx +55 -0
- package/archive/TextArea/index.tsx +125 -0
- package/archive/TextArea/style.module.css +60 -0
- package/archive/Timeline/Timeline.stories.tsx +92 -0
- package/archive/Timeline/index.tsx +254 -0
- package/archive/Timeline/style.module.css +134 -0
- package/archive/TimelineV2/TimelineV2.stories.tsx +95 -0
- package/archive/TimelineV2/index.tsx +70 -0
- package/archive/TimelineV2/style.module.css +28 -0
- package/archive/Tubestops/Tubestops.stories.tsx +42 -0
- package/archive/Tubestops/index.tsx +58 -0
- package/archive/Tubestops/style.module.css +54 -0
- package/archive/UserIcon/UserIcon.stories.tsx +52 -0
- package/archive/UserIcon/index.tsx +46 -0
- package/archive/UserIcon/style.module.css +19 -0
- package/archive/Video/Video.stories.tsx +23 -0
- package/archive/Video/index.tsx +47 -0
- package/archive/fonts/Sora/OFL.txt +93 -0
- package/archive/fonts/Sora/README.txt +70 -0
- package/archive/fonts/Sora/Sora-VariableFont_wght.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-Bold.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-ExtraBold.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-ExtraLight.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-Light.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-Medium.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-Regular.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-SemiBold.ttf +0 -0
- package/archive/fonts/Sora/static/Sora-Thin.ttf +0 -0
- package/archive/theme.ts +39 -0
- package/archive/typography/Fonts/Fonts.stories.tsx +14 -0
- package/archive/typography/Fonts/Fonts.tsx +181 -0
- package/lib/components/Accordion/Accordion.stories.d.ts +94 -0
- package/lib/components/Accordion/index.d.ts +9 -0
- package/lib/components/Accordion/index.js +15 -0
- package/lib/components/AlertBar/AlertBar.stories.d.ts +162 -0
- package/lib/components/AlertBar/index.d.ts +13 -0
- package/lib/components/AlertBar/index.js +49 -0
- package/lib/components/Avatar/Avatar.stories.d.ts +44 -0
- package/lib/components/Avatar/index.d.ts +4 -0
- package/lib/components/index.d.ts +4 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -0
- package/lib/styles/base.css +116 -0
- package/lib/utils/controls.d.ts +36 -0
- package/lib/utils/matchMedia.d.ts +2 -0
- package/lib/utils/screens.d.ts +7 -0
- package/package.json +8 -9
- package/src/components/Accordion/Accordion.stories.tsx +116 -0
- package/src/components/Accordion/index.tsx +30 -0
- package/src/components/AlertBar/AlertBar.stories.tsx +95 -0
- package/src/components/AlertBar/index.tsx +115 -0
- package/src/components/Avatar/Avatar.stories.tsx +19 -0
- package/src/components/Avatar/index.tsx +495 -0
- package/src/components/index.ts +119 -0
- package/src/documentation/Colours.mdx +192 -0
- package/src/documentation/Introduction.mdx +9 -0
- package/src/index.ts +1 -0
- package/src/styles/base.css +116 -0
- package/src/utils/controls.ts +44 -0
- package/src/utils/matchMedia.ts +9 -0
- package/src/utils/screens.ts +7 -0
- package/storybook-build/assets/Accordion.stories-Cn994N1H.js +103 -0
- package/storybook-build/assets/AlertBar.stories-BkzNXFBh.js +202 -0
- package/storybook-build/assets/Avatar.stories-CpH6xVwM.js +418 -0
- package/storybook-build/assets/Color-6VNJS4EI-DQV2onvt.js +1378 -0
- package/storybook-build/assets/Colours-r29qjFlW.js +324 -0
- package/storybook-build/assets/DocsRenderer-NNNQARDV-OgWasCIs.js +44 -0
- package/storybook-build/assets/Introduction-Bs1PgnBZ.js +40 -0
- package/storybook-build/assets/WithTooltip-V3YHNWJZ-vi2V5TOO.js +15 -0
- package/storybook-build/assets/_commonjsHelpers-LQfde5yM.js +35 -0
- package/storybook-build/assets/axe-DnFZVv9V.js +32561 -0
- package/storybook-build/assets/chunk-EIRT5I3Z-DFD8udmD.js +480 -0
- package/storybook-build/assets/context-CIRBAiUz.js +20 -0
- package/storybook-build/assets/controls-DJSGrQKd.js +23 -0
- package/storybook-build/assets/entry-preview-DmlPV4-3.js +41 -0
- package/storybook-build/assets/entry-preview-docs-D46Drugi.js +11861 -0
- package/storybook-build/assets/formatter-SWP5E3XI-BWIasvKP.js +14427 -0
- package/storybook-build/assets/iframe-Dzzzanqi.js +144 -0
- package/storybook-build/assets/index-0FT4HXk-.js +7222 -0
- package/storybook-build/assets/index-B9Tccxv4.js +107 -0
- package/storybook-build/assets/index-BdOSk9or.js +41 -0
- package/storybook-build/assets/index-CU7cYjZD.js +9604 -0
- package/storybook-build/assets/index-Clz-aGG3.js +39 -0
- package/storybook-build/assets/index-CpyNLP69.js +63 -0
- package/storybook-build/assets/index-DM9bPmif.js +319 -0
- package/storybook-build/assets/index-ex9_VrIg.js +3734 -0
- package/storybook-build/assets/jsx-runtime-D2-sc1j1.js +35 -0
- package/storybook-build/assets/preview-3kSipVgK.js +430 -0
- package/storybook-build/assets/preview-B4rAxPmB.js +27 -0
- package/storybook-build/assets/preview-BMkwWyrh.js +2920 -0
- package/storybook-build/assets/preview-BeQelhbu.js +204 -0
- package/storybook-build/assets/preview-BiG-rflf.js +2444 -0
- package/storybook-build/assets/preview-BiYUJ7TP.js +22 -0
- package/storybook-build/assets/preview-C4ItOQzM.js +34 -0
- package/storybook-build/assets/preview-CWyhKACi.css +886 -0
- package/storybook-build/assets/preview-CtOV68TG.js +10 -0
- package/storybook-build/assets/preview-De9E9xaR.js +140 -0
- package/storybook-build/assets/preview-bL4x2zrN.js +99 -0
- package/storybook-build/assets/preview-gxqyGMHu.js +323 -0
- package/storybook-build/assets/react-18-B-gfo82w.js +29 -0
- package/storybook-build/assets/syntaxhighlighter-B5GMVT5T-DrY_Dc6-.js +15 -0
- package/storybook-build/favicon.svg +7 -0
- package/storybook-build/iframe.html +458 -0
- package/storybook-build/index.html +163 -0
- package/storybook-build/index.json +1 -0
- package/storybook-build/preview-stats.json +172 -0
- package/storybook-build/project.json +1 -0
- package/storybook-build/sb-addons/a11y-9/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/a11y-9/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/essentials-actions-2/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/essentials-actions-2/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/essentials-backgrounds-3/manager-bundle.js +12 -0
- package/storybook-build/sb-addons/essentials-backgrounds-3/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/essentials-controls-1/manager-bundle.js +63 -0
- package/storybook-build/sb-addons/essentials-controls-1/manager-bundle.js.LEGAL.txt +18 -0
- package/storybook-build/sb-addons/essentials-measure-6/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/essentials-measure-6/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/essentials-outline-7/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/essentials-outline-7/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/essentials-toolbars-5/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/essentials-toolbars-5/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/essentials-viewport-4/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/essentials-viewport-4/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/interactions-8/manager-bundle.js +12 -0
- package/storybook-build/sb-addons/interactions-8/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/links-0/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/links-0/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/storybook-12/manager-bundle.js +151 -0
- package/storybook-build/sb-addons/storybook-12/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/storybook-react-i18next-11/manager-bundle.js +3 -0
- package/storybook-build/sb-addons/storybook-react-i18next-11/manager-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-addons/themes-10/register-bundle.js +5 -0
- package/storybook-build/sb-addons/themes-10/register-bundle.js.LEGAL.txt +0 -0
- package/storybook-build/sb-common-assets/fonts.css +31 -0
- package/storybook-build/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/storybook-build/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/storybook-build/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/storybook-build/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/storybook-build/sb-manager/WithTooltip-V3YHNWJZ-TRLNWEGW.js +1 -0
- package/storybook-build/sb-manager/chunk-4IYAVH3S.js +348 -0
- package/storybook-build/sb-manager/chunk-CXYKRFSY.js +9 -0
- package/storybook-build/sb-manager/chunk-KZYAAUOR.js +406 -0
- package/storybook-build/sb-manager/chunk-LVLAH4SI.js +7 -0
- package/storybook-build/sb-manager/chunk-ZEU7PDD3.js +1 -0
- package/storybook-build/sb-manager/formatter-SWP5E3XI-7BGIK6BL.js +156 -0
- package/storybook-build/sb-manager/globals-module-info.js +1 -0
- package/storybook-build/sb-manager/globals.js +1 -0
- package/storybook-build/sb-manager/index.js +1 -0
- package/storybook-build/sb-manager/runtime.js +1 -0
- package/storybook-build/sb-manager/syntaxhighlighter-B5GMVT5T-EA5ASEYD.js +1 -0
- package/storybook-build/sb-preview/globals.js +1 -0
- package/storybook-build/sb-preview/runtime.js +112 -0
- package/storybook-build/src/components/Accordion/Accordion.stories.d.ts +94 -0
- package/storybook-build/src/components/Accordion/index.d.ts +9 -0
- package/storybook-build/src/components/AlertBar/AlertBar.stories.d.ts +162 -0
- package/storybook-build/src/components/AlertBar/index.d.ts +13 -0
- package/storybook-build/src/components/Avatar/Avatar.stories.d.ts +44 -0
- package/storybook-build/src/components/Avatar/index.d.ts +4 -0
- package/storybook-build/src/components/index.d.ts +7 -0
- package/storybook-build/src/index.d.ts +1 -0
- package/storybook-build/src/utils/controls.d.ts +36 -0
- package/storybook-build/src/utils/matchMedia.d.ts +2 -0
- package/storybook-build/src/utils/screens.d.ts +7 -0
- package/storybook-build/src/utils/theme.d.ts +3 -0
- package/storybook-build/stories.json +1 -0
- package/storybook-build/styles/base.css +116 -0
- package/svg.d.ts +4 -0
- package/tailwind.config.ts +81 -0
- package/tsconfig.json +43 -0
- package/tsconfig.node.json +12 -0
- package/vite.config.mjs +64 -0
|
@@ -0,0 +1,2920 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "./jsx-runtime-D2-sc1j1.js";
|
|
2
|
+
import { c as create } from "./chunk-EIRT5I3Z-DFD8udmD.js";
|
|
3
|
+
import { r as reactExports } from "./index-DM9bPmif.js";
|
|
4
|
+
import { I as I18nContext, R as ReportNamespaces } from "./context-CIRBAiUz.js";
|
|
5
|
+
import "./_commonjsHelpers-LQfde5yM.js";
|
|
6
|
+
function warn() {
|
|
7
|
+
if (console && console.warn) {
|
|
8
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
|
+
args[_key] = arguments[_key];
|
|
10
|
+
}
|
|
11
|
+
if (typeof args[0] === "string")
|
|
12
|
+
args[0] = `react-i18next:: ${args[0]}`;
|
|
13
|
+
console.warn(...args);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const alreadyWarned = {};
|
|
17
|
+
function warnOnce() {
|
|
18
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
19
|
+
args[_key2] = arguments[_key2];
|
|
20
|
+
}
|
|
21
|
+
if (typeof args[0] === "string" && alreadyWarned[args[0]])
|
|
22
|
+
return;
|
|
23
|
+
if (typeof args[0] === "string")
|
|
24
|
+
alreadyWarned[args[0]] = /* @__PURE__ */ new Date();
|
|
25
|
+
warn(...args);
|
|
26
|
+
}
|
|
27
|
+
const loadedClb = (i18n, cb) => () => {
|
|
28
|
+
if (i18n.isInitialized) {
|
|
29
|
+
cb();
|
|
30
|
+
} else {
|
|
31
|
+
const initialized = () => {
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
i18n.off("initialized", initialized);
|
|
34
|
+
}, 0);
|
|
35
|
+
cb();
|
|
36
|
+
};
|
|
37
|
+
i18n.on("initialized", initialized);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function loadNamespaces(i18n, ns, cb) {
|
|
41
|
+
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
42
|
+
}
|
|
43
|
+
function loadLanguages(i18n, lng, ns, cb) {
|
|
44
|
+
if (typeof ns === "string")
|
|
45
|
+
ns = [ns];
|
|
46
|
+
ns.forEach((n) => {
|
|
47
|
+
if (i18n.options.ns.indexOf(n) < 0)
|
|
48
|
+
i18n.options.ns.push(n);
|
|
49
|
+
});
|
|
50
|
+
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
51
|
+
}
|
|
52
|
+
function oldI18nextHasLoadedNamespace(ns, i18n) {
|
|
53
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
54
|
+
const lng = i18n.languages[0];
|
|
55
|
+
const fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
|
|
56
|
+
const lastLng = i18n.languages[i18n.languages.length - 1];
|
|
57
|
+
if (lng.toLowerCase() === "cimode")
|
|
58
|
+
return true;
|
|
59
|
+
const loadNotPending = (l, n) => {
|
|
60
|
+
const loadState = i18n.services.backendConnector.state[`${l}|${n}`];
|
|
61
|
+
return loadState === -1 || loadState === 2;
|
|
62
|
+
};
|
|
63
|
+
if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns))
|
|
64
|
+
return false;
|
|
65
|
+
if (i18n.hasResourceBundle(lng, ns))
|
|
66
|
+
return true;
|
|
67
|
+
if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages)
|
|
68
|
+
return true;
|
|
69
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns)))
|
|
70
|
+
return true;
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
function hasLoadedNamespace(ns, i18n) {
|
|
74
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
75
|
+
if (!i18n.languages || !i18n.languages.length) {
|
|
76
|
+
warnOnce("i18n.languages were undefined or empty", i18n.languages);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const isNewerI18next = i18n.options.ignoreJSONStructure !== void 0;
|
|
80
|
+
if (!isNewerI18next) {
|
|
81
|
+
return oldI18nextHasLoadedNamespace(ns, i18n, options);
|
|
82
|
+
}
|
|
83
|
+
return i18n.hasLoadedNamespace(ns, {
|
|
84
|
+
lng: options.lng,
|
|
85
|
+
precheck: (i18nInstance2, loadNotPending) => {
|
|
86
|
+
if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns))
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
|
|
92
|
+
const htmlEntities = {
|
|
93
|
+
"&": "&",
|
|
94
|
+
"&": "&",
|
|
95
|
+
"<": "<",
|
|
96
|
+
"<": "<",
|
|
97
|
+
">": ">",
|
|
98
|
+
">": ">",
|
|
99
|
+
"'": "'",
|
|
100
|
+
"'": "'",
|
|
101
|
+
""": '"',
|
|
102
|
+
""": '"',
|
|
103
|
+
" ": " ",
|
|
104
|
+
" ": " ",
|
|
105
|
+
"©": "©",
|
|
106
|
+
"©": "©",
|
|
107
|
+
"®": "®",
|
|
108
|
+
"®": "®",
|
|
109
|
+
"…": "…",
|
|
110
|
+
"…": "…",
|
|
111
|
+
"/": "/",
|
|
112
|
+
"/": "/"
|
|
113
|
+
};
|
|
114
|
+
const unescapeHtmlEntity = (m) => htmlEntities[m];
|
|
115
|
+
const unescape = (text) => text.replace(matchHtmlEntity, unescapeHtmlEntity);
|
|
116
|
+
let defaultOptions = {
|
|
117
|
+
bindI18n: "languageChanged",
|
|
118
|
+
bindI18nStore: "",
|
|
119
|
+
transEmptyNodeValue: "",
|
|
120
|
+
transSupportBasicHtmlNodes: true,
|
|
121
|
+
transWrapTextNodes: "",
|
|
122
|
+
transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"],
|
|
123
|
+
useSuspense: true,
|
|
124
|
+
unescape
|
|
125
|
+
};
|
|
126
|
+
function setDefaults() {
|
|
127
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
128
|
+
defaultOptions = {
|
|
129
|
+
...defaultOptions,
|
|
130
|
+
...options
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function getDefaults() {
|
|
134
|
+
return defaultOptions;
|
|
135
|
+
}
|
|
136
|
+
let i18nInstance;
|
|
137
|
+
function setI18n(instance2) {
|
|
138
|
+
i18nInstance = instance2;
|
|
139
|
+
}
|
|
140
|
+
function getI18n() {
|
|
141
|
+
return i18nInstance;
|
|
142
|
+
}
|
|
143
|
+
const initReactI18next = {
|
|
144
|
+
type: "3rdParty",
|
|
145
|
+
init(instance2) {
|
|
146
|
+
setDefaults(instance2.options.react);
|
|
147
|
+
setI18n(instance2);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const usePrevious = (value, ignore) => {
|
|
151
|
+
const ref = reactExports.useRef();
|
|
152
|
+
reactExports.useEffect(() => {
|
|
153
|
+
ref.current = value;
|
|
154
|
+
}, [value, ignore]);
|
|
155
|
+
return ref.current;
|
|
156
|
+
};
|
|
157
|
+
function alwaysNewT(i18n, language, namespace, keyPrefix) {
|
|
158
|
+
return i18n.getFixedT(language, namespace, keyPrefix);
|
|
159
|
+
}
|
|
160
|
+
function useMemoizedT(i18n, language, namespace, keyPrefix) {
|
|
161
|
+
return reactExports.useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
|
|
162
|
+
}
|
|
163
|
+
function useTranslation(ns) {
|
|
164
|
+
let props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
165
|
+
const {
|
|
166
|
+
i18n: i18nFromProps
|
|
167
|
+
} = props;
|
|
168
|
+
const {
|
|
169
|
+
i18n: i18nFromContext,
|
|
170
|
+
defaultNS: defaultNSFromContext
|
|
171
|
+
} = reactExports.useContext(I18nContext) || {};
|
|
172
|
+
const i18n = i18nFromProps || i18nFromContext || getI18n();
|
|
173
|
+
if (i18n && !i18n.reportNamespaces)
|
|
174
|
+
i18n.reportNamespaces = new ReportNamespaces();
|
|
175
|
+
if (!i18n) {
|
|
176
|
+
warnOnce("You will need to pass in an i18next instance by using initReactI18next");
|
|
177
|
+
const notReadyT = (k, optsOrDefaultValue) => {
|
|
178
|
+
if (typeof optsOrDefaultValue === "string")
|
|
179
|
+
return optsOrDefaultValue;
|
|
180
|
+
if (optsOrDefaultValue && typeof optsOrDefaultValue === "object" && typeof optsOrDefaultValue.defaultValue === "string")
|
|
181
|
+
return optsOrDefaultValue.defaultValue;
|
|
182
|
+
return Array.isArray(k) ? k[k.length - 1] : k;
|
|
183
|
+
};
|
|
184
|
+
const retNotReady = [notReadyT, {}, false];
|
|
185
|
+
retNotReady.t = notReadyT;
|
|
186
|
+
retNotReady.i18n = {};
|
|
187
|
+
retNotReady.ready = false;
|
|
188
|
+
return retNotReady;
|
|
189
|
+
}
|
|
190
|
+
if (i18n.options.react && i18n.options.react.wait !== void 0)
|
|
191
|
+
warnOnce("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
|
|
192
|
+
const i18nOptions = {
|
|
193
|
+
...getDefaults(),
|
|
194
|
+
...i18n.options.react,
|
|
195
|
+
...props
|
|
196
|
+
};
|
|
197
|
+
const {
|
|
198
|
+
useSuspense,
|
|
199
|
+
keyPrefix
|
|
200
|
+
} = i18nOptions;
|
|
201
|
+
let namespaces = defaultNSFromContext || i18n.options && i18n.options.defaultNS;
|
|
202
|
+
namespaces = typeof namespaces === "string" ? [namespaces] : namespaces || ["translation"];
|
|
203
|
+
if (i18n.reportNamespaces.addUsedNamespaces)
|
|
204
|
+
i18n.reportNamespaces.addUsedNamespaces(namespaces);
|
|
205
|
+
const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n) => hasLoadedNamespace(n, i18n, i18nOptions));
|
|
206
|
+
const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
|
|
207
|
+
const getT = () => memoGetT;
|
|
208
|
+
const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
|
|
209
|
+
const [t, setT] = reactExports.useState(getT);
|
|
210
|
+
let joinedNS = namespaces.join();
|
|
211
|
+
if (props.lng)
|
|
212
|
+
joinedNS = `${props.lng}${joinedNS}`;
|
|
213
|
+
const previousJoinedNS = usePrevious(joinedNS);
|
|
214
|
+
const isMounted = reactExports.useRef(true);
|
|
215
|
+
reactExports.useEffect(() => {
|
|
216
|
+
const {
|
|
217
|
+
bindI18n,
|
|
218
|
+
bindI18nStore
|
|
219
|
+
} = i18nOptions;
|
|
220
|
+
isMounted.current = true;
|
|
221
|
+
if (!ready && !useSuspense) {
|
|
222
|
+
if (props.lng) {
|
|
223
|
+
loadLanguages(i18n, props.lng, namespaces, () => {
|
|
224
|
+
if (isMounted.current)
|
|
225
|
+
setT(getNewT);
|
|
226
|
+
});
|
|
227
|
+
} else {
|
|
228
|
+
loadNamespaces(i18n, namespaces, () => {
|
|
229
|
+
if (isMounted.current)
|
|
230
|
+
setT(getNewT);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
|
|
235
|
+
setT(getNewT);
|
|
236
|
+
}
|
|
237
|
+
function boundReset() {
|
|
238
|
+
if (isMounted.current)
|
|
239
|
+
setT(getNewT);
|
|
240
|
+
}
|
|
241
|
+
if (bindI18n && i18n)
|
|
242
|
+
i18n.on(bindI18n, boundReset);
|
|
243
|
+
if (bindI18nStore && i18n)
|
|
244
|
+
i18n.store.on(bindI18nStore, boundReset);
|
|
245
|
+
return () => {
|
|
246
|
+
isMounted.current = false;
|
|
247
|
+
if (bindI18n && i18n)
|
|
248
|
+
bindI18n.split(" ").forEach((e) => i18n.off(e, boundReset));
|
|
249
|
+
if (bindI18nStore && i18n)
|
|
250
|
+
bindI18nStore.split(" ").forEach((e) => i18n.store.off(e, boundReset));
|
|
251
|
+
};
|
|
252
|
+
}, [i18n, joinedNS]);
|
|
253
|
+
reactExports.useEffect(() => {
|
|
254
|
+
if (isMounted.current && ready) {
|
|
255
|
+
setT(getT);
|
|
256
|
+
}
|
|
257
|
+
}, [i18n, keyPrefix, ready]);
|
|
258
|
+
const ret = [t, i18n, ready];
|
|
259
|
+
ret.t = t;
|
|
260
|
+
ret.i18n = i18n;
|
|
261
|
+
ret.ready = ready;
|
|
262
|
+
if (ready)
|
|
263
|
+
return ret;
|
|
264
|
+
if (!ready && !useSuspense)
|
|
265
|
+
return ret;
|
|
266
|
+
throw new Promise((resolve) => {
|
|
267
|
+
if (props.lng) {
|
|
268
|
+
loadLanguages(i18n, props.lng, namespaces, () => resolve());
|
|
269
|
+
} else {
|
|
270
|
+
loadNamespaces(i18n, namespaces, () => resolve());
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
const consoleLogger = {
|
|
275
|
+
type: "logger",
|
|
276
|
+
log(args) {
|
|
277
|
+
this.output("log", args);
|
|
278
|
+
},
|
|
279
|
+
warn(args) {
|
|
280
|
+
this.output("warn", args);
|
|
281
|
+
},
|
|
282
|
+
error(args) {
|
|
283
|
+
this.output("error", args);
|
|
284
|
+
},
|
|
285
|
+
output(type, args) {
|
|
286
|
+
if (console && console[type])
|
|
287
|
+
console[type].apply(console, args);
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
class Logger {
|
|
291
|
+
constructor(concreteLogger) {
|
|
292
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
293
|
+
this.init(concreteLogger, options);
|
|
294
|
+
}
|
|
295
|
+
init(concreteLogger) {
|
|
296
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
297
|
+
this.prefix = options.prefix || "i18next:";
|
|
298
|
+
this.logger = concreteLogger || consoleLogger;
|
|
299
|
+
this.options = options;
|
|
300
|
+
this.debug = options.debug;
|
|
301
|
+
}
|
|
302
|
+
log() {
|
|
303
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
304
|
+
args[_key] = arguments[_key];
|
|
305
|
+
}
|
|
306
|
+
return this.forward(args, "log", "", true);
|
|
307
|
+
}
|
|
308
|
+
warn() {
|
|
309
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
310
|
+
args[_key2] = arguments[_key2];
|
|
311
|
+
}
|
|
312
|
+
return this.forward(args, "warn", "", true);
|
|
313
|
+
}
|
|
314
|
+
error() {
|
|
315
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
316
|
+
args[_key3] = arguments[_key3];
|
|
317
|
+
}
|
|
318
|
+
return this.forward(args, "error", "");
|
|
319
|
+
}
|
|
320
|
+
deprecate() {
|
|
321
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
322
|
+
args[_key4] = arguments[_key4];
|
|
323
|
+
}
|
|
324
|
+
return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
|
|
325
|
+
}
|
|
326
|
+
forward(args, lvl, prefix, debugOnly) {
|
|
327
|
+
if (debugOnly && !this.debug)
|
|
328
|
+
return null;
|
|
329
|
+
if (typeof args[0] === "string")
|
|
330
|
+
args[0] = `${prefix}${this.prefix} ${args[0]}`;
|
|
331
|
+
return this.logger[lvl](args);
|
|
332
|
+
}
|
|
333
|
+
create(moduleName) {
|
|
334
|
+
return new Logger(this.logger, {
|
|
335
|
+
...{
|
|
336
|
+
prefix: `${this.prefix}:${moduleName}:`
|
|
337
|
+
},
|
|
338
|
+
...this.options
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
clone(options) {
|
|
342
|
+
options = options || this.options;
|
|
343
|
+
options.prefix = options.prefix || this.prefix;
|
|
344
|
+
return new Logger(this.logger, options);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
var baseLogger = new Logger();
|
|
348
|
+
class EventEmitter {
|
|
349
|
+
constructor() {
|
|
350
|
+
this.observers = {};
|
|
351
|
+
}
|
|
352
|
+
on(events, listener) {
|
|
353
|
+
events.split(" ").forEach((event) => {
|
|
354
|
+
if (!this.observers[event])
|
|
355
|
+
this.observers[event] = /* @__PURE__ */ new Map();
|
|
356
|
+
const numListeners = this.observers[event].get(listener) || 0;
|
|
357
|
+
this.observers[event].set(listener, numListeners + 1);
|
|
358
|
+
});
|
|
359
|
+
return this;
|
|
360
|
+
}
|
|
361
|
+
off(event, listener) {
|
|
362
|
+
if (!this.observers[event])
|
|
363
|
+
return;
|
|
364
|
+
if (!listener) {
|
|
365
|
+
delete this.observers[event];
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
this.observers[event].delete(listener);
|
|
369
|
+
}
|
|
370
|
+
emit(event) {
|
|
371
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
372
|
+
args[_key - 1] = arguments[_key];
|
|
373
|
+
}
|
|
374
|
+
if (this.observers[event]) {
|
|
375
|
+
const cloned = Array.from(this.observers[event].entries());
|
|
376
|
+
cloned.forEach((_ref) => {
|
|
377
|
+
let [observer, numTimesAdded] = _ref;
|
|
378
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
379
|
+
observer(...args);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
if (this.observers["*"]) {
|
|
384
|
+
const cloned = Array.from(this.observers["*"].entries());
|
|
385
|
+
cloned.forEach((_ref2) => {
|
|
386
|
+
let [observer, numTimesAdded] = _ref2;
|
|
387
|
+
for (let i = 0; i < numTimesAdded; i++) {
|
|
388
|
+
observer.apply(observer, [event, ...args]);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function defer() {
|
|
395
|
+
let res;
|
|
396
|
+
let rej;
|
|
397
|
+
const promise = new Promise((resolve, reject) => {
|
|
398
|
+
res = resolve;
|
|
399
|
+
rej = reject;
|
|
400
|
+
});
|
|
401
|
+
promise.resolve = res;
|
|
402
|
+
promise.reject = rej;
|
|
403
|
+
return promise;
|
|
404
|
+
}
|
|
405
|
+
function makeString(object) {
|
|
406
|
+
if (object == null)
|
|
407
|
+
return "";
|
|
408
|
+
return "" + object;
|
|
409
|
+
}
|
|
410
|
+
function copy(a, s, t) {
|
|
411
|
+
a.forEach((m) => {
|
|
412
|
+
if (s[m])
|
|
413
|
+
t[m] = s[m];
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const lastOfPathSeparatorRegExp = /###/g;
|
|
417
|
+
function getLastOfPath(object, path, Empty) {
|
|
418
|
+
function cleanKey(key) {
|
|
419
|
+
return key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
|
|
420
|
+
}
|
|
421
|
+
function canNotTraverseDeeper() {
|
|
422
|
+
return !object || typeof object === "string";
|
|
423
|
+
}
|
|
424
|
+
const stack = typeof path !== "string" ? path : path.split(".");
|
|
425
|
+
let stackIndex = 0;
|
|
426
|
+
while (stackIndex < stack.length - 1) {
|
|
427
|
+
if (canNotTraverseDeeper())
|
|
428
|
+
return {};
|
|
429
|
+
const key = cleanKey(stack[stackIndex]);
|
|
430
|
+
if (!object[key] && Empty)
|
|
431
|
+
object[key] = new Empty();
|
|
432
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
433
|
+
object = object[key];
|
|
434
|
+
} else {
|
|
435
|
+
object = {};
|
|
436
|
+
}
|
|
437
|
+
++stackIndex;
|
|
438
|
+
}
|
|
439
|
+
if (canNotTraverseDeeper())
|
|
440
|
+
return {};
|
|
441
|
+
return {
|
|
442
|
+
obj: object,
|
|
443
|
+
k: cleanKey(stack[stackIndex])
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function setPath(object, path, newValue) {
|
|
447
|
+
const {
|
|
448
|
+
obj,
|
|
449
|
+
k
|
|
450
|
+
} = getLastOfPath(object, path, Object);
|
|
451
|
+
if (obj !== void 0 || path.length === 1) {
|
|
452
|
+
obj[k] = newValue;
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
let e = path[path.length - 1];
|
|
456
|
+
let p = path.slice(0, path.length - 1);
|
|
457
|
+
let last = getLastOfPath(object, p, Object);
|
|
458
|
+
while (last.obj === void 0 && p.length) {
|
|
459
|
+
e = `${p[p.length - 1]}.${e}`;
|
|
460
|
+
p = p.slice(0, p.length - 1);
|
|
461
|
+
last = getLastOfPath(object, p, Object);
|
|
462
|
+
if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
|
|
463
|
+
last.obj = void 0;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
last.obj[`${last.k}.${e}`] = newValue;
|
|
467
|
+
}
|
|
468
|
+
function pushPath(object, path, newValue, concat) {
|
|
469
|
+
const {
|
|
470
|
+
obj,
|
|
471
|
+
k
|
|
472
|
+
} = getLastOfPath(object, path, Object);
|
|
473
|
+
obj[k] = obj[k] || [];
|
|
474
|
+
obj[k].push(newValue);
|
|
475
|
+
}
|
|
476
|
+
function getPath(object, path) {
|
|
477
|
+
const {
|
|
478
|
+
obj,
|
|
479
|
+
k
|
|
480
|
+
} = getLastOfPath(object, path);
|
|
481
|
+
if (!obj)
|
|
482
|
+
return void 0;
|
|
483
|
+
return obj[k];
|
|
484
|
+
}
|
|
485
|
+
function getPathWithDefaults(data, defaultData, key) {
|
|
486
|
+
const value = getPath(data, key);
|
|
487
|
+
if (value !== void 0) {
|
|
488
|
+
return value;
|
|
489
|
+
}
|
|
490
|
+
return getPath(defaultData, key);
|
|
491
|
+
}
|
|
492
|
+
function deepExtend(target, source, overwrite) {
|
|
493
|
+
for (const prop in source) {
|
|
494
|
+
if (prop !== "__proto__" && prop !== "constructor") {
|
|
495
|
+
if (prop in target) {
|
|
496
|
+
if (typeof target[prop] === "string" || target[prop] instanceof String || typeof source[prop] === "string" || source[prop] instanceof String) {
|
|
497
|
+
if (overwrite)
|
|
498
|
+
target[prop] = source[prop];
|
|
499
|
+
} else {
|
|
500
|
+
deepExtend(target[prop], source[prop], overwrite);
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
target[prop] = source[prop];
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return target;
|
|
508
|
+
}
|
|
509
|
+
function regexEscape(str) {
|
|
510
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
511
|
+
}
|
|
512
|
+
var _entityMap = {
|
|
513
|
+
"&": "&",
|
|
514
|
+
"<": "<",
|
|
515
|
+
">": ">",
|
|
516
|
+
'"': """,
|
|
517
|
+
"'": "'",
|
|
518
|
+
"/": "/"
|
|
519
|
+
};
|
|
520
|
+
function escape(data) {
|
|
521
|
+
if (typeof data === "string") {
|
|
522
|
+
return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
|
|
523
|
+
}
|
|
524
|
+
return data;
|
|
525
|
+
}
|
|
526
|
+
class RegExpCache {
|
|
527
|
+
constructor(capacity) {
|
|
528
|
+
this.capacity = capacity;
|
|
529
|
+
this.regExpMap = /* @__PURE__ */ new Map();
|
|
530
|
+
this.regExpQueue = [];
|
|
531
|
+
}
|
|
532
|
+
getRegExp(pattern) {
|
|
533
|
+
const regExpFromCache = this.regExpMap.get(pattern);
|
|
534
|
+
if (regExpFromCache !== void 0) {
|
|
535
|
+
return regExpFromCache;
|
|
536
|
+
}
|
|
537
|
+
const regExpNew = new RegExp(pattern);
|
|
538
|
+
if (this.regExpQueue.length === this.capacity) {
|
|
539
|
+
this.regExpMap.delete(this.regExpQueue.shift());
|
|
540
|
+
}
|
|
541
|
+
this.regExpMap.set(pattern, regExpNew);
|
|
542
|
+
this.regExpQueue.push(pattern);
|
|
543
|
+
return regExpNew;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
const chars = [" ", ",", "?", "!", ";"];
|
|
547
|
+
const looksLikeObjectPathRegExpCache = new RegExpCache(20);
|
|
548
|
+
function looksLikeObjectPath(key, nsSeparator, keySeparator) {
|
|
549
|
+
nsSeparator = nsSeparator || "";
|
|
550
|
+
keySeparator = keySeparator || "";
|
|
551
|
+
const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
|
|
552
|
+
if (possibleChars.length === 0)
|
|
553
|
+
return true;
|
|
554
|
+
const r2 = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
|
|
555
|
+
let matched = !r2.test(key);
|
|
556
|
+
if (!matched) {
|
|
557
|
+
const ki = key.indexOf(keySeparator);
|
|
558
|
+
if (ki > 0 && !r2.test(key.substring(0, ki))) {
|
|
559
|
+
matched = true;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return matched;
|
|
563
|
+
}
|
|
564
|
+
function deepFind(obj, path) {
|
|
565
|
+
let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
|
|
566
|
+
if (!obj)
|
|
567
|
+
return void 0;
|
|
568
|
+
if (obj[path])
|
|
569
|
+
return obj[path];
|
|
570
|
+
const tokens = path.split(keySeparator);
|
|
571
|
+
let current = obj;
|
|
572
|
+
for (let i = 0; i < tokens.length; ) {
|
|
573
|
+
if (!current || typeof current !== "object") {
|
|
574
|
+
return void 0;
|
|
575
|
+
}
|
|
576
|
+
let next;
|
|
577
|
+
let nextPath = "";
|
|
578
|
+
for (let j = i; j < tokens.length; ++j) {
|
|
579
|
+
if (j !== i) {
|
|
580
|
+
nextPath += keySeparator;
|
|
581
|
+
}
|
|
582
|
+
nextPath += tokens[j];
|
|
583
|
+
next = current[nextPath];
|
|
584
|
+
if (next !== void 0) {
|
|
585
|
+
if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
i += j - i + 1;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
current = next;
|
|
593
|
+
}
|
|
594
|
+
return current;
|
|
595
|
+
}
|
|
596
|
+
function getCleanedCode(code) {
|
|
597
|
+
if (code && code.indexOf("_") > 0)
|
|
598
|
+
return code.replace("_", "-");
|
|
599
|
+
return code;
|
|
600
|
+
}
|
|
601
|
+
class ResourceStore extends EventEmitter {
|
|
602
|
+
constructor(data) {
|
|
603
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
604
|
+
ns: ["translation"],
|
|
605
|
+
defaultNS: "translation"
|
|
606
|
+
};
|
|
607
|
+
super();
|
|
608
|
+
this.data = data || {};
|
|
609
|
+
this.options = options;
|
|
610
|
+
if (this.options.keySeparator === void 0) {
|
|
611
|
+
this.options.keySeparator = ".";
|
|
612
|
+
}
|
|
613
|
+
if (this.options.ignoreJSONStructure === void 0) {
|
|
614
|
+
this.options.ignoreJSONStructure = true;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
addNamespaces(ns) {
|
|
618
|
+
if (this.options.ns.indexOf(ns) < 0) {
|
|
619
|
+
this.options.ns.push(ns);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
removeNamespaces(ns) {
|
|
623
|
+
const index = this.options.ns.indexOf(ns);
|
|
624
|
+
if (index > -1) {
|
|
625
|
+
this.options.ns.splice(index, 1);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
getResource(lng, ns, key) {
|
|
629
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
630
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
631
|
+
const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
|
|
632
|
+
let path;
|
|
633
|
+
if (lng.indexOf(".") > -1) {
|
|
634
|
+
path = lng.split(".");
|
|
635
|
+
} else {
|
|
636
|
+
path = [lng, ns];
|
|
637
|
+
if (key) {
|
|
638
|
+
if (Array.isArray(key)) {
|
|
639
|
+
path.push(...key);
|
|
640
|
+
} else if (typeof key === "string" && keySeparator) {
|
|
641
|
+
path.push(...key.split(keySeparator));
|
|
642
|
+
} else {
|
|
643
|
+
path.push(key);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
const result = getPath(this.data, path);
|
|
648
|
+
if (!result && !ns && !key && lng.indexOf(".") > -1) {
|
|
649
|
+
lng = path[0];
|
|
650
|
+
ns = path[1];
|
|
651
|
+
key = path.slice(2).join(".");
|
|
652
|
+
}
|
|
653
|
+
if (result || !ignoreJSONStructure || typeof key !== "string")
|
|
654
|
+
return result;
|
|
655
|
+
return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
|
|
656
|
+
}
|
|
657
|
+
addResource(lng, ns, key, value) {
|
|
658
|
+
let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
|
|
659
|
+
silent: false
|
|
660
|
+
};
|
|
661
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
662
|
+
let path = [lng, ns];
|
|
663
|
+
if (key)
|
|
664
|
+
path = path.concat(keySeparator ? key.split(keySeparator) : key);
|
|
665
|
+
if (lng.indexOf(".") > -1) {
|
|
666
|
+
path = lng.split(".");
|
|
667
|
+
value = ns;
|
|
668
|
+
ns = path[1];
|
|
669
|
+
}
|
|
670
|
+
this.addNamespaces(ns);
|
|
671
|
+
setPath(this.data, path, value);
|
|
672
|
+
if (!options.silent)
|
|
673
|
+
this.emit("added", lng, ns, key, value);
|
|
674
|
+
}
|
|
675
|
+
addResources(lng, ns, resources2) {
|
|
676
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
|
|
677
|
+
silent: false
|
|
678
|
+
};
|
|
679
|
+
for (const m in resources2) {
|
|
680
|
+
if (typeof resources2[m] === "string" || Object.prototype.toString.apply(resources2[m]) === "[object Array]")
|
|
681
|
+
this.addResource(lng, ns, m, resources2[m], {
|
|
682
|
+
silent: true
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
if (!options.silent)
|
|
686
|
+
this.emit("added", lng, ns, resources2);
|
|
687
|
+
}
|
|
688
|
+
addResourceBundle(lng, ns, resources2, deep, overwrite) {
|
|
689
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
|
|
690
|
+
silent: false,
|
|
691
|
+
skipCopy: false
|
|
692
|
+
};
|
|
693
|
+
let path = [lng, ns];
|
|
694
|
+
if (lng.indexOf(".") > -1) {
|
|
695
|
+
path = lng.split(".");
|
|
696
|
+
deep = resources2;
|
|
697
|
+
resources2 = ns;
|
|
698
|
+
ns = path[1];
|
|
699
|
+
}
|
|
700
|
+
this.addNamespaces(ns);
|
|
701
|
+
let pack = getPath(this.data, path) || {};
|
|
702
|
+
if (!options.skipCopy)
|
|
703
|
+
resources2 = JSON.parse(JSON.stringify(resources2));
|
|
704
|
+
if (deep) {
|
|
705
|
+
deepExtend(pack, resources2, overwrite);
|
|
706
|
+
} else {
|
|
707
|
+
pack = {
|
|
708
|
+
...pack,
|
|
709
|
+
...resources2
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
setPath(this.data, path, pack);
|
|
713
|
+
if (!options.silent)
|
|
714
|
+
this.emit("added", lng, ns, resources2);
|
|
715
|
+
}
|
|
716
|
+
removeResourceBundle(lng, ns) {
|
|
717
|
+
if (this.hasResourceBundle(lng, ns)) {
|
|
718
|
+
delete this.data[lng][ns];
|
|
719
|
+
}
|
|
720
|
+
this.removeNamespaces(ns);
|
|
721
|
+
this.emit("removed", lng, ns);
|
|
722
|
+
}
|
|
723
|
+
hasResourceBundle(lng, ns) {
|
|
724
|
+
return this.getResource(lng, ns) !== void 0;
|
|
725
|
+
}
|
|
726
|
+
getResourceBundle(lng, ns) {
|
|
727
|
+
if (!ns)
|
|
728
|
+
ns = this.options.defaultNS;
|
|
729
|
+
if (this.options.compatibilityAPI === "v1")
|
|
730
|
+
return {
|
|
731
|
+
...{},
|
|
732
|
+
...this.getResource(lng, ns)
|
|
733
|
+
};
|
|
734
|
+
return this.getResource(lng, ns);
|
|
735
|
+
}
|
|
736
|
+
getDataByLanguage(lng) {
|
|
737
|
+
return this.data[lng];
|
|
738
|
+
}
|
|
739
|
+
hasLanguageSomeTranslations(lng) {
|
|
740
|
+
const data = this.getDataByLanguage(lng);
|
|
741
|
+
const n = data && Object.keys(data) || [];
|
|
742
|
+
return !!n.find((v) => data[v] && Object.keys(data[v]).length > 0);
|
|
743
|
+
}
|
|
744
|
+
toJSON() {
|
|
745
|
+
return this.data;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
var postProcessor = {
|
|
749
|
+
processors: {},
|
|
750
|
+
addPostProcessor(module) {
|
|
751
|
+
this.processors[module.name] = module;
|
|
752
|
+
},
|
|
753
|
+
handle(processors, value, key, options, translator) {
|
|
754
|
+
processors.forEach((processor) => {
|
|
755
|
+
if (this.processors[processor])
|
|
756
|
+
value = this.processors[processor].process(value, key, options, translator);
|
|
757
|
+
});
|
|
758
|
+
return value;
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
const checkedLoadedFor = {};
|
|
762
|
+
class Translator extends EventEmitter {
|
|
763
|
+
constructor(services) {
|
|
764
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
765
|
+
super();
|
|
766
|
+
copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
|
|
767
|
+
this.options = options;
|
|
768
|
+
if (this.options.keySeparator === void 0) {
|
|
769
|
+
this.options.keySeparator = ".";
|
|
770
|
+
}
|
|
771
|
+
this.logger = baseLogger.create("translator");
|
|
772
|
+
}
|
|
773
|
+
changeLanguage(lng) {
|
|
774
|
+
if (lng)
|
|
775
|
+
this.language = lng;
|
|
776
|
+
}
|
|
777
|
+
exists(key) {
|
|
778
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
779
|
+
interpolation: {}
|
|
780
|
+
};
|
|
781
|
+
if (key === void 0 || key === null) {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
const resolved = this.resolve(key, options);
|
|
785
|
+
return resolved && resolved.res !== void 0;
|
|
786
|
+
}
|
|
787
|
+
extractFromKey(key, options) {
|
|
788
|
+
let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
|
|
789
|
+
if (nsSeparator === void 0)
|
|
790
|
+
nsSeparator = ":";
|
|
791
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
792
|
+
let namespaces = options.ns || this.options.defaultNS || [];
|
|
793
|
+
const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
|
|
794
|
+
const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
|
|
795
|
+
if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
|
|
796
|
+
const m = key.match(this.interpolator.nestingRegexp);
|
|
797
|
+
if (m && m.length > 0) {
|
|
798
|
+
return {
|
|
799
|
+
key,
|
|
800
|
+
namespaces
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
const parts = key.split(nsSeparator);
|
|
804
|
+
if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1)
|
|
805
|
+
namespaces = parts.shift();
|
|
806
|
+
key = parts.join(keySeparator);
|
|
807
|
+
}
|
|
808
|
+
if (typeof namespaces === "string")
|
|
809
|
+
namespaces = [namespaces];
|
|
810
|
+
return {
|
|
811
|
+
key,
|
|
812
|
+
namespaces
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
translate(keys, options, lastKey) {
|
|
816
|
+
if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
|
|
817
|
+
options = this.options.overloadTranslationOptionHandler(arguments);
|
|
818
|
+
}
|
|
819
|
+
if (typeof options === "object")
|
|
820
|
+
options = {
|
|
821
|
+
...options
|
|
822
|
+
};
|
|
823
|
+
if (!options)
|
|
824
|
+
options = {};
|
|
825
|
+
if (keys === void 0 || keys === null)
|
|
826
|
+
return "";
|
|
827
|
+
if (!Array.isArray(keys))
|
|
828
|
+
keys = [String(keys)];
|
|
829
|
+
const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
|
|
830
|
+
const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
|
|
831
|
+
const {
|
|
832
|
+
key,
|
|
833
|
+
namespaces
|
|
834
|
+
} = this.extractFromKey(keys[keys.length - 1], options);
|
|
835
|
+
const namespace = namespaces[namespaces.length - 1];
|
|
836
|
+
const lng = options.lng || this.language;
|
|
837
|
+
const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
|
|
838
|
+
if (lng && lng.toLowerCase() === "cimode") {
|
|
839
|
+
if (appendNamespaceToCIMode) {
|
|
840
|
+
const nsSeparator = options.nsSeparator || this.options.nsSeparator;
|
|
841
|
+
if (returnDetails) {
|
|
842
|
+
return {
|
|
843
|
+
res: `${namespace}${nsSeparator}${key}`,
|
|
844
|
+
usedKey: key,
|
|
845
|
+
exactUsedKey: key,
|
|
846
|
+
usedLng: lng,
|
|
847
|
+
usedNS: namespace,
|
|
848
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
return `${namespace}${nsSeparator}${key}`;
|
|
852
|
+
}
|
|
853
|
+
if (returnDetails) {
|
|
854
|
+
return {
|
|
855
|
+
res: key,
|
|
856
|
+
usedKey: key,
|
|
857
|
+
exactUsedKey: key,
|
|
858
|
+
usedLng: lng,
|
|
859
|
+
usedNS: namespace,
|
|
860
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
return key;
|
|
864
|
+
}
|
|
865
|
+
const resolved = this.resolve(keys, options);
|
|
866
|
+
let res = resolved && resolved.res;
|
|
867
|
+
const resUsedKey = resolved && resolved.usedKey || key;
|
|
868
|
+
const resExactUsedKey = resolved && resolved.exactUsedKey || key;
|
|
869
|
+
const resType = Object.prototype.toString.apply(res);
|
|
870
|
+
const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
|
|
871
|
+
const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
|
|
872
|
+
const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
|
|
873
|
+
const handleAsObject = typeof res !== "string" && typeof res !== "boolean" && typeof res !== "number";
|
|
874
|
+
if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === "string" && resType === "[object Array]")) {
|
|
875
|
+
if (!options.returnObjects && !this.options.returnObjects) {
|
|
876
|
+
if (!this.options.returnedObjectHandler) {
|
|
877
|
+
this.logger.warn("accessing an object - but returnObjects options is not enabled!");
|
|
878
|
+
}
|
|
879
|
+
const r2 = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
|
|
880
|
+
...options,
|
|
881
|
+
ns: namespaces
|
|
882
|
+
}) : `key '${key} (${this.language})' returned an object instead of string.`;
|
|
883
|
+
if (returnDetails) {
|
|
884
|
+
resolved.res = r2;
|
|
885
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
886
|
+
return resolved;
|
|
887
|
+
}
|
|
888
|
+
return r2;
|
|
889
|
+
}
|
|
890
|
+
if (keySeparator) {
|
|
891
|
+
const resTypeIsArray = resType === "[object Array]";
|
|
892
|
+
const copy2 = resTypeIsArray ? [] : {};
|
|
893
|
+
const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
|
|
894
|
+
for (const m in res) {
|
|
895
|
+
if (Object.prototype.hasOwnProperty.call(res, m)) {
|
|
896
|
+
const deepKey = `${newKeyToUse}${keySeparator}${m}`;
|
|
897
|
+
copy2[m] = this.translate(deepKey, {
|
|
898
|
+
...options,
|
|
899
|
+
...{
|
|
900
|
+
joinArrays: false,
|
|
901
|
+
ns: namespaces
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
if (copy2[m] === deepKey)
|
|
905
|
+
copy2[m] = res[m];
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
res = copy2;
|
|
909
|
+
}
|
|
910
|
+
} else if (handleAsObjectInI18nFormat && typeof joinArrays === "string" && resType === "[object Array]") {
|
|
911
|
+
res = res.join(joinArrays);
|
|
912
|
+
if (res)
|
|
913
|
+
res = this.extendTranslation(res, keys, options, lastKey);
|
|
914
|
+
} else {
|
|
915
|
+
let usedDefault = false;
|
|
916
|
+
let usedKey = false;
|
|
917
|
+
const needsPluralHandling = options.count !== void 0 && typeof options.count !== "string";
|
|
918
|
+
const hasDefaultValue = Translator.hasDefaultValue(options);
|
|
919
|
+
const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
|
|
920
|
+
const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
|
|
921
|
+
ordinal: false
|
|
922
|
+
}) : "";
|
|
923
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
924
|
+
const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
|
|
925
|
+
if (!this.isValidLookup(res) && hasDefaultValue) {
|
|
926
|
+
usedDefault = true;
|
|
927
|
+
res = defaultValue;
|
|
928
|
+
}
|
|
929
|
+
if (!this.isValidLookup(res)) {
|
|
930
|
+
usedKey = true;
|
|
931
|
+
res = key;
|
|
932
|
+
}
|
|
933
|
+
const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
|
|
934
|
+
const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
|
|
935
|
+
const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
|
|
936
|
+
if (usedKey || usedDefault || updateMissing) {
|
|
937
|
+
this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
|
|
938
|
+
if (keySeparator) {
|
|
939
|
+
const fk = this.resolve(key, {
|
|
940
|
+
...options,
|
|
941
|
+
keySeparator: false
|
|
942
|
+
});
|
|
943
|
+
if (fk && fk.res)
|
|
944
|
+
this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
|
|
945
|
+
}
|
|
946
|
+
let lngs = [];
|
|
947
|
+
const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
|
|
948
|
+
if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
|
|
949
|
+
for (let i = 0; i < fallbackLngs.length; i++) {
|
|
950
|
+
lngs.push(fallbackLngs[i]);
|
|
951
|
+
}
|
|
952
|
+
} else if (this.options.saveMissingTo === "all") {
|
|
953
|
+
lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
|
|
954
|
+
} else {
|
|
955
|
+
lngs.push(options.lng || this.language);
|
|
956
|
+
}
|
|
957
|
+
const send = (l, k, specificDefaultValue) => {
|
|
958
|
+
const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
|
|
959
|
+
if (this.options.missingKeyHandler) {
|
|
960
|
+
this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
961
|
+
} else if (this.backendConnector && this.backendConnector.saveMissing) {
|
|
962
|
+
this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
|
|
963
|
+
}
|
|
964
|
+
this.emit("missingKey", l, namespace, k, res);
|
|
965
|
+
};
|
|
966
|
+
if (this.options.saveMissing) {
|
|
967
|
+
if (this.options.saveMissingPlurals && needsPluralHandling) {
|
|
968
|
+
lngs.forEach((language) => {
|
|
969
|
+
const suffixes = this.pluralResolver.getSuffixes(language, options);
|
|
970
|
+
if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
|
|
971
|
+
suffixes.push(`${this.options.pluralSeparator}zero`);
|
|
972
|
+
}
|
|
973
|
+
suffixes.forEach((suffix) => {
|
|
974
|
+
send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
} else {
|
|
978
|
+
send(lngs, key, defaultValue);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
res = this.extendTranslation(res, keys, options, resolved, lastKey);
|
|
983
|
+
if (usedKey && res === key && this.options.appendNamespaceToMissingKey)
|
|
984
|
+
res = `${namespace}:${key}`;
|
|
985
|
+
if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
|
|
986
|
+
if (this.options.compatibilityAPI !== "v1") {
|
|
987
|
+
res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
|
|
988
|
+
} else {
|
|
989
|
+
res = this.options.parseMissingKeyHandler(res);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
if (returnDetails) {
|
|
994
|
+
resolved.res = res;
|
|
995
|
+
resolved.usedParams = this.getUsedParamsDetails(options);
|
|
996
|
+
return resolved;
|
|
997
|
+
}
|
|
998
|
+
return res;
|
|
999
|
+
}
|
|
1000
|
+
extendTranslation(res, key, options, resolved, lastKey) {
|
|
1001
|
+
var _this = this;
|
|
1002
|
+
if (this.i18nFormat && this.i18nFormat.parse) {
|
|
1003
|
+
res = this.i18nFormat.parse(res, {
|
|
1004
|
+
...this.options.interpolation.defaultVariables,
|
|
1005
|
+
...options
|
|
1006
|
+
}, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
|
|
1007
|
+
resolved
|
|
1008
|
+
});
|
|
1009
|
+
} else if (!options.skipInterpolation) {
|
|
1010
|
+
if (options.interpolation)
|
|
1011
|
+
this.interpolator.init({
|
|
1012
|
+
...options,
|
|
1013
|
+
...{
|
|
1014
|
+
interpolation: {
|
|
1015
|
+
...this.options.interpolation,
|
|
1016
|
+
...options.interpolation
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
const skipOnVariables = typeof res === "string" && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
|
|
1021
|
+
let nestBef;
|
|
1022
|
+
if (skipOnVariables) {
|
|
1023
|
+
const nb = res.match(this.interpolator.nestingRegexp);
|
|
1024
|
+
nestBef = nb && nb.length;
|
|
1025
|
+
}
|
|
1026
|
+
let data = options.replace && typeof options.replace !== "string" ? options.replace : options;
|
|
1027
|
+
if (this.options.interpolation.defaultVariables)
|
|
1028
|
+
data = {
|
|
1029
|
+
...this.options.interpolation.defaultVariables,
|
|
1030
|
+
...data
|
|
1031
|
+
};
|
|
1032
|
+
res = this.interpolator.interpolate(res, data, options.lng || this.language, options);
|
|
1033
|
+
if (skipOnVariables) {
|
|
1034
|
+
const na = res.match(this.interpolator.nestingRegexp);
|
|
1035
|
+
const nestAft = na && na.length;
|
|
1036
|
+
if (nestBef < nestAft)
|
|
1037
|
+
options.nest = false;
|
|
1038
|
+
}
|
|
1039
|
+
if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res)
|
|
1040
|
+
options.lng = resolved.usedLng;
|
|
1041
|
+
if (options.nest !== false)
|
|
1042
|
+
res = this.interpolator.nest(res, function() {
|
|
1043
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1044
|
+
args[_key] = arguments[_key];
|
|
1045
|
+
}
|
|
1046
|
+
if (lastKey && lastKey[0] === args[0] && !options.context) {
|
|
1047
|
+
_this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
|
|
1048
|
+
return null;
|
|
1049
|
+
}
|
|
1050
|
+
return _this.translate(...args, key);
|
|
1051
|
+
}, options);
|
|
1052
|
+
if (options.interpolation)
|
|
1053
|
+
this.interpolator.reset();
|
|
1054
|
+
}
|
|
1055
|
+
const postProcess = options.postProcess || this.options.postProcess;
|
|
1056
|
+
const postProcessorNames = typeof postProcess === "string" ? [postProcess] : postProcess;
|
|
1057
|
+
if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
|
|
1058
|
+
res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
|
|
1059
|
+
i18nResolved: {
|
|
1060
|
+
...resolved,
|
|
1061
|
+
usedParams: this.getUsedParamsDetails(options)
|
|
1062
|
+
},
|
|
1063
|
+
...options
|
|
1064
|
+
} : options, this);
|
|
1065
|
+
}
|
|
1066
|
+
return res;
|
|
1067
|
+
}
|
|
1068
|
+
resolve(keys) {
|
|
1069
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1070
|
+
let found;
|
|
1071
|
+
let usedKey;
|
|
1072
|
+
let exactUsedKey;
|
|
1073
|
+
let usedLng;
|
|
1074
|
+
let usedNS;
|
|
1075
|
+
if (typeof keys === "string")
|
|
1076
|
+
keys = [keys];
|
|
1077
|
+
keys.forEach((k) => {
|
|
1078
|
+
if (this.isValidLookup(found))
|
|
1079
|
+
return;
|
|
1080
|
+
const extracted = this.extractFromKey(k, options);
|
|
1081
|
+
const key = extracted.key;
|
|
1082
|
+
usedKey = key;
|
|
1083
|
+
let namespaces = extracted.namespaces;
|
|
1084
|
+
if (this.options.fallbackNS)
|
|
1085
|
+
namespaces = namespaces.concat(this.options.fallbackNS);
|
|
1086
|
+
const needsPluralHandling = options.count !== void 0 && typeof options.count !== "string";
|
|
1087
|
+
const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
|
|
1088
|
+
const needsContextHandling = options.context !== void 0 && (typeof options.context === "string" || typeof options.context === "number") && options.context !== "";
|
|
1089
|
+
const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
|
|
1090
|
+
namespaces.forEach((ns) => {
|
|
1091
|
+
if (this.isValidLookup(found))
|
|
1092
|
+
return;
|
|
1093
|
+
usedNS = ns;
|
|
1094
|
+
if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
|
|
1095
|
+
checkedLoadedFor[`${codes[0]}-${ns}`] = true;
|
|
1096
|
+
this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
1097
|
+
}
|
|
1098
|
+
codes.forEach((code) => {
|
|
1099
|
+
if (this.isValidLookup(found))
|
|
1100
|
+
return;
|
|
1101
|
+
usedLng = code;
|
|
1102
|
+
const finalKeys = [key];
|
|
1103
|
+
if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
|
|
1104
|
+
this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
|
|
1105
|
+
} else {
|
|
1106
|
+
let pluralSuffix;
|
|
1107
|
+
if (needsPluralHandling)
|
|
1108
|
+
pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
|
|
1109
|
+
const zeroSuffix = `${this.options.pluralSeparator}zero`;
|
|
1110
|
+
const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
|
|
1111
|
+
if (needsPluralHandling) {
|
|
1112
|
+
finalKeys.push(key + pluralSuffix);
|
|
1113
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
1114
|
+
finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
1115
|
+
}
|
|
1116
|
+
if (needsZeroSuffixLookup) {
|
|
1117
|
+
finalKeys.push(key + zeroSuffix);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (needsContextHandling) {
|
|
1121
|
+
const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
|
|
1122
|
+
finalKeys.push(contextKey);
|
|
1123
|
+
if (needsPluralHandling) {
|
|
1124
|
+
finalKeys.push(contextKey + pluralSuffix);
|
|
1125
|
+
if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
|
|
1126
|
+
finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
|
|
1127
|
+
}
|
|
1128
|
+
if (needsZeroSuffixLookup) {
|
|
1129
|
+
finalKeys.push(contextKey + zeroSuffix);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
let possibleKey;
|
|
1135
|
+
while (possibleKey = finalKeys.pop()) {
|
|
1136
|
+
if (!this.isValidLookup(found)) {
|
|
1137
|
+
exactUsedKey = possibleKey;
|
|
1138
|
+
found = this.getResource(code, ns, possibleKey, options);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
});
|
|
1143
|
+
});
|
|
1144
|
+
return {
|
|
1145
|
+
res: found,
|
|
1146
|
+
usedKey,
|
|
1147
|
+
exactUsedKey,
|
|
1148
|
+
usedLng,
|
|
1149
|
+
usedNS
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
isValidLookup(res) {
|
|
1153
|
+
return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
|
|
1154
|
+
}
|
|
1155
|
+
getResource(code, ns, key) {
|
|
1156
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1157
|
+
if (this.i18nFormat && this.i18nFormat.getResource)
|
|
1158
|
+
return this.i18nFormat.getResource(code, ns, key, options);
|
|
1159
|
+
return this.resourceStore.getResource(code, ns, key, options);
|
|
1160
|
+
}
|
|
1161
|
+
getUsedParamsDetails() {
|
|
1162
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1163
|
+
const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
|
|
1164
|
+
const useOptionsReplaceForData = options.replace && typeof options.replace !== "string";
|
|
1165
|
+
let data = useOptionsReplaceForData ? options.replace : options;
|
|
1166
|
+
if (useOptionsReplaceForData && typeof options.count !== "undefined") {
|
|
1167
|
+
data.count = options.count;
|
|
1168
|
+
}
|
|
1169
|
+
if (this.options.interpolation.defaultVariables) {
|
|
1170
|
+
data = {
|
|
1171
|
+
...this.options.interpolation.defaultVariables,
|
|
1172
|
+
...data
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
if (!useOptionsReplaceForData) {
|
|
1176
|
+
data = {
|
|
1177
|
+
...data
|
|
1178
|
+
};
|
|
1179
|
+
for (const key of optionsKeys) {
|
|
1180
|
+
delete data[key];
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
return data;
|
|
1184
|
+
}
|
|
1185
|
+
static hasDefaultValue(options) {
|
|
1186
|
+
const prefix = "defaultValue";
|
|
1187
|
+
for (const option in options) {
|
|
1188
|
+
if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
function capitalize(string) {
|
|
1196
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1197
|
+
}
|
|
1198
|
+
class LanguageUtil {
|
|
1199
|
+
constructor(options) {
|
|
1200
|
+
this.options = options;
|
|
1201
|
+
this.supportedLngs = this.options.supportedLngs || false;
|
|
1202
|
+
this.logger = baseLogger.create("languageUtils");
|
|
1203
|
+
}
|
|
1204
|
+
getScriptPartFromCode(code) {
|
|
1205
|
+
code = getCleanedCode(code);
|
|
1206
|
+
if (!code || code.indexOf("-") < 0)
|
|
1207
|
+
return null;
|
|
1208
|
+
const p = code.split("-");
|
|
1209
|
+
if (p.length === 2)
|
|
1210
|
+
return null;
|
|
1211
|
+
p.pop();
|
|
1212
|
+
if (p[p.length - 1].toLowerCase() === "x")
|
|
1213
|
+
return null;
|
|
1214
|
+
return this.formatLanguageCode(p.join("-"));
|
|
1215
|
+
}
|
|
1216
|
+
getLanguagePartFromCode(code) {
|
|
1217
|
+
code = getCleanedCode(code);
|
|
1218
|
+
if (!code || code.indexOf("-") < 0)
|
|
1219
|
+
return code;
|
|
1220
|
+
const p = code.split("-");
|
|
1221
|
+
return this.formatLanguageCode(p[0]);
|
|
1222
|
+
}
|
|
1223
|
+
formatLanguageCode(code) {
|
|
1224
|
+
if (typeof code === "string" && code.indexOf("-") > -1) {
|
|
1225
|
+
const specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
|
|
1226
|
+
let p = code.split("-");
|
|
1227
|
+
if (this.options.lowerCaseLng) {
|
|
1228
|
+
p = p.map((part) => part.toLowerCase());
|
|
1229
|
+
} else if (p.length === 2) {
|
|
1230
|
+
p[0] = p[0].toLowerCase();
|
|
1231
|
+
p[1] = p[1].toUpperCase();
|
|
1232
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1)
|
|
1233
|
+
p[1] = capitalize(p[1].toLowerCase());
|
|
1234
|
+
} else if (p.length === 3) {
|
|
1235
|
+
p[0] = p[0].toLowerCase();
|
|
1236
|
+
if (p[1].length === 2)
|
|
1237
|
+
p[1] = p[1].toUpperCase();
|
|
1238
|
+
if (p[0] !== "sgn" && p[2].length === 2)
|
|
1239
|
+
p[2] = p[2].toUpperCase();
|
|
1240
|
+
if (specialCases.indexOf(p[1].toLowerCase()) > -1)
|
|
1241
|
+
p[1] = capitalize(p[1].toLowerCase());
|
|
1242
|
+
if (specialCases.indexOf(p[2].toLowerCase()) > -1)
|
|
1243
|
+
p[2] = capitalize(p[2].toLowerCase());
|
|
1244
|
+
}
|
|
1245
|
+
return p.join("-");
|
|
1246
|
+
}
|
|
1247
|
+
return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
|
|
1248
|
+
}
|
|
1249
|
+
isSupportedCode(code) {
|
|
1250
|
+
if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
|
|
1251
|
+
code = this.getLanguagePartFromCode(code);
|
|
1252
|
+
}
|
|
1253
|
+
return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
|
|
1254
|
+
}
|
|
1255
|
+
getBestMatchFromCodes(codes) {
|
|
1256
|
+
if (!codes)
|
|
1257
|
+
return null;
|
|
1258
|
+
let found;
|
|
1259
|
+
codes.forEach((code) => {
|
|
1260
|
+
if (found)
|
|
1261
|
+
return;
|
|
1262
|
+
const cleanedLng = this.formatLanguageCode(code);
|
|
1263
|
+
if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng))
|
|
1264
|
+
found = cleanedLng;
|
|
1265
|
+
});
|
|
1266
|
+
if (!found && this.options.supportedLngs) {
|
|
1267
|
+
codes.forEach((code) => {
|
|
1268
|
+
if (found)
|
|
1269
|
+
return;
|
|
1270
|
+
const lngOnly = this.getLanguagePartFromCode(code);
|
|
1271
|
+
if (this.isSupportedCode(lngOnly))
|
|
1272
|
+
return found = lngOnly;
|
|
1273
|
+
found = this.options.supportedLngs.find((supportedLng) => {
|
|
1274
|
+
if (supportedLng === lngOnly)
|
|
1275
|
+
return supportedLng;
|
|
1276
|
+
if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0)
|
|
1277
|
+
return;
|
|
1278
|
+
if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly)
|
|
1279
|
+
return supportedLng;
|
|
1280
|
+
if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1)
|
|
1281
|
+
return supportedLng;
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
if (!found)
|
|
1286
|
+
found = this.getFallbackCodes(this.options.fallbackLng)[0];
|
|
1287
|
+
return found;
|
|
1288
|
+
}
|
|
1289
|
+
getFallbackCodes(fallbacks, code) {
|
|
1290
|
+
if (!fallbacks)
|
|
1291
|
+
return [];
|
|
1292
|
+
if (typeof fallbacks === "function")
|
|
1293
|
+
fallbacks = fallbacks(code);
|
|
1294
|
+
if (typeof fallbacks === "string")
|
|
1295
|
+
fallbacks = [fallbacks];
|
|
1296
|
+
if (Object.prototype.toString.apply(fallbacks) === "[object Array]")
|
|
1297
|
+
return fallbacks;
|
|
1298
|
+
if (!code)
|
|
1299
|
+
return fallbacks.default || [];
|
|
1300
|
+
let found = fallbacks[code];
|
|
1301
|
+
if (!found)
|
|
1302
|
+
found = fallbacks[this.getScriptPartFromCode(code)];
|
|
1303
|
+
if (!found)
|
|
1304
|
+
found = fallbacks[this.formatLanguageCode(code)];
|
|
1305
|
+
if (!found)
|
|
1306
|
+
found = fallbacks[this.getLanguagePartFromCode(code)];
|
|
1307
|
+
if (!found)
|
|
1308
|
+
found = fallbacks.default;
|
|
1309
|
+
return found || [];
|
|
1310
|
+
}
|
|
1311
|
+
toResolveHierarchy(code, fallbackCode) {
|
|
1312
|
+
const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
|
|
1313
|
+
const codes = [];
|
|
1314
|
+
const addCode = (c) => {
|
|
1315
|
+
if (!c)
|
|
1316
|
+
return;
|
|
1317
|
+
if (this.isSupportedCode(c)) {
|
|
1318
|
+
codes.push(c);
|
|
1319
|
+
} else {
|
|
1320
|
+
this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
if (typeof code === "string" && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
|
|
1324
|
+
if (this.options.load !== "languageOnly")
|
|
1325
|
+
addCode(this.formatLanguageCode(code));
|
|
1326
|
+
if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly")
|
|
1327
|
+
addCode(this.getScriptPartFromCode(code));
|
|
1328
|
+
if (this.options.load !== "currentOnly")
|
|
1329
|
+
addCode(this.getLanguagePartFromCode(code));
|
|
1330
|
+
} else if (typeof code === "string") {
|
|
1331
|
+
addCode(this.formatLanguageCode(code));
|
|
1332
|
+
}
|
|
1333
|
+
fallbackCodes.forEach((fc) => {
|
|
1334
|
+
if (codes.indexOf(fc) < 0)
|
|
1335
|
+
addCode(this.formatLanguageCode(fc));
|
|
1336
|
+
});
|
|
1337
|
+
return codes;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
let sets = [{
|
|
1341
|
+
lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
|
|
1342
|
+
nr: [1, 2],
|
|
1343
|
+
fc: 1
|
|
1344
|
+
}, {
|
|
1345
|
+
lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kk", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"],
|
|
1346
|
+
nr: [1, 2],
|
|
1347
|
+
fc: 2
|
|
1348
|
+
}, {
|
|
1349
|
+
lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
|
|
1350
|
+
nr: [1],
|
|
1351
|
+
fc: 3
|
|
1352
|
+
}, {
|
|
1353
|
+
lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
|
|
1354
|
+
nr: [1, 2, 5],
|
|
1355
|
+
fc: 4
|
|
1356
|
+
}, {
|
|
1357
|
+
lngs: ["ar"],
|
|
1358
|
+
nr: [0, 1, 2, 3, 11, 100],
|
|
1359
|
+
fc: 5
|
|
1360
|
+
}, {
|
|
1361
|
+
lngs: ["cs", "sk"],
|
|
1362
|
+
nr: [1, 2, 5],
|
|
1363
|
+
fc: 6
|
|
1364
|
+
}, {
|
|
1365
|
+
lngs: ["csb", "pl"],
|
|
1366
|
+
nr: [1, 2, 5],
|
|
1367
|
+
fc: 7
|
|
1368
|
+
}, {
|
|
1369
|
+
lngs: ["cy"],
|
|
1370
|
+
nr: [1, 2, 3, 8],
|
|
1371
|
+
fc: 8
|
|
1372
|
+
}, {
|
|
1373
|
+
lngs: ["fr"],
|
|
1374
|
+
nr: [1, 2],
|
|
1375
|
+
fc: 9
|
|
1376
|
+
}, {
|
|
1377
|
+
lngs: ["ga"],
|
|
1378
|
+
nr: [1, 2, 3, 7, 11],
|
|
1379
|
+
fc: 10
|
|
1380
|
+
}, {
|
|
1381
|
+
lngs: ["gd"],
|
|
1382
|
+
nr: [1, 2, 3, 20],
|
|
1383
|
+
fc: 11
|
|
1384
|
+
}, {
|
|
1385
|
+
lngs: ["is"],
|
|
1386
|
+
nr: [1, 2],
|
|
1387
|
+
fc: 12
|
|
1388
|
+
}, {
|
|
1389
|
+
lngs: ["jv"],
|
|
1390
|
+
nr: [0, 1],
|
|
1391
|
+
fc: 13
|
|
1392
|
+
}, {
|
|
1393
|
+
lngs: ["kw"],
|
|
1394
|
+
nr: [1, 2, 3, 4],
|
|
1395
|
+
fc: 14
|
|
1396
|
+
}, {
|
|
1397
|
+
lngs: ["lt"],
|
|
1398
|
+
nr: [1, 2, 10],
|
|
1399
|
+
fc: 15
|
|
1400
|
+
}, {
|
|
1401
|
+
lngs: ["lv"],
|
|
1402
|
+
nr: [1, 2, 0],
|
|
1403
|
+
fc: 16
|
|
1404
|
+
}, {
|
|
1405
|
+
lngs: ["mk"],
|
|
1406
|
+
nr: [1, 2],
|
|
1407
|
+
fc: 17
|
|
1408
|
+
}, {
|
|
1409
|
+
lngs: ["mnk"],
|
|
1410
|
+
nr: [0, 1, 2],
|
|
1411
|
+
fc: 18
|
|
1412
|
+
}, {
|
|
1413
|
+
lngs: ["mt"],
|
|
1414
|
+
nr: [1, 2, 11, 20],
|
|
1415
|
+
fc: 19
|
|
1416
|
+
}, {
|
|
1417
|
+
lngs: ["or"],
|
|
1418
|
+
nr: [2, 1],
|
|
1419
|
+
fc: 2
|
|
1420
|
+
}, {
|
|
1421
|
+
lngs: ["ro"],
|
|
1422
|
+
nr: [1, 2, 20],
|
|
1423
|
+
fc: 20
|
|
1424
|
+
}, {
|
|
1425
|
+
lngs: ["sl"],
|
|
1426
|
+
nr: [5, 1, 2, 3],
|
|
1427
|
+
fc: 21
|
|
1428
|
+
}, {
|
|
1429
|
+
lngs: ["he", "iw"],
|
|
1430
|
+
nr: [1, 2, 20, 21],
|
|
1431
|
+
fc: 22
|
|
1432
|
+
}];
|
|
1433
|
+
let _rulesPluralsTypes = {
|
|
1434
|
+
1: function(n) {
|
|
1435
|
+
return Number(n > 1);
|
|
1436
|
+
},
|
|
1437
|
+
2: function(n) {
|
|
1438
|
+
return Number(n != 1);
|
|
1439
|
+
},
|
|
1440
|
+
3: function(n) {
|
|
1441
|
+
return 0;
|
|
1442
|
+
},
|
|
1443
|
+
4: function(n) {
|
|
1444
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1445
|
+
},
|
|
1446
|
+
5: function(n) {
|
|
1447
|
+
return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5);
|
|
1448
|
+
},
|
|
1449
|
+
6: function(n) {
|
|
1450
|
+
return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2);
|
|
1451
|
+
},
|
|
1452
|
+
7: function(n) {
|
|
1453
|
+
return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1454
|
+
},
|
|
1455
|
+
8: function(n) {
|
|
1456
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3);
|
|
1457
|
+
},
|
|
1458
|
+
9: function(n) {
|
|
1459
|
+
return Number(n >= 2);
|
|
1460
|
+
},
|
|
1461
|
+
10: function(n) {
|
|
1462
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4);
|
|
1463
|
+
},
|
|
1464
|
+
11: function(n) {
|
|
1465
|
+
return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3);
|
|
1466
|
+
},
|
|
1467
|
+
12: function(n) {
|
|
1468
|
+
return Number(n % 10 != 1 || n % 100 == 11);
|
|
1469
|
+
},
|
|
1470
|
+
13: function(n) {
|
|
1471
|
+
return Number(n !== 0);
|
|
1472
|
+
},
|
|
1473
|
+
14: function(n) {
|
|
1474
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3);
|
|
1475
|
+
},
|
|
1476
|
+
15: function(n) {
|
|
1477
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
|
|
1478
|
+
},
|
|
1479
|
+
16: function(n) {
|
|
1480
|
+
return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2);
|
|
1481
|
+
},
|
|
1482
|
+
17: function(n) {
|
|
1483
|
+
return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1);
|
|
1484
|
+
},
|
|
1485
|
+
18: function(n) {
|
|
1486
|
+
return Number(n == 0 ? 0 : n == 1 ? 1 : 2);
|
|
1487
|
+
},
|
|
1488
|
+
19: function(n) {
|
|
1489
|
+
return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3);
|
|
1490
|
+
},
|
|
1491
|
+
20: function(n) {
|
|
1492
|
+
return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2);
|
|
1493
|
+
},
|
|
1494
|
+
21: function(n) {
|
|
1495
|
+
return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0);
|
|
1496
|
+
},
|
|
1497
|
+
22: function(n) {
|
|
1498
|
+
return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3);
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
const nonIntlVersions = ["v1", "v2", "v3"];
|
|
1502
|
+
const intlVersions = ["v4"];
|
|
1503
|
+
const suffixesOrder = {
|
|
1504
|
+
zero: 0,
|
|
1505
|
+
one: 1,
|
|
1506
|
+
two: 2,
|
|
1507
|
+
few: 3,
|
|
1508
|
+
many: 4,
|
|
1509
|
+
other: 5
|
|
1510
|
+
};
|
|
1511
|
+
function createRules() {
|
|
1512
|
+
const rules = {};
|
|
1513
|
+
sets.forEach((set) => {
|
|
1514
|
+
set.lngs.forEach((l) => {
|
|
1515
|
+
rules[l] = {
|
|
1516
|
+
numbers: set.nr,
|
|
1517
|
+
plurals: _rulesPluralsTypes[set.fc]
|
|
1518
|
+
};
|
|
1519
|
+
});
|
|
1520
|
+
});
|
|
1521
|
+
return rules;
|
|
1522
|
+
}
|
|
1523
|
+
class PluralResolver {
|
|
1524
|
+
constructor(languageUtils) {
|
|
1525
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1526
|
+
this.languageUtils = languageUtils;
|
|
1527
|
+
this.options = options;
|
|
1528
|
+
this.logger = baseLogger.create("pluralResolver");
|
|
1529
|
+
if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
|
|
1530
|
+
this.options.compatibilityJSON = "v3";
|
|
1531
|
+
this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
|
|
1532
|
+
}
|
|
1533
|
+
this.rules = createRules();
|
|
1534
|
+
}
|
|
1535
|
+
addRule(lng, obj) {
|
|
1536
|
+
this.rules[lng] = obj;
|
|
1537
|
+
}
|
|
1538
|
+
getRule(code) {
|
|
1539
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1540
|
+
if (this.shouldUseIntlApi()) {
|
|
1541
|
+
try {
|
|
1542
|
+
return new Intl.PluralRules(getCleanedCode(code === "dev" ? "en" : code), {
|
|
1543
|
+
type: options.ordinal ? "ordinal" : "cardinal"
|
|
1544
|
+
});
|
|
1545
|
+
} catch (err) {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
|
|
1550
|
+
}
|
|
1551
|
+
needsPlural(code) {
|
|
1552
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1553
|
+
const rule = this.getRule(code, options);
|
|
1554
|
+
if (this.shouldUseIntlApi()) {
|
|
1555
|
+
return rule && rule.resolvedOptions().pluralCategories.length > 1;
|
|
1556
|
+
}
|
|
1557
|
+
return rule && rule.numbers.length > 1;
|
|
1558
|
+
}
|
|
1559
|
+
getPluralFormsOfKey(code, key) {
|
|
1560
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1561
|
+
return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
|
|
1562
|
+
}
|
|
1563
|
+
getSuffixes(code) {
|
|
1564
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1565
|
+
const rule = this.getRule(code, options);
|
|
1566
|
+
if (!rule) {
|
|
1567
|
+
return [];
|
|
1568
|
+
}
|
|
1569
|
+
if (this.shouldUseIntlApi()) {
|
|
1570
|
+
return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
|
|
1571
|
+
}
|
|
1572
|
+
return rule.numbers.map((number) => this.getSuffix(code, number, options));
|
|
1573
|
+
}
|
|
1574
|
+
getSuffix(code, count) {
|
|
1575
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1576
|
+
const rule = this.getRule(code, options);
|
|
1577
|
+
if (rule) {
|
|
1578
|
+
if (this.shouldUseIntlApi()) {
|
|
1579
|
+
return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
|
|
1580
|
+
}
|
|
1581
|
+
return this.getSuffixRetroCompatible(rule, count);
|
|
1582
|
+
}
|
|
1583
|
+
this.logger.warn(`no plural rule found for: ${code}`);
|
|
1584
|
+
return "";
|
|
1585
|
+
}
|
|
1586
|
+
getSuffixRetroCompatible(rule, count) {
|
|
1587
|
+
const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
|
|
1588
|
+
let suffix = rule.numbers[idx];
|
|
1589
|
+
if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1590
|
+
if (suffix === 2) {
|
|
1591
|
+
suffix = "plural";
|
|
1592
|
+
} else if (suffix === 1) {
|
|
1593
|
+
suffix = "";
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
|
|
1597
|
+
if (this.options.compatibilityJSON === "v1") {
|
|
1598
|
+
if (suffix === 1)
|
|
1599
|
+
return "";
|
|
1600
|
+
if (typeof suffix === "number")
|
|
1601
|
+
return `_plural_${suffix.toString()}`;
|
|
1602
|
+
return returnSuffix();
|
|
1603
|
+
} else if (this.options.compatibilityJSON === "v2") {
|
|
1604
|
+
return returnSuffix();
|
|
1605
|
+
} else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
|
|
1606
|
+
return returnSuffix();
|
|
1607
|
+
}
|
|
1608
|
+
return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
|
|
1609
|
+
}
|
|
1610
|
+
shouldUseIntlApi() {
|
|
1611
|
+
return !nonIntlVersions.includes(this.options.compatibilityJSON);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
function deepFindWithDefaults(data, defaultData, key) {
|
|
1615
|
+
let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
|
|
1616
|
+
let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
|
|
1617
|
+
let path = getPathWithDefaults(data, defaultData, key);
|
|
1618
|
+
if (!path && ignoreJSONStructure && typeof key === "string") {
|
|
1619
|
+
path = deepFind(data, key, keySeparator);
|
|
1620
|
+
if (path === void 0)
|
|
1621
|
+
path = deepFind(defaultData, key, keySeparator);
|
|
1622
|
+
}
|
|
1623
|
+
return path;
|
|
1624
|
+
}
|
|
1625
|
+
class Interpolator {
|
|
1626
|
+
constructor() {
|
|
1627
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1628
|
+
this.logger = baseLogger.create("interpolator");
|
|
1629
|
+
this.options = options;
|
|
1630
|
+
this.format = options.interpolation && options.interpolation.format || ((value) => value);
|
|
1631
|
+
this.init(options);
|
|
1632
|
+
}
|
|
1633
|
+
init() {
|
|
1634
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1635
|
+
if (!options.interpolation)
|
|
1636
|
+
options.interpolation = {
|
|
1637
|
+
escapeValue: true
|
|
1638
|
+
};
|
|
1639
|
+
const iOpts = options.interpolation;
|
|
1640
|
+
this.escape = iOpts.escape !== void 0 ? iOpts.escape : escape;
|
|
1641
|
+
this.escapeValue = iOpts.escapeValue !== void 0 ? iOpts.escapeValue : true;
|
|
1642
|
+
this.useRawValueToEscape = iOpts.useRawValueToEscape !== void 0 ? iOpts.useRawValueToEscape : false;
|
|
1643
|
+
this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || "{{";
|
|
1644
|
+
this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || "}}";
|
|
1645
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ",";
|
|
1646
|
+
this.unescapePrefix = iOpts.unescapeSuffix ? "" : iOpts.unescapePrefix || "-";
|
|
1647
|
+
this.unescapeSuffix = this.unescapePrefix ? "" : iOpts.unescapeSuffix || "";
|
|
1648
|
+
this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape("$t(");
|
|
1649
|
+
this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(")");
|
|
1650
|
+
this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ",";
|
|
1651
|
+
this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1e3;
|
|
1652
|
+
this.alwaysFormat = iOpts.alwaysFormat !== void 0 ? iOpts.alwaysFormat : false;
|
|
1653
|
+
this.resetRegExp();
|
|
1654
|
+
}
|
|
1655
|
+
reset() {
|
|
1656
|
+
if (this.options)
|
|
1657
|
+
this.init(this.options);
|
|
1658
|
+
}
|
|
1659
|
+
resetRegExp() {
|
|
1660
|
+
const getOrResetRegExp = (existingRegExp, pattern) => {
|
|
1661
|
+
if (existingRegExp && existingRegExp.source === pattern) {
|
|
1662
|
+
existingRegExp.lastIndex = 0;
|
|
1663
|
+
return existingRegExp;
|
|
1664
|
+
}
|
|
1665
|
+
return new RegExp(pattern, "g");
|
|
1666
|
+
};
|
|
1667
|
+
this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
|
|
1668
|
+
this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
|
|
1669
|
+
this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
|
|
1670
|
+
}
|
|
1671
|
+
interpolate(str, data, lng, options) {
|
|
1672
|
+
let match;
|
|
1673
|
+
let value;
|
|
1674
|
+
let replaces;
|
|
1675
|
+
const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
|
|
1676
|
+
function regexSafe(val) {
|
|
1677
|
+
return val.replace(/\$/g, "$$$$");
|
|
1678
|
+
}
|
|
1679
|
+
const handleFormat = (key) => {
|
|
1680
|
+
if (key.indexOf(this.formatSeparator) < 0) {
|
|
1681
|
+
const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
|
|
1682
|
+
return this.alwaysFormat ? this.format(path, void 0, lng, {
|
|
1683
|
+
...options,
|
|
1684
|
+
...data,
|
|
1685
|
+
interpolationkey: key
|
|
1686
|
+
}) : path;
|
|
1687
|
+
}
|
|
1688
|
+
const p = key.split(this.formatSeparator);
|
|
1689
|
+
const k = p.shift().trim();
|
|
1690
|
+
const f = p.join(this.formatSeparator).trim();
|
|
1691
|
+
return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
|
|
1692
|
+
...options,
|
|
1693
|
+
...data,
|
|
1694
|
+
interpolationkey: k
|
|
1695
|
+
});
|
|
1696
|
+
};
|
|
1697
|
+
this.resetRegExp();
|
|
1698
|
+
const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
|
|
1699
|
+
const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
|
|
1700
|
+
const todos = [{
|
|
1701
|
+
regex: this.regexpUnescape,
|
|
1702
|
+
safeValue: (val) => regexSafe(val)
|
|
1703
|
+
}, {
|
|
1704
|
+
regex: this.regexp,
|
|
1705
|
+
safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
|
|
1706
|
+
}];
|
|
1707
|
+
todos.forEach((todo) => {
|
|
1708
|
+
replaces = 0;
|
|
1709
|
+
while (match = todo.regex.exec(str)) {
|
|
1710
|
+
const matchedVar = match[1].trim();
|
|
1711
|
+
value = handleFormat(matchedVar);
|
|
1712
|
+
if (value === void 0) {
|
|
1713
|
+
if (typeof missingInterpolationHandler === "function") {
|
|
1714
|
+
const temp = missingInterpolationHandler(str, match, options);
|
|
1715
|
+
value = typeof temp === "string" ? temp : "";
|
|
1716
|
+
} else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
|
|
1717
|
+
value = "";
|
|
1718
|
+
} else if (skipOnVariables) {
|
|
1719
|
+
value = match[0];
|
|
1720
|
+
continue;
|
|
1721
|
+
} else {
|
|
1722
|
+
this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
|
|
1723
|
+
value = "";
|
|
1724
|
+
}
|
|
1725
|
+
} else if (typeof value !== "string" && !this.useRawValueToEscape) {
|
|
1726
|
+
value = makeString(value);
|
|
1727
|
+
}
|
|
1728
|
+
const safeValue = todo.safeValue(value);
|
|
1729
|
+
str = str.replace(match[0], safeValue);
|
|
1730
|
+
if (skipOnVariables) {
|
|
1731
|
+
todo.regex.lastIndex += value.length;
|
|
1732
|
+
todo.regex.lastIndex -= match[0].length;
|
|
1733
|
+
} else {
|
|
1734
|
+
todo.regex.lastIndex = 0;
|
|
1735
|
+
}
|
|
1736
|
+
replaces++;
|
|
1737
|
+
if (replaces >= this.maxReplaces) {
|
|
1738
|
+
break;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
return str;
|
|
1743
|
+
}
|
|
1744
|
+
nest(str, fc) {
|
|
1745
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1746
|
+
let match;
|
|
1747
|
+
let value;
|
|
1748
|
+
let clonedOptions;
|
|
1749
|
+
function handleHasOptions(key, inheritedOptions) {
|
|
1750
|
+
const sep = this.nestingOptionsSeparator;
|
|
1751
|
+
if (key.indexOf(sep) < 0)
|
|
1752
|
+
return key;
|
|
1753
|
+
const c = key.split(new RegExp(`${sep}[ ]*{`));
|
|
1754
|
+
let optionsString = `{${c[1]}`;
|
|
1755
|
+
key = c[0];
|
|
1756
|
+
optionsString = this.interpolate(optionsString, clonedOptions);
|
|
1757
|
+
const matchedSingleQuotes = optionsString.match(/'/g);
|
|
1758
|
+
const matchedDoubleQuotes = optionsString.match(/"/g);
|
|
1759
|
+
if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
|
|
1760
|
+
optionsString = optionsString.replace(/'/g, '"');
|
|
1761
|
+
}
|
|
1762
|
+
try {
|
|
1763
|
+
clonedOptions = JSON.parse(optionsString);
|
|
1764
|
+
if (inheritedOptions)
|
|
1765
|
+
clonedOptions = {
|
|
1766
|
+
...inheritedOptions,
|
|
1767
|
+
...clonedOptions
|
|
1768
|
+
};
|
|
1769
|
+
} catch (e) {
|
|
1770
|
+
this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
|
|
1771
|
+
return `${key}${sep}${optionsString}`;
|
|
1772
|
+
}
|
|
1773
|
+
if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1)
|
|
1774
|
+
delete clonedOptions.defaultValue;
|
|
1775
|
+
return key;
|
|
1776
|
+
}
|
|
1777
|
+
while (match = this.nestingRegexp.exec(str)) {
|
|
1778
|
+
let formatters = [];
|
|
1779
|
+
clonedOptions = {
|
|
1780
|
+
...options
|
|
1781
|
+
};
|
|
1782
|
+
clonedOptions = clonedOptions.replace && typeof clonedOptions.replace !== "string" ? clonedOptions.replace : clonedOptions;
|
|
1783
|
+
clonedOptions.applyPostProcessor = false;
|
|
1784
|
+
delete clonedOptions.defaultValue;
|
|
1785
|
+
let doReduce = false;
|
|
1786
|
+
if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
|
|
1787
|
+
const r2 = match[1].split(this.formatSeparator).map((elem) => elem.trim());
|
|
1788
|
+
match[1] = r2.shift();
|
|
1789
|
+
formatters = r2;
|
|
1790
|
+
doReduce = true;
|
|
1791
|
+
}
|
|
1792
|
+
value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
|
|
1793
|
+
if (value && match[0] === str && typeof value !== "string")
|
|
1794
|
+
return value;
|
|
1795
|
+
if (typeof value !== "string")
|
|
1796
|
+
value = makeString(value);
|
|
1797
|
+
if (!value) {
|
|
1798
|
+
this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
|
|
1799
|
+
value = "";
|
|
1800
|
+
}
|
|
1801
|
+
if (doReduce) {
|
|
1802
|
+
value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
|
|
1803
|
+
...options,
|
|
1804
|
+
interpolationkey: match[1].trim()
|
|
1805
|
+
}), value.trim());
|
|
1806
|
+
}
|
|
1807
|
+
str = str.replace(match[0], value);
|
|
1808
|
+
this.regexp.lastIndex = 0;
|
|
1809
|
+
}
|
|
1810
|
+
return str;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
function parseFormatStr(formatStr) {
|
|
1814
|
+
let formatName = formatStr.toLowerCase().trim();
|
|
1815
|
+
const formatOptions = {};
|
|
1816
|
+
if (formatStr.indexOf("(") > -1) {
|
|
1817
|
+
const p = formatStr.split("(");
|
|
1818
|
+
formatName = p[0].toLowerCase().trim();
|
|
1819
|
+
const optStr = p[1].substring(0, p[1].length - 1);
|
|
1820
|
+
if (formatName === "currency" && optStr.indexOf(":") < 0) {
|
|
1821
|
+
if (!formatOptions.currency)
|
|
1822
|
+
formatOptions.currency = optStr.trim();
|
|
1823
|
+
} else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
|
|
1824
|
+
if (!formatOptions.range)
|
|
1825
|
+
formatOptions.range = optStr.trim();
|
|
1826
|
+
} else {
|
|
1827
|
+
const opts = optStr.split(";");
|
|
1828
|
+
opts.forEach((opt) => {
|
|
1829
|
+
if (!opt)
|
|
1830
|
+
return;
|
|
1831
|
+
const [key, ...rest] = opt.split(":");
|
|
1832
|
+
const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
|
|
1833
|
+
if (!formatOptions[key.trim()])
|
|
1834
|
+
formatOptions[key.trim()] = val;
|
|
1835
|
+
if (val === "false")
|
|
1836
|
+
formatOptions[key.trim()] = false;
|
|
1837
|
+
if (val === "true")
|
|
1838
|
+
formatOptions[key.trim()] = true;
|
|
1839
|
+
if (!isNaN(val))
|
|
1840
|
+
formatOptions[key.trim()] = parseInt(val, 10);
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
return {
|
|
1845
|
+
formatName,
|
|
1846
|
+
formatOptions
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
function createCachedFormatter(fn) {
|
|
1850
|
+
const cache = {};
|
|
1851
|
+
return function invokeFormatter(val, lng, options) {
|
|
1852
|
+
const key = lng + JSON.stringify(options);
|
|
1853
|
+
let formatter = cache[key];
|
|
1854
|
+
if (!formatter) {
|
|
1855
|
+
formatter = fn(getCleanedCode(lng), options);
|
|
1856
|
+
cache[key] = formatter;
|
|
1857
|
+
}
|
|
1858
|
+
return formatter(val);
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
class Formatter {
|
|
1862
|
+
constructor() {
|
|
1863
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1864
|
+
this.logger = baseLogger.create("formatter");
|
|
1865
|
+
this.options = options;
|
|
1866
|
+
this.formats = {
|
|
1867
|
+
number: createCachedFormatter((lng, opt) => {
|
|
1868
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1869
|
+
...opt
|
|
1870
|
+
});
|
|
1871
|
+
return (val) => formatter.format(val);
|
|
1872
|
+
}),
|
|
1873
|
+
currency: createCachedFormatter((lng, opt) => {
|
|
1874
|
+
const formatter = new Intl.NumberFormat(lng, {
|
|
1875
|
+
...opt,
|
|
1876
|
+
style: "currency"
|
|
1877
|
+
});
|
|
1878
|
+
return (val) => formatter.format(val);
|
|
1879
|
+
}),
|
|
1880
|
+
datetime: createCachedFormatter((lng, opt) => {
|
|
1881
|
+
const formatter = new Intl.DateTimeFormat(lng, {
|
|
1882
|
+
...opt
|
|
1883
|
+
});
|
|
1884
|
+
return (val) => formatter.format(val);
|
|
1885
|
+
}),
|
|
1886
|
+
relativetime: createCachedFormatter((lng, opt) => {
|
|
1887
|
+
const formatter = new Intl.RelativeTimeFormat(lng, {
|
|
1888
|
+
...opt
|
|
1889
|
+
});
|
|
1890
|
+
return (val) => formatter.format(val, opt.range || "day");
|
|
1891
|
+
}),
|
|
1892
|
+
list: createCachedFormatter((lng, opt) => {
|
|
1893
|
+
const formatter = new Intl.ListFormat(lng, {
|
|
1894
|
+
...opt
|
|
1895
|
+
});
|
|
1896
|
+
return (val) => formatter.format(val);
|
|
1897
|
+
})
|
|
1898
|
+
};
|
|
1899
|
+
this.init(options);
|
|
1900
|
+
}
|
|
1901
|
+
init(services) {
|
|
1902
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
1903
|
+
interpolation: {}
|
|
1904
|
+
};
|
|
1905
|
+
const iOpts = options.interpolation;
|
|
1906
|
+
this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ",";
|
|
1907
|
+
}
|
|
1908
|
+
add(name, fc) {
|
|
1909
|
+
this.formats[name.toLowerCase().trim()] = fc;
|
|
1910
|
+
}
|
|
1911
|
+
addCached(name, fc) {
|
|
1912
|
+
this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
|
|
1913
|
+
}
|
|
1914
|
+
format(value, format, lng) {
|
|
1915
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1916
|
+
const formats = format.split(this.formatSeparator);
|
|
1917
|
+
const result = formats.reduce((mem, f) => {
|
|
1918
|
+
const {
|
|
1919
|
+
formatName,
|
|
1920
|
+
formatOptions
|
|
1921
|
+
} = parseFormatStr(f);
|
|
1922
|
+
if (this.formats[formatName]) {
|
|
1923
|
+
let formatted = mem;
|
|
1924
|
+
try {
|
|
1925
|
+
const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
|
|
1926
|
+
const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
|
|
1927
|
+
formatted = this.formats[formatName](mem, l, {
|
|
1928
|
+
...formatOptions,
|
|
1929
|
+
...options,
|
|
1930
|
+
...valOptions
|
|
1931
|
+
});
|
|
1932
|
+
} catch (error) {
|
|
1933
|
+
this.logger.warn(error);
|
|
1934
|
+
}
|
|
1935
|
+
return formatted;
|
|
1936
|
+
} else {
|
|
1937
|
+
this.logger.warn(`there was no format function for ${formatName}`);
|
|
1938
|
+
}
|
|
1939
|
+
return mem;
|
|
1940
|
+
}, value);
|
|
1941
|
+
return result;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
function removePending(q, name) {
|
|
1945
|
+
if (q.pending[name] !== void 0) {
|
|
1946
|
+
delete q.pending[name];
|
|
1947
|
+
q.pendingCount--;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
class Connector extends EventEmitter {
|
|
1951
|
+
constructor(backend, store, services) {
|
|
1952
|
+
let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
1953
|
+
super();
|
|
1954
|
+
this.backend = backend;
|
|
1955
|
+
this.store = store;
|
|
1956
|
+
this.services = services;
|
|
1957
|
+
this.languageUtils = services.languageUtils;
|
|
1958
|
+
this.options = options;
|
|
1959
|
+
this.logger = baseLogger.create("backendConnector");
|
|
1960
|
+
this.waitingReads = [];
|
|
1961
|
+
this.maxParallelReads = options.maxParallelReads || 10;
|
|
1962
|
+
this.readingCalls = 0;
|
|
1963
|
+
this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
|
|
1964
|
+
this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
|
|
1965
|
+
this.state = {};
|
|
1966
|
+
this.queue = [];
|
|
1967
|
+
if (this.backend && this.backend.init) {
|
|
1968
|
+
this.backend.init(services, options.backend, options);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
queueLoad(languages, namespaces, options, callback) {
|
|
1972
|
+
const toLoad = {};
|
|
1973
|
+
const pending = {};
|
|
1974
|
+
const toLoadLanguages = {};
|
|
1975
|
+
const toLoadNamespaces = {};
|
|
1976
|
+
languages.forEach((lng) => {
|
|
1977
|
+
let hasAllNamespaces = true;
|
|
1978
|
+
namespaces.forEach((ns) => {
|
|
1979
|
+
const name = `${lng}|${ns}`;
|
|
1980
|
+
if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
|
|
1981
|
+
this.state[name] = 2;
|
|
1982
|
+
} else if (this.state[name] < 0)
|
|
1983
|
+
;
|
|
1984
|
+
else if (this.state[name] === 1) {
|
|
1985
|
+
if (pending[name] === void 0)
|
|
1986
|
+
pending[name] = true;
|
|
1987
|
+
} else {
|
|
1988
|
+
this.state[name] = 1;
|
|
1989
|
+
hasAllNamespaces = false;
|
|
1990
|
+
if (pending[name] === void 0)
|
|
1991
|
+
pending[name] = true;
|
|
1992
|
+
if (toLoad[name] === void 0)
|
|
1993
|
+
toLoad[name] = true;
|
|
1994
|
+
if (toLoadNamespaces[ns] === void 0)
|
|
1995
|
+
toLoadNamespaces[ns] = true;
|
|
1996
|
+
}
|
|
1997
|
+
});
|
|
1998
|
+
if (!hasAllNamespaces)
|
|
1999
|
+
toLoadLanguages[lng] = true;
|
|
2000
|
+
});
|
|
2001
|
+
if (Object.keys(toLoad).length || Object.keys(pending).length) {
|
|
2002
|
+
this.queue.push({
|
|
2003
|
+
pending,
|
|
2004
|
+
pendingCount: Object.keys(pending).length,
|
|
2005
|
+
loaded: {},
|
|
2006
|
+
errors: [],
|
|
2007
|
+
callback
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
return {
|
|
2011
|
+
toLoad: Object.keys(toLoad),
|
|
2012
|
+
pending: Object.keys(pending),
|
|
2013
|
+
toLoadLanguages: Object.keys(toLoadLanguages),
|
|
2014
|
+
toLoadNamespaces: Object.keys(toLoadNamespaces)
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
loaded(name, err, data) {
|
|
2018
|
+
const s = name.split("|");
|
|
2019
|
+
const lng = s[0];
|
|
2020
|
+
const ns = s[1];
|
|
2021
|
+
if (err)
|
|
2022
|
+
this.emit("failedLoading", lng, ns, err);
|
|
2023
|
+
if (data) {
|
|
2024
|
+
this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
|
|
2025
|
+
skipCopy: true
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
this.state[name] = err ? -1 : 2;
|
|
2029
|
+
const loaded = {};
|
|
2030
|
+
this.queue.forEach((q) => {
|
|
2031
|
+
pushPath(q.loaded, [lng], ns);
|
|
2032
|
+
removePending(q, name);
|
|
2033
|
+
if (err)
|
|
2034
|
+
q.errors.push(err);
|
|
2035
|
+
if (q.pendingCount === 0 && !q.done) {
|
|
2036
|
+
Object.keys(q.loaded).forEach((l) => {
|
|
2037
|
+
if (!loaded[l])
|
|
2038
|
+
loaded[l] = {};
|
|
2039
|
+
const loadedKeys = q.loaded[l];
|
|
2040
|
+
if (loadedKeys.length) {
|
|
2041
|
+
loadedKeys.forEach((n) => {
|
|
2042
|
+
if (loaded[l][n] === void 0)
|
|
2043
|
+
loaded[l][n] = true;
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
});
|
|
2047
|
+
q.done = true;
|
|
2048
|
+
if (q.errors.length) {
|
|
2049
|
+
q.callback(q.errors);
|
|
2050
|
+
} else {
|
|
2051
|
+
q.callback();
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
this.emit("loaded", loaded);
|
|
2056
|
+
this.queue = this.queue.filter((q) => !q.done);
|
|
2057
|
+
}
|
|
2058
|
+
read(lng, ns, fcName) {
|
|
2059
|
+
let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
|
|
2060
|
+
let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
|
|
2061
|
+
let callback = arguments.length > 5 ? arguments[5] : void 0;
|
|
2062
|
+
if (!lng.length)
|
|
2063
|
+
return callback(null, {});
|
|
2064
|
+
if (this.readingCalls >= this.maxParallelReads) {
|
|
2065
|
+
this.waitingReads.push({
|
|
2066
|
+
lng,
|
|
2067
|
+
ns,
|
|
2068
|
+
fcName,
|
|
2069
|
+
tried,
|
|
2070
|
+
wait,
|
|
2071
|
+
callback
|
|
2072
|
+
});
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
this.readingCalls++;
|
|
2076
|
+
const resolver = (err, data) => {
|
|
2077
|
+
this.readingCalls--;
|
|
2078
|
+
if (this.waitingReads.length > 0) {
|
|
2079
|
+
const next = this.waitingReads.shift();
|
|
2080
|
+
this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
|
|
2081
|
+
}
|
|
2082
|
+
if (err && data && tried < this.maxRetries) {
|
|
2083
|
+
setTimeout(() => {
|
|
2084
|
+
this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
|
|
2085
|
+
}, wait);
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
callback(err, data);
|
|
2089
|
+
};
|
|
2090
|
+
const fc = this.backend[fcName].bind(this.backend);
|
|
2091
|
+
if (fc.length === 2) {
|
|
2092
|
+
try {
|
|
2093
|
+
const r2 = fc(lng, ns);
|
|
2094
|
+
if (r2 && typeof r2.then === "function") {
|
|
2095
|
+
r2.then((data) => resolver(null, data)).catch(resolver);
|
|
2096
|
+
} else {
|
|
2097
|
+
resolver(null, r2);
|
|
2098
|
+
}
|
|
2099
|
+
} catch (err) {
|
|
2100
|
+
resolver(err);
|
|
2101
|
+
}
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
return fc(lng, ns, resolver);
|
|
2105
|
+
}
|
|
2106
|
+
prepareLoading(languages, namespaces) {
|
|
2107
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2108
|
+
let callback = arguments.length > 3 ? arguments[3] : void 0;
|
|
2109
|
+
if (!this.backend) {
|
|
2110
|
+
this.logger.warn("No backend was added via i18next.use. Will not load resources.");
|
|
2111
|
+
return callback && callback();
|
|
2112
|
+
}
|
|
2113
|
+
if (typeof languages === "string")
|
|
2114
|
+
languages = this.languageUtils.toResolveHierarchy(languages);
|
|
2115
|
+
if (typeof namespaces === "string")
|
|
2116
|
+
namespaces = [namespaces];
|
|
2117
|
+
const toLoad = this.queueLoad(languages, namespaces, options, callback);
|
|
2118
|
+
if (!toLoad.toLoad.length) {
|
|
2119
|
+
if (!toLoad.pending.length)
|
|
2120
|
+
callback();
|
|
2121
|
+
return null;
|
|
2122
|
+
}
|
|
2123
|
+
toLoad.toLoad.forEach((name) => {
|
|
2124
|
+
this.loadOne(name);
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
load(languages, namespaces, callback) {
|
|
2128
|
+
this.prepareLoading(languages, namespaces, {}, callback);
|
|
2129
|
+
}
|
|
2130
|
+
reload(languages, namespaces, callback) {
|
|
2131
|
+
this.prepareLoading(languages, namespaces, {
|
|
2132
|
+
reload: true
|
|
2133
|
+
}, callback);
|
|
2134
|
+
}
|
|
2135
|
+
loadOne(name) {
|
|
2136
|
+
let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
2137
|
+
const s = name.split("|");
|
|
2138
|
+
const lng = s[0];
|
|
2139
|
+
const ns = s[1];
|
|
2140
|
+
this.read(lng, ns, "read", void 0, void 0, (err, data) => {
|
|
2141
|
+
if (err)
|
|
2142
|
+
this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
|
|
2143
|
+
if (!err && data)
|
|
2144
|
+
this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
|
|
2145
|
+
this.loaded(name, err, data);
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
|
|
2149
|
+
let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
|
|
2150
|
+
let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
|
|
2151
|
+
};
|
|
2152
|
+
if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
|
|
2153
|
+
this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
|
|
2154
|
+
return;
|
|
2155
|
+
}
|
|
2156
|
+
if (key === void 0 || key === null || key === "")
|
|
2157
|
+
return;
|
|
2158
|
+
if (this.backend && this.backend.create) {
|
|
2159
|
+
const opts = {
|
|
2160
|
+
...options,
|
|
2161
|
+
isUpdate
|
|
2162
|
+
};
|
|
2163
|
+
const fc = this.backend.create.bind(this.backend);
|
|
2164
|
+
if (fc.length < 6) {
|
|
2165
|
+
try {
|
|
2166
|
+
let r2;
|
|
2167
|
+
if (fc.length === 5) {
|
|
2168
|
+
r2 = fc(languages, namespace, key, fallbackValue, opts);
|
|
2169
|
+
} else {
|
|
2170
|
+
r2 = fc(languages, namespace, key, fallbackValue);
|
|
2171
|
+
}
|
|
2172
|
+
if (r2 && typeof r2.then === "function") {
|
|
2173
|
+
r2.then((data) => clb(null, data)).catch(clb);
|
|
2174
|
+
} else {
|
|
2175
|
+
clb(null, r2);
|
|
2176
|
+
}
|
|
2177
|
+
} catch (err) {
|
|
2178
|
+
clb(err);
|
|
2179
|
+
}
|
|
2180
|
+
} else {
|
|
2181
|
+
fc(languages, namespace, key, fallbackValue, clb, opts);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
if (!languages || !languages[0])
|
|
2185
|
+
return;
|
|
2186
|
+
this.store.addResource(languages[0], namespace, key, fallbackValue);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
function get() {
|
|
2190
|
+
return {
|
|
2191
|
+
debug: false,
|
|
2192
|
+
initImmediate: true,
|
|
2193
|
+
ns: ["translation"],
|
|
2194
|
+
defaultNS: ["translation"],
|
|
2195
|
+
fallbackLng: ["dev"],
|
|
2196
|
+
fallbackNS: false,
|
|
2197
|
+
supportedLngs: false,
|
|
2198
|
+
nonExplicitSupportedLngs: false,
|
|
2199
|
+
load: "all",
|
|
2200
|
+
preload: false,
|
|
2201
|
+
simplifyPluralSuffix: true,
|
|
2202
|
+
keySeparator: ".",
|
|
2203
|
+
nsSeparator: ":",
|
|
2204
|
+
pluralSeparator: "_",
|
|
2205
|
+
contextSeparator: "_",
|
|
2206
|
+
partialBundledLanguages: false,
|
|
2207
|
+
saveMissing: false,
|
|
2208
|
+
updateMissing: false,
|
|
2209
|
+
saveMissingTo: "fallback",
|
|
2210
|
+
saveMissingPlurals: true,
|
|
2211
|
+
missingKeyHandler: false,
|
|
2212
|
+
missingInterpolationHandler: false,
|
|
2213
|
+
postProcess: false,
|
|
2214
|
+
postProcessPassResolved: false,
|
|
2215
|
+
returnNull: false,
|
|
2216
|
+
returnEmptyString: true,
|
|
2217
|
+
returnObjects: false,
|
|
2218
|
+
joinArrays: false,
|
|
2219
|
+
returnedObjectHandler: false,
|
|
2220
|
+
parseMissingKeyHandler: false,
|
|
2221
|
+
appendNamespaceToMissingKey: false,
|
|
2222
|
+
appendNamespaceToCIMode: false,
|
|
2223
|
+
overloadTranslationOptionHandler: function handle(args) {
|
|
2224
|
+
let ret = {};
|
|
2225
|
+
if (typeof args[1] === "object")
|
|
2226
|
+
ret = args[1];
|
|
2227
|
+
if (typeof args[1] === "string")
|
|
2228
|
+
ret.defaultValue = args[1];
|
|
2229
|
+
if (typeof args[2] === "string")
|
|
2230
|
+
ret.tDescription = args[2];
|
|
2231
|
+
if (typeof args[2] === "object" || typeof args[3] === "object") {
|
|
2232
|
+
const options = args[3] || args[2];
|
|
2233
|
+
Object.keys(options).forEach((key) => {
|
|
2234
|
+
ret[key] = options[key];
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
return ret;
|
|
2238
|
+
},
|
|
2239
|
+
interpolation: {
|
|
2240
|
+
escapeValue: true,
|
|
2241
|
+
format: (value) => value,
|
|
2242
|
+
prefix: "{{",
|
|
2243
|
+
suffix: "}}",
|
|
2244
|
+
formatSeparator: ",",
|
|
2245
|
+
unescapePrefix: "-",
|
|
2246
|
+
nestingPrefix: "$t(",
|
|
2247
|
+
nestingSuffix: ")",
|
|
2248
|
+
nestingOptionsSeparator: ",",
|
|
2249
|
+
maxReplaces: 1e3,
|
|
2250
|
+
skipOnVariables: true
|
|
2251
|
+
}
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
function transformOptions(options) {
|
|
2255
|
+
if (typeof options.ns === "string")
|
|
2256
|
+
options.ns = [options.ns];
|
|
2257
|
+
if (typeof options.fallbackLng === "string")
|
|
2258
|
+
options.fallbackLng = [options.fallbackLng];
|
|
2259
|
+
if (typeof options.fallbackNS === "string")
|
|
2260
|
+
options.fallbackNS = [options.fallbackNS];
|
|
2261
|
+
if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
|
|
2262
|
+
options.supportedLngs = options.supportedLngs.concat(["cimode"]);
|
|
2263
|
+
}
|
|
2264
|
+
return options;
|
|
2265
|
+
}
|
|
2266
|
+
function noop() {
|
|
2267
|
+
}
|
|
2268
|
+
function bindMemberFunctions(inst) {
|
|
2269
|
+
const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
|
|
2270
|
+
mems.forEach((mem) => {
|
|
2271
|
+
if (typeof inst[mem] === "function") {
|
|
2272
|
+
inst[mem] = inst[mem].bind(inst);
|
|
2273
|
+
}
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
class I18n extends EventEmitter {
|
|
2277
|
+
constructor() {
|
|
2278
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2279
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2280
|
+
super();
|
|
2281
|
+
this.options = transformOptions(options);
|
|
2282
|
+
this.services = {};
|
|
2283
|
+
this.logger = baseLogger;
|
|
2284
|
+
this.modules = {
|
|
2285
|
+
external: []
|
|
2286
|
+
};
|
|
2287
|
+
bindMemberFunctions(this);
|
|
2288
|
+
if (callback && !this.isInitialized && !options.isClone) {
|
|
2289
|
+
if (!this.options.initImmediate) {
|
|
2290
|
+
this.init(options, callback);
|
|
2291
|
+
return this;
|
|
2292
|
+
}
|
|
2293
|
+
setTimeout(() => {
|
|
2294
|
+
this.init(options, callback);
|
|
2295
|
+
}, 0);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
init() {
|
|
2299
|
+
var _this = this;
|
|
2300
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2301
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2302
|
+
this.isInitializing = true;
|
|
2303
|
+
if (typeof options === "function") {
|
|
2304
|
+
callback = options;
|
|
2305
|
+
options = {};
|
|
2306
|
+
}
|
|
2307
|
+
if (!options.defaultNS && options.defaultNS !== false && options.ns) {
|
|
2308
|
+
if (typeof options.ns === "string") {
|
|
2309
|
+
options.defaultNS = options.ns;
|
|
2310
|
+
} else if (options.ns.indexOf("translation") < 0) {
|
|
2311
|
+
options.defaultNS = options.ns[0];
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
const defOpts = get();
|
|
2315
|
+
this.options = {
|
|
2316
|
+
...defOpts,
|
|
2317
|
+
...this.options,
|
|
2318
|
+
...transformOptions(options)
|
|
2319
|
+
};
|
|
2320
|
+
if (this.options.compatibilityAPI !== "v1") {
|
|
2321
|
+
this.options.interpolation = {
|
|
2322
|
+
...defOpts.interpolation,
|
|
2323
|
+
...this.options.interpolation
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
if (options.keySeparator !== void 0) {
|
|
2327
|
+
this.options.userDefinedKeySeparator = options.keySeparator;
|
|
2328
|
+
}
|
|
2329
|
+
if (options.nsSeparator !== void 0) {
|
|
2330
|
+
this.options.userDefinedNsSeparator = options.nsSeparator;
|
|
2331
|
+
}
|
|
2332
|
+
function createClassOnDemand(ClassOrObject) {
|
|
2333
|
+
if (!ClassOrObject)
|
|
2334
|
+
return null;
|
|
2335
|
+
if (typeof ClassOrObject === "function")
|
|
2336
|
+
return new ClassOrObject();
|
|
2337
|
+
return ClassOrObject;
|
|
2338
|
+
}
|
|
2339
|
+
if (!this.options.isClone) {
|
|
2340
|
+
if (this.modules.logger) {
|
|
2341
|
+
baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
|
|
2342
|
+
} else {
|
|
2343
|
+
baseLogger.init(null, this.options);
|
|
2344
|
+
}
|
|
2345
|
+
let formatter;
|
|
2346
|
+
if (this.modules.formatter) {
|
|
2347
|
+
formatter = this.modules.formatter;
|
|
2348
|
+
} else if (typeof Intl !== "undefined") {
|
|
2349
|
+
formatter = Formatter;
|
|
2350
|
+
}
|
|
2351
|
+
const lu = new LanguageUtil(this.options);
|
|
2352
|
+
this.store = new ResourceStore(this.options.resources, this.options);
|
|
2353
|
+
const s = this.services;
|
|
2354
|
+
s.logger = baseLogger;
|
|
2355
|
+
s.resourceStore = this.store;
|
|
2356
|
+
s.languageUtils = lu;
|
|
2357
|
+
s.pluralResolver = new PluralResolver(lu, {
|
|
2358
|
+
prepend: this.options.pluralSeparator,
|
|
2359
|
+
compatibilityJSON: this.options.compatibilityJSON,
|
|
2360
|
+
simplifyPluralSuffix: this.options.simplifyPluralSuffix
|
|
2361
|
+
});
|
|
2362
|
+
if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
|
|
2363
|
+
s.formatter = createClassOnDemand(formatter);
|
|
2364
|
+
s.formatter.init(s, this.options);
|
|
2365
|
+
this.options.interpolation.format = s.formatter.format.bind(s.formatter);
|
|
2366
|
+
}
|
|
2367
|
+
s.interpolator = new Interpolator(this.options);
|
|
2368
|
+
s.utils = {
|
|
2369
|
+
hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
|
|
2370
|
+
};
|
|
2371
|
+
s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
|
|
2372
|
+
s.backendConnector.on("*", function(event) {
|
|
2373
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
2374
|
+
args[_key - 1] = arguments[_key];
|
|
2375
|
+
}
|
|
2376
|
+
_this.emit(event, ...args);
|
|
2377
|
+
});
|
|
2378
|
+
if (this.modules.languageDetector) {
|
|
2379
|
+
s.languageDetector = createClassOnDemand(this.modules.languageDetector);
|
|
2380
|
+
if (s.languageDetector.init)
|
|
2381
|
+
s.languageDetector.init(s, this.options.detection, this.options);
|
|
2382
|
+
}
|
|
2383
|
+
if (this.modules.i18nFormat) {
|
|
2384
|
+
s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
|
|
2385
|
+
if (s.i18nFormat.init)
|
|
2386
|
+
s.i18nFormat.init(this);
|
|
2387
|
+
}
|
|
2388
|
+
this.translator = new Translator(this.services, this.options);
|
|
2389
|
+
this.translator.on("*", function(event) {
|
|
2390
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
2391
|
+
args[_key2 - 1] = arguments[_key2];
|
|
2392
|
+
}
|
|
2393
|
+
_this.emit(event, ...args);
|
|
2394
|
+
});
|
|
2395
|
+
this.modules.external.forEach((m) => {
|
|
2396
|
+
if (m.init)
|
|
2397
|
+
m.init(this);
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
this.format = this.options.interpolation.format;
|
|
2401
|
+
if (!callback)
|
|
2402
|
+
callback = noop;
|
|
2403
|
+
if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
|
|
2404
|
+
const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2405
|
+
if (codes.length > 0 && codes[0] !== "dev")
|
|
2406
|
+
this.options.lng = codes[0];
|
|
2407
|
+
}
|
|
2408
|
+
if (!this.services.languageDetector && !this.options.lng) {
|
|
2409
|
+
this.logger.warn("init: no languageDetector is used and no lng is defined");
|
|
2410
|
+
}
|
|
2411
|
+
const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
|
|
2412
|
+
storeApi.forEach((fcName) => {
|
|
2413
|
+
this[fcName] = function() {
|
|
2414
|
+
return _this.store[fcName](...arguments);
|
|
2415
|
+
};
|
|
2416
|
+
});
|
|
2417
|
+
const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
|
|
2418
|
+
storeApiChained.forEach((fcName) => {
|
|
2419
|
+
this[fcName] = function() {
|
|
2420
|
+
_this.store[fcName](...arguments);
|
|
2421
|
+
return _this;
|
|
2422
|
+
};
|
|
2423
|
+
});
|
|
2424
|
+
const deferred = defer();
|
|
2425
|
+
const load = () => {
|
|
2426
|
+
const finish = (err, t) => {
|
|
2427
|
+
this.isInitializing = false;
|
|
2428
|
+
if (this.isInitialized && !this.initializedStoreOnce)
|
|
2429
|
+
this.logger.warn("init: i18next is already initialized. You should call init just once!");
|
|
2430
|
+
this.isInitialized = true;
|
|
2431
|
+
if (!this.options.isClone)
|
|
2432
|
+
this.logger.log("initialized", this.options);
|
|
2433
|
+
this.emit("initialized", this.options);
|
|
2434
|
+
deferred.resolve(t);
|
|
2435
|
+
callback(err, t);
|
|
2436
|
+
};
|
|
2437
|
+
if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized)
|
|
2438
|
+
return finish(null, this.t.bind(this));
|
|
2439
|
+
this.changeLanguage(this.options.lng, finish);
|
|
2440
|
+
};
|
|
2441
|
+
if (this.options.resources || !this.options.initImmediate) {
|
|
2442
|
+
load();
|
|
2443
|
+
} else {
|
|
2444
|
+
setTimeout(load, 0);
|
|
2445
|
+
}
|
|
2446
|
+
return deferred;
|
|
2447
|
+
}
|
|
2448
|
+
loadResources(language) {
|
|
2449
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2450
|
+
let usedCallback = callback;
|
|
2451
|
+
const usedLng = typeof language === "string" ? language : this.language;
|
|
2452
|
+
if (typeof language === "function")
|
|
2453
|
+
usedCallback = language;
|
|
2454
|
+
if (!this.options.resources || this.options.partialBundledLanguages) {
|
|
2455
|
+
if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0))
|
|
2456
|
+
return usedCallback();
|
|
2457
|
+
const toLoad = [];
|
|
2458
|
+
const append = (lng) => {
|
|
2459
|
+
if (!lng)
|
|
2460
|
+
return;
|
|
2461
|
+
if (lng === "cimode")
|
|
2462
|
+
return;
|
|
2463
|
+
const lngs = this.services.languageUtils.toResolveHierarchy(lng);
|
|
2464
|
+
lngs.forEach((l) => {
|
|
2465
|
+
if (l === "cimode")
|
|
2466
|
+
return;
|
|
2467
|
+
if (toLoad.indexOf(l) < 0)
|
|
2468
|
+
toLoad.push(l);
|
|
2469
|
+
});
|
|
2470
|
+
};
|
|
2471
|
+
if (!usedLng) {
|
|
2472
|
+
const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
|
|
2473
|
+
fallbacks.forEach((l) => append(l));
|
|
2474
|
+
} else {
|
|
2475
|
+
append(usedLng);
|
|
2476
|
+
}
|
|
2477
|
+
if (this.options.preload) {
|
|
2478
|
+
this.options.preload.forEach((l) => append(l));
|
|
2479
|
+
}
|
|
2480
|
+
this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
|
|
2481
|
+
if (!e && !this.resolvedLanguage && this.language)
|
|
2482
|
+
this.setResolvedLanguage(this.language);
|
|
2483
|
+
usedCallback(e);
|
|
2484
|
+
});
|
|
2485
|
+
} else {
|
|
2486
|
+
usedCallback(null);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
reloadResources(lngs, ns, callback) {
|
|
2490
|
+
const deferred = defer();
|
|
2491
|
+
if (!lngs)
|
|
2492
|
+
lngs = this.languages;
|
|
2493
|
+
if (!ns)
|
|
2494
|
+
ns = this.options.ns;
|
|
2495
|
+
if (!callback)
|
|
2496
|
+
callback = noop;
|
|
2497
|
+
this.services.backendConnector.reload(lngs, ns, (err) => {
|
|
2498
|
+
deferred.resolve();
|
|
2499
|
+
callback(err);
|
|
2500
|
+
});
|
|
2501
|
+
return deferred;
|
|
2502
|
+
}
|
|
2503
|
+
use(module) {
|
|
2504
|
+
if (!module)
|
|
2505
|
+
throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
|
|
2506
|
+
if (!module.type)
|
|
2507
|
+
throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
|
|
2508
|
+
if (module.type === "backend") {
|
|
2509
|
+
this.modules.backend = module;
|
|
2510
|
+
}
|
|
2511
|
+
if (module.type === "logger" || module.log && module.warn && module.error) {
|
|
2512
|
+
this.modules.logger = module;
|
|
2513
|
+
}
|
|
2514
|
+
if (module.type === "languageDetector") {
|
|
2515
|
+
this.modules.languageDetector = module;
|
|
2516
|
+
}
|
|
2517
|
+
if (module.type === "i18nFormat") {
|
|
2518
|
+
this.modules.i18nFormat = module;
|
|
2519
|
+
}
|
|
2520
|
+
if (module.type === "postProcessor") {
|
|
2521
|
+
postProcessor.addPostProcessor(module);
|
|
2522
|
+
}
|
|
2523
|
+
if (module.type === "formatter") {
|
|
2524
|
+
this.modules.formatter = module;
|
|
2525
|
+
}
|
|
2526
|
+
if (module.type === "3rdParty") {
|
|
2527
|
+
this.modules.external.push(module);
|
|
2528
|
+
}
|
|
2529
|
+
return this;
|
|
2530
|
+
}
|
|
2531
|
+
setResolvedLanguage(l) {
|
|
2532
|
+
if (!l || !this.languages)
|
|
2533
|
+
return;
|
|
2534
|
+
if (["cimode", "dev"].indexOf(l) > -1)
|
|
2535
|
+
return;
|
|
2536
|
+
for (let li = 0; li < this.languages.length; li++) {
|
|
2537
|
+
const lngInLngs = this.languages[li];
|
|
2538
|
+
if (["cimode", "dev"].indexOf(lngInLngs) > -1)
|
|
2539
|
+
continue;
|
|
2540
|
+
if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
|
|
2541
|
+
this.resolvedLanguage = lngInLngs;
|
|
2542
|
+
break;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
changeLanguage(lng, callback) {
|
|
2547
|
+
var _this2 = this;
|
|
2548
|
+
this.isLanguageChangingTo = lng;
|
|
2549
|
+
const deferred = defer();
|
|
2550
|
+
this.emit("languageChanging", lng);
|
|
2551
|
+
const setLngProps = (l) => {
|
|
2552
|
+
this.language = l;
|
|
2553
|
+
this.languages = this.services.languageUtils.toResolveHierarchy(l);
|
|
2554
|
+
this.resolvedLanguage = void 0;
|
|
2555
|
+
this.setResolvedLanguage(l);
|
|
2556
|
+
};
|
|
2557
|
+
const done = (err, l) => {
|
|
2558
|
+
if (l) {
|
|
2559
|
+
setLngProps(l);
|
|
2560
|
+
this.translator.changeLanguage(l);
|
|
2561
|
+
this.isLanguageChangingTo = void 0;
|
|
2562
|
+
this.emit("languageChanged", l);
|
|
2563
|
+
this.logger.log("languageChanged", l);
|
|
2564
|
+
} else {
|
|
2565
|
+
this.isLanguageChangingTo = void 0;
|
|
2566
|
+
}
|
|
2567
|
+
deferred.resolve(function() {
|
|
2568
|
+
return _this2.t(...arguments);
|
|
2569
|
+
});
|
|
2570
|
+
if (callback)
|
|
2571
|
+
callback(err, function() {
|
|
2572
|
+
return _this2.t(...arguments);
|
|
2573
|
+
});
|
|
2574
|
+
};
|
|
2575
|
+
const setLng = (lngs) => {
|
|
2576
|
+
if (!lng && !lngs && this.services.languageDetector)
|
|
2577
|
+
lngs = [];
|
|
2578
|
+
const l = typeof lngs === "string" ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
|
|
2579
|
+
if (l) {
|
|
2580
|
+
if (!this.language) {
|
|
2581
|
+
setLngProps(l);
|
|
2582
|
+
}
|
|
2583
|
+
if (!this.translator.language)
|
|
2584
|
+
this.translator.changeLanguage(l);
|
|
2585
|
+
if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage)
|
|
2586
|
+
this.services.languageDetector.cacheUserLanguage(l);
|
|
2587
|
+
}
|
|
2588
|
+
this.loadResources(l, (err) => {
|
|
2589
|
+
done(err, l);
|
|
2590
|
+
});
|
|
2591
|
+
};
|
|
2592
|
+
if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
|
|
2593
|
+
setLng(this.services.languageDetector.detect());
|
|
2594
|
+
} else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
|
|
2595
|
+
if (this.services.languageDetector.detect.length === 0) {
|
|
2596
|
+
this.services.languageDetector.detect().then(setLng);
|
|
2597
|
+
} else {
|
|
2598
|
+
this.services.languageDetector.detect(setLng);
|
|
2599
|
+
}
|
|
2600
|
+
} else {
|
|
2601
|
+
setLng(lng);
|
|
2602
|
+
}
|
|
2603
|
+
return deferred;
|
|
2604
|
+
}
|
|
2605
|
+
getFixedT(lng, ns, keyPrefix) {
|
|
2606
|
+
var _this3 = this;
|
|
2607
|
+
const fixedT = function(key, opts) {
|
|
2608
|
+
let options;
|
|
2609
|
+
if (typeof opts !== "object") {
|
|
2610
|
+
for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
2611
|
+
rest[_key3 - 2] = arguments[_key3];
|
|
2612
|
+
}
|
|
2613
|
+
options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
|
|
2614
|
+
} else {
|
|
2615
|
+
options = {
|
|
2616
|
+
...opts
|
|
2617
|
+
};
|
|
2618
|
+
}
|
|
2619
|
+
options.lng = options.lng || fixedT.lng;
|
|
2620
|
+
options.lngs = options.lngs || fixedT.lngs;
|
|
2621
|
+
options.ns = options.ns || fixedT.ns;
|
|
2622
|
+
options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
|
|
2623
|
+
const keySeparator = _this3.options.keySeparator || ".";
|
|
2624
|
+
let resultKey;
|
|
2625
|
+
if (options.keyPrefix && Array.isArray(key)) {
|
|
2626
|
+
resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
|
|
2627
|
+
} else {
|
|
2628
|
+
resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
|
|
2629
|
+
}
|
|
2630
|
+
return _this3.t(resultKey, options);
|
|
2631
|
+
};
|
|
2632
|
+
if (typeof lng === "string") {
|
|
2633
|
+
fixedT.lng = lng;
|
|
2634
|
+
} else {
|
|
2635
|
+
fixedT.lngs = lng;
|
|
2636
|
+
}
|
|
2637
|
+
fixedT.ns = ns;
|
|
2638
|
+
fixedT.keyPrefix = keyPrefix;
|
|
2639
|
+
return fixedT;
|
|
2640
|
+
}
|
|
2641
|
+
t() {
|
|
2642
|
+
return this.translator && this.translator.translate(...arguments);
|
|
2643
|
+
}
|
|
2644
|
+
exists() {
|
|
2645
|
+
return this.translator && this.translator.exists(...arguments);
|
|
2646
|
+
}
|
|
2647
|
+
setDefaultNamespace(ns) {
|
|
2648
|
+
this.options.defaultNS = ns;
|
|
2649
|
+
}
|
|
2650
|
+
hasLoadedNamespace(ns) {
|
|
2651
|
+
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
2652
|
+
if (!this.isInitialized) {
|
|
2653
|
+
this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
|
|
2654
|
+
return false;
|
|
2655
|
+
}
|
|
2656
|
+
if (!this.languages || !this.languages.length) {
|
|
2657
|
+
this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
|
|
2658
|
+
return false;
|
|
2659
|
+
}
|
|
2660
|
+
const lng = options.lng || this.resolvedLanguage || this.languages[0];
|
|
2661
|
+
const fallbackLng = this.options ? this.options.fallbackLng : false;
|
|
2662
|
+
const lastLng = this.languages[this.languages.length - 1];
|
|
2663
|
+
if (lng.toLowerCase() === "cimode")
|
|
2664
|
+
return true;
|
|
2665
|
+
const loadNotPending = (l, n) => {
|
|
2666
|
+
const loadState = this.services.backendConnector.state[`${l}|${n}`];
|
|
2667
|
+
return loadState === -1 || loadState === 2;
|
|
2668
|
+
};
|
|
2669
|
+
if (options.precheck) {
|
|
2670
|
+
const preResult = options.precheck(this, loadNotPending);
|
|
2671
|
+
if (preResult !== void 0)
|
|
2672
|
+
return preResult;
|
|
2673
|
+
}
|
|
2674
|
+
if (this.hasResourceBundle(lng, ns))
|
|
2675
|
+
return true;
|
|
2676
|
+
if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages)
|
|
2677
|
+
return true;
|
|
2678
|
+
if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns)))
|
|
2679
|
+
return true;
|
|
2680
|
+
return false;
|
|
2681
|
+
}
|
|
2682
|
+
loadNamespaces(ns, callback) {
|
|
2683
|
+
const deferred = defer();
|
|
2684
|
+
if (!this.options.ns) {
|
|
2685
|
+
if (callback)
|
|
2686
|
+
callback();
|
|
2687
|
+
return Promise.resolve();
|
|
2688
|
+
}
|
|
2689
|
+
if (typeof ns === "string")
|
|
2690
|
+
ns = [ns];
|
|
2691
|
+
ns.forEach((n) => {
|
|
2692
|
+
if (this.options.ns.indexOf(n) < 0)
|
|
2693
|
+
this.options.ns.push(n);
|
|
2694
|
+
});
|
|
2695
|
+
this.loadResources((err) => {
|
|
2696
|
+
deferred.resolve();
|
|
2697
|
+
if (callback)
|
|
2698
|
+
callback(err);
|
|
2699
|
+
});
|
|
2700
|
+
return deferred;
|
|
2701
|
+
}
|
|
2702
|
+
loadLanguages(lngs, callback) {
|
|
2703
|
+
const deferred = defer();
|
|
2704
|
+
if (typeof lngs === "string")
|
|
2705
|
+
lngs = [lngs];
|
|
2706
|
+
const preloaded = this.options.preload || [];
|
|
2707
|
+
const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
|
|
2708
|
+
if (!newLngs.length) {
|
|
2709
|
+
if (callback)
|
|
2710
|
+
callback();
|
|
2711
|
+
return Promise.resolve();
|
|
2712
|
+
}
|
|
2713
|
+
this.options.preload = preloaded.concat(newLngs);
|
|
2714
|
+
this.loadResources((err) => {
|
|
2715
|
+
deferred.resolve();
|
|
2716
|
+
if (callback)
|
|
2717
|
+
callback(err);
|
|
2718
|
+
});
|
|
2719
|
+
return deferred;
|
|
2720
|
+
}
|
|
2721
|
+
dir(lng) {
|
|
2722
|
+
if (!lng)
|
|
2723
|
+
lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
|
|
2724
|
+
if (!lng)
|
|
2725
|
+
return "rtl";
|
|
2726
|
+
const 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", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
|
|
2727
|
+
const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
|
|
2728
|
+
return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
|
|
2729
|
+
}
|
|
2730
|
+
static createInstance() {
|
|
2731
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2732
|
+
let callback = arguments.length > 1 ? arguments[1] : void 0;
|
|
2733
|
+
return new I18n(options, callback);
|
|
2734
|
+
}
|
|
2735
|
+
cloneInstance() {
|
|
2736
|
+
let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
2737
|
+
let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
|
|
2738
|
+
const forkResourceStore = options.forkResourceStore;
|
|
2739
|
+
if (forkResourceStore)
|
|
2740
|
+
delete options.forkResourceStore;
|
|
2741
|
+
const mergedOptions = {
|
|
2742
|
+
...this.options,
|
|
2743
|
+
...options,
|
|
2744
|
+
...{
|
|
2745
|
+
isClone: true
|
|
2746
|
+
}
|
|
2747
|
+
};
|
|
2748
|
+
const clone = new I18n(mergedOptions);
|
|
2749
|
+
if (options.debug !== void 0 || options.prefix !== void 0) {
|
|
2750
|
+
clone.logger = clone.logger.clone(options);
|
|
2751
|
+
}
|
|
2752
|
+
const membersToCopy = ["store", "services", "language"];
|
|
2753
|
+
membersToCopy.forEach((m) => {
|
|
2754
|
+
clone[m] = this[m];
|
|
2755
|
+
});
|
|
2756
|
+
clone.services = {
|
|
2757
|
+
...this.services
|
|
2758
|
+
};
|
|
2759
|
+
clone.services.utils = {
|
|
2760
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2761
|
+
};
|
|
2762
|
+
if (forkResourceStore) {
|
|
2763
|
+
clone.store = new ResourceStore(this.store.data, mergedOptions);
|
|
2764
|
+
clone.services.resourceStore = clone.store;
|
|
2765
|
+
}
|
|
2766
|
+
clone.translator = new Translator(clone.services, mergedOptions);
|
|
2767
|
+
clone.translator.on("*", function(event) {
|
|
2768
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
2769
|
+
args[_key4 - 1] = arguments[_key4];
|
|
2770
|
+
}
|
|
2771
|
+
clone.emit(event, ...args);
|
|
2772
|
+
});
|
|
2773
|
+
clone.init(mergedOptions, callback);
|
|
2774
|
+
clone.translator.options = mergedOptions;
|
|
2775
|
+
clone.translator.backendConnector.services.utils = {
|
|
2776
|
+
hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
|
|
2777
|
+
};
|
|
2778
|
+
return clone;
|
|
2779
|
+
}
|
|
2780
|
+
toJSON() {
|
|
2781
|
+
return {
|
|
2782
|
+
options: this.options,
|
|
2783
|
+
store: this.store,
|
|
2784
|
+
language: this.language,
|
|
2785
|
+
languages: this.languages,
|
|
2786
|
+
resolvedLanguage: this.resolvedLanguage
|
|
2787
|
+
};
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
const instance = I18n.createInstance();
|
|
2791
|
+
instance.createInstance = I18n.createInstance;
|
|
2792
|
+
instance.createInstance;
|
|
2793
|
+
instance.dir;
|
|
2794
|
+
instance.init;
|
|
2795
|
+
instance.loadResources;
|
|
2796
|
+
instance.reloadResources;
|
|
2797
|
+
instance.use;
|
|
2798
|
+
instance.changeLanguage;
|
|
2799
|
+
instance.getFixedT;
|
|
2800
|
+
instance.t;
|
|
2801
|
+
instance.exists;
|
|
2802
|
+
instance.setDefaultNamespace;
|
|
2803
|
+
instance.hasLoadedNamespace;
|
|
2804
|
+
instance.loadNamespaces;
|
|
2805
|
+
instance.loadLanguages;
|
|
2806
|
+
const common$1 = {
|
|
2807
|
+
helloWorld: "Hello World",
|
|
2808
|
+
"class": "i18n-en"
|
|
2809
|
+
};
|
|
2810
|
+
const card$1 = {
|
|
2811
|
+
header: "Card Header",
|
|
2812
|
+
content: "Card Content",
|
|
2813
|
+
footer: "Card Footer"
|
|
2814
|
+
};
|
|
2815
|
+
const en = {
|
|
2816
|
+
common: common$1,
|
|
2817
|
+
card: card$1
|
|
2818
|
+
};
|
|
2819
|
+
const common = {
|
|
2820
|
+
helloWorld: "こんにちは、世界",
|
|
2821
|
+
"class": "i18n-ja"
|
|
2822
|
+
};
|
|
2823
|
+
const card = {
|
|
2824
|
+
header: "ヘッダー",
|
|
2825
|
+
content: "コンテンツ",
|
|
2826
|
+
footer: "フッター"
|
|
2827
|
+
};
|
|
2828
|
+
const ja = {
|
|
2829
|
+
common,
|
|
2830
|
+
card
|
|
2831
|
+
};
|
|
2832
|
+
const defaultNS = "common";
|
|
2833
|
+
const resources = {
|
|
2834
|
+
en,
|
|
2835
|
+
ja
|
|
2836
|
+
};
|
|
2837
|
+
instance.use(initReactI18next).init({
|
|
2838
|
+
defaultNS,
|
|
2839
|
+
fallbackLng: "en",
|
|
2840
|
+
resources
|
|
2841
|
+
});
|
|
2842
|
+
function r(e) {
|
|
2843
|
+
var t, f, n = "";
|
|
2844
|
+
if ("string" == typeof e || "number" == typeof e)
|
|
2845
|
+
n += e;
|
|
2846
|
+
else if ("object" == typeof e)
|
|
2847
|
+
if (Array.isArray(e)) {
|
|
2848
|
+
var o = e.length;
|
|
2849
|
+
for (t = 0; t < o; t++)
|
|
2850
|
+
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
2851
|
+
} else
|
|
2852
|
+
for (f in e)
|
|
2853
|
+
e[f] && (n && (n += " "), n += f);
|
|
2854
|
+
return n;
|
|
2855
|
+
}
|
|
2856
|
+
function clsx() {
|
|
2857
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++)
|
|
2858
|
+
(e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
2859
|
+
return n;
|
|
2860
|
+
}
|
|
2861
|
+
const withI18n = (Story) => {
|
|
2862
|
+
const { t } = useTranslation();
|
|
2863
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: clsx(t("class"), "h-full w-full"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Story, {}) });
|
|
2864
|
+
};
|
|
2865
|
+
const preview = {
|
|
2866
|
+
decorators: [withI18n],
|
|
2867
|
+
globals: {
|
|
2868
|
+
locale: "en",
|
|
2869
|
+
locales: {
|
|
2870
|
+
en: { title: "English", left: "🇬🇧" },
|
|
2871
|
+
ja: { title: "日本語", left: "🇯🇵" }
|
|
2872
|
+
}
|
|
2873
|
+
},
|
|
2874
|
+
parameters: {
|
|
2875
|
+
backgrounds: { disable: true },
|
|
2876
|
+
chromatic: {
|
|
2877
|
+
// Disable snapshot testing for all stories, we only want it to test stories we explicitly opt-in
|
|
2878
|
+
disableSnapshot: true
|
|
2879
|
+
},
|
|
2880
|
+
controls: {
|
|
2881
|
+
expanded: true,
|
|
2882
|
+
color: /(background|color)$/i,
|
|
2883
|
+
date: /Date$/
|
|
2884
|
+
},
|
|
2885
|
+
i18n: instance,
|
|
2886
|
+
options: {
|
|
2887
|
+
storySort: {
|
|
2888
|
+
method: "alphabetical",
|
|
2889
|
+
order: [
|
|
2890
|
+
"guides",
|
|
2891
|
+
["Introduction", "Installation"],
|
|
2892
|
+
"typeset",
|
|
2893
|
+
"colour",
|
|
2894
|
+
["Palette", "Themes"],
|
|
2895
|
+
"components",
|
|
2896
|
+
["*"]
|
|
2897
|
+
]
|
|
2898
|
+
}
|
|
2899
|
+
},
|
|
2900
|
+
themes: {
|
|
2901
|
+
clearable: false,
|
|
2902
|
+
default: "default",
|
|
2903
|
+
list: [
|
|
2904
|
+
{ name: "local", class: "theme-local" }
|
|
2905
|
+
]
|
|
2906
|
+
},
|
|
2907
|
+
docs: {
|
|
2908
|
+
toc: {
|
|
2909
|
+
headingSelector: ".sbdocs > h1, .sbdocs > h2, .sbdocs > h3"
|
|
2910
|
+
},
|
|
2911
|
+
theme: create({
|
|
2912
|
+
base: "light",
|
|
2913
|
+
fontBase: '"DM Sans", sans-serif'
|
|
2914
|
+
})
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
};
|
|
2918
|
+
export {
|
|
2919
|
+
preview as default
|
|
2920
|
+
};
|