Skip to content

Commit e847954

Browse files
committed
fix: add translation of the seeded data
1 parent 4093edd commit e847954

11 files changed

Lines changed: 244 additions & 16 deletions

File tree

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if git diff --cached --name-only | grep -qE '\.(tsx?|jsx?)$|\.po$'; then
1010

1111
# Add compiled locale files to the commit
1212
git add packages/locale/locales/**/*.po
13+
git add apps/erp/app/utils/seedDataDisplayName.ts
1314
fi
1415

1516
# Regenerate MCP tools if any .service.ts file was modified

apps/erp/app/components/Form/Account.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ComboboxProps } from "@carbon/form";
22
import { Combobox } from "@carbon/form";
33
import { Badge, Combobox as ComboboxBase, useMount } from "@carbon/react";
4+
import { useLingui } from "@lingui/react/macro";
45
import { useEffect, useMemo, useState } from "react";
56
import { useFetcher } from "react-router";
67
import type { AccountClass, getAccountsList } from "~/modules/accounting";
@@ -10,6 +11,7 @@ import {
1011
getClientCache,
1112
getCompanyId
1213
} from "~/utils/react-query";
14+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1315

1416
type AccountData = {
1517
id: string;
@@ -61,6 +63,7 @@ const badgeColors: Record<
6163
};
6264

6365
function useAccountOptions(classes?: AccountClass[]) {
66+
const { i18n } = useLingui();
6467
const accounts = useAccounts(classes);
6568

6669
return useMemo(
@@ -69,13 +72,15 @@ function useAccountOptions(classes?: AccountClass[]) {
6972
value: c.id,
7073
label: (
7174
<div className="flex items-center justify-between w-full gap-2">
72-
<span className="truncate">{c.name}</span>
75+
<span className="truncate">
76+
{translateSeedDisplayName(c.name, i18n)}
77+
</span>
7378
{c.class && <Badge variant={badgeColors[c.class]}>{c.class}</Badge>}
7479
</div>
7580
),
7681
helper: c.number
7782
})),
78-
[accounts]
83+
[accounts, i18n]
7984
);
8085
}
8186

apps/erp/app/components/Form/CustomerType.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import type { ComboboxProps } from "@carbon/form";
22
import { CreatableCombobox } from "@carbon/form";
33
import { useDisclosure, useMount } from "@carbon/react";
4+
import { useLingui } from "@lingui/react/macro";
45
import { useMemo, useRef, useState } from "react";
56
import { useFetcher } from "react-router";
67
import { Enumerable } from "~/components/Enumerable";
78
import type { getCustomerTypesList } from "~/modules/sales";
89
import { CustomerTypeForm } from "~/modules/sales/ui/CustomerTypes";
910
import { path } from "~/utils/path";
11+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1012

1113
type CustomerTypeSelectProps = Omit<ComboboxProps, "options"> & {
1214
exclude?: string[];
@@ -59,6 +61,7 @@ CustomerType.displayName = "CustomerType";
5961
export default CustomerType;
6062

6163
export const useCustomerTypes = () => {
64+
const { i18n } = useLingui();
6265
const customerTypeFetcher =
6366
useFetcher<Awaited<ReturnType<typeof getCustomerTypesList>>>();
6467

@@ -71,9 +74,9 @@ export const useCustomerTypes = () => {
7174

7275
return dataSource.map((c) => ({
7376
value: c.id,
74-
label: c.name
77+
label: translateSeedDisplayName(c.name, i18n)
7578
}));
76-
}, [customerTypeFetcher.data?.data]);
79+
}, [customerTypeFetcher.data?.data, i18n]);
7780

7881
return options;
7982
};

apps/erp/app/components/Form/Location.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import type { CreatableComboboxProps } from "@carbon/form";
22
import { CreatableCombobox } from "@carbon/form";
33
import { useDisclosure, useMount } from "@carbon/react";
44
import { getLocalTimeZone } from "@internationalized/date";
5+
import { useLingui } from "@lingui/react/macro";
56
import { useMemo, useRef, useState } from "react";
67
import { useFetcher } from "react-router";
78
import { useUser } from "~/hooks";
89
import type { getLocationsList } from "~/modules/resources";
910
import LocationForm from "~/modules/resources/ui/Locations/LocationForm";
1011
import { path } from "~/utils/path";
12+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1113
import { Enumerable } from "../Enumerable";
1214

1315
type LocationSelectProps = Omit<
@@ -77,6 +79,7 @@ Location.displayName = "Location";
7779
export default Location;
7880

7981
export const useLocations = () => {
82+
const { i18n } = useLingui();
8083
const locationFetcher =
8184
useFetcher<Awaited<ReturnType<typeof getLocationsList>>>();
8285

@@ -89,10 +92,10 @@ export const useLocations = () => {
8992
locationFetcher.data?.data
9093
? locationFetcher.data?.data.map((c) => ({
9194
value: c.id,
92-
label: c.name
95+
label: translateSeedDisplayName(c.name, i18n)
9396
}))
9497
: [],
95-
[locationFetcher.data]
98+
[locationFetcher.data, i18n]
9699
);
97100

98101
return options;

apps/erp/app/components/Form/PaymentTerm.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import type { ComboboxProps } from "@carbon/form";
22
import { Combobox, CreatableCombobox } from "@carbon/form";
33
import { useDisclosure, useMount } from "@carbon/react";
4+
import { useLingui } from "@lingui/react/macro";
45
import { useMemo, useRef, useState } from "react";
56
import { useFetcher } from "react-router";
67
import { usePermissions } from "~/hooks";
78
import type { getPaymentTermsList } from "~/modules/accounting";
89
import PaymentTermForm from "~/modules/accounting/ui/PaymentTerms/PaymentTermForm";
910
import { path } from "~/utils/path";
11+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1012

1113
type PaymentTermSelectProps = Omit<ComboboxProps, "options" | "inline"> & {
1214
inline?: boolean;
@@ -75,6 +77,7 @@ PaymentTerm.displayName = "PaymentTerm";
7577
export default PaymentTerm;
7678

7779
export const usePaymentTerm = () => {
80+
const { i18n } = useLingui();
7881
const paymentTermFetcher =
7982
useFetcher<Awaited<ReturnType<typeof getPaymentTermsList>>>();
8083

@@ -85,9 +88,9 @@ export const usePaymentTerm = () => {
8588
const options = useMemo(() => {
8689
return (paymentTermFetcher.data?.data ?? []).map((c) => ({
8790
value: c.id,
88-
label: c.name
91+
label: translateSeedDisplayName(c.name, i18n)
8992
}));
90-
}, [paymentTermFetcher.data?.data]);
93+
}, [paymentTermFetcher.data?.data, i18n]);
9194

9295
return options;
9396
};

apps/erp/app/components/Form/ScrapReason.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ComboboxProps } from "@carbon/form";
22
import { Combobox } from "@carbon/form";
33
import { useMount } from "@carbon/react";
4+
import { useLingui } from "@lingui/react/macro";
45
import { useMemo } from "react";
56
import { useFetcher } from "react-router";
67
import { useRouteData } from "~/hooks";
@@ -9,6 +10,7 @@ import type {
910
ScrapReason as ScrapReasonType
1011
} from "~/modules/production";
1112
import { path } from "~/utils/path";
13+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1214

1315
type ScrapReasonSelectProps = Omit<ComboboxProps, "options">;
1416

@@ -29,6 +31,7 @@ ScrapReason.displayName = "ScrapReason";
2931
export default ScrapReason;
3032

3133
export const useScrapReasons = () => {
34+
const { i18n } = useLingui();
3235
const scrapReasonFetcher =
3336
useFetcher<Awaited<ReturnType<typeof getScrapReasonsList>>>();
3437

@@ -50,12 +53,13 @@ export const useScrapReasons = () => {
5053

5154
return dataSource.map((c) => ({
5255
value: c.id,
53-
label: c.name
56+
label: translateSeedDisplayName(c.name, i18n)
5457
}));
5558
}, [
5659
scrapReasonFetcher.data?.data,
5760
hasScrapReasonData,
58-
sharedProductionData?.scrapReasons
61+
sharedProductionData?.scrapReasons,
62+
i18n
5963
]);
6064

6165
return options;

apps/erp/app/components/Form/SupplierType.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import type { ComboboxProps } from "@carbon/form";
22
import { CreatableCombobox } from "@carbon/form";
33
import { useDisclosure, useMount } from "@carbon/react";
4+
import { useLingui } from "@lingui/react/macro";
45
import { useMemo, useRef, useState } from "react";
56
import { useFetcher } from "react-router";
67
import { Enumerable } from "~/components/Enumerable";
78
import type { getSupplierTypesList } from "~/modules/purchasing";
89
import SupplierTypeForm from "~/modules/purchasing/ui/SupplierTypes/SupplierTypeForm";
910

1011
import { path } from "~/utils/path";
12+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1113

1214
type SupplierTypeSelectProps = Omit<ComboboxProps, "options">;
1315

@@ -57,6 +59,7 @@ SupplierType.displayName = "SupplierType";
5759
export default SupplierType;
5860

5961
export const useSupplierTypes = () => {
62+
const { i18n } = useLingui();
6063
const supplierTypeFetcher =
6164
useFetcher<Awaited<ReturnType<typeof getSupplierTypesList>>>();
6265

@@ -69,9 +72,9 @@ export const useSupplierTypes = () => {
6972

7073
return dataSource.map((c) => ({
7174
value: c.id,
72-
label: c.name
75+
label: translateSeedDisplayName(c.name, i18n)
7376
}));
74-
}, [supplierTypeFetcher.data?.data]);
77+
}, [supplierTypeFetcher.data?.data, i18n]);
7578

7679
return options;
7780
};

apps/erp/app/components/Form/UnitOfMeasure.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ComboboxProps } from "@carbon/form";
22
import { CreatableCombobox } from "@carbon/form";
33
import { useDisclosure, useMount } from "@carbon/react";
4+
import { useLingui } from "@lingui/react/macro";
45
import { useMemo, useRef, useState } from "react";
56
import { useFetcher } from "react-router";
67
import { useRouteData } from "~/hooks";
@@ -10,6 +11,7 @@ import type {
1011
} from "~/modules/items";
1112
import UnitOfMeasureForm from "~/modules/items/ui/UnitOfMeasure/UnitOfMeasureForm";
1213
import { path } from "~/utils/path";
14+
import { translateSeedDisplayName } from "~/utils/seedDataDisplayName";
1315
import { Enumerable } from "../Enumerable";
1416

1517
type UnitOfMeasureSelectProps = Omit<ComboboxProps, "options" | "inline"> & {
@@ -28,6 +30,7 @@ const UnitOfMeasurePreview = (
2830
};
2931

3032
const UnitOfMeasure = (props: UnitOfMeasureSelectProps) => {
33+
const { t } = useLingui();
3134
const options = useUnitOfMeasure();
3235

3336
const newUnitOfMeasureModal = useDisclosure();
@@ -41,7 +44,7 @@ const UnitOfMeasure = (props: UnitOfMeasureSelectProps) => {
4144
options={options}
4245
{...props}
4346
inline={props.inline ? UnitOfMeasurePreview : undefined}
44-
label={props?.label ?? "Unit of Measure"}
47+
label={props?.label ?? t`Unit of Measure`}
4548
onCreateOption={(option) => {
4649
newUnitOfMeasureModal.onOpen();
4750
setCreated(option);
@@ -70,6 +73,7 @@ UnitOfMeasure.displayName = "UnitOfMeasure";
7073
export default UnitOfMeasure;
7174

7275
export const useUnitOfMeasure = () => {
76+
const { i18n } = useLingui();
7377
const uomFetcher =
7478
useFetcher<Awaited<ReturnType<typeof getUnitOfMeasuresList>>>();
7579

@@ -91,12 +95,13 @@ export const useUnitOfMeasure = () => {
9195

9296
return dataSource.map((c) => ({
9397
value: c.code,
94-
label: c.name
98+
label: translateSeedDisplayName(c.name, i18n)
9599
}));
96100
}, [
97101
hasSharedPartData,
98102
sharedPartData?.unitOfMeasures,
99-
uomFetcher.data?.data
103+
uomFetcher.data?.data,
104+
i18n
100105
]);
101106

102107
return options;

0 commit comments

Comments
 (0)