Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 37fd586

Browse files
committed
starting some translations
1 parent 294a5b1 commit 37fd586

File tree

7 files changed

+72
-25
lines changed

7 files changed

+72
-25
lines changed

src/components/modals/addRow/handlers/FilenameTextHandler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { AddRowModalHandlerResponse } from "cdm/ModalsModel";
2+
import { t } from "lang/helpers";
23
import { Setting } from "obsidian";
34
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
45

56
export class FilenameTextHandler extends AbstractHandlerClass<AddRowModalHandlerResponse> {
6-
settingTitle: string = "Filename";
7+
settingTitle: string = t("add_row_modal_filename_text_title");
78
textElId: string = "AddRowModalManager-addRow-input";
89
handle(
910
response: AddRowModalHandlerResponse
@@ -29,7 +30,7 @@ export class FilenameTextHandler extends AbstractHandlerClass<AddRowModalHandler
2930
**************/
3031
new Setting(containerEl)
3132
.setName(this.settingTitle)
32-
.setDesc("Filename associated with the new row")
33+
.setDesc(t("add_row_modal_filename_text_desc"))
3334
.addText(text => {
3435
text.inputEl.setAttribute("id", this.textElId);
3536
text.inputEl.onkeydown = (e: KeyboardEvent) => {
@@ -39,7 +40,7 @@ export class FilenameTextHandler extends AbstractHandlerClass<AddRowModalHandler
3940
break;
4041
}
4142
};
42-
text.setPlaceholder("Enter filename")
43+
text.setPlaceholder(t("add_row_modal_filename_text_placeholder"))
4344
.setValue(newFilename)
4445
.onChange(async (value: string): Promise<void> => {
4546
newFilename = value;
@@ -48,7 +49,7 @@ export class FilenameTextHandler extends AbstractHandlerClass<AddRowModalHandler
4849
.addButton((button) => {
4950
button
5051
.setIcon("create-new")
51-
.setTooltip("Add new row")
52+
.setTooltip(t("add_row_modal_filename_text_button_tooltip"))
5253
.onClick(addNewRowPromise);
5354
});
5455
return this.goNext(response);

src/components/modals/addRow/handlers/TemplateDropdownHandler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { AddRowModalHandlerResponse } from "cdm/ModalsModel";
2+
import { t } from "lang/helpers";
23
import { Setting } from "obsidian";
34
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
45
import { StringSuggest } from "settings/suggesters/StringSuggester";
56

67
export class TemplateDropdownHandler extends AbstractHandlerClass<AddRowModalHandlerResponse> {
7-
settingTitle: string = "Row Template";
8+
settingTitle: string = t("add_row_modal_template_dropdown_title");
89
handle(
910
response: AddRowModalHandlerResponse
1011
): AddRowModalHandlerResponse {
@@ -25,13 +26,13 @@ export class TemplateDropdownHandler extends AbstractHandlerClass<AddRowModalHan
2526

2627
new Setting(containerEl)
2728
.setName(this.settingTitle)
28-
.setDesc('Select from the existing templates to create a new row. The list is related with template folder setting. Leave empty to create an empty file.')
29+
.setDesc(t('add_row_modal_template_dropdown_desc'))
2930
.addSearch((cb) => {
3031
new StringSuggest(
3132
cb.inputEl,
3233
avaliableOptions
3334
);
34-
cb.setPlaceholder("Select a template...")
35+
cb.setPlaceholder(t("add_row_modal_template_dropdown_placeholder"))
3536
.setValue(rowTemplate.template)
3637
.onChange(updateTemplatHandler);
3738

src/components/modals/newColumn/addColumnModal.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { add_setting_header } from "settings/SettingsComponents";
66
import { select_new_column_section } from "components/modals/newColumn/SelectNewColumnSection";
77
import { c } from "helpers/StylesHelper";
88
import { applyPluginModalStyle } from "components/styles/ModalStyles";
9+
import { t } from "lang/helpers";
910

1011
export class AddColumnModal extends Modal {
1112
view: DatabaseView;
@@ -49,7 +50,7 @@ export class AddColumnModalManager {
4950
/** Common modal headings */
5051
containerEl.addClass(c(StyleClasses.ADD_COLUMN_MODAL));
5152
applyPluginModalStyle(containerEl);
52-
add_setting_header(containerEl, `Columns menu`, 'h2');
53+
add_setting_header(containerEl, t("add_row_modal_section_title"), 'h2');
5354

5455
const addColumnBody = containerEl.createDiv();
5556
addColumnBody.setAttribute("id", StyleClasses.ADD_COLUMN_MODAL_BODY);

src/components/modals/newColumn/handlers/AddEmptyColumnHandler.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Notice, Setting } from "obsidian";
55
import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
66

77
export class AddEmptyColumnHandler extends AbstractHandlerClass<AddColumnModalHandlerResponse> {
8-
settingTitle: string = "Add empty column";
8+
settingTitle: string = t("add_row_modal_add_empty_column_title");
99
textElId: string = "SettingsModalManager-addEmptyColumn-input";
1010
handle(
1111
response: AddColumnModalHandlerResponse
@@ -25,7 +25,11 @@ export class AddEmptyColumnHandler extends AbstractHandlerClass<AddColumnModalHa
2525
isEmpty ? undefined : newColumnName,
2626
typeOfNewColumn ? typeOfNewColumn : DynamicInputType.TEXT
2727
);
28-
new Notice(isEmpty ? "New column added" : `"${newColumnName}" added to the table`, 1500);
28+
new Notice(
29+
isEmpty ?
30+
t("add_row_modal_add_empty_notice_empty") :
31+
t("add_row_modal_add_empty_notice_informed", newColumnName),
32+
1500);
2933
(activeDocument.getElementById(this.textElId) as HTMLInputElement).value = "";
3034
}
3135

@@ -38,7 +42,7 @@ export class AddEmptyColumnHandler extends AbstractHandlerClass<AddColumnModalHa
3842
**************/
3943
new Setting(containerEl)
4044
.setName(this.settingTitle)
41-
.setDesc("Add a new column which do not exist yet in any row")
45+
.setDesc(t("add_row_modal_add_empty_column_desc"))
4246
.addText(text => {
4347
text.inputEl.setAttribute("id", this.textElId);
4448
text.inputEl.onkeydown = (e: KeyboardEvent) => {
@@ -48,7 +52,7 @@ export class AddEmptyColumnHandler extends AbstractHandlerClass<AddColumnModalHa
4852
break;
4953
}
5054
};
51-
text.setPlaceholder("Column name")
55+
text.setPlaceholder(t("add_row_modal_add_empty_column_placeholder"))
5256
.setValue(newColumnName)
5357
.onChange(async (value: string): Promise<void> => {
5458
newColumnName = value;
@@ -62,7 +66,7 @@ export class AddEmptyColumnHandler extends AbstractHandlerClass<AddColumnModalHa
6266
.addExtraButton((button) => {
6367
button
6468
.setIcon("create-new")
65-
.setTooltip("Add new column")
69+
.setTooltip(t("add_row_modal_add_empty_column_button_tooltip"))
6670
.onClick(addNewColumnPromise);
6771
});
6872
return this.goNext(response);

src/components/modals/newColumn/handlers/AddExistingColumnHandler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AbstractHandlerClass } from "patterns/chain/AbstractHandler";
88
import { StringSuggest } from "settings/suggesters/StringSuggester";
99

1010
export class AddExistingColumnHandler extends AbstractHandlerClass<AddColumnModalHandlerResponse> {
11-
settingTitle: string = 'Add existing column';
11+
settingTitle: string = t("add_row_modal_add_existing_column_title");
1212
handle(response: AddColumnModalHandlerResponse): AddColumnModalHandlerResponse {
1313
const { containerEl, addColumnModalManager } = response;
1414
const { configState, columnState } = addColumnModalManager.props;
@@ -44,14 +44,14 @@ export class AddExistingColumnHandler extends AbstractHandlerClass<AddColumnModa
4444
filteredColumns[columnName] = columnName;
4545
});
4646
new Setting(containerEl)
47-
.setName('Select an existing column to add')
48-
.setDesc('Select an existing column to add not included yet in the table')
47+
.setName(this.settingTitle)
48+
.setDesc(t("add_row_modal_add_existing_column_desc"))
4949
.addSearch((cb) => {
5050
new StringSuggest(
5151
cb.inputEl,
5252
filteredColumns
5353
);
54-
cb.setPlaceholder("Search column...")
54+
cb.setPlaceholder(t("add_row_modal_add_existing_column_placeholder"))
5555
.setValue(selectedColumn)
5656
.onChange((value: string) => {
5757
selectedColumn = value;
@@ -65,10 +65,10 @@ export class AddExistingColumnHandler extends AbstractHandlerClass<AddColumnModa
6565
})
6666
.addExtraButton((cb) => {
6767
cb.setIcon("create-new")
68-
.setTooltip("Create the selected column and refresh the table")
68+
.setTooltip(t("add_row_modal_add_existing_column_button_tooltip"))
6969
.onClick(async (): Promise<void> => {
7070
if (!selectedColumn || filteredColumns[selectedColumn] === undefined) {
71-
new Notice("You need to select a column to add", 1500);
71+
new Notice(t("add_row_modal_add_existing_notice_error_empty"), 1500);
7272
return;
7373
}
7474
columnState.actions.addToLeft(
@@ -79,7 +79,7 @@ export class AddExistingColumnHandler extends AbstractHandlerClass<AddColumnModa
7979
addColumnModalManager.addColumnModal.enableReset = true;
8080
// Refresh the modal to remove the selected column from the dropdown
8181
addColumnModalManager.reset(response);
82-
new Notice(`"${selectedColumn}" added to the table`, 1500);
82+
new Notice(t("add_row_modal_add_existing_notice_correct", selectedColumn), 1500);
8383

8484
});
8585
});

src/lang/helpers.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,25 @@ const localeMap: { [k: string]: Partial<typeof en> } = {
5454
const lang = localStorage.getItem('language');
5555
const locale = localeMap[lang || 'en'];
5656

57-
export function t(str: keyof typeof en): string {
57+
/**
58+
* Translate a string to the current language or English if not found.
59+
*
60+
* You can pass in arguments to replace in the string using {0}, {1}, etc.
61+
* @param str
62+
* @param args
63+
* @returns
64+
*/
65+
export function t(str: keyof typeof en, ...args: string[]): string {
5866
if (!locale) {
5967
LOGGER.error('Error: database locale not found', lang);
6068
}
69+
const translated = (locale && locale[str]) || en[str];
6170

62-
return (locale && locale[str]) || en[str] || str;
71+
if (!translated) {
72+
LOGGER.warn('String key not found in locale', str);
73+
return str;
74+
}
75+
76+
// Replace any arguments in the string
77+
return args.reduce((acc, arg, i) => acc.replace(`{${i}}`, arg), translated);
6378
}

src/lang/locale/en.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,36 @@ export default {
6666
"inlinks": "Inlinks",
6767
"outlinks": "Outlinks",
6868
"new_column": "New column",
69-
/** MODALS */
70-
"confirm_modal_ok": "Yes",
71-
"confirm_modal_ko": "No",
7269
/** NEW INLINE PROPERTIES POSITION */
7370
"top": "Top",
7471
"bottom": "Bottom",
7572
"last_field": "Last field",
73+
/******************************************
74+
* MODALS
75+
******************************************/
76+
/** CONFIRM MODAL */
77+
"confirm_modal_ok": "Yes",
78+
"confirm_modal_ko": "No",
79+
/** ADD ROW MODAL */
80+
"add_row_modal_filename_text_title": "Filename",
81+
"add_row_modal_filename_text_desc": "Filename associated with the new row",
82+
"add_row_modal_filename_text_placeholder": "Enter filename",
83+
"add_row_modal_filename_text_button_tooltip": "Add new row",
84+
"add_row_modal_template_dropdown_title": "Row Template",
85+
"add_row_modal_template_dropdown_desc": "Select from the existing templates to create a new row. The list is related with template folder setting. Leave empty to create an empty file.",
86+
"add_row_modal_template_dropdown_placeholder": "Select a template...",
87+
/** ADD COLUMN MODAL */
88+
"add_row_modal_section_title": "Columns menu",
89+
"add_row_modal_add_empty_column_title": "Add empty column",
90+
"add_row_modal_add_empty_column_desc": "Add a new column which do not exist yet in any row",
91+
"add_row_modal_add_empty_column_placeholder": "Column name",
92+
"add_row_modal_add_empty_column_button_tooltip": "Add new column",
93+
"add_row_modal_add_empty_notice_empty": "New column added",
94+
"add_row_modal_add_empty_notice_informed": "{0} added to the table",
95+
"add_row_modal_add_existing_column_title": "Select an existing column to add",
96+
"add_row_modal_add_existing_column_desc": "Select an existing column to add not included yet in the table",
97+
"add_row_modal_add_existing_column_placeholder": "Search column...",
98+
"add_row_modal_add_existing_column_button_tooltip": "Create the selected column and refresh the table",
99+
"add_row_modal_add_existing_notice_error_empty": "You need to select a column to add",
100+
"add_row_modal_add_existing_notice_correct": "{0} added to the table",
76101
};

0 commit comments

Comments
 (0)