MCPcopy Create free account
hub / github.com/baiwumm/react-admin / initializeLang

Function initializeLang

Xmw_server/src/utils/index.ts:64–94  ·  view source on GitHub ↗
(
  resource: XmwInternational[],
  lang: string,
  name = 'name',
)

Source from the content-addressed store, hash-verified

62 * @author: 白雾茫茫丶
63 */
64export const initializeLang = (
65 resource: XmwInternational[],
66 lang: string,
67 name = 'name',
68): Record<string, any> => {
69 const result = {};
70 // 遍历数组
71 for (let i = 0; i < resource.length; i++) {
72 const resourceItem = resource[i];
73 // 递归函数
74 function recursive(obj: XmwInternational, serilKey = '') {
75 // 拼接对象名
76 let pKey = serilKey;
77 pKey += pKey ? `.${obj[name]}` : obj[name];
78 // 当前层级是否有数据,给 result 赋值
79 if (obj[lang]) {
80 result[pKey] = obj[lang];
81 }
82 // 判断是否有子级,有就递归遍历
83 if (obj.children?.length && Array.isArray(obj.children)) {
84 for (let j = 0; j < obj.children.length; j++) {
85 const child = obj.children[j];
86 recursive(child, pKey);
87 }
88 }
89 }
90 // 循环执行
91 recursive(resourceItem);
92 }
93 return result;
94};
95
96/**
97 * @description: 生成文件上传文件夹

Callers 1

getAllLocalesLangMethod · 0.90

Calls 1

recursiveFunction · 0.85

Tested by

no test coverage detected