Skip to content

Commit dd41427

Browse files
committed
Added translations for the error that can come from project.ts
1 parent 5dc4c5b commit dd41427

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

src/i18n/locales/en/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
"COPY_ELLIPSIS": "Copy...",
7979
"MECHANISMS": "Mechanisms",
8080
"OPMODES": "OpModes",
81+
"INVALID_CLASS_NAME": "{{name}} is not a valid name. Please enter a different name.",
82+
"CLASS_NAME_ALREADY_EXISTS": "Another Mechanism or OpMode is already named {{name}}. Please enter a different name.",
8183
"THEME_MODAL": {
8284
"LIGHT": "Light Theme",
8385
"LIGHT_DESCRIPTION": "Clean and bright interface for daytime use",

src/i18n/locales/es/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
},
8080
"MECHANISMS": "Mecanismos",
8181
"OPMODES": "OpModes",
82+
"INVALID_CLASS_NAME": "{{name}} no es un nombre válido. Por favor ingrese un nombre diferente.",
83+
"CLASS_NAME_ALREADY_EXISTS": "Otro Mecanismo u OpMode ya se llama {{name}}. Por favor ingrese un nombre diferente.",
8284
"THEME_MODAL": {
8385
"LIGHT": "Tema Claro",
8486
"LIGHT_DESCRIPTION": "Interfaz limpia y brillante para uso diurno",

src/i18n/locales/he/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
"COPY_ELLIPSIS": "העתק...",
7979
"MECHANISMS": "מנגנונים",
8080
"OPMODES": "אופמודים",
81+
"INVALID_CLASS_NAME": "{{name}} אינו שם תקין. אנא הזן שם אחר.",
82+
"CLASS_NAME_ALREADY_EXISTS": "מנגנון או אופמוד אחר כבר נקרא {{name}}. אנא הזן שם אחר.",
8183
"THEME_MODAL": {
8284
"LIGHT": "ערכת נושא בהירה",
8385
"LIGHT_DESCRIPTION": "ממשק נקי ובהיר לשימוש ביום",

src/reactComponents/ClassNameComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function ClassNameComponent(props: ClassNameComponentProps): Reac
6666
return;
6767
}
6868

69-
const {ok, error} = storageProject.isClassNameOk(props.project, newClassName);
69+
const {ok, error} = storageProject.isClassNameOk(props.project, newClassName, t);
7070
if (ok) {
7171
clearError();
7272
props.onAddNewItem();

src/storage/project.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,19 @@ export async function copyModuleInProject(
322322
* Checks if the proposed class name is valid and does not conflict with existing names in the project.
323323
* @param project The project to check against.
324324
* @param proposedClassName The proposed class name to validate.
325+
* @param t Translation function for internationalized error messages.
325326
* @returns An object containing a boolean `ok` indicating if the name is valid, and an `error` message if it is not.
326327
*/
327-
export function isClassNameOk(project: Project, proposedClassName: string) {
328+
export function isClassNameOk(project: Project, proposedClassName: string, t: (key: string, params?: any) => string) {
328329
let ok = true;
329330
let error = '';
330331

331332
if (!storageNames.isValidClassName(proposedClassName)) {
332333
ok = false;
333-
error = proposedClassName + ' is not a valid name. Please enter a different name.';
334+
error = t('INVALID_CLASS_NAME', { name: proposedClassName });
334335
} else if (findModuleByClassName(project, proposedClassName) != null) {
335336
ok = false;
336-
error = 'Another Mechanism or OpMode is already named ' + proposedClassName + '. Please enter a different name.'
337+
error = t('CLASS_NAME_ALREADY_EXISTS', { name: proposedClassName });
337338
}
338339

339340
return {

0 commit comments

Comments
 (0)