Skip to content

Commit

Permalink
✨ feat(i18n): remove unnecessary po files
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Apr 28, 2024
1 parent 663d9ad commit bf7f586
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 12,025 deletions.
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npm run translations:extract

1 change: 0 additions & 1 deletion scripts/translate.js

This file was deleted.

74 changes: 74 additions & 0 deletions scripts/translate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* eslint-disable no-continue */
import gettextParser from "gettext-parser";

import fs from "fs";
import path from "path";

const translateText = async (input, language) => {
const response = await fetch(
`https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${language}&dt=t&q=${encodeURI(
input
)}`
);

if (!response.ok) {
const error = await response.json();
throw new Error(`Failed to translate text: ${JSON.stringify(error)}`);
}

return (await response.json())[0][0][0];
};

const getFileMessages = (folderPath, file) => {
const poContent = fs.readFileSync(path.join(folderPath, file), "utf8");
const po = gettextParser.po.parse(poContent);

return [
po,
Object.values(po.translations[""]).map((message) => ({
id: message.msgid,
translation: message.msgstr[0],
})),
];
};

async function translatePoFiles(folderPath) {
const files = fs.readdirSync(folderPath);

for (const file of files) {
if (path.extname(file) !== ".po") {
continue;
}

const language = file.split(".")[0];

if (language === "pseudo") {
continue;
}

const [po, fileMessages] = getFileMessages(folderPath, file);

for (const message of fileMessages) {
if (message.translation) {
continue;
}

if (!message.id) {
continue;
}

const translation = await translateText(message.id, language);

console.log(`${language}: ${message.id} => ${translation}`);

po.translations[""][message.id] = {
msgid: message.id,
msgstr: [translation],
};
}

fs.writeFileSync(path.join(folderPath, file), gettextParser.po.compile(po));
}
}

translatePoFiles("./src/translations/locales");
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ describe("Table Filters", () => {
value: ["option-1", "option-2"],
});
},
{ timeout: 5000 }
{ timeout: 10000 }
);

await userEvent.selectOptions(
Expand Down
7 changes: 5 additions & 2 deletions src/frontend/views/integrations/Password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SchemaForm } from "frontend/components/SchemaForm";
import { Spacer } from "frontend/design-system/primitives/Spacer";
import { Typo } from "frontend/design-system/primitives/Typo";
import { msg } from "@lingui/macro";
import { useLingui } from "@lingui/react";
import { usePasswordStore } from "./password.store";

export function PasswordMessage() {
Expand All @@ -20,13 +21,15 @@ export function PasswordToReveal({
label: string;
isLoading: boolean;
}) {
const { _ } = useLingui();
const passwordStore = usePasswordStore();

return (
<>
<Typo.SM $textStyle="italic">
For security reasons, Please input your account password to be able to
manage {label}
{_(
msg`For security reasons, Please input your account password to be able to manage ${label}`
)}
</Typo.SM>
<Spacer />
<SchemaForm
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/views/integrations/storage/Credentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ISchemaFormConfig } from "shared/form-schemas/types";
import { IStorageIntegration } from "shared/types/actions";
import { msg } from "@lingui/macro";
import { i18nNoop } from "translations/fake";
import { useLingui } from "@lingui/react";
import { STORAGE_INTEGRATIONS_CRUD_CONFIG } from "./constants";
import {
useActivateStorageMutation,
Expand All @@ -31,6 +32,8 @@ export function StorageCredentialsSettings() {
const currentStorageDetails: IStorageIntegration | undefined =
storageList.data.find((datum) => datum.key === currentStorage);

const { _ } = useLingui();

useEffect(() => {
setCurrentStorage(activeStorageIntegration.data.data);
}, [activeStorageIntegration.data]);
Expand Down Expand Up @@ -74,7 +77,9 @@ export function StorageCredentialsSettings() {
>
{storageCredentialsConfiguration.data === undefined ? (
<PasswordToReveal
label={`${STORAGE_INTEGRATIONS_CRUD_CONFIG.TEXT_LANG.TITLE} Configuration`}
label={`${_(
STORAGE_INTEGRATIONS_CRUD_CONFIG.TEXT_LANG.TITLE
)} Configuration`}
isLoading={storageCredentialsConfiguration.isLoading}
/>
) : (
Expand Down
Loading

0 comments on commit bf7f586

Please sign in to comment.