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

feat(i18n): localize siderbar and serp widgets #148

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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
3 changes: 1 addition & 2 deletions client/src/generated/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ model/instrument-type.ts
model/jwt-response.ts
model/list-favorite-response.ts
model/manufacture-date.ts
model/manufacturer-name.ts
model/manufacturer.ts
model/manufacture-type.ts
model/profile-details.ts
model/registration-request.ts
model/release-date.ts
Expand Down
8 changes: 7 additions & 1 deletion client/src/generated/model/basic-material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ export interface BasicMaterial {
* @type {string}
* @memberof BasicMaterial
*/
basic_material: string;
i18n_code: string;
/**
*
* @type {string}
* @memberof BasicMaterial
*/
localized_text?: string;
}
8 changes: 7 additions & 1 deletion client/src/generated/model/country.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ export interface Country {
* @type {string}
* @memberof Country
*/
country: string;
i18n_code: string;
/**
*
* @type {string}
* @memberof Country
*/
localized_text?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { InstrumentType } from "./instrument-type";
import type { ManufactureDate } from "./manufacture-date";
// May contain unused imports in some cases
// @ts-ignore
import type { ManufacturerName } from "./manufacturer-name";
import type { ManufactureType } from "./manufacture-type";
// May contain unused imports in some cases
// @ts-ignore
import type { ReleaseDate } from "./release-date";
Expand All @@ -57,10 +57,10 @@ export interface GetInstrumentsByCriteriaRequestBody {
instrument_types?: Array<InstrumentType> | null;
/**
*
* @type {Array<ManufacturerName>}
* @type {Array<ManufactureType>}
* @memberof GetInstrumentsByCriteriaRequestBody
*/
manufacturer_names?: Array<ManufacturerName> | null;
manufacturer_types?: Array<ManufactureType> | null;
/**
*
* @type {ManufactureDate}
Expand Down
6 changes: 3 additions & 3 deletions client/src/generated/model/get-manufacturers-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// May contain unused imports in some cases
// @ts-ignore
import type { Manufacturer } from "./manufacturer";
import type { ManufactureType } from "./manufacture-type";

/**
*
Expand All @@ -24,8 +24,8 @@ import type { Manufacturer } from "./manufacturer";
export interface GetManufacturersResponse {
/**
*
* @type {Array<Manufacturer>}
* @type {Array<ManufactureType>}
* @memberof GetManufacturersResponse
*/
content: Array<Manufacturer>;
content: Array<ManufactureType>;
}
3 changes: 1 addition & 2 deletions client/src/generated/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export * from "./instrument-type";
export * from "./jwt-response";
export * from "./list-favorite-response";
export * from "./manufacture-date";
export * from "./manufacturer";
export * from "./manufacturer-name";
export * from "./manufacture-type";
export * from "./profile-details";
export * from "./registration-request";
export * from "./release-date";
Expand Down
6 changes: 3 additions & 3 deletions client/src/generated/model/instrument-detail-without-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { InstrumentType } from "./instrument-type";
import type { ManufactureDate } from "./manufacture-date";
// May contain unused imports in some cases
// @ts-ignore
import type { ManufacturerName } from "./manufacturer-name";
import type { ManufactureType } from "./manufacture-type";
// May contain unused imports in some cases
// @ts-ignore
import type { ReleaseDate } from "./release-date";
Expand All @@ -54,10 +54,10 @@ export interface InstrumentDetailWithoutId {
instrument_type: InstrumentType;
/**
*
* @type {ManufacturerName}
* @type {ManufactureType}
* @memberof InstrumentDetailWithoutId
*/
manufacturer_name: ManufacturerName;
manufacturer_type: ManufactureType;
/**
*
* @type {ManufactureDate}
Expand Down
6 changes: 3 additions & 3 deletions client/src/generated/model/instrument-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { InstrumentType } from "./instrument-type";
import type { ManufactureDate } from "./manufacture-date";
// May contain unused imports in some cases
// @ts-ignore
import type { ManufacturerName } from "./manufacturer-name";
import type { ManufactureType } from "./manufacture-type";
// May contain unused imports in some cases
// @ts-ignore
import type { ReleaseDate } from "./release-date";
Expand Down Expand Up @@ -63,10 +63,10 @@ export interface InstrumentDetail {
instrument_type: InstrumentType;
/**
*
* @type {ManufacturerName}
* @type {ManufactureType}
* @memberof InstrumentDetail
*/
manufacturer_name: ManufacturerName;
manufacturer_type: ManufactureType;
/**
*
* @type {ManufactureDate}
Expand Down
2 changes: 1 addition & 1 deletion client/src/generated/model/instrument-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface InstrumentType {
* @type {string}
* @memberof InstrumentType
*/
code: string;
i18n_code: string;
/**
*
* @type {string}
Expand Down
27 changes: 0 additions & 27 deletions client/src/generated/model/manufacturer-name.ts

This file was deleted.

27 changes: 0 additions & 27 deletions client/src/generated/model/manufacturer.ts

This file was deleted.

17 changes: 9 additions & 8 deletions client/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { initReactI18next } from "react-i18next";

export const I18N_INSTRUMENT_TYPE_FILTER = "instrument.type.filter";
export const I18N_INSTRUMENT_CARD_MANUFACTURER = "instrument.card.manufacturer";
export const I18N_MANUFACTURER_DATE = "instrument.manufacturer.manufacture.date";
export const I18N_RELEASE_DATE = "instrument.manufacturer.release.date"
export const I18N_MANUFACTURER_DATE =
"instrument.manufacturer.manufacture.date";
export const I18N_RELEASE_DATE = "instrument.manufacturer.release.date";
export const I18N_COUNTRY = "country";
export const I18N_INSTRUMENT_BASIC_MATERIALS = "instrument.basic.materials";
export const I18N_INSTRUMENT_DATE_FROM = "instrument.date.from";
Expand All @@ -21,7 +22,7 @@ const resources = {
[I18N_INSTRUMENT_BASIC_MATERIALS]: "Basic Materials",
[I18N_INSTRUMENT_DATE_FROM]: "From",
[I18N_INSTRUMENT_DATE_TO]: "To",
}
},
},
ru: {
translation: {
Expand All @@ -33,8 +34,8 @@ const resources = {
[I18N_INSTRUMENT_BASIC_MATERIALS]: "Основные материалы",
[I18N_INSTRUMENT_DATE_FROM]: "С",
[I18N_INSTRUMENT_DATE_TO]: "По",
}
}
},
},
};

i18n
Expand All @@ -43,8 +44,8 @@ i18n
resources,
lng: window.navigator.language,
interpolation: {
escapeValue: false // react already safes from xss
}
escapeValue: false, // react already safes from xss
},
});

export default i18n;
export default i18n;
7 changes: 4 additions & 3 deletions client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import App from "./app/App";
import { ThemeProvider } from "shared/dark-mode/use-dark-mode";

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
document.getElementById("root") as HTMLElement,
);
root.render(
<ThemeProvider>
<React.StrictMode>
<App />
</React.StrictMode>,
</ThemeProvider>
</React.StrictMode>
,
</ThemeProvider>,
);
4 changes: 2 additions & 2 deletions client/src/pages/catalogue/api/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const loader = async (): Promise<CatalogueLoader> => {
{
instrument_name: null,
instrument_types: null,
manufacturer_names: null,
manufacturer_types: null,
manufacture_date_from: null,
manufacture_date_to: null,
release_date_from: null,
Expand All @@ -39,7 +39,7 @@ export const loader = async (): Promise<CatalogueLoader> => {
defaultFilter: {
instrumentName: null,
instrumentTypes: null,
manufacturerNames: null,
manufacturerTypes: null,
manufactureDateFrom: null,
manufactureDateTo: null,
releaseDateFrom: null,
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/catalogue/ui/Catalogue.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function CataloguePage() {
{
instrument_name: filters.instrumentName,
instrument_types: filters.instrumentTypes,
manufacturer_names: filters.manufacturerNames,
manufacturer_types: filters.manufacturerTypes,
manufacture_date_from: filters.manufactureDateFrom,
manufacture_date_to: filters.manufactureDateTo,
release_date_from: filters.releaseDateFrom,
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/create-instrument/api/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const action: ActionFunction = async ({
const {
instrumentName,
instrumentType,
manufacturerName,
manufactureType,
manufactureDate,
releaseDate,
country,
Expand All @@ -36,7 +36,7 @@ export const action: ActionFunction = async ({
instrument_detail: {
instrument_name: instrumentName,
instrument_type: instrumentType,
manufacturer_name: manufacturerName,
manufacturer_type: manufactureType,
manufacturer_date: manufactureDate,
release_date: releaseDate,
country: country,
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/create-instrument/api/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
Country,
BasicMaterial,
InstrumentType,
Manufacturer,
ManufactureType,
} from "generated/model";
import { GetInstrumentBasicMaterialsApi } from "generated/api/get-instrument-basic-materials-api";
import { GetCountriesApi } from "generated/api";
Expand All @@ -20,7 +20,7 @@ const getManufacturers = new GetManufacturersApi(apiConfig);

export interface CreateInstrumentLoader {
instrumentTypes: InstrumentType[];
manufacturers: Manufacturer[];
manufacturerTypes: ManufactureType[];
materials: BasicMaterial[];
countries: Country[];
}
Expand All @@ -39,7 +39,7 @@ export const loader: LoaderFunction =

return {
instrumentTypes: instrumentTypesRequest.data.content,
manufacturers: manufacturersRequest.data.content,
manufacturerTypes: manufacturersRequest.data.content,
materials: instrumentBasicMaterialsRequest.data.content,
countries: countriesRequest.data.content,
};
Expand Down
27 changes: 14 additions & 13 deletions client/src/pages/create-instrument/ui/CreateInstrument.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { FooterWidget } from "widgets/footer";
import { Form, useActionData, useLoaderData } from "react-router-dom";
import { CreateInstrumentLoader } from "pages/create-instrument";
import { CreateInstrumentAction } from "pages/create-instrument/api/action";
import { I18N_COUNTRY, I18N_MANUFACTURER_DATE, I18N_RELEASE_DATE } from "../../../i18n";
import {
I18N_COUNTRY,
I18N_MANUFACTURER_DATE,
I18N_RELEASE_DATE,
} from "../../../i18n";
import { useTranslation } from "react-i18next";

export const CreateInstrumentPage = () => {
Expand Down Expand Up @@ -51,7 +55,7 @@ export const CreateInstrumentPage = () => {
>
{loader.instrumentTypes.map((instrumentType) => (
<option
key={instrumentType.code}
key={instrumentType.i18n_code}
value={instrumentType.localized_text}
>
{instrumentType.localized_text}
Expand All @@ -72,12 +76,12 @@ export const CreateInstrumentPage = () => {
className={styles.create_instrument__form__field__value}
required
>
{loader.manufacturers.map((manufacturer) => (
{loader.manufacturerTypes.map((manufacturer) => (
<option
key={manufacturer.manufacturer}
value={manufacturer.manufacturer}
key={manufacturer.i18n_code}
value={manufacturer.localized_message}
>
{manufacturer.manufacturer}
{manufacturer.localized_message}
</option>
))}
</select>
Expand Down Expand Up @@ -133,8 +137,8 @@ export const CreateInstrumentPage = () => {
required
>
{loader.countries.map((country) => (
<option key={country.country} value={country.country}>
{country.country}
<option key={country.i18n_code} value={country.localized_text}>
{country.localized_text}
</option>
))}
</select>
Expand All @@ -154,11 +158,8 @@ export const CreateInstrumentPage = () => {
required
>
{loader.materials.map((material) => (
<option
key={material.basic_material}
value={material.basic_material}
>
{material.basic_material}
<option key={material.i18n_code} value={material.localized_text}>
{material.localized_text}
</option>
))}
</select>
Expand Down
Loading
Loading