@nocobase/plugin-localization 2.1.0-beta.34 → 2.1.0-beta.36

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,31 @@
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
+ export type TranslationScope = 'all' | 'builtIn' | 'custom';
10
+ export type LocalizationTextRecord = {
11
+ id: string | number;
12
+ text: string;
13
+ module?: string;
14
+ translation?: string;
15
+ translationId?: string | number;
16
+ };
17
+ type BuildFindTextsOptions = {
18
+ app: any;
19
+ mode: string;
20
+ locale: string;
21
+ scope: TranslationScope;
22
+ textIds?: Array<string | number>;
23
+ fields?: string[];
24
+ sort?: string[];
25
+ };
26
+ export declare const normalizeTextRecord: (row: any) => LocalizationTextRecord | undefined;
27
+ export declare const getModuleName: (row: LocalizationTextRecord) => string;
28
+ export declare const normalizeModuleName: (module: string) => string;
29
+ export declare const isBuiltInText: (row: LocalizationTextRecord, resources: Record<string, Record<string, string>>) => boolean;
30
+ export declare const buildFindTextsOptions: (options: BuildFindTextsOptions) => Promise<any>;
31
+ export {};
@@ -0,0 +1,107 @@
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 translation_scope_exports = {};
28
+ __export(translation_scope_exports, {
29
+ buildFindTextsOptions: () => buildFindTextsOptions,
30
+ getModuleName: () => getModuleName,
31
+ isBuiltInText: () => isBuiltInText,
32
+ normalizeModuleName: () => normalizeModuleName,
33
+ normalizeTextRecord: () => normalizeTextRecord
34
+ });
35
+ module.exports = __toCommonJS(translation_scope_exports);
36
+ var import_database = require("@nocobase/database");
37
+ var import_server = require("@nocobase/server");
38
+ const normalizeTextRecord = (row) => {
39
+ if (!row) {
40
+ return void 0;
41
+ }
42
+ return typeof row.toJSON === "function" ? row.toJSON() : row;
43
+ };
44
+ const getModuleName = (row) => {
45
+ var _a;
46
+ return (_a = row.module) == null ? void 0 : _a.replace("resources.", "");
47
+ };
48
+ const normalizeModuleName = (module2) => {
49
+ return module2.startsWith(import_server.OFFICIAL_PLUGIN_PREFIX) ? module2.replace(import_server.OFFICIAL_PLUGIN_PREFIX, "") : module2;
50
+ };
51
+ const isBuiltInText = (row, resources) => {
52
+ const moduleName = getModuleName(row);
53
+ return Boolean(moduleName && resources[normalizeModuleName(moduleName)]);
54
+ };
55
+ const getBuiltInModules = async (app) => {
56
+ const builtInResources = await app.localeManager.getBuiltInResources("en-US");
57
+ return Array.from(new Set(Object.keys(builtInResources).map((module2) => `resources.${normalizeModuleName(module2)}`)));
58
+ };
59
+ const addWhereCondition = (options, condition) => {
60
+ if (!options.where) {
61
+ options.where = condition;
62
+ return;
63
+ }
64
+ options.where = {
65
+ [import_database.Op.and]: [options.where, condition]
66
+ };
67
+ };
68
+ const buildFindTextsOptions = async (options) => {
69
+ const { app, mode, locale, scope = "all", textIds, fields, sort } = options;
70
+ const findOptions = {};
71
+ if (fields) {
72
+ findOptions.fields = fields;
73
+ }
74
+ if (sort) {
75
+ findOptions.sort = sort;
76
+ }
77
+ if (mode === "selected" || textIds) {
78
+ addWhereCondition(findOptions, {
79
+ id: {
80
+ [import_database.Op.in]: textIds || []
81
+ }
82
+ });
83
+ }
84
+ if (scope !== "all") {
85
+ const builtInModules = await getBuiltInModules(app);
86
+ addWhereCondition(findOptions, {
87
+ module: {
88
+ [scope === "builtIn" ? import_database.Op.in : import_database.Op.notIn]: builtInModules
89
+ }
90
+ });
91
+ }
92
+ if (mode === "incremental") {
93
+ findOptions.include = [{ association: "translations", where: { locale }, required: false }];
94
+ addWhereCondition(findOptions, {
95
+ "$translations.id$": null
96
+ });
97
+ }
98
+ return findOptions;
99
+ };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ buildFindTextsOptions,
103
+ getModuleName,
104
+ isBuiltInText,
105
+ normalizeModuleName,
106
+ normalizeTextRecord
107
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-localization",
3
- "version": "2.1.0-beta.34",
3
+ "version": "2.1.0-beta.36",
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",
@@ -30,5 +30,5 @@
30
30
  "description": "Allows to manage localization resources of the application.",
31
31
  "description.ru-RU": "Позволяет управлять ресурсами локализации приложения.",
32
32
  "description.zh-CN": "支持管理应用程序的本地化资源。",
33
- "gitHead": "ca804833299c547f8d49f8d58f73273a4bfcd03c"
33
+ "gitHead": "397d45c744f6eb48b3a0cd785c87cbf1257c3513"
34
34
  }
@@ -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([["300"],{151:function(e,t,n){n.r(t),n.d(t,{default:function(){return x},LocalizationPageContent:function(){return O}});var r=n(375),l=n(230),a=n(485),o=n(694),i=n(550),u=n(625),c=n(59),s=n(155),d=n.n(s),m="localization",f="localizationTranslations",p=JSON.parse('{"UU":"@nocobase/plugin-localization"}').UU;function h(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[p,"client"]})}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function v(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function E(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function w(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return g(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 g(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 S(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=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(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var C=c.Typography.Text;function T(e,t){return l.Schema.compile(e,{t:t})}var k=function(e){var t=e.value;return null==t?null:d().createElement("span",null,t)};function x(){return d().createElement(O,null)}function O(){var e,t,n,l=(0,o.useFlowContext)(),i=h(),p=l.app.apiClient,g=(null==(e=(t=p.auth).getLocale)?void 0:e.call(t))||p.auth.locale||"en-US",y=w(c.Form.useForm(),1)[0],x=w((0,s.useState)({page:1,pageSize:50,hasTranslation:!0}),2),O=x[0],j=x[1],I=w((0,s.useState)([]),2),F=I[0],A=I[1],D=w((0,s.useState)(null),2),R=D[0],B=D[1],M=(null==(n=a.languageCodes[g])?void 0:n.label)||g,U=(0,u.useRequest)(function(){return v(function(){return S(this,function(e){switch(e.label){case 0:return[4,p.resource("localizationTexts").list(E(b({},O),{hasTranslation:String(O.hasTranslation)}))];case 1:var t,n,r,l,a,o;return[2,{rows:(null==(o=null==(t=e.sent())?void 0:t.data)?void 0:o.data)||[],modules:(null==o||null==(n=o.meta)?void 0:n.modules)||[],count:(null==o||null==(r=o.meta)?void 0:r.count)||0,page:null==o||null==(l=o.meta)?void 0:l.page,pageSize:null==o||null==(a=o.meta)?void 0:a.pageSize}]}})})()},{refreshDeps:[O]}),K=U.data,L=U.loading,_=U.refresh,q=(0,u.useRequest)(function(){return v(function(){var e,t;return S(this,function(n){switch(n.label){case 0:return[4,p.resource(m).getSources()];case 1:return[2,(null==(t=n.sent())||null==(e=t.data)?void 0:e.data)||[]]}})})()}),G=q.data,N=q.loading,J=(null==K?void 0:K.rows)||[],V=(0,s.useMemo)(function(){return((null==K?void 0:K.modules)||[]).map(function(e){return{value:e.value,label:T(e.label,i)}})},[null==K?void 0:K.modules,i]);(0,s.useEffect)(function(){R?y.setFieldsValue({translation:R.translation}):y.resetFields()},[R,y]);var W=function(e){j(function(t){return E(b({},t,e),{page:1})})},$=[{title:i("Text"),dataIndex:"text",ellipsis:!0},{title:i("Translation"),dataIndex:"translation",ellipsis:!0,render:function(e){return d().createElement(k,{value:e})}},{title:i("Module"),dataIndex:"moduleTitle",width:220,render:function(e,t){return t.moduleTitle?d().createElement(c.Tag,null,T(t.moduleTitle,i)):d().createElement(c.Tag,null,t.module)}},{title:i("Actions"),key:"actions",width:240,render:function(e,t){return d().createElement(c.Space,{split:d().createElement(c.Divider,{type:"vertical"}),style:{whiteSpace:"nowrap"}},d().createElement(c.Button,{type:"link",size:"small",onClick:function(){return B(t)}},i("Edit")),t.translationId?d().createElement(c.Popconfirm,{title:i("Delete translation"),description:i("Are you sure you want to delete it?"),onConfirm:function(){return v(function(){return S(this,function(e){switch(e.label){case 0:if(!t.translationId)return[2];return[4,p.resource(f).destroy({filterByTk:t.translationId})];case 1:return e.sent(),_(),[2]}})})()}},d().createElement(c.Button,{type:"link",size:"small"},i("Delete translation"))):null)}}],H={current:(null==K?void 0:K.page)||O.page,pageSize:(null==K?void 0:K.pageSize)||O.pageSize,total:(null==K?void 0:K.count)||0,showSizeChanger:!0,onChange:function(e,t){return j(function(n){return E(b({},n),{page:e,pageSize:t})})}};return d().createElement(c.Card,{bordered:!1},d().createElement(c.Space,{direction:"vertical",size:16,style:{width:"100%"}},d().createElement(c.Row,{justify:"space-between",align:"middle",gutter:[16,16]},d().createElement(c.Col,{flex:"auto"},d().createElement(c.Space,{wrap:!0,align:"center"},d().createElement(c.Typography,null,d().createElement(C,{strong:!0},i("Current language")),d().createElement(c.Tag,{style:{marginLeft:10}},M)),d().createElement(c.Select,{allowClear:!0,showSearch:!0,optionFilterProp:"label",placeholder:i("Module"),style:{minWidth:220},options:V,onChange:function(e){return W({module:e})}}),d().createElement(c.Input.Search,{allowClear:!0,placeholder:i("Keyword"),style:{width:220},onSearch:function(e){return W({keyword:e})}}),d().createElement(c.Radio.Group,{optionType:"button",value:O.hasTranslation,onChange:function(e){return W({hasTranslation:e.target.value})},options:[{label:i("All"),value:!0},{label:i("No translation"),value:!1}]}))),d().createElement(c.Col,null,d().createElement(c.Space,{wrap:!0,align:"center"},d().createElement(c.Popconfirm,{title:i("Delete translation"),description:i("Are you sure you want to delete it?"),onConfirm:function(){return v(function(){var e,t;return S(this,function(n){switch(n.label){case 0:if(e=new Set(F.map(function(e){return String(e)})),!(t=J.filter(function(t){return e.has(String(t.id))}).map(function(e){return e.translationId}).filter(Boolean)).length)return c.message.error(i("Please select the records you want to delete")),[2];return[4,p.resource(f).destroy({filterByTk:t})];case 1:return n.sent(),A([]),_(),[2]}})})()}},d().createElement(c.Button,{danger:!0,disabled:!F.length},i("Delete translation"))),d().createElement(c.Button,{icon:d().createElement(r.ReloadOutlined,null),loading:L,onClick:_},i("Refresh")),d().createElement(z,{sources:void 0===G?[]:G,loading:N,refresh:_}),d().createElement(c.Button,{type:"primary",icon:d().createElement(r.UploadOutlined,null),onClick:function(){return v(function(){return S(this,function(e){switch(e.label){case 0:return[4,p.resource(m).publish()];case 1:return e.sent(),window.location.reload(),[2]}})})()}},i("Publish")),d().createElement(P,{selectedRowKeys:F})))),d().createElement(c.Table,{rowKey:"id",loading:L,columns:$,dataSource:J,pagination:H,rowSelection:{selectedRowKeys:F,onChange:A}})),d().createElement(c.Drawer,{title:i("Edit"),open:!!R,width:720,onClose:function(){return B(null)},footer:d().createElement(c.Space,{style:{display:"flex",justifyContent:"flex-end"}},d().createElement(c.Button,{onClick:function(){return B(null)}},i("Cancel")),d().createElement(c.Button,{type:"primary",onClick:function(){return v(function(){var e;return S(this,function(t){switch(t.label){case 0:return[4,y.validateFields()];case 1:if(e=t.sent(),!R)return[2];return[4,p.resource(f).updateOrCreate({filterKeys:["textId","locale"],values:{textId:R.id,locale:g,translation:e.translation}})];case 2:return t.sent(),B(null),_(),[2]}})})()}},i("Submit")))},R?d().createElement(c.Space,{direction:"vertical",size:16,style:{width:"100%"}},d().createElement("div",null,d().createElement(C,{strong:!0},i("Module")),d().createElement("div",{style:{marginTop:8}},R.moduleTitle?d().createElement(c.Tag,null,T(R.moduleTitle,i)):d().createElement(c.Tag,null,R.module))),d().createElement("div",null,d().createElement(C,{strong:!0},i("Text")),d().createElement(c.Typography.Paragraph,{style:{marginTop:8}},R.text)),d().createElement(c.Form,{form:y,layout:"vertical"},d().createElement(c.Form.Item,{name:"translation",label:d().createElement(C,{strong:!0},i("Translation")),rules:[{required:!0,message:i("Translation")}]},d().createElement(c.Input.TextArea,{autoSize:{minRows:4}})))):null))}function P(e){var t,n,r,a=e.selectedRowKeys,u=(0,o.useFlowContext)(),f=h(),p=u.app.apiClient,g=(null==(t=(n=p.auth).getLocale)?void 0:t.call(n))||p.auth.locale||"en-US",y=w((0,s.useState)(null),2),b=y[0],E=y[1],C=[{mode:"incremental",title:f("Incremental translation")},{mode:"selected",title:f("Selected translation")},{mode:"full",title:f("Full translation")}];return d().createElement(i.AIEmployeeShortcut,{aiEmployee:{username:"lina"},tasks:C,size:32,mask:!1,onTaskClick:function(e){var t;return t=e.mode,v(function(){var e,n,r,o,u,s,h;return S(this,function(y){switch(y.label){case 0:if("selected"===t&&!a.length)return c.message.error(f("Please select the records you want to translate")),[2];E(t),y.label=1;case 1:return y.trys.push([1,5,6,7]),n={mode:t,locale:g,employeeUsername:"lina",textIds:"selected"===t?a:void 0},[4,p.resource(m).aiTranslatePreview({values:n})];case 2:return u=(null==(o=(null==(r=y.sent())||null==(e=r.data)?void 0:e.data)||(null==r?void 0:r.data))?void 0:o.providerTitle)?l.Schema.compile(o.providerTitle,{t:f}):null==o?void 0:o.provider,s=(null==o?void 0:o.model)?(0,i.formatModelLabel)(o.model):void 0,[4,new Promise(function(e){var t;c.Modal.confirm({title:f("Confirm translation task"),content:d().createElement(c.Space,{direction:"vertical",size:8},d().createElement("div",null,f("Entries to translate"),": ",null!=(t=null==o?void 0:o.count)?t:0),d().createElement("div",null,f("Provider"),": ",u||"-"),d().createElement("div",null,f("Model"),": ",s||"-")),okText:f("Confirm"),cancelText:f("Cancel"),onOk:function(){return e(!0)},onCancel:function(){return e(!1)}})})];case 3:if(!y.sent())return[2];return[4,p.resource(m).aiTranslate({values:n})];case 4:return y.sent(),c.message.success(f("Async task created")),[3,7];case 5:return h=y.sent(),c.message.error((null==h?void 0:h.message)||f("Failed to create async task")),[3,7];case 6:return E(null),[7];case 7:return[2]}})})()},loadingTaskTitle:null==(r=C.find(function(e){return e.mode===b}))?void 0:r.title,taskLoadingTitle:f("Creating...")})}function z(e){var t=e.sources,n=e.loading,l=e.refresh,a=(0,o.useFlowContext)(),i=h(),u=a.app.apiClient,f=w((0,s.useState)([]),2),p=f[0],g=f[1],y=w((0,s.useState)(!1),2),b=y[0],E=y[1],C=w((0,s.useState)(!1),2),k=C[0],x=C[1],O=(0,s.useMemo)(function(){return t.map(function(e){return e.name})},[t]);(0,s.useEffect)(function(){g(O)},[O]);var P=p.length>0&&p.length<O.length,z=O.length>0&&p.length===O.length;if(n)return null;var j=d().createElement(d().Fragment,null,d().createElement(c.Checkbox,{indeterminate:P,onChange:function(e){g(e.target.checked?O:[])},checked:z},i("All")),d().createElement(c.Divider,{style:{margin:"5px 0"}}),d().createElement(c.Checkbox.Group,{onChange:function(e){g(e)},value:p},d().createElement("div",null,t.map(function(e){return d().createElement("div",{key:e.name},d().createElement(c.Checkbox,{value:e.name},T(e.title,i)))}))),d().createElement(c.Divider,{style:{margin:"5px 0"}}),d().createElement(c.Checkbox,{checked:b,onChange:function(e){return E(e.target.checked)}},i("Reset built-in translations")));return d().createElement(c.Popover,{placement:"bottomRight",content:j},d().createElement(c.Button,{icon:d().createElement(r.SyncOutlined,null),loading:k,onClick:function(){return v(function(){return S(this,function(e){switch(e.label){case 0:if(!p.length)return[2,c.message.error(i("Please select the resources you want to synchronize"))];x(!0),e.label=1;case 1:return e.trys.push([1,,3,4]),[4,u.resource(m).sync({values:{types:p,resetTranslations:b}})];case 2:return e.sent(),l(),[3,4];case 3:return x(!1),[7];case 4:return[2]}})})()}},i("Sync")))}}}]);
@@ -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_client_v2=self.webpackChunk_nocobase_plugin_localization_client_v2||[]).push([["796"],{647:function(e,t,n){n.r(t),n.d(t,{default:function(){return k},LocalizationPageContent:function(){return O}});var r=n(375),l=n(230),a=n(485),o=n(694),i=n(550),u=n(625),c=n(59),s=n(155),d=n.n(s),f=n(941),m=JSON.parse('{"UU":"@nocobase/plugin-localization"}').UU;function p(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[m,"client"]})}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function v(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function g(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){v(a,r,l,o,i,"next",e)}function i(e){v(a,r,l,o,i,"throw",e)}o(void 0)})}}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}function b(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function E(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return h(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 h(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 w(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=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(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var S=c.Typography.Text;function C(e,t){return l.Schema.compile(e,{t:t})}var T=function(e){var t=e.value;return null==t?null:d().createElement("span",null,t)};function k(){return d().createElement(O,null)}function O(){var e,t,n,l=(0,o.useFlowContext)(),i=p(),m=l.app.apiClient,h=(null==(e=(t=m.auth).getLocale)?void 0:e.call(t))||m.auth.locale||"en-US",v=E(c.Form.useForm(),1)[0],k=E((0,s.useState)({page:1,pageSize:50,hasTranslation:!0}),2),O=k[0],j=k[1],z=E((0,s.useState)([]),2),I=z[0],F=z[1],A=E((0,s.useState)(null),2),D=A[0],M=A[1],R=(null==(n=a.languageCodes[h])?void 0:n.label)||h,B=(0,u.useRequest)(function(){return g(function(){return w(this,function(e){switch(e.label){case 0:return[4,m.resource(f.qQ).list(b(y({},O),{hasTranslation:String(O.hasTranslation)}))];case 1:var t,n,r,l,a,o;return[2,{rows:(null==(o=null==(t=e.sent())?void 0:t.data)?void 0:o.data)||[],modules:(null==o||null==(n=o.meta)?void 0:n.modules)||[],count:(null==o||null==(r=o.meta)?void 0:r.count)||0,page:null==o||null==(l=o.meta)?void 0:l.page,pageSize:null==o||null==(a=o.meta)?void 0:a.pageSize}]}})})()},{refreshDeps:[O]}),_=B.data,U=B.loading,K=B.refresh,L=(0,u.useRequest)(function(){return g(function(){var e,t;return w(this,function(n){switch(n.label){case 0:return[4,m.resource(f.ft).getSources()];case 1:return[2,(null==(t=n.sent())||null==(e=t.data)?void 0:e.data)||[]]}})})()}),q=L.data,G=L.loading,Y=(null==_?void 0:_.rows)||[],N=(0,s.useMemo)(function(){return((null==_?void 0:_.modules)||[]).map(function(e){return{value:e.value,label:C(e.label,i)}})},[null==_?void 0:_.modules,i]);(0,s.useEffect)(function(){D?v.setFieldsValue({translation:D.translation}):v.resetFields()},[D,v]);var J=function(e){j(function(t){return b(y({},t,e),{page:1})})},Q=[{title:i("Text"),dataIndex:"text",ellipsis:!0},{title:i("Translation"),dataIndex:"translation",ellipsis:!0,render:function(e){return d().createElement(T,{value:e})}},{title:i("Module"),dataIndex:"moduleTitle",width:220,render:function(e,t){return t.moduleTitle?d().createElement(c.Tag,null,C(t.moduleTitle,i)):d().createElement(c.Tag,null,t.module)}},{title:i("Actions"),key:"actions",width:240,render:function(e,t){return d().createElement(c.Space,{split:d().createElement(c.Divider,{type:"vertical"}),style:{whiteSpace:"nowrap"}},d().createElement(c.Button,{type:"link",size:"small",onClick:function(){return M(t)}},i("Edit")),t.translationId?d().createElement(c.Popconfirm,{title:i("Delete translation"),description:i("Are you sure you want to delete it?"),onConfirm:function(){return g(function(){return w(this,function(e){switch(e.label){case 0:if(!t.translationId)return[2];return[4,m.resource(f.MY).destroy({filterByTk:t.translationId})];case 1:return e.sent(),K(),[2]}})})()}},d().createElement(c.Button,{type:"link",size:"small"},i("Delete translation"))):null)}}],V={current:(null==_?void 0:_.page)||O.page,pageSize:(null==_?void 0:_.pageSize)||O.pageSize,total:(null==_?void 0:_.count)||0,showSizeChanger:!0,onChange:function(e,t){return j(function(n){return b(y({},n),{page:e,pageSize:t})})}};return d().createElement(c.Card,{bordered:!1},d().createElement(c.Space,{direction:"vertical",size:16,style:{width:"100%"}},d().createElement(c.Row,{justify:"space-between",align:"middle",gutter:[16,16]},d().createElement(c.Col,{flex:"auto"},d().createElement(c.Space,{wrap:!0,align:"center"},d().createElement(c.Typography,null,d().createElement(S,{strong:!0},i("Current language")),d().createElement(c.Tag,{style:{marginLeft:10}},R)),d().createElement(c.Select,{allowClear:!0,showSearch:!0,optionFilterProp:"label",placeholder:i("Module"),style:{minWidth:220},options:N,onChange:function(e){return J({module:e})}}),d().createElement(c.Input.Search,{allowClear:!0,placeholder:i("Keyword"),style:{width:220},onSearch:function(e){return J({keyword:e})}}),d().createElement(c.Radio.Group,{optionType:"button",value:O.hasTranslation,onChange:function(e){return J({hasTranslation:e.target.value})},options:[{label:i("All"),value:!0},{label:i("No translation"),value:!1}]}))),d().createElement(c.Col,null,d().createElement(c.Space,{wrap:!0,align:"center"},d().createElement(c.Popconfirm,{title:i("Delete translation"),description:i("Are you sure you want to delete it?"),onConfirm:function(){return g(function(){var e,t;return w(this,function(n){switch(n.label){case 0:if(e=new Set(I.map(function(e){return String(e)})),!(t=Y.filter(function(t){return e.has(String(t.id))}).map(function(e){return e.translationId}).filter(Boolean)).length)return c.message.error(i("Please select the records you want to delete")),[2];return[4,m.resource(f.MY).destroy({filterByTk:t})];case 1:return n.sent(),F([]),K(),[2]}})})()}},d().createElement(c.Button,{danger:!0,disabled:!I.length},i("Delete translation"))),d().createElement(c.Button,{icon:d().createElement(r.ReloadOutlined,null),loading:U,onClick:K},i("Refresh")),d().createElement(P,{sources:void 0===q?[]:q,loading:G,refresh:K}),d().createElement(c.Button,{type:"primary",icon:d().createElement(r.UploadOutlined,null),onClick:function(){return g(function(){return w(this,function(e){switch(e.label){case 0:return[4,m.resource(f.ft).publish()];case 1:return e.sent(),window.location.reload(),[2]}})})()}},i("Publish")),d().createElement(x,{selectedRowKeys:I})))),d().createElement(c.Table,{rowKey:"id",loading:U,columns:Q,dataSource:Y,pagination:V,rowSelection:{selectedRowKeys:I,onChange:F}})),d().createElement(c.Drawer,{title:i("Edit"),open:!!D,width:720,onClose:function(){return M(null)},footer:d().createElement(c.Space,{style:{display:"flex",justifyContent:"flex-end"}},d().createElement(c.Button,{onClick:function(){return M(null)}},i("Cancel")),d().createElement(c.Button,{type:"primary",onClick:function(){return g(function(){var e;return w(this,function(t){switch(t.label){case 0:return[4,v.validateFields()];case 1:if(e=t.sent(),!D)return[2];return[4,m.resource(f.MY).updateOrCreate({filterKeys:["textId","locale"],values:{textId:D.id,locale:h,translation:e.translation}})];case 2:return t.sent(),M(null),K(),[2]}})})()}},i("Submit")))},D?d().createElement(c.Space,{direction:"vertical",size:16,style:{width:"100%"}},d().createElement("div",null,d().createElement(S,{strong:!0},i("Module")),d().createElement("div",{style:{marginTop:8}},D.moduleTitle?d().createElement(c.Tag,null,C(D.moduleTitle,i)):d().createElement(c.Tag,null,D.module))),d().createElement("div",null,d().createElement(S,{strong:!0},i("Text")),d().createElement(c.Typography.Paragraph,{style:{marginTop:8}},D.text)),d().createElement(c.Form,{form:v,layout:"vertical"},d().createElement(c.Form.Item,{name:"translation",label:d().createElement(S,{strong:!0},i("Translation")),rules:[{required:!0,message:i("Translation")}]},d().createElement(c.Input.TextArea,{autoSize:{minRows:4}})))):null))}function x(e){var t,n,r,a=e.selectedRowKeys,u=(0,o.useFlowContext)(),m=p(),h=u.app.apiClient,v=(null==(t=(n=h.auth).getLocale)?void 0:t.call(n))||h.auth.locale||"en-US",y=E((0,s.useState)(null),2),b=y[0],S=y[1],C=[{mode:"incremental",title:m("Incremental translation")},{mode:"selected",title:m("Selected translation")},{mode:"full",title:m("Full translation")}];return d().createElement(i.AIEmployeeShortcut,{aiEmployee:{username:"lina"},tasks:C,size:32,mask:!1,onTaskClick:function(e){var t;return t=e.mode,g(function(){var e,n,r,o,u,s,p;return w(this,function(g){switch(g.label){case 0:if("selected"===t&&!a.length)return c.message.error(m("Please select the records you want to translate")),[2];S(t),g.label=1;case 1:return g.trys.push([1,5,6,7]),n={mode:t,locale:v,employeeUsername:"lina",textIds:"selected"===t?a:void 0},[4,h.resource(f.ft).aiTranslatePreview({values:n})];case 2:return u=(null==(o=(null==(r=g.sent())||null==(e=r.data)?void 0:e.data)||(null==r?void 0:r.data))?void 0:o.providerTitle)?l.Schema.compile(o.providerTitle,{t:m}):null==o?void 0:o.provider,s=(null==o?void 0:o.model)?(0,i.formatModelLabel)(o.model):void 0,[4,new Promise(function(e){var t;c.Modal.confirm({title:m("Confirm translation task"),content:d().createElement(c.Space,{direction:"vertical",size:8},d().createElement("div",null,m("Entries to translate"),": ",null!=(t=null==o?void 0:o.count)?t:0),d().createElement("div",null,m("Provider"),": ",u||"-"),d().createElement("div",null,m("Model"),": ",s||"-")),okText:m("Confirm"),cancelText:m("Cancel"),onOk:function(){return e(!0)},onCancel:function(){return e(!1)}})})];case 3:if(!g.sent())return[2];return[4,h.resource(f.ft).aiTranslate({values:n})];case 4:return g.sent(),c.message.success(m("Async task created")),[3,7];case 5:return p=g.sent(),c.message.error((null==p?void 0:p.message)||m("Failed to create async task")),[3,7];case 6:return S(null),[7];case 7:return[2]}})})()},loadingTaskTitle:null==(r=C.find(function(e){return e.mode===b}))?void 0:r.title,taskLoadingTitle:m("Creating...")})}function P(e){var t=e.sources,n=e.loading,l=e.refresh,a=(0,o.useFlowContext)(),i=p(),u=a.app.apiClient,m=E((0,s.useState)([]),2),h=m[0],v=m[1],y=E((0,s.useState)(!1),2),b=y[0],S=y[1],T=E((0,s.useState)(!1),2),k=T[0],O=T[1],x=(0,s.useMemo)(function(){return t.map(function(e){return e.name})},[t]);(0,s.useEffect)(function(){v(x)},[x]);var P=h.length>0&&h.length<x.length,j=x.length>0&&h.length===x.length;if(n)return null;var z=d().createElement(d().Fragment,null,d().createElement(c.Checkbox,{indeterminate:P,onChange:function(e){v(e.target.checked?x:[])},checked:j},i("All")),d().createElement(c.Divider,{style:{margin:"5px 0"}}),d().createElement(c.Checkbox.Group,{onChange:function(e){v(e)},value:h},d().createElement("div",null,t.map(function(e){return d().createElement("div",{key:e.name},d().createElement(c.Checkbox,{value:e.name},C(e.title,i)))}))),d().createElement(c.Divider,{style:{margin:"5px 0"}}),d().createElement(c.Checkbox,{checked:b,onChange:function(e){return S(e.target.checked)}},i("Reset built-in translations")));return d().createElement(c.Popover,{placement:"bottomRight",content:z},d().createElement(c.Button,{icon:d().createElement(r.SyncOutlined,null),loading:k,onClick:function(){return g(function(){return w(this,function(e){switch(e.label){case 0:if(!h.length)return[2,c.message.error(i("Please select the resources you want to synchronize"))];O(!0),e.label=1;case 1:return e.trys.push([1,,3,4]),[4,u.resource(f.ft).sync({values:{types:h,resetTranslations:b}})];case 2:return e.sent(),l(),[3,4];case 3:return O(!1),[7];case 4:return[2]}})})()}},i("Sync")))}}}]);