mirror of
https://github.com/vrabe/obsidian-cjk-count.git
synced 2026-07-22 05:49:45 +00:00
Add translations
This commit is contained in:
parent
fae1918c32
commit
430db322d8
3 changed files with 20 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ A word count Obsidian plugin that only counts Chinese, Japanese and Korean (CJK)
|
|||
|
||||
## Limitation
|
||||
|
||||
No translation currently. It only displays Chinese.
|
||||
We only have English and Chinese UI now in `src/i18n.js` with a very simple localization framework(?).
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
|
|
|
|||
13
src/i18n.js
Normal file
13
src/i18n.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const translation = {
|
||||
en: {
|
||||
characters: "characters",
|
||||
},
|
||||
zh: {
|
||||
characters: "字",
|
||||
},
|
||||
"zh-TW": {
|
||||
characters: "字",
|
||||
},
|
||||
};
|
||||
|
||||
export default translation;
|
||||
|
|
@ -1,12 +1,15 @@
|
|||
import { MarkdownView, Plugin } from "obsidian";
|
||||
import { MarkdownView, Plugin, getLanguage } from "obsidian";
|
||||
import { lettersRegExp } from "cjk-regex-compact";
|
||||
import translation from "./i18n";
|
||||
|
||||
const translatedText = translation[getLanguage()] ?? translation["en"];
|
||||
|
||||
export default class CJKCountPlugin extends Plugin {
|
||||
#statusBarItemEl;
|
||||
|
||||
async onload() {
|
||||
this.#statusBarItemEl = this.addStatusBarItem();
|
||||
this.#statusBarItemEl.setText("0 字");
|
||||
this.#statusBarItemEl.setText(`0 ${translatedText.characters}`);
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("file-open", () => {
|
||||
|
|
@ -29,6 +32,6 @@ export default class CJKCountPlugin extends Plugin {
|
|||
characterCount = characters ? characters.length : 0;
|
||||
}
|
||||
|
||||
this.#statusBarItemEl.setText(`${characterCount} 字`);
|
||||
this.#statusBarItemEl.setText(`${characterCount} ${translatedText.characters}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue