diff --git a/i18n/ar/command.json b/i18n/ar/command.json new file mode 100644 index 0000000..e15e643 --- /dev/null +++ b/i18n/ar/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "إنشاء ملاحظة جديدة (بتاريخ اليوم)" +} diff --git a/i18n/ar/notice.json b/i18n/ar/notice.json new file mode 100644 index 0000000..0a1be4a --- /dev/null +++ b/i18n/ar/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "الملف {filename} موجود بالفعل.", + "FILE_CREATED": "تم إنشاء الملف {filename}.", + "FOLDER_NOT_FOUND": "تعذر العثور على مجلد الملف الحالي.", + "ERROR_CREATING_FILE": "خطأ في إنشاء الملف: {error}" +} diff --git a/i18n/en.json b/i18n/en.json deleted file mode 100644 index 6e4b6a3..0000000 --- a/i18n/en.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "COMMANDS": { "CREATE_TODAY_NOTE": "Create New Note (Today's Date)" }, - "NOTICES": { - "FILE_EXISTS": "File {filename} already exists.", - "FILE_CREATED": "File {filename} has been created.", - "FOLDER_NOT_FOUND": "Could not find the current file's folder.", - "ERROR_CREATING_FILE": "Error creating file: {error}" - } -} diff --git a/i18n/en/command.json b/i18n/en/command.json new file mode 100644 index 0000000..505d3b7 --- /dev/null +++ b/i18n/en/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "Create New Note (Today's Date)" +} diff --git a/i18n/en/notice.json b/i18n/en/notice.json new file mode 100644 index 0000000..386292b --- /dev/null +++ b/i18n/en/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "File {filename} already exists.", + "FILE_CREATED": "File {filename} has been created.", + "FOLDER_NOT_FOUND": "Could not find the current file's folder.", + "ERROR_CREATING_FILE": "Error creating file: {error}" +} diff --git a/i18n/es-ES/command.json b/i18n/es-ES/command.json new file mode 100644 index 0000000..909942e --- /dev/null +++ b/i18n/es-ES/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "Crear Nueva Nota (Fecha de Hoy)" +} diff --git a/i18n/es-ES/notice.json b/i18n/es-ES/notice.json new file mode 100644 index 0000000..334b57b --- /dev/null +++ b/i18n/es-ES/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "El archivo {filename} ya existe.", + "FILE_CREATED": "El archivo {filename} ha sido creado.", + "FOLDER_NOT_FOUND": "No se pudo encontrar la carpeta del archivo actual.", + "ERROR_CREATING_FILE": "Error al crear el archivo: {error}" +} diff --git a/i18n/ja/command.json b/i18n/ja/command.json new file mode 100644 index 0000000..a888137 --- /dev/null +++ b/i18n/ja/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "新規ノート作成(今日の日付)" +} diff --git a/i18n/ja/notice.json b/i18n/ja/notice.json new file mode 100644 index 0000000..871c52e --- /dev/null +++ b/i18n/ja/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "ファイル {filename} はすでに存在します。", + "FILE_CREATED": "ファイル {filename} が作成されました。", + "FOLDER_NOT_FOUND": "現在のファイルのフォルダが見つかりませんでした。", + "ERROR_CREATING_FILE": "ファイル作成エラー: {error}" +} diff --git a/i18n/ko.json b/i18n/ko.json deleted file mode 100644 index 8d0107d..0000000 --- a/i18n/ko.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "COMMANDS": { "CREATE_TODAY_NOTE": "새 노트 생성 (오늘 날짜)" }, - "NOTICES": { - "FILE_EXISTS": "{filename} 파일이 이미 존재합니다.", - "FILE_CREATED": "{filename} 파일이 생성되었습니다.", - "FOLDER_NOT_FOUND": "현재 파일의 폴더를 찾을 수 없습니다.", - "ERROR_CREATING_FILE": "파일 생성 중 오류가 발생했습니다: {error}" - } -} diff --git a/i18n/ko/command.json b/i18n/ko/command.json new file mode 100644 index 0000000..8ca1d56 --- /dev/null +++ b/i18n/ko/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "새 노트 생성 (오늘 날짜)" +} diff --git a/i18n/ko/notice.json b/i18n/ko/notice.json new file mode 100644 index 0000000..d829ecc --- /dev/null +++ b/i18n/ko/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "파일 {filename}이(가) 이미 존재합니다.", + "FILE_CREATED": "파일 {filename}이(가) 생성되었습니다.", + "FOLDER_NOT_FOUND": "현재 파일의 폴더를 찾을 수 없습니다.", + "ERROR_CREATING_FILE": "파일 생성 오류: {error}" +} diff --git a/i18n/zh-CN/command.json b/i18n/zh-CN/command.json new file mode 100644 index 0000000..22ecb81 --- /dev/null +++ b/i18n/zh-CN/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "创建新笔记(今日日期)" +} diff --git a/i18n/zh-CN/notice.json b/i18n/zh-CN/notice.json new file mode 100644 index 0000000..cbac7c2 --- /dev/null +++ b/i18n/zh-CN/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "文件 {filename} 已存在。", + "FILE_CREATED": "文件 {filename} 已创建。", + "FOLDER_NOT_FOUND": "无法找到当前文件的文件夹。", + "ERROR_CREATING_FILE": "创建文件时出错:{error}" +} diff --git a/i18n/zh-TW/command.json b/i18n/zh-TW/command.json new file mode 100644 index 0000000..dbd2f10 --- /dev/null +++ b/i18n/zh-TW/command.json @@ -0,0 +1,3 @@ +{ + "CREATE_TODAY_NOTE": "建立新筆記(今日日期)" +} diff --git a/i18n/zh-TW/notice.json b/i18n/zh-TW/notice.json new file mode 100644 index 0000000..6dc69e2 --- /dev/null +++ b/i18n/zh-TW/notice.json @@ -0,0 +1,6 @@ +{ + "FILE_EXISTS": "檔案 {filename} 已經存在。", + "FILE_CREATED": "檔案 {filename} 已建立。", + "FOLDER_NOT_FOUND": "找不到目前檔案的資料夾。", + "ERROR_CREATING_FILE": "建立檔案時發生錯誤:{error}" +} diff --git a/main.ts b/main.ts index 8fb38a8..d4924b2 100644 --- a/main.ts +++ b/main.ts @@ -1,8 +1,72 @@ import { App, Editor, MarkdownView, Modal, Notice, Plugin, TFile, TAbstractFile } from 'obsidian'; import * as moment from 'moment'; // Import JSON files directly -import koTranslations from './i18n/ko.json'; -import enTranslations from './i18n/en.json'; +// Import translations +import arCommand from './i18n/ar/command.json'; +import arNotice from './i18n/ar/notice.json'; +import enCommand from './i18n/en/command.json'; +import enNotice from './i18n/en/notice.json'; +import esCommand from './i18n/es-ES/command.json'; +import esNotice from './i18n/es-ES/notice.json'; +import jaCommand from './i18n/ja/command.json'; +import jaNotice from './i18n/ja/notice.json'; +import koCommand from './i18n/ko/command.json'; +import koNotice from './i18n/ko/notice.json'; +import zhCNCommand from './i18n/zh-CN/command.json'; +import zhCNNotice from './i18n/zh-CN/notice.json'; +import zhTWCommand from './i18n/zh-TW/command.json'; +import zhTWNotice from './i18n/zh-TW/notice.json'; + +type TranslationData = { + COMMANDS: typeof enCommand; + NOTICES: typeof enNotice; +}; + +type TranslationsMap = { + [key: string]: TranslationData; +}; + +// Language code mapping +const LANG_CODE_MAP: { [key: string]: string } = { + 'ar': 'ar', + 'en': 'en', + 'es-ES': 'es', + 'ja': 'ja', + 'ko': 'ko', + 'zh-CN': 'zh', + 'zh-TW': 'zh-TW' +}; + +const translations: TranslationsMap = { + ar: { + COMMANDS: arCommand, + NOTICES: arNotice + }, + en: { + COMMANDS: enCommand, + NOTICES: enNotice + }, + es: { + COMMANDS: esCommand, + NOTICES: esNotice + }, + ja: { + COMMANDS: jaCommand, + NOTICES: jaNotice + }, + ko: { + COMMANDS: koCommand, + NOTICES: koNotice + }, + zh: { + COMMANDS: zhCNCommand, + NOTICES: zhCNNotice + }, + 'zh-TW': { + COMMANDS: zhTWCommand, + NOTICES: zhTWNotice + } +}; interface Translations { COMMANDS: { @@ -19,11 +83,12 @@ interface Translations { export default class KarsPlugin extends Plugin { getText(key: string, vars: Record = {}): string { // Get language setting from localStorage - const language = window.localStorage.getItem('language') || 'en'; - const translations = language === 'ko' ? koTranslations : enTranslations; + const rawLanguage = window.localStorage.getItem('language') || 'en'; + const language = LANG_CODE_MAP[rawLanguage] || rawLanguage; + const currentTranslations = translations[language] || translations.en; const keys = key.split('.'); - let value: any = translations; + let value: any = currentTranslations; for (const k of keys) { if (!value || !value[k]) return key; value = value[k];