@nocobase/plugin-localization 2.0.0-beta.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/177bd849c95cf6cc.js +10 -0
- package/dist/client/i18n-missing-handler.d.ts +25 -0
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +8 -6
- package/dist/server/actions/localizationTexts.d.ts +1 -0
- package/dist/server/actions/localizationTexts.js +31 -1
- package/dist/server/plugin.d.ts +5 -1
- package/dist/server/plugin.js +13 -1
- package/package.json +2 -2
- package/dist/client/0c4d30d25f0064b4.js +0 -10
|
@@ -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([["121"],{730:function(e,t,n){n.r(t),n.d(t,{Localization:function(){return O}});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(551),m={name:"localization",disableTranslation:!0,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"})}}'}]}}]},d={type:"void",name:"localization","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:m,resourceName:"localizationTexts",request:{resource:"localizationTexts",action:"list",params:{pageSize:50}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:m},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:"id",rowSelection:{type:"checkbox",getCheckboxProps:function(e){return{disabled:!(null==e?void 0:e.translationId)}}},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 h(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 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;o=n[t],t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o})}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 v(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){var c=[l,i];if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&c[0]?o.return:c[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,c[1])).done)return r;switch(o=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,o=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){a.label=c[1];break}if(6===c[0]&&a.label<r[1]){a.label=r[1],r=c;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(c);break}r[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],o=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}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 h(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 h(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=e.data,l=(0,a.useAPIClient)(),i=(0,p.F)().t;return{run:function(){return h(function(){var e,a,u,s,p;return g(this,function(m){switch(m.label){case 0:if(!(a=(null==t?void 0:t.selectedRowKeys)||[]).length||(u=(null==r||null==(e=r.data)?void 0:e.rows)||(null==r?void 0:r.data)||(null==r?void 0:r.rows)||[],s=new Set(a.map(function(e){return String(e)})),!(p=u.filter(function(e){return s.has(String(e.id))}).map(function(e){return e.translationId}).filter(Boolean)).length))return[2,c.message.error(i("Please select the records you want to delete"))];return[4,l.resource("localizationTranslations").destroy({filterByTk:p})];case 1:return m.sent(),null==n||n({selectedRowKeys:[]}),o(),[2]}})})()}}},S=function(){var e=(0,a.useAPIClient)();return{run:function(){return h(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=v((0,u.useState)(!1),2),i=r[0],m=r[1],d=v((0,u.useState)([]),2),f=d[0],y=d[1],b=v((0,u.useState)([]),2),x=b[0],A=b[1],C=v((0,u.useState)(!1),2),T=C[0],w=C[1],S=v((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||null==(t=e.data)?void 0:t.data})},{onSuccess:function(e){var t=e.map(function(e){return e.name});y(t),A(t)}}),P=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,(P||[]).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:h(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 m(!0),[4,n.resource("localization").sync({values:{types:x}})];case 1:return o.sent(),m(!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||null==(t=o.meta)||null==(e=t.modules)?void 0:e.map(function(e){return{value:e.value,label:l.Schema.compile(e.label,{t:n})}}))||[]},[null==o||null==(e=o.meta)?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(x(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(x(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=(0,p.F)().t,t=(0,a.useRecord)(),n=t.moduleTitle,o=t.module;return n?s().createElement(c.Tag,null,l.Schema.compile(n,{t:e})):s().createElement(c.Tag,null,o)},O=function(){var e,t=(0,p.F)().t,n=(0,a.useAPIClient)().auth.getLocale(),o=(null==(e=a.locale[n])?void 0:e.label)||n;return s().createElement(c.Card,{bordered:!1},s().createElement(a.SchemaComponent,{schema:d,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:P},scope:{t:t,useDestroyTranslationAction:T,useBulkDestroyTranslationAction:w,useUpdateTranslationAction:C,usePublishAction:S,useModules:E}}))}}}]);
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { FlowEngineContext } from '@nocobase/flow-engine';
|
|
10
|
+
export declare class MissingKeyHandler {
|
|
11
|
+
private context;
|
|
12
|
+
static DEBOUNCE_DELAY: number;
|
|
13
|
+
static fallbackNS: string;
|
|
14
|
+
private sentMissingKeys;
|
|
15
|
+
private pendingMissingKeys;
|
|
16
|
+
private submitPendingKeysDebounced;
|
|
17
|
+
private missingKeyHandler;
|
|
18
|
+
private currentLocale?;
|
|
19
|
+
constructor(context: FlowEngineContext);
|
|
20
|
+
register(): void;
|
|
21
|
+
unregister(): void;
|
|
22
|
+
private isFallbackClient;
|
|
23
|
+
private removeClientFallback;
|
|
24
|
+
private submitPendingKeys;
|
|
25
|
+
}
|
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@formily/core"),require("ahooks"),require("@nocobase/client"),require("react"),require("@formily/react"),require("@ant-design/icons"),require("antd"),require("react-i18next")):"function"==typeof define&&define.amd?define("@nocobase/plugin-localization",["@formily/core","ahooks","@nocobase/client","react","@formily/react","@ant-design/icons","antd","react-i18next"],t):"object"==typeof exports?exports["@nocobase/plugin-localization"]=t(require("@formily/core"),require("ahooks"),require("@nocobase/client"),require("react"),require("@formily/react"),require("@ant-design/icons"),require("antd"),require("react-i18next")):e["@nocobase/plugin-localization"]=t(e["@formily/core"],e.ahooks,e["@nocobase/client"],e.react,e["@formily/react"],e["@ant-design/icons"],e.antd,e["react-i18next"])}(self,function(e,t,n,r,o,i,u,c){return function(){var a,l,f,s,p,d,b={551:function(e,t,n){"use strict";n.d(t,{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(e){e.exports=function(e,t){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,t),t}},482:function(e){"use strict";e.exports=i},563:function(t){"use strict";t.exports=e},505:function(e){"use strict";e.exports=o},772:function(e){"use strict";e.exports=n},749:function(e){"use strict";e.exports=t},721:function(e){"use strict";e.exports=u},156:function(e){"use strict";e.exports=r},238:function(e){"use strict";e.exports=c}},y={};function h(e){var t=y[e];if(void 0!==t)return t.exports;var n=y[e]={exports:{}};return b[e](n,n.exports,h),n.exports}h.m=b,h.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return h.d(t,{a:t}),t},h.d=function(e,t){for(var n in t)h.o(t,n)&&!h.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},h.f={},h.e=function(e){return Promise.all(Object.keys(h.f).reduce(function(t,n){return h.f[n](e,t),t},[]))},h.u=function(e){return"0c4d30d25f0064b4.js"},h.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),h.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a={},l="@nocobase/plugin-localization:",h.l=function(e,t,n,r){if(a[e])return void a[e].push(t);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")==e||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=e),a[e]=[t];var s=function(t,n){o.onerror=o.onload=null,clearTimeout(p);var r=a[e];if(delete a[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(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(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(f=window.__webpack_public_path__||"/").endsWith("/")||(f+="/"),h.p=f+"static/plugins/@nocobase/plugin-localization/dist/client/",s={909:0},h.f.j=function(e,t){var n=h.o(s,e)?s[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=s[e]=[t,r]});t.push(n[2]=r);var o=h.p+h.u(e),i=Error();h.l(o,function(t){if(h.o(s,e)&&(0!==(n=s[e])&&(s[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",i.name="ChunkLoadError",i.type=r,i.request=o,n[1](i)}},"chunk-"+e,e)}},p=function(e,t){var n,r,o=t[0],i=t[1],u=t[2],c=0;if(o.some(function(e){return 0!==s[e]})){for(n in i)h.o(i,n)&&(h.m[n]=i[n]);u&&u(h)}for(e&&e(t);c<o.length;c++)r=o[c],h.o(s,r)&&s[r]&&s[r][0](),s[r]=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 f}});var e=h(772),t=h(551),n=h(581);function r(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function o(e,t,n){return(o=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&u(o,n.prototype),o}).apply(null,arguments)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var l=(0,e.lazy)(function(){return n("imported_-237jod_component",h.e("121").then(h.bind(h,730)))},"Localization").Localization,f=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return e=o,t=arguments,e=i(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],i(this).constructor):e.apply(this,t))}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&u(o,e),n=[{key:"load",value:function(){var e,n=this;return(e=function(){return function(e,t){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){var a=[i,c];if(n)throw TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===a[0]||2===a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}}}(this,function(e){return n.app.pluginSettingsManager.add(t.A,{title:'{{t("Localization", { ns: "'.concat(t.A,'" })}}'),icon:"GlobalOutlined",Component:l,aclSnippet:"pm.localization.localization"}),[2]})},function(){var t=this,n=arguments;return new Promise(function(o,i){var u=e.apply(t,n);function c(e){r(u,o,i,c,a,"next",e)}function a(e){r(u,o,i,c,a,"throw",e)}c(void 0)})})()}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(o.prototype,n),o}(c(e.Plugin));v.default=f}(),v}()});
|
|
10
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("@formily/core"),require("ahooks"),require("@nocobase/client"),require("react"),require("@formily/react"),require("lodash"),require("@ant-design/icons"),require("antd"),require("react-i18next")):"function"==typeof define&&define.amd?define("@nocobase/plugin-localization",["@formily/core","ahooks","@nocobase/client","react","@formily/react","lodash","@ant-design/icons","antd","react-i18next"],n):"object"==typeof exports?exports["@nocobase/plugin-localization"]=n(require("@formily/core"),require("ahooks"),require("@nocobase/client"),require("react"),require("@formily/react"),require("lodash"),require("@ant-design/icons"),require("antd"),require("react-i18next")):e["@nocobase/plugin-localization"]=n(e["@formily/core"],e.ahooks,e["@nocobase/client"],e.react,e["@formily/react"],e.lodash,e["@ant-design/icons"],e.antd,e["react-i18next"])}(self,function(e,n,t,r,i,o,a,u,c){return function(){var s,l,f,p,d,y,b={551:function(e,n,t){"use strict";t.d(n,{A:function(){return i},F:function(){return o}});var r=t(238),i="localization",o=function(){return(0,r.useTranslation)([i,"client"],{nsMode:"fallback"})}},581:function(e){e.exports=function(e,n){return"undefined"!=typeof __deoptimization_sideEffect__&&__deoptimization_sideEffect__(e,n),n}},482:function(e){"use strict";e.exports=a},563:function(n){"use strict";n.exports=e},505:function(e){"use strict";e.exports=i},772:function(e){"use strict";e.exports=t},749:function(e){"use strict";e.exports=n},721:function(e){"use strict";e.exports=u},467:function(e){"use strict";e.exports=o},156:function(e){"use strict";e.exports=r},238:function(e){"use strict";e.exports=c}},h={};function v(e){var n=h[e];if(void 0!==n)return n.exports;var t=h[e]={exports:{}};return b[e](t,t.exports,v),t.exports}v.m=b,v.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return v.d(n,{a:n}),n},v.d=function(e,n){for(var t in n)v.o(n,t)&&!v.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},v.f={},v.e=function(e){return Promise.all(Object.keys(v.f).reduce(function(n,t){return v.f[t](e,n),n},[]))},v.u=function(e){return"177bd849c95cf6cc.js"},v.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),v.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},s={},l="@nocobase/plugin-localization:",v.l=function(e,n,t,r){if(s[e])return void s[e].push(n);if(void 0!==t)for(var i,o,a=document.getElementsByTagName("script"),u=0;u<a.length;u++){var c=a[u];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")==l+t){i=c;break}}i||(o=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,v.nc&&i.setAttribute("nonce",v.nc),i.setAttribute("data-webpack",l+t),i.src=e),s[e]=[n];var f=function(n,t){i.onerror=i.onload=null,clearTimeout(p);var r=s[e];if(delete s[e],i.parentNode&&i.parentNode.removeChild(i),r&&r.forEach(function(e){return e(t)}),n)return n(t)},p=setTimeout(f.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=f.bind(null,i.onerror),i.onload=f.bind(null,i.onload),o&&document.head.appendChild(i)},v.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(f=window.__webpack_public_path__||"/").endsWith("/")||(f+="/"),v.p=f+"static/plugins/@nocobase/plugin-localization/dist/client/",p={909:0},v.f.j=function(e,n){var t=v.o(p,e)?p[e]:void 0;if(0!==t)if(t)n.push(t[2]);else{var r=new Promise(function(n,r){t=p[e]=[n,r]});n.push(t[2]=r);var i=v.p+v.u(e),o=Error();v.l(i,function(n){if(v.o(p,e)&&(0!==(t=p[e])&&(p[e]=void 0),t)){var r=n&&("load"===n.type?"missing":n.type),i=n&&n.target&&n.target.src;o.message="Loading chunk "+e+" failed.\n("+r+": "+i+")",o.name="ChunkLoadError",o.type=r,o.request=i,t[1](o)}},"chunk-"+e,e)}},d=function(e,n){var t,r,i=n[0],o=n[1],a=n[2],u=0;if(i.some(function(e){return 0!==p[e]})){for(t in o)v.o(o,t)&&(v.m[t]=o[t]);a&&a(v)}for(e&&e(n);u<i.length;u++)r=i[u],v.o(p,r)&&p[r]&&p[r][0](),p[r]=0},(y=self.webpackChunk_nocobase_plugin_localization=self.webpackChunk_nocobase_plugin_localization||[]).forEach(d.bind(null,0)),y.push=d.bind(null,y.push.bind(y));var g={};return!function(){"use strict";v.r(g),v.d(g,{PluginLocalizationClient:function(){return b},default:function(){return h}});var e=v(772),n=v(551),t=v(467),r=v.n(t);function i(e,n,t,r,i,o,a){try{var u=e[o](a),c=u.value}catch(e){t(e);return}u.done?n(c):Promise.resolve(c).then(r,i)}function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}var a=function(){var e;function n(e){var t=this;if(!(this instanceof n))throw TypeError("Cannot call a class as a function");o(this,"context",void 0),o(this,"sentMissingKeys",void 0),o(this,"pendingMissingKeys",void 0),o(this,"submitPendingKeysDebounced",void 0),o(this,"missingKeyHandler",void 0),o(this,"currentLocale",void 0),this.context=e,this.sentMissingKeys=new Set,this.pendingMissingKeys=new Map,this.submitPendingKeysDebounced=r().debounce(function(){t.submitPendingKeys()},n.DEBOUNCE_DELAY)}return e=[{key:"register",value:function(){var e=this,n=this.context.i18n;n.options.saveMissing=!0,this.missingKeyHandler=function(n,t,r){if(e.context.flowSettingsEnabled&&"client"!==t&&"ui-schema-storage"!==t){var i,o="".concat(t,":").concat(r);if(!(!r||e.sentMissingKeys.has(o)))try{e.currentLocale=null==(i=e.context.i18n)?void 0:i.language,e.sentMissingKeys.add(o),e.pendingMissingKeys.set(o,{key:r,ns:t}),e.submitPendingKeysDebounced()}catch(e){console.error("[i18n] Error in missingKeyHandler:",e)}}},n.on("missingKey",this.missingKeyHandler)}},{key:"unregister",value:function(){var e=this.context.i18n;e.options.saveMissing=!1,this.missingKeyHandler&&(e.off("missingKey",this.missingKeyHandler),this.missingKeyHandler=void 0)}},{key:"isFallbackClient",value:function(e,t){if(e!==n.fallbackNS)return!1;var r=!0,i=!1,o=void 0;try{for(var a,u=this.pendingMissingKeys.values()[Symbol.iterator]();!(r=(a=u.next()).done);r=!0){var c=a.value;if(c.key===t&&c.ns!==n.fallbackNS)return!0}}catch(e){i=!0,o=e}finally{try{r||null==u.return||u.return()}finally{if(i)throw o}}var s=!0,l=!1,f=void 0;try{for(var p,d=this.sentMissingKeys[Symbol.iterator]();!(s=(p=d.next()).done);s=!0){var y=p.value,b=y.indexOf(":");if(b>-1){var h=y.slice(0,b);if(y.slice(b+1)===t&&h!==n.fallbackNS)return!0}}}catch(e){l=!0,f=e}finally{try{s||null==d.return||d.return()}finally{if(l)throw f}}return!1}},{key:"removeClientFallback",value:function(e){e&&this.pendingMissingKeys.delete("".concat(n.fallbackNS,":").concat(e))}},{key:"submitPendingKeys",value:function(){var e,n=this;return(e=function(){var e;return function(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){var c=[o,u];if(t)throw TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&c[0]?r.return:c[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,c[1])).done)return i;switch(r=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){a.label=c[1];break}if(6===c[0]&&a.label<i[1]){a.label=i[1],i=c;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(c);break}i[2]&&a.ops.pop(),a.trys.pop();continue}c=n.call(e,a)}catch(e){c=[6,e],r=0}finally{t=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(t){switch(t.label){case 0:if(0===n.pendingMissingKeys.size)return[2];t.label=1;case 1:return t.trys.push([1,3,,4]),e=Array.from(n.pendingMissingKeys.values()).map(function(e){return{text:e.key,ns:e.ns}}),[4,n.context.api.request({method:"POST",url:"/localizationTexts:missing",data:{keys:e,locale:n.currentLocale}})];case 2:return t.sent(),n.pendingMissingKeys.clear(),[3,4];case 3:return console.error("[i18n] Failed to submit missing keys:",t.sent()),[3,4];case 4:return[2]}})},function(){var n=this,t=arguments;return new Promise(function(r,o){var a=e.apply(n,t);function u(e){i(a,r,o,u,c,"next",e)}function c(e){i(a,r,o,u,c,"throw",e)}u(void 0)})})()}}],function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,e),n}();o(a,"DEBOUNCE_DELAY",2e3),o(a,"fallbackNS","client");var u=v(581);function c(e,n,t,r,i,o,a){try{var u=e[o](a),c=u.value}catch(e){t(e);return}u.done?n(c):Promise.resolve(c).then(r,i)}function s(e,n,t){return(s=d()?Reflect.construct:function(e,n,t){var r=[null];r.push.apply(r,n);var i=new(Function.bind.apply(e,r));return t&&f(i,t.prototype),i}).apply(null,arguments)}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,n){return(f=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function p(e){var n="function"==typeof Map?new Map:void 0;return(p=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(e))return n.get(e);n.set(e,t)}function t(){return s(e,arguments,l(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),f(t,e)})(e)}function d(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(d=function(){return!!e})()}var y=(0,e.lazy)(function(){return u("imported_-237jod_component",v.e("121").then(v.bind(v,730)))},"Localization").Localization,b=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,n;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,n=arguments,e=l(e),function(e,n){var t;if(n&&("object"==((t=n)&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t)||"function"==typeof n))return n;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,d()?Reflect.construct(e,n||[],l(this).constructor):e.apply(this,n))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&f(r,e),t=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){var c=[o,u];if(t)throw TypeError("Generator is already executing.");for(;a;)try{if(t=1,r&&(i=2&c[0]?r.return:c[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,c[1])).done)return i;switch(r=0,i&&(c=[2&c[0],i.value]),c[0]){case 0:case 1:i=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(i=(i=a.trys).length>0&&i[i.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!i||c[1]>i[0]&&c[1]<i[3])){a.label=c[1];break}if(6===c[0]&&a.label<i[1]){a.label=i[1],i=c;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(c);break}i[2]&&a.ops.pop(),a.trys.pop();continue}c=n.call(e,a)}catch(e){c=[6,e],r=0}finally{t=i=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(e){return new a(t.engine.context).register(),t.app.pluginSettingsManager.add(n.A,{title:'{{t("Localization", { ns: "'.concat(n.A,'" })}}'),icon:"GlobalOutlined",Component:y,aclSnippet:"pm.localization.localization"}),[2]})},function(){var n=this,t=arguments;return new Promise(function(r,i){var o=e.apply(n,t);function a(e){c(o,r,i,a,u,"next",e)}function u(e){c(o,r,i,a,u,"throw",e)}a(void 0)})})()}}],function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r.prototype,t),r}(p(e.Plugin)),h=b}(),g}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -11,14 +11,16 @@ module.exports = {
|
|
|
11
11
|
"@ant-design/icons": "5.6.1",
|
|
12
12
|
"@formily/core": "2.3.7",
|
|
13
13
|
"@formily/react": "2.3.7",
|
|
14
|
-
"@nocobase/client": "2.0.0
|
|
14
|
+
"@nocobase/client": "2.0.0",
|
|
15
15
|
"ahooks": "3.7.8",
|
|
16
16
|
"antd": "5.24.2",
|
|
17
17
|
"react": "18.2.0",
|
|
18
|
-
"@nocobase/
|
|
19
|
-
"
|
|
20
|
-
"@nocobase/
|
|
21
|
-
"@nocobase/
|
|
22
|
-
"@nocobase/
|
|
18
|
+
"@nocobase/flow-engine": "2.0.0",
|
|
19
|
+
"lodash": "4.17.21",
|
|
20
|
+
"@nocobase/database": "2.0.0",
|
|
21
|
+
"@nocobase/server": "2.0.0",
|
|
22
|
+
"@nocobase/utils": "2.0.0",
|
|
23
|
+
"@nocobase/cache": "2.0.0",
|
|
24
|
+
"@nocobase/actions": "2.0.0",
|
|
23
25
|
"react-i18next": "11.18.6"
|
|
24
26
|
};
|
|
@@ -141,4 +141,34 @@ const list = async (ctx, next) => {
|
|
|
141
141
|
};
|
|
142
142
|
await next();
|
|
143
143
|
};
|
|
144
|
-
|
|
144
|
+
const missing = async (ctx, next) => {
|
|
145
|
+
var _a;
|
|
146
|
+
const { keys, locale } = ctx.request.body || {};
|
|
147
|
+
const currentRoles = ctx.state.currentRoles || [];
|
|
148
|
+
if (!currentRoles.includes("root")) {
|
|
149
|
+
const roles = await ctx.db.getRepository("roles").find({
|
|
150
|
+
filter: {
|
|
151
|
+
name: currentRoles
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const hasUiSnippet = roles.some((role) => {
|
|
155
|
+
const snippets = role.get("snippets") || [];
|
|
156
|
+
return snippets.includes("ui.*");
|
|
157
|
+
});
|
|
158
|
+
if (!hasUiSnippet) {
|
|
159
|
+
ctx.throw(403, "No permission");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if ((keys == null ? void 0 : keys.length) > 0) {
|
|
163
|
+
const plugin = (_a = ctx.app.pm) == null ? void 0 : _a.get("localization");
|
|
164
|
+
const currentLocale = locale || ctx.get("X-Locale") || "en-US";
|
|
165
|
+
await (plugin == null ? void 0 : plugin.addNewTexts(
|
|
166
|
+
keys.map((key) => ({ text: key.text, module: `resources.${key.ns}` })),
|
|
167
|
+
{
|
|
168
|
+
locale: currentLocale
|
|
169
|
+
}
|
|
170
|
+
));
|
|
171
|
+
}
|
|
172
|
+
await next();
|
|
173
|
+
};
|
|
174
|
+
var localizationTexts_default = { list, missing };
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
9
10
|
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
10
11
|
import Resources from './resources';
|
|
11
12
|
import { SourceManager } from './source-manager';
|
|
@@ -15,7 +16,10 @@ export declare class PluginLocalizationServer extends Plugin {
|
|
|
15
16
|
addNewTexts: (texts: {
|
|
16
17
|
text: string;
|
|
17
18
|
module: string;
|
|
18
|
-
}[], options?:
|
|
19
|
+
}[], options?: {
|
|
20
|
+
transaction?: any;
|
|
21
|
+
locale?: string;
|
|
22
|
+
}) => Promise<void>;
|
|
19
23
|
afterAdd(): void;
|
|
20
24
|
beforeLoad(): void;
|
|
21
25
|
load(): Promise<void>;
|
package/dist/server/plugin.js
CHANGED
|
@@ -62,7 +62,7 @@ class PluginLocalizationServer extends import_server.Plugin {
|
|
|
62
62
|
{
|
|
63
63
|
transaction: options == null ? void 0 : options.transaction
|
|
64
64
|
}
|
|
65
|
-
).then((newTexts) => {
|
|
65
|
+
).then(async (newTexts) => {
|
|
66
66
|
this.resources.updateCacheTexts(newTexts, options == null ? void 0 : options.transaction);
|
|
67
67
|
this.sendSyncMessage(
|
|
68
68
|
{
|
|
@@ -71,6 +71,18 @@ class PluginLocalizationServer extends import_server.Plugin {
|
|
|
71
71
|
},
|
|
72
72
|
{ transaction: options == null ? void 0 : options.transaction }
|
|
73
73
|
);
|
|
74
|
+
if ((options == null ? void 0 : options.locale) && (newTexts == null ? void 0 : newTexts.length)) {
|
|
75
|
+
await this.db.getModel("localizationTranslations").bulkCreate(
|
|
76
|
+
newTexts.map((text) => ({
|
|
77
|
+
locale: options.locale,
|
|
78
|
+
translation: text.get("text"),
|
|
79
|
+
textId: text.get("id")
|
|
80
|
+
})),
|
|
81
|
+
{
|
|
82
|
+
transaction: options == null ? void 0 : options.transaction
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
74
86
|
}).catch((err) => {
|
|
75
87
|
this.log.error(err);
|
|
76
88
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-localization",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"homepage": "https://docs.nocobase.com/handbook/localization-management",
|
|
6
6
|
"homepage.ru-RU": "https://docs-ru.nocobase.com/handbook/localization-management",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"description": "Allows to manage localization resources of the application.",
|
|
26
26
|
"description.ru-RU": "Позволяет управлять ресурсами локализации приложения.",
|
|
27
27
|
"description.zh-CN": "支持管理应用程序的本地化资源。",
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "3590c0087a56f0f285a5357f43a80bdc62b11bec"
|
|
29
29
|
}
|
|
@@ -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([["121"],{730: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(551),m={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"})}}'}]}}]},d={type:"void",name:"localization","x-decorator":"ResourceActionProvider","x-decorator-props":{collection:m,resourceName:"localizationTexts",request:{resource:"localizationTexts",action:"list",params:{pageSize:50}}},"x-component":"CollectionProvider_deprecated","x-component-props":{collection:m},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 h(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 x(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;o=n[t],t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o})}return e}function b(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 v(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){var c=[l,i];if(n)throw TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&c[0]?o.return:c[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,c[1])).done)return r;switch(o=0,r&&(c=[2&c[0],r.value]),c[0]){case 0:case 1:r=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,o=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(r=(r=a.trys).length>0&&r[r.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!r||c[1]>r[0]&&c[1]<r[3])){a.label=c[1];break}if(6===c[0]&&a.label<r[1]){a.label=r[1],r=c;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(c);break}r[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],o=0}finally{n=r=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}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 h(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 h(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 h(function(){var e;return g(this,function(a){switch(a.label){case 0:if(!(null==t||null==(e=t.selectedRowKeys)?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 h(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=v((0,u.useState)(!1),2),i=r[0],m=r[1],d=v((0,u.useState)([]),2),f=d[0],y=d[1],x=v((0,u.useState)([]),2),b=x[0],A=x[1],C=v((0,u.useState)(!1),2),T=C[0],w=C[1],S=v((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||null==(t=e.data)?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:b},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:h(function(){return g(this,function(o){switch(o.label){case 0:if(!b.length)return[2,c.message.error(e("Please select the resources you want to synchronize"))];return m(!0),[4,n.resource("localization").sync({values:{types:b}})];case 1:return o.sent(),m(!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||null==(t=o.meta)||null==(e=t.modules)?void 0:e.map(function(e){return{value:e.value,label:l.Schema.compile(e.label,{t:n})}}))||[]},[null==o||null==(e=o.meta)?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(x({},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(b(x({},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(b(x({},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.label)||n;return s().createElement(c.Card,{bordered:!1},s().createElement(a.SchemaComponent,{schema:d,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}}))}}}]);
|