Skip to content

Commit

Permalink
feat: add script to add translations inline
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRFelix committed Jan 9, 2024
1 parent daae88f commit 91478f2
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 18 deletions.
Empty file added README.md
Empty file.
3 changes: 2 additions & 1 deletion cms/osmosis-update.json
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": {}
}
3 changes: 2 additions & 1 deletion cms/swap-rotating-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
"arrow_color": "#CBFD50",
"featured": true
}
]
],
"localization": {}
}
74 changes: 74 additions & 0 deletions cms/top-announcement-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,79 @@
"localStorageKey": "top-announcement-banner-test",
"startDate": "2024-01-08T00:00:00.000Z",
"endDate": "2024-02-01T00:00:00.000Z"
},
"localization": {
"en": {
"top-announcement-banner": {
"title": "Testing!",
"linkLearnMore": "Click here to learn more."
}
},
"es": {
"top-announcement-banner": {
"title": "¡Pruebas!",
"linkLearnMore": "Clic aquí para saber más."
}
},
"fa": {
"top-announcement-banner": {
"title": "آزمایش کردن!",
"linkLearnMore": "برای اطلاعات بیشتر اینجا کلیک کنید."
}
},
"fr": {
"top-announcement-banner": {
"title": "Essai!",
"linkLearnMore": "Cliquez ici pour en savoir plus."
}
},
"ko": {
"top-announcement-banner": {
"title": "테스트!",
"linkLearnMore": "자세한 내용을 보려면 여기를 클릭하세요."
}
},
"pl": {
"top-announcement-banner": {
"title": "Testowanie!",
"linkLearnMore": "Kliknij tutaj, aby dowiedzieć się więcej."
}
},
"pt-br": {
"top-announcement-banner": {
"title": "Testando!",
"linkLearnMore": "Clique aqui para saber mais."
}
},
"ro": {
"top-announcement-banner": {
"title": "Testare!",
"linkLearnMore": "Apasa aici pentru a afla mai multe."
}
},
"tr": {
"top-announcement-banner": {
"title": "Test yapmak!",
"linkLearnMore": "Daha fazlasını öğrenmek için buraya tıklayın."
}
},
"zh-cn": {
"top-announcement-banner": {
"title": "测试!",
"linkLearnMore": "点击这里了解更多。"
}
},
"zh-hk": {
"top-announcement-banner": {
"title": "測試!",
"linkLearnMore": "點這裡了解更多。"
}
},
"zh-tw": {
"top-announcement-banner": {
"title": "測試!",
"linkLearnMore": "點這裡了解更多。"
}
}
}
}
2 changes: 1 addition & 1 deletion localizations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "Testing!",
"linkLearnMore": "Click here to learn more."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/es.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "¡Pruebas!",
"linkLearnMore": "Clic aquí para saber más."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/fa.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "آزمایش کردن!",
"linkLearnMore": "برای اطلاعات بیشتر اینجا کلیک کنید."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/fr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "Essai!",
"linkLearnMore": "Cliquez ici pour en savoir plus."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/ko.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "테스트!",
"linkLearnMore": "자세한 내용을 보려면 여기를 클릭하세요."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/pl.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "Testowanie!",
"linkLearnMore": "Kliknij tutaj, aby dowiedzieć się więcej."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/pt-br.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "Testando!",
"linkLearnMore": "Clique aqui para saber mais."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/ro.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "Testare!",
"linkLearnMore": "Apasa aici pentru a afla mai multe."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/tr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "Test yapmak!",
"linkLearnMore": "Daha fazlasını öğrenmek için buraya tıklayın."
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/zh-cn.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "测试!",
"linkLearnMore": "点击这里了解更多。"
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/zh-hk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "測試!",
"linkLearnMore": "點這裡了解更多。"
}
Expand Down
2 changes: 1 addition & 1 deletion localizations/zh-tw.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"topAnnouncementBanner": {
"top-announcement-banner": {
"title": "測試!",
"linkLearnMore": "點這裡了解更多。"
}
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
"main": "index.js",
"scripts": {
"test": "vitest",
"machine-translate": "inlang machine translate --project ./project.inlang"
"machine-translate": "inlang machine translate --project ./project.inlang",
"inline-translations": "tsx ./scripts/translate-cms.js"
},
"keywords": [],
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@inlang/cli": "^2.0.0",
"ajv": "^8.12.0",
"ajv-cli": "^5.0.0",
"ajv-formats": "^2.1.1",
"vitest": "^1.1.3",
"@inlang/cli": "^2.0.0"
"prettier": "^3.1.1",
"tsx": "^4.7.0",
"vitest": "^1.1.3"
}
}
46 changes: 46 additions & 0 deletions scripts/translate-cms.js
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",
});
});
29 changes: 28 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ esbuild-wasm@^0.19.2:
resolved "https://registry.yarnpkg.com/esbuild-wasm/-/esbuild-wasm-0.19.11.tgz#4ed96cdd1a289bc08432a25fd38b7331d3eac98d"
integrity sha512-MIhnpc1TxERUHomteO/ZZHp+kUawGEc03D/8vMHGzffLvbFLeDe6mwxqEZwlqBNY7SLWbyp6bBQAcCen8+wpjQ==

esbuild@^0.19.3:
esbuild@^0.19.3, esbuild@~0.19.10:
version "0.19.11"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.19.11.tgz#4a02dca031e768b5556606e1b468fe72e3325d96"
integrity sha512-HJ96Hev2hX/6i5cDVwcqiJBBtuo9+FeIJOtZ9W1kA5M6AMJRHUZlpYZ1/SbEwtO0ioNAW8rUooVpC/WehY2SfA==
Expand Down Expand Up @@ -491,6 +491,13 @@ get-stream@^8.0.1:
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-8.0.1.tgz#def9dfd71742cd7754a7761ed43749a27d02eca2"
integrity sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==

get-tsconfig@^4.7.2:
version "4.7.2"
resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.7.2.tgz#0dcd6fb330391d46332f4c6c1bf89a6514c2ddce"
integrity sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==
dependencies:
resolve-pkg-maps "^1.0.0"

glob@^7.1.0:
version "7.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b"
Expand Down Expand Up @@ -715,6 +722,11 @@ postcss@^8.4.32:
picocolors "^1.0.0"
source-map-js "^1.0.2"

prettier@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.1.tgz#6ba9f23165d690b6cbdaa88cb0807278f7019848"
integrity sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==

pretty-format@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.7.0.tgz#ca42c758310f365bfa71a0bda0a807160b776812"
Expand All @@ -739,6 +751,11 @@ require-from-string@^2.0.2:
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"
integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==

resolve-pkg-maps@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f"
integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==

rollup@^4.2.0:
version "4.9.3"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.9.3.tgz#12f54775f359409641b5a71a86fe226a7c1d6b67"
Expand Down Expand Up @@ -830,6 +847,16 @@ tinyspy@^2.2.0:
resolved "https://registry.yarnpkg.com/tinyspy/-/tinyspy-2.2.0.tgz#9dc04b072746520b432f77ea2c2d17933de5d6ce"
integrity sha512-d2eda04AN/cPOR89F7Xv5bK/jrQEhmcLFe6HFldoeO9AJtps+fqEnh486vnT/8y4bw38pSyxDcTCAq+Ks2aJTg==

tsx@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.7.0.tgz#1689cfe7dda495ca1f9a66d4cad79cb57b9f6f4a"
integrity sha512-I+t79RYPlEYlHn9a+KzwrvEwhJg35h/1zHsLC2JXvhC2mdynMv6Zxzvhv5EMV6VF5qJlLlkSnMVvdZV3PSIGcg==
dependencies:
esbuild "~0.19.10"
get-tsconfig "^4.7.2"
optionalDependencies:
fsevents "~2.3.3"

type-detect@^4.0.0, type-detect@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"
Expand Down

0 comments on commit 91478f2

Please sign in to comment.