Use case or problem
There are some common libraries that Obsidian uses that would be great if plugin developers had access to as well. It was mentioned that moment
is available, but there’s these that spring to mind (would love to hear more in the comments):
i18next
: For localization of plugin UI text.
- whatever lib Obsidian uses for drag-and-drop UI, if there is one (
SortableJS
?)
Has there been thinking on exposing other libraries aside from moment
that Obsidian uses, that plugin devs could make use of?
Proposed solution
Allow i18next
(and other libraries) to be importable from Obsidian.
Current workaround (optional)
i18next
: I amended Obsidian’s types to expose this object. (Example in comment below.)
- drag-and-drop UI: I’ve added
SortableJS
as a dependency.
1 Like
Literally within days of externalizing my UI’s strings thanks to i18next
, and providing some instructions, I had three contributors translate my plugin to Chinese (Simplified), German, and Ukrainian.
Here’s how easy it was to add localization to my plugin’s UI:
// in types.d.ts
declare global {
// provides access to Obsidian's translation framework
var i18next: any;
}
...
// in my plugin onload()
i18next.addResourceBundle('en', 'plugin-note-toolbar', {
hello: 'Hello!'
});
i18next.addResourceBundle('es', 'plugin-note-toolbar', {
hello: 'Hola!'
});
...
// in my settings UI
const t = i18next.getFixedT(null, 'plugin-note-toolbar', null);
console.log(t('hello'));
// prints "Hello!" if language is set to English, or "Hola!" if language is set to Español
// falls back to English if other language strings aren't set
1 Like
moved to developers and api
1 Like