@nocobase/plugin-localization 1.6.0-beta.3 → 1.6.0-beta.5

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.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ "use strict";(self.webpackChunk_nocobase_plugin_localization=self.webpackChunk_nocobase_plugin_localization||[]).push([["517"],{668:function(e,t,n){n.r(t),n.d(t,{Localization:function(){return P}});var o=n("482"),r=n("563"),l=n("505"),a=n("772"),i=n("749"),c=n("721"),u=n("156"),s=n.n(u),p=n("573"),d={name:"localization",fields:[{interface:"input",type:"string",name:"text",uiSchema:{type:"string",title:'{{t("Text")}}',"x-component":"Input.TextArea",required:!0}},{interface:"input",type:"string",name:"translation",uiSchema:{type:"string",title:'{{t("Translation")}}',"x-component":"Input.TextArea"}},{interface:"select",type:"string",name:"moduleTitle",uiSchema:{type:"string",title:'{{t("Module")}}',"x-component":"Select",enum:[{value:"Menu",label:'{{t("Menu")}}'},{value:"Collections & Fields",label:'{{t("Collections & Fields", {ns:"localization"})}}'}]}}]},m={type:"void",name:"localization","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:d,resourceName:"localizationTexts",request:{resource:"localizationTexts",action:"list",params:{pageSize:50}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:d},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{currentLang:{type:"void","x-align":"left","x-component":"CurrentLang"},filter:{type:"void",title:'{{t("Filter")}}',"x-align":"left","x-component":"Filter"},deleteTranslation:{type:"void",title:'{{t("Delete translation")}}',"x-component":"Action","x-component-props":{icon:"DeleteOutlined",useAction:"{{ useBulkDestroyTranslationAction }}",confirm:{title:"{{t('Delete translation')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},sync:{type:"void",title:'{{t("Sync")}}',"x-component":"Sync"},publish:{type:"void",title:'{{t("Publish")}}',"x-component":"Action","x-component-props":{icon:"UploadOutlined",type:"primary",useAction:"{{ usePublishAction }}"}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"translationId",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}"},properties:{text:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{text:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},translation:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{translation:{type:"string","x-component":"CollectionField","x-component-props":{component:"TranslationField"},"x-read-pretty":!0}}},moduleTitle:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{moduleTitle:{type:"string","x-component":"ModuleTitle"}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Edit")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Edit")}}',properties:{moduleTitle:{title:'{{t("Module")}}',"x-component":"ModuleTitle","x-decorator":"FormItem"},text:{"x-component":"CollectionField","x-decorator":"FormItem","x-read-pretty":!0},translation:{"x-component":"CollectionField","x-decorator":"FormItem",required:!0},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useUpdateTranslationAction }}"}}}}}}}},deleteTranslation:{type:"void",title:'{{ t("Delete translation") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete translation')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{useDestroyTranslationAction}}"},"x-visible":"{{useHasTranslation()}}"}}}}}}}}};function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function y(e,t,n,o,r,l,a){try{var i=e[l](a),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(o,r)}function v(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var l=e.apply(t,n);function a(e){y(l,o,r,a,i,"next",e)}function i(e){y(l,o,r,a,i,"throw",e)}a(void 0)})}}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(t){var o,r,l;o=e,r=t,l=n[t],r in o?Object.defineProperty(o,r,{value:l,enumerable:!0,configurable:!0,writable:!0}):o[r]=l})}return e}function x(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n.push.apply(n,o)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,o,r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var l=[],a=!0,i=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,o=e}finally{try{!a&&null!=r.return&&r.return()}finally{if(i)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,o,r,l,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){return function(l){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&l[0]?o.return:l[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,l[1])).done)return r;switch(o=0,r&&(l=[2&l[0],r.value]),l[0]){case 0:case 1:r=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,o=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!r||l[1]>r[0]&&l[1]<r[3])){a.label=l[1];break}if(6===l[0]&&a.label<r[1]){a.label=r[1],r=l;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(l);break}r[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],o=0}finally{n=r=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,i])}}}var A=c.Typography.Text,C=function(){var e=(0,l.useField)(),t=(0,l.useForm)(),n=(0,a.useActionContext)(),o=(0,a.useResourceActionContext)().refresh,r=(0,a.useResourceContext)().targetKey,i=(0,a.useRecord)()[r],c=(0,a.useAPIClient)(),u=c.auth.getLocale();return{run:function(){return v(function(){return g(this,function(r){switch(r.label){case 0:return[4,t.submit()];case 1:r.sent(),e.data=e.data||{},e.data.loading=!0,r.label=2;case 2:return r.trys.push([2,5,6,7]),[4,c.resource("localizationTranslations").updateOrCreate({filterKeys:["textId","locale"],values:{textId:i,locale:u,translation:t.values.translation}})];case 3:return r.sent(),n.setVisible(!1),[4,t.reset()];case 4:return r.sent(),o(),[3,7];case 5:return console.log(r.sent()),[3,7];case 6:return e.data.loading=!1,[7];case 7:return[2]}})})()}}},T=function(){var e=(0,a.useResourceActionContext)().refresh,t=(0,a.useAPIClient)(),n=(0,a.useRecord)().translationId;return{run:function(){return v(function(){return g(this,function(o){switch(o.label){case 0:if(!n)return[2];return[4,t.resource("localizationTranslations").destroy({filterByTk:n})];case 1:return o.sent(),e(),[2]}})})()}}},w=function(){var e=(0,a.useResourceActionContext)(),t=e.state,n=e.setState,o=e.refresh,r=(0,a.useAPIClient)(),l=(0,p.F)().t;return{run:function(){return v(function(){var e;return g(this,function(a){switch(a.label){case 0:if(!(null==t?void 0:null===(e=t.selectedRowKeys)||void 0===e?void 0:e.length))return[2,c.message.error(l("Please select the records you want to delete"))];return[4,r.resource("localizationTranslations").destroy({filterByTk:null==t?void 0:t.selectedRowKeys})];case 1:return a.sent(),null==n||n({selectedRowKeys:[]}),o(),[2]}})})()}}},S=function(){var e=(0,a.useAPIClient)();return{run:function(){return v(function(){return g(this,function(t){switch(t.label){case 0:return[4,e.resource("localization").publish()];case 1:return t.sent(),window.location.reload(),[2]}})})()}}},F=function(){var e=(0,p.F)().t,t=(0,a.useResourceActionContext)().refresh,n=(0,a.useAPIClient)(),r=b((0,u.useState)(!1),2),i=r[0],d=r[1],m=b((0,u.useState)([]),2),f=m[0],y=m[1],h=b((0,u.useState)([]),2),x=h[0],A=h[1],C=b((0,u.useState)(!1),2),T=C[0],w=C[1],S=b((0,u.useState)(!0),2),F=S[0],E=S[1],k=(0,a.useRequest)(function(){return n.resource("localization").getSources().then(function(e){var t;return null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.data})},{onSuccess:function(e){var t=e.map(function(e){return e.name});y(t),A(t)}}),O=k.data;return k.loading?null:s().createElement(a.StablePopover,{placement:"bottomRight",content:s().createElement(s().Fragment,null,s().createElement(c.Checkbox,{indeterminate:T,onChange:function(e){A(e.target.checked?f:[]),w(!1),E(e.target.checked)},checked:F},e("All")),s().createElement(c.Divider,{style:{margin:"5px 0"}}),s().createElement(c.Checkbox.Group,{onChange:function(e){A(e),w(!!e.length&&e.length<f.length),E(e.length===f.length)},value:x},s().createElement(c.Col,null,(O||[]).map(function(t){return s().createElement(c.Row,{key:t.name},s().createElement(c.Checkbox,{value:t.name},l.Schema.compile(t.title,{t:e})))}))))},s().createElement(c.Button,{icon:s().createElement(o.SyncOutlined,null),loading:i,onClick:v(function(){return g(this,function(o){switch(o.label){case 0:if(!x.length)return[2,c.message.error(e("Please select the resources you want to synchronize"))];return d(!0),[4,n.resource("localization").sync({values:{types:x}})];case 1:return o.sent(),d(!1),t(),[2]}})})},e("Sync")))},E=function(){var e,t=(0,p.F)().t,n=(0,i.useMemoizedFn)(t),o=(0,a.useResourceActionContext)().data;return(0,u.useMemo)(function(){var e,t;return(null==o?void 0:null===(t=o.meta)||void 0===t?void 0:null===(e=t.modules)||void 0===e?void 0:e.map(function(e){return{value:e.value,label:l.Schema.compile(e.label,{t:n})}}))||[]},[null==o?void 0:null===(e=o.meta)||void 0===e?void 0:e.modules,n])},k=function(){var e=(0,p.F)().t,t=(0,a.useResourceActionContext)().run,n=E(),o=(0,u.useMemo)(function(){return(0,r.createForm)({initialValues:{hasTranslation:!0}})},[]),i=function(e){t(h({},e||o.values))};return(0,u.useEffect)(function(){o.query("module").take().dataSource=n},[o,n]),s().createElement(a.FormProvider,{form:o},s().createElement("div",{style:{display:"flex"}},s().createElement(l.Field,{name:"module",dataSource:n,component:[a.Select,{allowClear:!0,placeholder:e("Module"),onChange:function(e){return i(x(h({},o.values),{module:e}))}}]}),s().createElement(l.Field,{name:"keyword",component:[c.Input.Search,{placeholder:e("Keyword"),allowClear:!0,style:{marginLeft:"8px",width:"fit-content"},onSearch:function(e){return i(x(h({},o.values),{keyword:e}))}}]}),s().createElement(l.Field,{name:"hasTranslation",dataSource:[{label:e("All"),value:!0},{label:e("No translation"),value:!1}],component:[a.Radio.Group,{defaultValue:!0,style:{marginLeft:"8px",width:"fit-content"},optionType:"button",onChange:function(){return i()}}]})))},O=function(){var e=(0,p.F)().t,t=(0,a.useRecord)().moduleTitle;return s().createElement(c.Tag,null,l.Schema.compile(t,{t:e}))},P=function(){var e,t=(0,p.F)().t,n=(0,a.useAPIClient)().auth.getLocale(),o=(null===(e=a.locale[n])||void 0===e?void 0:e.label)||n;return s().createElement(c.Card,{bordered:!1},s().createElement(a.SchemaComponent,{schema:m,components:{TranslationField:function(e){return void 0!==e.value?s().createElement(a.Input.TextArea,e):s().createElement("div",null)},CurrentLang:function(){return s().createElement(c.Typography,null,s().createElement(A,{strong:!0},t("Current language")),s().createElement(c.Tag,{style:{marginLeft:"10px"}},o))},Sync:F,Filter:k,ModuleTitle:O},scope:{t:t,useDestroyTranslationAction:T,useBulkDestroyTranslationAction:w,useUpdateTranslationAction:C,usePublishAction:S,useModules:E}}))}}}]);
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-i18next"),require("@formily/core"),require("@nocobase/client"),require("ahooks"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("react")):"function"==typeof define&&define.amd?define("@nocobase/plugin-localization",["react-i18next","@formily/core","@nocobase/client","ahooks","antd","@ant-design/icons","@formily/react","react"],e):"object"==typeof exports?exports["@nocobase/plugin-localization"]=e(require("react-i18next"),require("@formily/core"),require("@nocobase/client"),require("ahooks"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("react")):t["@nocobase/plugin-localization"]=e(t["react-i18next"],t["@formily/core"],t["@nocobase/client"],t.ahooks,t.antd,t["@ant-design/icons"],t["@formily/react"],t.react)}(self,function(t,e,n,r,o,i,u,c){return function(){var a,l,f,s,p,d,b={573:function(t,e,n){"use strict";n.d(e,{A:function(){return o},F:function(){return i}});var r=n(238),o="localization",i=function(){return(0,r.useTranslation)([o,"client"],{nsMode:"fallback"})}},581:function(t){t.exports=function(t,e){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(t,e),e}},482:function(t){"use strict";t.exports=i},563:function(t){"use strict";t.exports=e},505:function(t){"use strict";t.exports=u},772:function(t){"use strict";t.exports=n},749:function(t){"use strict";t.exports=r},721:function(t){"use strict";t.exports=o},156:function(t){"use strict";t.exports=c},238:function(e){"use strict";e.exports=t}},y={};function h(t){var e=y[t];if(void 0!==e)return e.exports;var n=y[t]={exports:{}};return b[t](n,n.exports,h),n.exports}h.m=b,h.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return h.d(e,{a:e}),e},h.d=function(t,e){for(var n in e)h.o(e,n)&&!h.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},h.f={},h.e=function(t){return Promise.all(Object.keys(h.f).reduce(function(e,n){return h.f[n](t,e),e},[]))},h.u=function(t){return"c63d67828fd1a082.js"},h.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),h.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a={},l="@nocobase/plugin-localization:",h.l=function(t,e,n,r){if(a[t]){a[t].push(e);return}if(void 0!==n){for(var o,i,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var f=u[c];if(f.getAttribute("src")==t||f.getAttribute("data-webpack")==l+n){o=f;break}}}!o&&(i=!0,(o=document.createElement("script")).charset="utf-8",o.timeout=120,h.nc&&o.setAttribute("nonce",h.nc),o.setAttribute("data-webpack",l+n),o.src=t),a[t]=[e];var s=function(e,n){o.onerror=o.onload=null,clearTimeout(p);var r=a[t];if(delete a[t],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(t){return t(n)}),e)return e(n)},p=setTimeout(s.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=s.bind(null,o.onerror),o.onload=s.bind(null,o.onload),i&&document.head.appendChild(o)},h.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},h.p=(!(f=window.__nocobase_public_path__||"/").endsWith("/")&&(f+="/"),f+"static/plugins/@nocobase/plugin-localization/dist/client/"),s={909:0},h.f.j=function(t,e){var n=h.o(s,t)?s[t]:void 0;if(0!==n){if(n)e.push(n[2]);else{var r=new Promise(function(e,r){n=s[t]=[e,r]});e.push(n[2]=r);var o=h.p+h.u(t),i=Error();h.l(o,function(e){if(h.o(s,t)&&(0!==(n=s[t])&&(s[t]=void 0),n)){var r=e&&("load"===e.type?"missing":e.type),o=e&&e.target&&e.target.src;i.message="Loading chunk "+t+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+t,t)}}},p=function(t,e){var n=e[0],r=e[1],o=e[2],i,u,c=0;if(n.some(function(t){return 0!==s[t]})){for(i in r)h.o(r,i)&&(h.m[i]=r[i]);o&&o(h)}for(t&&t(e);c<n.length;c++)u=n[c],h.o(s,u)&&s[u]&&s[u][0](),s[u]=0},(d=self.webpackChunk_nocobase_plugin_localization=self.webpackChunk_nocobase_plugin_localization||[]).forEach(p.bind(null,0)),d.push=p.bind(null,d.push.bind(d));var v={};return!function(){"use strict";h.r(v),h.d(v,{PluginLocalizationClient:function(){return s}});var t=h(772),e=h(573),n=h(581);function r(t,e,n,r,o,i,u){try{var c=t[i](u),a=c.value}catch(t){n(t);return}c.done?e(a):Promise.resolve(a).then(r,o)}function o(t,e,n){return(o=l()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t){var e="function"==typeof Map?new Map:void 0;return(a=function(t){var n;if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return o(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,t)})(t)}function l(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(l=function(){return!!t})()}var f=(0,t.lazy)(function(){return n("imported_-237jod_component",h.e("517").then(h.bind(h,668)))},"Localization").Localization,s=function(t){var n,o,a;function s(){var t,e,n;return!function(t,e){if(!(t instanceof e))throw TypeError("Cannot call a class as a function")}(this,s),t=this,e=s,n=arguments,e=u(e),function(t,e){return e&&("object"===function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}(e)||"function"==typeof e)?e:function(t){if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,l()?Reflect.construct(e,n||[],u(t).constructor):e.apply(t,n))}return!function(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(s,t),n=s,o=[{key:"load",value:function(){var t,n=this;return(t=function(){return function(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(t){return n.app.pluginSettingsManager.add(e.A,{title:'{{t("Localization", { ns: "'.concat(e.A,'" })}}'),icon:"GlobalOutlined",Component:f,aclSnippet:"pm.localization.localization"}),[2]})},function(){var e=this,n=arguments;return new Promise(function(o,i){var u=t.apply(e,n);function c(t){r(u,o,i,c,a,"next",t)}function a(t){r(u,o,i,c,a,"throw",t)}c(void 0)})})()}}],i(n.prototype,o),s}(a(t.Plugin));v.default=s}(),v}()});
10
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react-i18next"),require("@formily/core"),require("@nocobase/client"),require("ahooks"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("react")):"function"==typeof define&&define.amd?define("@nocobase/plugin-localization",["react-i18next","@formily/core","@nocobase/client","ahooks","antd","@ant-design/icons","@formily/react","react"],e):"object"==typeof exports?exports["@nocobase/plugin-localization"]=e(require("react-i18next"),require("@formily/core"),require("@nocobase/client"),require("ahooks"),require("antd"),require("@ant-design/icons"),require("@formily/react"),require("react")):t["@nocobase/plugin-localization"]=e(t["react-i18next"],t["@formily/core"],t["@nocobase/client"],t.ahooks,t.antd,t["@ant-design/icons"],t["@formily/react"],t.react)}(self,function(t,e,n,r,o,i,u,c){return function(){var a,l,f,s,p,d,b={573:function(t,e,n){"use strict";n.d(e,{A:function(){return o},F:function(){return i}});var r=n(238),o="localization",i=function(){return(0,r.useTranslation)([o,"client"],{nsMode:"fallback"})}},581:function(t){t.exports=function(t,e){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(t,e),e}},482:function(t){"use strict";t.exports=i},563:function(t){"use strict";t.exports=e},505:function(t){"use strict";t.exports=u},772:function(t){"use strict";t.exports=n},749:function(t){"use strict";t.exports=r},721:function(t){"use strict";t.exports=o},156:function(t){"use strict";t.exports=c},238:function(e){"use strict";e.exports=t}},y={};function h(t){var e=y[t];if(void 0!==e)return e.exports;var n=y[t]={exports:{}};return b[t](n,n.exports,h),n.exports}h.m=b,h.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return h.d(e,{a:e}),e},h.d=function(t,e){for(var n in e)h.o(e,n)&&!h.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},h.f={},h.e=function(t){return Promise.all(Object.keys(h.f).reduce(function(e,n){return h.f[n](t,e),e},[]))},h.u=function(t){return"cea645024581ad7f.js"},h.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(t){if("object"==typeof window)return window}}(),h.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a={},l="@nocobase/plugin-localization:",h.l=function(t,e,n,r){if(a[t]){a[t].push(e);return}if(void 0!==n){for(var o,i,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var f=u[c];if(f.getAttribute("src")==t||f.getAttribute("data-webpack")==l+n){o=f;break}}}!o&&(i=!0,(o=document.createElement("script")).charset="utf-8",o.timeout=120,h.nc&&o.setAttribute("nonce",h.nc),o.setAttribute("data-webpack",l+n),o.src=t),a[t]=[e];var s=function(e,n){o.onerror=o.onload=null,clearTimeout(p);var r=a[t];if(delete a[t],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(t){return t(n)}),e)return e(n)},p=setTimeout(s.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=s.bind(null,o.onerror),o.onload=s.bind(null,o.onload),i&&document.head.appendChild(o)},h.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},h.p=(!(f=window.__nocobase_public_path__||"/").endsWith("/")&&(f+="/"),f+"static/plugins/@nocobase/plugin-localization/dist/client/"),s={909:0},h.f.j=function(t,e){var n=h.o(s,t)?s[t]:void 0;if(0!==n){if(n)e.push(n[2]);else{var r=new Promise(function(e,r){n=s[t]=[e,r]});e.push(n[2]=r);var o=h.p+h.u(t),i=Error();h.l(o,function(e){if(h.o(s,t)&&(0!==(n=s[t])&&(s[t]=void 0),n)){var r=e&&("load"===e.type?"missing":e.type),o=e&&e.target&&e.target.src;i.message="Loading chunk "+t+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+t,t)}}},p=function(t,e){var n=e[0],r=e[1],o=e[2],i,u,c=0;if(n.some(function(t){return 0!==s[t]})){for(i in r)h.o(r,i)&&(h.m[i]=r[i]);o&&o(h)}for(t&&t(e);c<n.length;c++)u=n[c],h.o(s,u)&&s[u]&&s[u][0](),s[u]=0},(d=self.webpackChunk_nocobase_plugin_localization=self.webpackChunk_nocobase_plugin_localization||[]).forEach(p.bind(null,0)),d.push=p.bind(null,d.push.bind(d));var v={};return!function(){"use strict";h.r(v),h.d(v,{PluginLocalizationClient:function(){return s}});var t=h(772),e=h(573),n=h(581);function r(t,e,n,r,o,i,u){try{var c=t[i](u),a=c.value}catch(t){n(t);return}c.done?e(a):Promise.resolve(a).then(r,o)}function o(t,e,n){return(o=l()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&c(o,n.prototype),o}).apply(null,arguments)}function i(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t){var e="function"==typeof Map?new Map:void 0;return(a=function(t){var n;if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;if("function"!=typeof t)throw TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return o(t,arguments,u(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,t)})(t)}function l(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(l=function(){return!!t})()}var f=(0,t.lazy)(function(){return n("imported_-237jod_component",h.e("517").then(h.bind(h,668)))},"Localization").Localization,s=function(t){var n,o,a;function s(){var t,e,n;return!function(t,e){if(!(t instanceof e))throw TypeError("Cannot call a class as a function")}(this,s),t=this,e=s,n=arguments,e=u(e),function(t,e){return e&&("object"===function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}(e)||"function"==typeof e)?e:function(t){if(void 0===t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,l()?Reflect.construct(e,n||[],u(t).constructor):e.apply(t,n))}return!function(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(s,t),n=s,o=[{key:"load",value:function(){var t,n=this;return(t=function(){return function(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(t){return n.app.pluginSettingsManager.add(e.A,{title:'{{t("Localization", { ns: "'.concat(e.A,'" })}}'),icon:"GlobalOutlined",Component:f,aclSnippet:"pm.localization.localization"}),[2]})},function(){var e=this,n=arguments;return new Promise(function(o,i){var u=t.apply(e,n);function c(t){r(u,o,i,c,a,"next",t)}function a(t){r(u,o,i,c,a,"throw",t)}c(void 0)})})()}}],i(n.prototype,o),s}(a(t.Plugin));v.default=s}(),v}()});
@@ -11,14 +11,14 @@ module.exports = {
11
11
  "@ant-design/icons": "5.2.6",
12
12
  "@formily/core": "2.3.0",
13
13
  "@formily/react": "2.3.0",
14
- "@nocobase/client": "1.6.0-beta.3",
14
+ "@nocobase/client": "1.6.0-beta.5",
15
15
  "ahooks": "3.7.8",
16
16
  "antd": "5.12.8",
17
17
  "react": "18.2.0",
18
- "@nocobase/database": "1.6.0-beta.3",
19
- "@nocobase/plugin-ui-schema-storage": "1.6.0-beta.3",
20
- "@nocobase/server": "1.6.0-beta.3",
21
- "@nocobase/cache": "1.6.0-beta.3",
22
- "react-i18next": "11.18.6",
23
- "@nocobase/actions": "1.6.0-beta.3"
18
+ "@nocobase/database": "1.6.0-beta.5",
19
+ "@nocobase/server": "1.6.0-beta.5",
20
+ "@nocobase/utils": "1.6.0-beta.5",
21
+ "@nocobase/cache": "1.6.0-beta.5",
22
+ "@nocobase/actions": "1.6.0-beta.5",
23
+ "react-i18next": "11.18.6"
24
24
  };
@@ -7,17 +7,9 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { Context, Next } from '@nocobase/actions';
10
- import { Database, Model } from '@nocobase/database';
11
- export declare const getResources: (ctx: Context) => Promise<{}>;
12
- export declare const getUISchemas: (db: Database) => Promise<Model<any, any>[]>;
13
- export declare const getTextsFromDB: (db: Database) => Promise<{}>;
14
- export declare const getSchemaUid: (db: Database, migrate?: boolean) => Promise<{
15
- adminSchemaUid: any;
16
- mobileSchemaUid: any;
17
- }>;
18
- export declare const getTextsFromMenu: (db: Database, migrate?: boolean) => Promise<{}>;
19
10
  declare const _default: {
20
11
  publish: (ctx: Context, next: Next) => Promise<void>;
21
12
  sync: (ctx: Context, next: Next) => Promise<void>;
13
+ getSources: (ctx: Context, next: Next) => Promise<void>;
22
14
  };
23
15
  export default _default;
@@ -26,165 +26,20 @@ var __copyProps = (to, from, except, desc) => {
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
27
  var localization_exports = {};
28
28
  __export(localization_exports, {
29
- default: () => localization_default,
30
- getResources: () => getResources,
31
- getSchemaUid: () => getSchemaUid,
32
- getTextsFromDB: () => getTextsFromDB,
33
- getTextsFromMenu: () => getTextsFromMenu,
34
- getUISchemas: () => getUISchemas
29
+ default: () => localization_default
35
30
  });
36
31
  module.exports = __toCommonJS(localization_exports);
37
- var import_database = require("@nocobase/database");
38
- var import_constans = require("../constans");
39
- var import_utils = require("../utils");
40
- var import_server = require("@nocobase/server");
41
- const getResourcesInstance = async (ctx) => {
42
- const plugin = ctx.app.getPlugin("localization");
43
- return plugin.resources;
44
- };
45
- const getResources = async (ctx) => {
46
- const resources = await ctx.app.localeManager.getCacheResources(ctx.get("X-Locale") || "en-US");
47
- const result = {};
48
- Object.entries(resources).forEach(([module2, resource]) => {
49
- if (module2.startsWith(import_server.OFFICIAL_PLUGIN_PREFIX)) {
50
- const name = module2.replace(import_server.OFFICIAL_PLUGIN_PREFIX, "");
51
- if (resources[name]) {
52
- return;
53
- }
54
- }
55
- result[module2] = resource;
56
- });
57
- return result;
58
- };
59
- const getUISchemas = async (db) => {
60
- const uiSchemas = await db.getModel("uiSchemas").findAll({
61
- attributes: ["schema"],
62
- where: {
63
- [import_database.Op.or]: [
64
- {
65
- schema: {
66
- title: {
67
- [import_database.Op.ne]: null
68
- }
69
- }
70
- },
71
- {
72
- schema: {
73
- "x-component-props": {
74
- title: {
75
- [import_database.Op.ne]: null
76
- }
77
- }
78
- }
79
- },
80
- {
81
- schema: {
82
- "x-decorator-props": {
83
- title: {
84
- [import_database.Op.ne]: null
85
- }
86
- }
87
- }
88
- },
89
- {
90
- schema: {
91
- "x-data-templates": {
92
- [import_database.Op.ne]: null
93
- }
94
- }
95
- }
96
- ]
97
- }
98
- });
99
- return uiSchemas;
100
- };
101
- const getTextsFromDB = async (db) => {
102
- const result = {};
103
- const collections = Array.from(db.collections.values());
104
- for (const collection of collections) {
105
- const fields = Array.from(collection.fields.values()).filter((field) => {
106
- var _a;
107
- return (_a = field.options) == null ? void 0 : _a.translation;
108
- }).map((field) => field.name);
109
- if (!fields.length) {
110
- continue;
111
- }
112
- const repo = db.getRepository(collection.name);
113
- const records = await repo.find({ fields });
114
- records.forEach((record) => {
115
- const texts = (0, import_utils.getTextsFromDBRecord)(fields, record);
116
- texts.forEach((text) => result[text] = "");
117
- });
118
- }
119
- return result;
120
- };
121
- const getSchemaUid = async (db, migrate = false) => {
122
- if (migrate) {
123
- const systemSettings = await db.getRepository("systemSettings").findOne();
124
- const options = (systemSettings == null ? void 0 : systemSettings.options) || {};
125
- const { adminSchemaUid, mobileSchemaUid } = options;
126
- return { adminSchemaUid, mobileSchemaUid };
127
- }
128
- return { adminSchemaUid: "nocobase-admin-menu", mobileSchemaUid: "nocobase-mobile-container" };
129
- };
130
- const getTextsFromMenu = async (db, migrate = false) => {
131
- var _a, _b, _c, _d;
132
- const result = {};
133
- const { adminSchemaUid, mobileSchemaUid } = await getSchemaUid(db, migrate);
134
- const repo = db.getRepository("uiSchemas");
135
- if (adminSchemaUid) {
136
- const schema = await repo.getProperties(adminSchemaUid);
137
- const extractTitle = (schema2) => {
138
- if (schema2 == null ? void 0 : schema2.properties) {
139
- Object.values(schema2.properties).forEach((item) => {
140
- if (item.title) {
141
- result[item.title] = "";
142
- }
143
- extractTitle(item);
144
- });
145
- }
146
- };
147
- extractTitle(schema);
148
- }
149
- if (mobileSchemaUid) {
150
- const schema = await repo.getProperties(mobileSchemaUid);
151
- if ((_b = (_a = schema == null ? void 0 : schema["properties"]) == null ? void 0 : _a.tabBar) == null ? void 0 : _b.properties) {
152
- Object.values((_d = (_c = schema["properties"]) == null ? void 0 : _c.tabBar) == null ? void 0 : _d.properties).forEach((item) => {
153
- var _a2;
154
- const title = (_a2 = item["x-component-props"]) == null ? void 0 : _a2.title;
155
- if (title) {
156
- result[title] = "";
157
- }
158
- });
159
- }
160
- }
161
- return result;
162
- };
163
32
  const sync = async (ctx, next) => {
164
33
  const startTime = Date.now();
165
34
  ctx.logger.info("Start sync localization resources");
166
- const resourcesInstance = await getResourcesInstance(ctx);
35
+ const plugin = ctx.app.pm.get("localization");
36
+ const resourcesInstance = plugin.resources;
167
37
  const locale = ctx.get("X-Locale") || "en-US";
168
38
  const { types = [] } = ctx.action.params.values || {};
169
39
  if (!types.length) {
170
40
  ctx.throw(400, ctx.t("Please provide synchronization source."));
171
41
  }
172
- let resources = { client: {} };
173
- if (types.includes("local")) {
174
- resources = await getResources(ctx);
175
- }
176
- if (types.includes("menu")) {
177
- const menuTexts = await getTextsFromMenu(ctx.db);
178
- resources[import_constans.NAMESPACE_MENUS] = {
179
- ...menuTexts
180
- };
181
- }
182
- if (types.includes("db")) {
183
- const dbTexts = await getTextsFromDB(ctx.db);
184
- resources[import_constans.NAMESPACE_COLLECTIONS] = {
185
- ...dbTexts
186
- };
187
- }
42
+ const resources = await plugin.sourceManager.sync(ctx, types);
188
43
  let textValues = [];
189
44
  Object.entries(resources).forEach(([module2, resource]) => {
190
45
  Object.keys(resource).forEach((text) => {
@@ -226,12 +81,13 @@ const publish = async (ctx, next) => {
226
81
  ctx.app.localeManager.reload();
227
82
  await next();
228
83
  };
229
- var localization_default = { publish, sync };
230
- // Annotate the CommonJS export names for ESM import in node:
231
- 0 && (module.exports = {
232
- getResources,
233
- getSchemaUid,
234
- getTextsFromDB,
235
- getTextsFromMenu,
236
- getUISchemas
237
- });
84
+ const getSources = async (ctx, next) => {
85
+ const plugin = ctx.app.pm.get("localization");
86
+ const sources = Array.from(plugin.sourceManager.sources.getEntities());
87
+ ctx.body = sources.map(([name, source]) => ({
88
+ name,
89
+ title: source.title
90
+ }));
91
+ await next();
92
+ };
93
+ var localization_default = { publish, sync, getSources };
@@ -31,7 +31,6 @@ __export(localizationTexts_exports, {
31
31
  module.exports = __toCommonJS(localizationTexts_exports);
32
32
  var import_actions = require("@nocobase/actions");
33
33
  var import_database = require("@nocobase/database");
34
- var import_constans = require("../constans");
35
34
  const appendTranslations = async (db, rows, locale) => {
36
35
  const texts = rows || [];
37
36
  const textIds = texts.map((text) => text.id);
@@ -105,12 +104,18 @@ const list = async (ctx, next) => {
105
104
  const [rows, count] = await listText(ctx.db, { module: module2, keyword, hasTranslation, locale, options });
106
105
  const cache = ctx.app.cache;
107
106
  const pm = ctx.app.pm;
107
+ const plugin = pm.get("localization");
108
108
  const plugins = await cache.wrap(`lm-plugins:${locale}`, () => pm.list({ locale }));
109
+ const sources = Array.from(plugin.sourceManager.sources.getValues());
110
+ const extendModules = sources.filter((source) => source.namespace).map((source) => ({
111
+ value: source.namespace,
112
+ label: source.title
113
+ }));
109
114
  const modules = [
110
- ...import_constans.EXTEND_MODULES,
111
- ...plugins.map((plugin) => ({
112
- value: plugin.alias || plugin.name,
113
- label: plugin.displayName
115
+ ...extendModules,
116
+ ...plugins.map((plugin2) => ({
117
+ value: plugin2.alias || plugin2.name,
118
+ label: plugin2.displayName
114
119
  }))
115
120
  ];
116
121
  for (const row of rows) {
@@ -127,10 +132,10 @@ const list = async (ctx, next) => {
127
132
  pageSize,
128
133
  totalPage: Math.ceil(count / pageSize),
129
134
  modules: [
130
- ...import_constans.EXTEND_MODULES,
131
- ...plugins.map((plugin) => ({
132
- value: plugin.alias || plugin.name,
133
- label: plugin.displayName
135
+ ...extendModules,
136
+ ...plugins.map((plugin2) => ({
137
+ value: plugin2.alias || plugin2.name,
138
+ label: plugin2.displayName
134
139
  }))
135
140
  ]
136
141
  };
@@ -34,6 +34,7 @@ var localization_texts_default = (0, import_database.defineCollection)({
34
34
  dumpRules: {
35
35
  group: "required"
36
36
  },
37
+ migrationRules: ["overwrite", "schema-only"],
37
38
  name: "localizationTexts",
38
39
  model: "LocalizationTextModel",
39
40
  createdBy: true,
@@ -35,6 +35,7 @@ var localization_translations_default = (0, import_database.defineCollection)({
35
35
  dumpRules: {
36
36
  group: "required"
37
37
  },
38
+ migrationRules: ["overwrite", "schema-only"],
38
39
  name: "localizationTranslations",
39
40
  model: "LocalizationTranslationModel",
40
41
  createdBy: true,
@@ -8,9 +8,4 @@
8
8
  */
9
9
  export declare const CACHE_KEY = "localization:texts";
10
10
  export declare const NAMESPACE_PREFIX = "lm-";
11
- export declare const NAMESPACE_MENUS: string;
12
11
  export declare const NAMESPACE_COLLECTIONS: string;
13
- export declare const EXTEND_MODULES: {
14
- value: string;
15
- label: string;
16
- }[];
@@ -24,34 +24,19 @@ var __copyProps = (to, from, except, desc) => {
24
24
  return to;
25
25
  };
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var constans_exports = {};
28
- __export(constans_exports, {
27
+ var constants_exports = {};
28
+ __export(constants_exports, {
29
29
  CACHE_KEY: () => CACHE_KEY,
30
- EXTEND_MODULES: () => EXTEND_MODULES,
31
30
  NAMESPACE_COLLECTIONS: () => NAMESPACE_COLLECTIONS,
32
- NAMESPACE_MENUS: () => NAMESPACE_MENUS,
33
31
  NAMESPACE_PREFIX: () => NAMESPACE_PREFIX
34
32
  });
35
- module.exports = __toCommonJS(constans_exports);
33
+ module.exports = __toCommonJS(constants_exports);
36
34
  const CACHE_KEY = "localization:texts";
37
35
  const NAMESPACE_PREFIX = "lm-";
38
- const NAMESPACE_MENUS = `${NAMESPACE_PREFIX}menus`;
39
36
  const NAMESPACE_COLLECTIONS = `${NAMESPACE_PREFIX}collections`;
40
- const EXTEND_MODULES = [
41
- {
42
- value: NAMESPACE_MENUS,
43
- label: "Menu"
44
- },
45
- {
46
- value: NAMESPACE_COLLECTIONS,
47
- label: "Collections & Fields"
48
- }
49
- ];
50
37
  // Annotate the CommonJS export names for ESM import in node:
51
38
  0 && (module.exports = {
52
39
  CACHE_KEY,
53
- EXTEND_MODULES,
54
40
  NAMESPACE_COLLECTIONS,
55
- NAMESPACE_MENUS,
56
41
  NAMESPACE_PREFIX
57
42
  });
@@ -6,7 +6,13 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+ import { Database } from '@nocobase/database';
9
10
  import { Migration } from '@nocobase/server';
11
+ export declare const getSchemaUid: (db: Database, migrate?: boolean) => Promise<{
12
+ adminSchemaUid: any;
13
+ mobileSchemaUid: any;
14
+ }>;
15
+ export declare const getTextsFromMenu: (db: Database, migrate?: boolean) => Promise<{}>;
10
16
  export default class FixModuleMigration extends Migration {
11
17
  appVersion: string;
12
18
  up(): Promise<void>;
@@ -26,13 +26,78 @@ var __copyProps = (to, from, except, desc) => {
26
26
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
27
  var fix_module_exports = {};
28
28
  __export(fix_module_exports, {
29
- default: () => FixModuleMigration
29
+ default: () => FixModuleMigration,
30
+ getSchemaUid: () => getSchemaUid,
31
+ getTextsFromMenu: () => getTextsFromMenu
30
32
  });
31
33
  module.exports = __toCommonJS(fix_module_exports);
32
34
  var import_database = require("@nocobase/database");
33
35
  var import_server = require("@nocobase/server");
34
- var import_localization = require("../actions/localization");
35
- var import_constans = require("../constans");
36
+ var import_constants = require("../constants");
37
+ var import_utils = require("../utils");
38
+ const NAMESPACE_MENUS = `${import_constants.NAMESPACE_PREFIX}menus`;
39
+ const getTextsFromDB = async (db) => {
40
+ const result = {};
41
+ const collections = Array.from(db.collections.values());
42
+ for (const collection of collections) {
43
+ const fields = Array.from(collection.fields.values()).filter((field) => {
44
+ var _a;
45
+ return (_a = field.options) == null ? void 0 : _a.translation;
46
+ }).map((field) => field.name);
47
+ if (!fields.length) {
48
+ continue;
49
+ }
50
+ const repo = db.getRepository(collection.name);
51
+ const records = await repo.find({ fields });
52
+ records.forEach((record) => {
53
+ const texts = (0, import_utils.getTextsFromDBRecord)(fields, record);
54
+ texts.forEach((text) => result[text] = "");
55
+ });
56
+ }
57
+ return result;
58
+ };
59
+ const getSchemaUid = async (db, migrate = false) => {
60
+ if (migrate) {
61
+ const systemSettings = await db.getRepository("systemSettings").findOne();
62
+ const options = (systemSettings == null ? void 0 : systemSettings.options) || {};
63
+ const { adminSchemaUid, mobileSchemaUid } = options;
64
+ return { adminSchemaUid, mobileSchemaUid };
65
+ }
66
+ return { adminSchemaUid: "nocobase-admin-menu", mobileSchemaUid: "nocobase-mobile-container" };
67
+ };
68
+ const getTextsFromMenu = async (db, migrate = false) => {
69
+ var _a, _b, _c, _d;
70
+ const result = {};
71
+ const { adminSchemaUid, mobileSchemaUid } = await getSchemaUid(db, migrate);
72
+ const repo = db.getRepository("uiSchemas");
73
+ if (adminSchemaUid) {
74
+ const schema = await repo.getProperties(adminSchemaUid);
75
+ const extractTitle = (schema2) => {
76
+ if (schema2 == null ? void 0 : schema2.properties) {
77
+ Object.values(schema2.properties).forEach((item) => {
78
+ if (item.title) {
79
+ result[item.title] = "";
80
+ }
81
+ extractTitle(item);
82
+ });
83
+ }
84
+ };
85
+ extractTitle(schema);
86
+ }
87
+ if (mobileSchemaUid) {
88
+ const schema = await repo.getProperties(mobileSchemaUid);
89
+ if ((_b = (_a = schema == null ? void 0 : schema["properties"]) == null ? void 0 : _a.tabBar) == null ? void 0 : _b.properties) {
90
+ Object.values((_d = (_c = schema["properties"]) == null ? void 0 : _c.tabBar) == null ? void 0 : _d.properties).forEach((item) => {
91
+ var _a2;
92
+ const title = (_a2 = item["x-component-props"]) == null ? void 0 : _a2.title;
93
+ if (title) {
94
+ result[title] = "";
95
+ }
96
+ });
97
+ }
98
+ }
99
+ return result;
100
+ };
36
101
  class FixModuleMigration extends import_server.Migration {
37
102
  appVersion = "<0.17.0-alpha.3";
38
103
  async up() {
@@ -41,15 +106,15 @@ class FixModuleMigration extends import_server.Migration {
41
106
  return;
42
107
  }
43
108
  const resources = await this.app.localeManager.getCacheResources("zh-CN");
44
- const menus = await (0, import_localization.getTextsFromMenu)(this.context.db, true);
45
- const collections = await (0, import_localization.getTextsFromDB)(this.context.db);
109
+ const menus = await getTextsFromMenu(this.context.db, true);
110
+ const collections = await getTextsFromDB(this.context.db);
46
111
  const db = this.context.db;
47
112
  await db.getCollection("localizationTexts").sync();
48
113
  await db.sequelize.transaction(async (t) => {
49
114
  const menuTexts = Object.keys(menus);
50
115
  await db.getModel("localizationTexts").update(
51
116
  {
52
- module: `resources.${import_constans.NAMESPACE_MENUS}`
117
+ module: `resources.${NAMESPACE_MENUS}`
53
118
  },
54
119
  {
55
120
  where: {
@@ -63,7 +128,7 @@ class FixModuleMigration extends import_server.Migration {
63
128
  const collectionTexts = Object.keys(collections);
64
129
  await db.getModel("localizationTexts").update(
65
130
  {
66
- module: `resources.${import_constans.NAMESPACE_COLLECTIONS}`
131
+ module: `resources.${import_constants.NAMESPACE_COLLECTIONS}`
67
132
  },
68
133
  {
69
134
  where: {
@@ -98,3 +163,8 @@ class FixModuleMigration extends import_server.Migration {
98
163
  async down() {
99
164
  }
100
165
  }
166
+ // Annotate the CommonJS export names for ESM import in node:
167
+ 0 && (module.exports = {
168
+ getSchemaUid,
169
+ getTextsFromMenu
170
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ on: string;
12
+ appVersion: string;
13
+ up(): Promise<void>;
14
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var update_ns_for_routes_exports = {};
28
+ __export(update_ns_for_routes_exports, {
29
+ default: () => update_ns_for_routes_default
30
+ });
31
+ module.exports = __toCommonJS(update_ns_for_routes_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class update_ns_for_routes_default extends import_server.Migration {
34
+ on = "afterLoad";
35
+ // 'beforeLoad' or 'afterLoad'
36
+ appVersion = "<1.6.1";
37
+ async up() {
38
+ await this.db.getRepository("localizationTexts").update({
39
+ values: {
40
+ module: "resources.lm-desktop-routes"
41
+ },
42
+ filter: {
43
+ module: "resources.lm-menus"
44
+ }
45
+ });
46
+ }
47
+ }
@@ -6,12 +6,16 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- import PluginUISchemaStorageServer from '@nocobase/plugin-ui-schema-storage';
10
9
  import { InstallOptions, Plugin } from '@nocobase/server';
11
10
  import Resources from './resources';
11
+ import { SourceManager } from './source-manager';
12
12
  export declare class PluginLocalizationServer extends Plugin {
13
13
  resources: Resources;
14
- registerUISchemahook(plugin?: PluginUISchemaStorageServer): void;
14
+ sourceManager: SourceManager;
15
+ addNewTexts: (texts: {
16
+ text: string;
17
+ module: string;
18
+ }[], options?: any) => Promise<void>;
15
19
  afterAdd(): void;
16
20
  beforeLoad(): void;
17
21
  load(): Promise<void>;
@@ -45,43 +45,38 @@ var import_localization = __toESM(require("./actions/localization"));
45
45
  var import_localizationTexts = __toESM(require("./actions/localizationTexts"));
46
46
  var import_resources = __toESM(require("./resources"));
47
47
  var import_utils = require("./utils");
48
- var import_constans = require("./constans");
48
+ var import_constants = require("./constants");
49
+ var import_source_manager = require("./source-manager");
50
+ var import_utils2 = require("@nocobase/utils");
51
+ var import_package = __toESM(require("../../package.json"));
49
52
  class PluginLocalizationServer extends import_server.Plugin {
50
53
  resources;
51
- registerUISchemahook(plugin) {
52
- const uiSchemaStoragePlugin = plugin || this.app.getPlugin("ui-schema-storage");
53
- if (!uiSchemaStoragePlugin) {
54
- return;
55
- }
56
- uiSchemaStoragePlugin.serverHooks.register("onSelfSave", "extractTextToLocale", async ({ schemaInstance }) => {
57
- var _a;
58
- const module2 = `resources.${import_constans.NAMESPACE_MENUS}`;
59
- const schema = schemaInstance.get("schema");
60
- const title = (schema == null ? void 0 : schema.title) || ((_a = schema == null ? void 0 : schema["x-component-props"]) == null ? void 0 : _a.title);
61
- if (!title) {
62
- return;
54
+ sourceManager = new import_source_manager.SourceManager();
55
+ addNewTexts = async (texts, options) => {
56
+ texts = await this.resources.filterExists(texts, options == null ? void 0 : options.transaction);
57
+ this.db.getModel("localizationTexts").bulkCreate(
58
+ texts.map(({ text, module: module2 }) => ({
59
+ module: module2,
60
+ text
61
+ })),
62
+ {
63
+ transaction: options == null ? void 0 : options.transaction
63
64
  }
64
- const result = await this.resources.filterExists([{ text: title, module: module2 }]);
65
- if (!result.length) {
66
- return;
67
- }
68
- this.db.getRepository("localizationTexts").create({
69
- values: {
70
- module: module2,
71
- text: title
72
- }
73
- }).then((res) => {
74
- this.resources.updateCacheTexts([res]);
75
- this.sendSyncMessage({
65
+ ).then((newTexts) => {
66
+ this.resources.updateCacheTexts(newTexts, options == null ? void 0 : options.transaction);
67
+ this.sendSyncMessage(
68
+ {
76
69
  type: "updateCacheTexts",
77
- texts: [res]
78
- });
79
- }).catch((err) => {
80
- this.log.error(err);
81
- });
70
+ texts: newTexts
71
+ },
72
+ { transaction: options == null ? void 0 : options.transaction }
73
+ );
74
+ }).catch((err) => {
75
+ this.log.error(err);
82
76
  });
83
- }
77
+ };
84
78
  afterAdd() {
79
+ this.app.on("afterLoad", () => this.sourceManager.handleTextsSaved(this.db, this.addNewTexts));
85
80
  }
86
81
  beforeLoad() {
87
82
  }
@@ -98,14 +93,68 @@ class PluginLocalizationServer extends import_server.Plugin {
98
93
  name: `pm.${this.name}.localization`,
99
94
  actions: ["localization:*", "localizationTexts:*", "localizationTranslations:*"]
100
95
  });
96
+ this.app.localeManager.registerResourceStorer("plugin-localization", {
97
+ getResources: (lang) => this.resources.getResources(lang),
98
+ reset: () => this.resources.reset()
99
+ });
100
+ const cache = await this.app.cacheManager.createCache({
101
+ name: "localization",
102
+ prefix: "localization",
103
+ store: "memory"
104
+ });
105
+ this.resources = new import_resources.default(this.db, cache);
106
+ this.sourceManager.registerSource("local", {
107
+ title: (0, import_utils2.tval)("System & Plugins", { ns: import_package.default.name }),
108
+ sync: async (ctx) => {
109
+ const resources = await ctx.app.localeManager.getCacheResources(ctx.get("X-Locale") || "en-US");
110
+ const result = {};
111
+ Object.entries(resources).forEach(([module2, resource]) => {
112
+ if (module2.startsWith(import_server.OFFICIAL_PLUGIN_PREFIX)) {
113
+ const name = module2.replace(import_server.OFFICIAL_PLUGIN_PREFIX, "");
114
+ if (resources[name]) {
115
+ return;
116
+ }
117
+ }
118
+ result[module2] = resource;
119
+ });
120
+ return result;
121
+ }
122
+ });
123
+ this.sourceManager.registerSource("db", {
124
+ title: (0, import_utils2.tval)("Collections & Fields", { ns: import_package.default.name }),
125
+ namespace: import_constants.NAMESPACE_COLLECTIONS,
126
+ sync: async (ctx) => {
127
+ const db = ctx.db;
128
+ const result = {};
129
+ const collections = Array.from(db.collections.values());
130
+ for (const collection of collections) {
131
+ const fields = Array.from(collection.fields.values()).filter((field) => {
132
+ var _a;
133
+ return (_a = field.options) == null ? void 0 : _a.translation;
134
+ }).map((field) => field.name);
135
+ if (!fields.length) {
136
+ continue;
137
+ }
138
+ const repo = db.getRepository(collection.name);
139
+ const records = await repo.find({ fields });
140
+ records.forEach((record) => {
141
+ const texts = (0, import_utils.getTextsFromDBRecord)(fields, record);
142
+ texts.forEach((text) => result[text] = "");
143
+ });
144
+ }
145
+ return {
146
+ [import_constants.NAMESPACE_COLLECTIONS]: result
147
+ };
148
+ }
149
+ });
101
150
  this.db.on("afterSave", async (instance, options) => {
102
- const module2 = `resources.${import_constans.NAMESPACE_COLLECTIONS}`;
151
+ const module2 = `resources.${import_constants.NAMESPACE_COLLECTIONS}`;
103
152
  const model = instance.constructor;
104
153
  const collection = model.collection;
105
154
  if (!collection) {
106
155
  return;
107
156
  }
108
- let texts = [];
157
+ const texts = [];
109
158
  const fields = Array.from(collection.fields.values()).filter((field) => {
110
159
  var _a;
111
160
  return ((_a = field.options) == null ? void 0 : _a.translation) && instance["_changed"].has(field.name);
@@ -117,38 +166,7 @@ class PluginLocalizationServer extends import_server.Plugin {
117
166
  textsFromDB.forEach((text) => {
118
167
  texts.push({ text, module: module2 });
119
168
  });
120
- texts = await this.resources.filterExists(texts, options == null ? void 0 : options.transaction);
121
- this.db.getModel("localizationTexts").bulkCreate(
122
- texts.map(({ text, module: module3 }) => ({
123
- module: module3,
124
- text
125
- })),
126
- {
127
- transaction: options == null ? void 0 : options.transaction
128
- }
129
- ).then((newTexts) => {
130
- this.resources.updateCacheTexts(newTexts, options == null ? void 0 : options.transaction);
131
- this.sendSyncMessage(
132
- {
133
- type: "updateCacheTexts",
134
- texts: newTexts
135
- },
136
- { transaction: options == null ? void 0 : options.transaction }
137
- );
138
- }).catch((err) => {
139
- this.log.error(err);
140
- });
141
- });
142
- const cache = await this.app.cacheManager.createCache({
143
- name: "localization",
144
- prefix: "localization",
145
- store: "memory"
146
- });
147
- this.resources = new import_resources.default(this.db, cache);
148
- this.registerUISchemahook();
149
- this.app.localeManager.registerResourceStorer("plugin-localization", {
150
- getResources: (lang) => this.resources.getResources(lang),
151
- reset: () => this.resources.reset()
169
+ await this.addNewTexts(texts, options);
152
170
  });
153
171
  }
154
172
  async handleSyncMessage(message) {
@@ -163,11 +181,6 @@ class PluginLocalizationServer extends import_server.Plugin {
163
181
  async afterEnable() {
164
182
  }
165
183
  async afterDisable() {
166
- const uiSchemaStoragePlugin = this.app.getPlugin("ui-schema-storage");
167
- if (!uiSchemaStoragePlugin) {
168
- return;
169
- }
170
- uiSchemaStoragePlugin.serverHooks.remove("onSelfSave", "extractTextToLocale");
171
184
  }
172
185
  async remove() {
173
186
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import { Context } from '@nocobase/actions';
10
+ import { Database } from '@nocobase/database';
11
+ import { Registry } from '@nocobase/utils';
12
+ export type Source = {
13
+ title: string;
14
+ sync: (ctx: Context) => Promise<{
15
+ [module: string]: {
16
+ [text: string]: string;
17
+ };
18
+ }>;
19
+ namespace?: string;
20
+ collections?: {
21
+ collection: string;
22
+ fields: string[];
23
+ }[];
24
+ };
25
+ export declare class SourceManager {
26
+ sources: Registry<Source>;
27
+ registerSource(name: string, source: Source): void;
28
+ sync(ctx: Context, types: string[]): Promise<{
29
+ [module: string]: any;
30
+ }>;
31
+ handleTextsSaved(db: Database, handler: (texts: {
32
+ text: string;
33
+ module: string;
34
+ }[], options?: any) => Promise<any>): void;
35
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var source_manager_exports = {};
28
+ __export(source_manager_exports, {
29
+ SourceManager: () => SourceManager
30
+ });
31
+ module.exports = __toCommonJS(source_manager_exports);
32
+ var import_utils = require("@nocobase/utils");
33
+ class SourceManager {
34
+ sources = new import_utils.Registry();
35
+ registerSource(name, source) {
36
+ this.sources.register(name, source);
37
+ }
38
+ async sync(ctx, types) {
39
+ const resources = { client: {} };
40
+ const sources = Array.from(this.sources.getKeys());
41
+ const syncSources = sources.filter((source) => types.includes(source));
42
+ const promises = syncSources.map((source) => this.sources.get(source).sync(ctx));
43
+ const results = await Promise.all(promises);
44
+ return results.reduce((result, resource) => {
45
+ return { ...result, ...resource };
46
+ }, resources);
47
+ }
48
+ handleTextsSaved(db, handler) {
49
+ const sources = this.sources;
50
+ for (const source of sources.getValues()) {
51
+ if (!source.collections) {
52
+ continue;
53
+ }
54
+ for (const { collection, fields } of source.collections) {
55
+ db.on(`${collection}.afterSave`, async (instance, options) => {
56
+ const texts = [];
57
+ const changedFields = fields.filter((field) => instance["_changed"].has(field));
58
+ if (!changedFields.length) {
59
+ return;
60
+ }
61
+ changedFields.forEach((field) => {
62
+ texts.push({ text: instance.get(field), module: `resources.${source.namespace}` });
63
+ });
64
+ await handler(texts, options);
65
+ });
66
+ }
67
+ }
68
+ }
69
+ }
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ SourceManager
73
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-localization",
3
- "version": "1.6.0-beta.3",
3
+ "version": "1.6.0-beta.5",
4
4
  "main": "dist/server/index.js",
5
5
  "homepage": "https://docs.nocobase.com/handbook/localization-management",
6
6
  "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/localization-management",
@@ -12,8 +12,6 @@
12
12
  "@nocobase/cache": "1.x",
13
13
  "@nocobase/client": "1.x",
14
14
  "@nocobase/database": "1.x",
15
- "@nocobase/plugin-client": "1.x",
16
- "@nocobase/plugin-ui-schema-storage": "1.x",
17
15
  "@nocobase/server": "1.x",
18
16
  "@nocobase/test": "1.x"
19
17
  },
@@ -24,5 +22,5 @@
24
22
  "displayName.zh-CN": "本地化",
25
23
  "description": "Allows to manage localization resources of the application.",
26
24
  "description.zh-CN": "支持管理应用程序的本地化资源。",
27
- "gitHead": "19a659c49d7eedd3d57e46f9df2e8540f55c99b7"
25
+ "gitHead": "66e7c7239b29361bc60543886d107ba0e00085d9"
28
26
  }
@@ -1,10 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- "use strict";(self.webpackChunk_nocobase_plugin_localization=self.webpackChunk_nocobase_plugin_localization||[]).push([["517"],{668:function(e,t,n){n.r(t),n.d(t,{Localization:function(){return P}});var o=n("482"),r=n("563"),l=n("505"),a=n("772"),i=n("749"),c=n("721"),u=n("156"),s=n.n(u),p=n("573"),d={name:"localization",fields:[{interface:"input",type:"string",name:"text",uiSchema:{type:"string",title:'{{t("Text")}}',"x-component":"Input.TextArea",required:!0}},{interface:"input",type:"string",name:"translation",uiSchema:{type:"string",title:'{{t("Translation")}}',"x-component":"Input.TextArea"}},{interface:"select",type:"string",name:"moduleTitle",uiSchema:{type:"string",title:'{{t("Module")}}',"x-component":"Select",enum:[{value:"Menu",label:'{{t("Menu")}}'},{value:"Collections & Fields",label:'{{t("Collections & Fields", {ns:"localization"})}}'}]}}]},m={type:"void",name:"localization","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:d,resourceName:"localizationTexts",request:{resource:"localizationTexts",action:"list",params:{pageSize:50}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:d},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{currentLang:{type:"void","x-align":"left","x-component":"CurrentLang"},filter:{type:"void",title:'{{t("Filter")}}',"x-align":"left","x-component":"Filter"},deleteTranslation:{type:"void",title:'{{t("Delete translation")}}',"x-component":"Action","x-component-props":{icon:"DeleteOutlined",useAction:"{{ useBulkDestroyTranslationAction }}",confirm:{title:"{{t('Delete translation')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},sync:{type:"void",title:'{{t("Sync")}}',"x-component":"Sync"},publish:{type:"void",title:'{{t("Publish")}}',"x-component":"Action","x-component-props":{icon:"UploadOutlined",type:"primary",useAction:"{{ usePublishAction }}"}}}},table:{type:"void","x-uid":"input","x-component":"Table.Void","x-component-props":{rowKey:"translationId",rowSelection:{type:"checkbox"},useDataSource:"{{ cm.useDataSourceFromRAC }}"},properties:{text:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{text:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},translation:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{translation:{type:"string","x-component":"CollectionField","x-component-props":{component:"TranslationField"},"x-read-pretty":!0}}},moduleTitle:{type:"void","x-decorator":"Table.Column.Decorator","x-component":"Table.Column",properties:{moduleTitle:{type:"string","x-component":"CollectionField","x-read-pretty":!0}}},actions:{type:"void",title:'{{t("Actions")}}',"x-component":"Table.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{update:{type:"void",title:'{{t("Edit")}}',"x-component":"Action.Link","x-component-props":{type:"primary"},properties:{drawer:{type:"void","x-component":"Action.Drawer","x-decorator":"Form","x-decorator-props":{useValues:"{{ cm.useValuesFromRecord }}"},title:'{{t("Edit")}}',properties:{moduleTitle:{"x-component":"CollectionField","x-decorator":"FormItem","x-read-pretty":!0},text:{"x-component":"CollectionField","x-decorator":"FormItem","x-read-pretty":!0},translation:{"x-component":"CollectionField","x-decorator":"FormItem",required:!0},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{t("Cancel")}}',"x-component":"Action","x-component-props":{useAction:"{{ cm.useCancelAction }}"}},submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useUpdateTranslationAction }}"}}}}}}}},deleteTranslation:{type:"void",title:'{{ t("Delete translation") }}',"x-component":"Action.Link","x-component-props":{confirm:{title:"{{t('Delete translation')}}",content:"{{t('Are you sure you want to delete it?')}}"},useAction:"{{useDestroyTranslationAction}}"},"x-visible":"{{useHasTranslation()}}"}}}}}}}}};function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function f(e,t,n,o,r,l,a){try{var i=e[l](a),c=i.value}catch(e){n(e);return}i.done?t(c):Promise.resolve(c).then(o,r)}function x(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var l=e.apply(t,n);function a(e){f(l,o,r,a,i,"next",e)}function i(e){f(l,o,r,a,i,"throw",e)}a(void 0)})}}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(t){var o,r,l;o=e,r=t,l=n[t],r in o?Object.defineProperty(o,r,{value:l,enumerable:!0,configurable:!0,writable:!0}):o[r]=l})}return e}function v(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n.push.apply(n,o)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,o,r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var l=[],a=!0,i=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);a=!0);}catch(e){i=!0,o=e}finally{try{!a&&null!=r.return&&r.return()}finally{if(i)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return y(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,o,r,l,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){return function(l){if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&l[0]?o.return:l[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,l[1])).done)return r;switch(o=0,r&&(l=[2&l[0],r.value]),l[0]){case 0:case 1:r=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,o=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!r||l[1]>r[0]&&l[1]<r[3])){a.label=l[1];break}if(6===l[0]&&a.label<r[1]){a.label=r[1],r=l;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(l);break}r[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],o=0}finally{n=r=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,i])}}}var C=c.Typography.Text,A=function(){var e=(0,l.useField)(),t=(0,l.useForm)(),n=(0,a.useActionContext)(),o=(0,a.useResourceActionContext)().refresh,r=(0,a.useResourceContext)().targetKey,i=(0,a.useRecord)()[r],c=(0,a.useAPIClient)(),u=c.auth.getLocale();return{run:function(){return x(function(){return g(this,function(r){switch(r.label){case 0:return[4,t.submit()];case 1:r.sent(),e.data=e.data||{},e.data.loading=!0,r.label=2;case 2:return r.trys.push([2,5,6,7]),[4,c.resource("localizationTranslations").updateOrCreate({filterKeys:["textId","locale"],values:{textId:i,locale:u,translation:t.values.translation}})];case 3:return r.sent(),n.setVisible(!1),[4,t.reset()];case 4:return r.sent(),o(),[3,7];case 5:return console.log(r.sent()),[3,7];case 6:return e.data.loading=!1,[7];case 7:return[2]}})})()}}},w=function(){var e=(0,a.useResourceActionContext)().refresh,t=(0,a.useAPIClient)(),n=(0,a.useRecord)().translationId;return{run:function(){return x(function(){return g(this,function(o){switch(o.label){case 0:if(!n)return[2];return[4,t.resource("localizationTranslations").destroy({filterByTk:n})];case 1:return o.sent(),e(),[2]}})})()}}},T=function(){var e=(0,a.useResourceActionContext)(),t=e.state,n=e.setState,o=e.refresh,r=(0,a.useAPIClient)(),l=(0,p.F)().t;return{run:function(){return x(function(){var e;return g(this,function(a){switch(a.label){case 0:if(!(null==t?void 0:null===(e=t.selectedRowKeys)||void 0===e?void 0:e.length))return[2,c.message.error(l("Please select the records you want to delete"))];return[4,r.resource("localizationTranslations").destroy({filterByTk:null==t?void 0:t.selectedRowKeys})];case 1:return a.sent(),null==n||n({selectedRowKeys:[]}),o(),[2]}})})()}}},S=function(){var e=(0,a.useAPIClient)();return{run:function(){return x(function(){return g(this,function(t){switch(t.label){case 0:return[4,e.resource("localization").publish()];case 1:return t.sent(),window.location.reload(),[2]}})})()}}},F=function(){var e=(0,p.F)().t,t=(0,a.useResourceActionContext)().refresh,n=(0,a.useAPIClient)(),r=h((0,u.useState)(!1),2),l=r[0],i=r[1],d=["local","menu","db"],m=h((0,u.useState)(d),2),y=m[0],f=m[1],b=h((0,u.useState)(!1),2),v=b[0],C=b[1],A=h((0,u.useState)(!0),2),w=A[0],T=A[1];return s().createElement(a.StablePopover,{placement:"bottomRight",content:s().createElement(s().Fragment,null,s().createElement(c.Checkbox,{indeterminate:v,onChange:function(e){f(e.target.checked?d:[]),C(!1),T(e.target.checked)},checked:w},e("All")),s().createElement(c.Divider,{style:{margin:"5px 0"}}),s().createElement(c.Checkbox.Group,{onChange:function(e){f(e),C(!!e.length&&e.length<d.length),T(e.length===d.length)},value:y},s().createElement(c.Col,null,s().createElement(c.Row,null,s().createElement(c.Checkbox,{value:"local"},e("System & Plugins"))),s().createElement(c.Row,null,s().createElement(c.Checkbox,{value:"db"},e("Collections & Fields"))),s().createElement(c.Row,null,s().createElement(c.Checkbox,{value:"menu"},e("Menu"))))))},s().createElement(c.Button,{icon:s().createElement(o.SyncOutlined,null),loading:l,onClick:x(function(){return g(this,function(o){switch(o.label){case 0:if(!y.length)return[2,c.message.error(e("Please select the resources you want to synchronize"))];return i(!0),[4,n.resource("localization").sync({values:{types:y}})];case 1:return o.sent(),i(!1),t(),[2]}})})},e("Sync")))},E=function(){var e,t=(0,p.F)().t,n=(0,i.useMemoizedFn)(t),o=(0,a.useResourceActionContext)().data;return(0,u.useMemo)(function(){var e,t;return(null==o?void 0:null===(t=o.meta)||void 0===t?void 0:null===(e=t.modules)||void 0===e?void 0:e.map(function(e){return{value:e.value,label:n(e.label)}}))||[]},[null==o?void 0:null===(e=o.meta)||void 0===e?void 0:e.modules,n])},k=function(){var e=(0,p.F)().t,t=(0,a.useResourceActionContext)().run,n=E(),o=(0,u.useMemo)(function(){return(0,r.createForm)({initialValues:{hasTranslation:!0}})},[]),i=function(e){t(b({},e||o.values))};return(0,u.useEffect)(function(){o.query("module").take().dataSource=n},[o,n]),s().createElement(a.FormProvider,{form:o},s().createElement("div",{style:{display:"flex"}},s().createElement(l.Field,{name:"module",dataSource:n,component:[a.Select,{allowClear:!0,placeholder:e("Module"),onChange:function(e){return i(v(b({},o.values),{module:e}))}}]}),s().createElement(l.Field,{name:"keyword",component:[c.Input.Search,{placeholder:e("Keyword"),allowClear:!0,style:{marginLeft:"8px",width:"fit-content"},onSearch:function(e){return i(v(b({},o.values),{keyword:e}))}}]}),s().createElement(l.Field,{name:"hasTranslation",dataSource:[{label:e("All"),value:!0},{label:e("No translation"),value:!1}],component:[a.Radio.Group,{defaultValue:!0,style:{marginLeft:"8px",width:"fit-content"},optionType:"button",onChange:function(){return i()}}]})))},P=function(){var e,t=(0,p.F)().t,n=(0,a.useAPIClient)().auth.getLocale(),o=(null===(e=a.locale[n])||void 0===e?void 0:e.label)||n;return s().createElement(c.Card,{bordered:!1},s().createElement(a.SchemaComponent,{schema:m,components:{TranslationField:function(e){return void 0!==e.value?s().createElement(a.Input.TextArea,e):s().createElement("div",null)},CurrentLang:function(){return s().createElement(c.Typography,null,s().createElement(C,{strong:!0},t("Current language")),s().createElement(c.Tag,{style:{marginLeft:"10px"}},o))},Sync:F,Filter:k},scope:{t:t,useDestroyTranslationAction:w,useBulkDestroyTranslationAction:T,useUpdateTranslationAction:A,usePublishAction:S,useModules:E}}))}}}]);