Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 7] Create plugin for i18n-management #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ module.exports = ({env}) => ({
enabled: true,
resolve: './src/plugins/github-action-trigger'
},
'ietn': {
enabled: true,
resolve: './src/plugins/ietn'
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
"strapi": "strapi",
"prebuild": "cd src/plugins/ietn && npm run build && cd ../github-action-trigger && npm run build"
},
"devDependencies": {
"graphql-request": "^6.1.0",
Expand Down
45 changes: 45 additions & 0 deletions src/api/i18n/content-types/i18n/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"kind": "collectionType",
"collectionName": "i18ns",
"info": {
"singularName": "i18n",
"pluralName": "i18ns",
"displayName": "i18n"
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"key": {
"type": "string",
"unique": true,
"required": true
},
"en": {
"type": "component",
"repeatable": false,
"component": "i18n.i18n"
},
"vi": {
"type": "component",
"repeatable": false,
"component": "i18n.i18n"
},
"zh": {
"type": "component",
"repeatable": false,
"component": "i18n.i18n"
},
"ja": {
"type": "component",
"repeatable": false,
"component": "i18n.i18n"
},
"ru": {
"type": "component",
"repeatable": false,
"component": "i18n.i18n"
}
}
}
7 changes: 7 additions & 0 deletions src/api/i18n/controllers/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* i18n controller
*/

import { factories } from '@strapi/strapi'

export default factories.createCoreController('api::i18n.i18n');
7 changes: 7 additions & 0 deletions src/api/i18n/routes/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* i18n router
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreRouter('api::i18n.i18n');
7 changes: 7 additions & 0 deletions src/api/i18n/services/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* i18n service
*/

import { factories } from '@strapi/strapi';

export default factories.createCoreService('api::i18n.i18n');
19 changes: 19 additions & 0 deletions src/components/i18n/i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"collectionName": "components_platform_i18ns",
"info": {
"displayName": "platform",
"description": ""
},
"options": {},
"attributes": {
"web": {
"type": "string"
},
"mobi": {
"type": "string"
},
"extension": {
"type": "string"
}
}
}
3 changes: 3 additions & 0 deletions src/plugins/ietn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Strapi plugin ietn

A quick description of ietn.
138 changes: 138 additions & 0 deletions src/plugins/ietn/admin/src/components/ietn/getDataGithub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {
fetchData,
url_mobi_en,
url_mobi_ja,
url_mobi_ru,
url_mobi_vi,
url_mobi_zh,
} from "./utils";

import {DataItem, MergeData} from "../../../../types";

export const fetchDataGithub = async () => {
try {
const combinedExtension: DataItem[] = [];
const combinedWeb: DataItem[] = [];

const data_mobi_en: any = await fetchData(url_mobi_en);
const data_mobi_ru: any = await fetchData(url_mobi_ru);
const data_mobi_vi: any = await fetchData(url_mobi_vi);
const data_mobi_zh: any = await fetchData(url_mobi_zh);
const data_mobi_ja: any = await fetchData(url_mobi_ja);

const combinedMobi: DataItem[] = [];

for (const sectionKey in data_mobi_en) {
const item: DataItem = {};
for (const commonKey in data_mobi_en[sectionKey]) {
item[sectionKey] = item[sectionKey] || {};

if (typeof data_mobi_en[sectionKey][commonKey] === "object") {
item[sectionKey][commonKey] = item[sectionKey][commonKey] || {};
for (const finalKey in data_mobi_en[sectionKey][commonKey]) {
item[sectionKey][commonKey][finalKey] = {
en: data_mobi_en[sectionKey][commonKey][finalKey],
vi: data_mobi_vi[sectionKey][commonKey][finalKey],
zh: data_mobi_zh[sectionKey][commonKey][finalKey],
ja: data_mobi_ja[sectionKey][commonKey][finalKey],
ru: data_mobi_ru[sectionKey][commonKey][finalKey],
};
}
} else if (typeof data_mobi_en[sectionKey][commonKey] === "string") {
item[sectionKey][commonKey] = {
en: data_mobi_en[sectionKey][commonKey],
vi: data_mobi_vi[sectionKey][commonKey],
zh: data_mobi_zh[sectionKey][commonKey],
ja: data_mobi_ja[sectionKey][commonKey],
ru: data_mobi_ru[sectionKey][commonKey],
};
}
}
combinedMobi.push(item);
}

const MergeDataCrawl: MergeData[] = [];
for (const index in combinedMobi) {
for (const key1 in combinedMobi[index]) {
for (const key2 in combinedMobi[index][key1]) {
if (combinedMobi[index][key1][key2].en === undefined) {
for (const key3 in combinedMobi[index][key1][key2]) {
const mergedItem: MergeData = {
en: {
web: combinedWeb[index]?.[key1]?.[key2]?.[key3]?.en || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.[key3]?.en || null,
extension:
combinedExtension[index]?.[key1]?.[key3]?.[key3]?.en ||
null,
},
ru: {
web: combinedWeb[index]?.[key1]?.[key2]?.[key3]?.ru || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.[key3]?.ru || null,
extension:
combinedExtension[index]?.[key1]?.[key2]?.[key3]?.ru ||
null,
},
ja: {
web: combinedWeb[index]?.[key1]?.[key2]?.[key3]?.ja || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.[key3]?.ja || null,
extension:
combinedExtension[index]?.[key1]?.[key2]?.[key3]?.ja ||
null,
},
zh: {
web: combinedWeb[index]?.[key1]?.[key2]?.[key3]?.zh || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.[key3]?.zh || null,
extension:
combinedExtension[index]?.[key1]?.[key2]?.[key3]?.zh ||
null,
},
vi: {
web: combinedWeb[index]?.[key1]?.[key2]?.[key3]?.vi || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.[key3]?.vi || null,
extension:
combinedExtension[index]?.[key1]?.[key2]?.[key3]?.vi ||
null,
},
key: `${key1}.${key2}.${key3}`,
};
MergeDataCrawl.push(mergedItem)
}
} else {
const mergedItem: MergeData = {
en: {
web: combinedWeb[index]?.[key1]?.[key2]?.en || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.en || null,
extension: combinedExtension[index]?.[key1]?.[key2]?.en || null,
},
ru: {
web: combinedWeb[index]?.[key1]?.[key2]?.ru || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.ru || null,
extension: combinedExtension[index]?.[key1]?.[key2]?.ru || null,
},
ja: {
web: combinedWeb[index]?.[key1]?.[key2]?.ja || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.ja || null,
extension: combinedExtension[index]?.[key1]?.[key2]?.ja || null,
},
zh: {
web: combinedWeb[index]?.[key1]?.[key2]?.zh || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.zh || null,
extension: combinedExtension[index]?.[key1]?.[key2]?.zh || null,
},
vi: {
web: combinedWeb[index]?.[key1]?.[key2]?.vi || null,
mobi: combinedMobi[index]?.[key1]?.[key2]?.vi || null,
extension: combinedExtension[index]?.[key1]?.[key2]?.vi || null,
},
key: `${key1}.${key2}`,
};
MergeDataCrawl.push(mergedItem);
}
}
}
}
return MergeDataCrawl;
} catch (error) {
console.error("Error:", error);
}
};
Loading