-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script to add translations inline
- Loading branch information
1 parent
daae88f
commit 91478f2
Showing
19 changed files
with
170 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"$schema": "../schemas/osmosis-update.schema.json", | ||
"iframeUrl": null | ||
"iframeUrl": null, | ||
"localization": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,5 +57,6 @@ | |
"arrow_color": "#CBFD50", | ||
"featured": true | ||
} | ||
] | ||
], | ||
"localization": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"topAnnouncementBanner": { | ||
"top-announcement-banner": { | ||
"title": "测试!", | ||
"linkLearnMore": "点击这里了解更多。" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"topAnnouncementBanner": { | ||
"top-announcement-banner": { | ||
"title": "測試!", | ||
"linkLearnMore": "點這裡了解更多。" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"topAnnouncementBanner": { | ||
"top-announcement-banner": { | ||
"title": "測試!", | ||
"linkLearnMore": "點這裡了解更多。" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import prettier from "prettier"; | ||
|
||
const cmsDirectoryPath = "./cms"; | ||
const localizationDirectoryPath = "./localizations"; | ||
const cmsFiles = fs.readdirSync(cmsDirectoryPath); | ||
|
||
const inlangSettings = JSON.parse( | ||
fs.readFileSync("project.inlang/settings.json", "utf8") | ||
); | ||
|
||
cmsFiles.forEach(async (filePath) => { | ||
const content = JSON.parse( | ||
fs.readFileSync(path.resolve(cmsDirectoryPath, filePath), "utf8") | ||
); | ||
|
||
content.localization = inlangSettings.languageTags.reduce( | ||
(acc, languageTag) => { | ||
const localizationFile = JSON.parse( | ||
fs.readFileSync( | ||
path.join(localizationDirectoryPath, `${languageTag}.json`), | ||
"utf8" | ||
) | ||
); | ||
|
||
const namespace = filePath.split(".")[0]; | ||
const namespaceContent = localizationFile[namespace]; | ||
|
||
if (!namespaceContent) { | ||
return acc; | ||
} | ||
|
||
acc[languageTag] = { [namespace]: namespaceContent }; | ||
return acc; | ||
}, | ||
{} | ||
); | ||
|
||
const formatted = await prettier.format(JSON.stringify(content), { | ||
parser: "json", | ||
}); | ||
fs.writeFileSync(path.resolve(cmsDirectoryPath, filePath), formatted, { | ||
encoding: "utf8", | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters