add: AddonLocal class for properities file. Update local label string in addontemplate

This commit is contained in:
l0o0 2022-12-28 23:04:04 +08:00
parent 2d19e5501b
commit 2307380f0d
9 changed files with 44 additions and 6 deletions

View File

@ -3,7 +3,7 @@
onload="Zotero.AddonTemplate.prefs.initPreferences(window)" onload="Zotero.AddonTemplate.prefs.initPreferences(window)"
> >
<groupbox> <groupbox>
<label><html:h2>Addon Template Example</html:h2></label> <label><html:h2>&zotero.__addonRef__.pref.title;</html:h2></label>
<checkbox <checkbox
id="zotero-prefpane-__addonRef__-enable" id="zotero-prefpane-__addonRef__-enable"
label="&zotero.__addonRef__.pref.enable.label;" label="&zotero.__addonRef__.pref.enable.label;"
@ -21,3 +21,6 @@
</hbox> </hbox>
</groupbox> </groupbox>
</vbox> </vbox>
<vbox>
<label value="&zotero.__addonRef__.help.version.label; &zotero.__addonRef__.help.releasetime.label;"></label>
</vbox>

View File

@ -0,0 +1,5 @@
menuitem.label=Addon Template: Menuitem
menupopup.label=Addon Template: Menupopup
menuitem.submenulabel=Addon Template
menuitem.filemenulabel=Addon Template: File Menuitem
prefs.title=Template

View File

@ -1,3 +1,4 @@
<!ENTITY zotero.__addonRef__.pref.title "Addon Template Example">
<!ENTITY zotero.__addonRef__.itemmenu.test.label "addon template"> <!ENTITY zotero.__addonRef__.itemmenu.test.label "addon template">
<!ENTITY zotero.__addonRef__.pref.enable.label "Enable"> <!ENTITY zotero.__addonRef__.pref.enable.label "Enable">
<!ENTITY zotero.__addonRef__.pref.input.label "Input"> <!ENTITY zotero.__addonRef__.pref.input.label "Input">

View File

@ -0,0 +1,5 @@
menuitem.label=Addon Template: 菜单
menupopup.label=Addon Template: 弹出菜单
menuitem.submenulabel=Addon Template
menuitem.filemenulabel=Addon Template: 文件菜单
prefs.title=插件模板

View File

@ -1,3 +1,4 @@
<!ENTITY zotero.__addonRef__.pref.title "插件模板设置示例">
<!ENTITY zotero.__addonRef__.itemmenu.test.label "插件模板"> <!ENTITY zotero.__addonRef__.itemmenu.test.label "插件模板">
<!ENTITY zotero.__addonRef__.pref.enable.label "开启"> <!ENTITY zotero.__addonRef__.pref.enable.label "开启">
<!ENTITY zotero.__addonRef__.pref.input.label "输入"> <!ENTITY zotero.__addonRef__.pref.input.label "输入">

View File

@ -1,14 +1,17 @@
import AddonEvents from "./events"; import AddonEvents from "./events";
import AddonPrefs from "./prefs"; import AddonPrefs from "./prefs";
import AddonViews from "./views"; import AddonViews from "./views";
import AddonLocale from "./locale";
import ZoteroToolkit from "zotero-plugin-toolkit"; import ZoteroToolkit from "zotero-plugin-toolkit";
import Locale from "./locale";
class Addon { class Addon {
public Zotero!: _ZoteroConstructable; public Zotero!: _ZoteroConstructable;
public events: AddonEvents; public events: AddonEvents;
public views: AddonViews; public views: AddonViews;
public prefs: AddonPrefs; public prefs: AddonPrefs;
public locale: AddonLocale;
public toolkit: ZoteroToolkit; public toolkit: ZoteroToolkit;
// root path to access the resources // root path to access the resources
public rootURI!: string; public rootURI!: string;
@ -17,6 +20,7 @@ class Addon {
this.events = new AddonEvents(this); this.events = new AddonEvents(this);
this.views = new AddonViews(this); this.views = new AddonViews(this);
this.prefs = new AddonPrefs(this); this.prefs = new AddonPrefs(this);
this.locale = new AddonLocale(this);
this.toolkit = new ZoteroToolkit(); this.toolkit = new ZoteroToolkit();
} }
} }

View File

@ -61,7 +61,7 @@ class AddonEvents extends AddonModule {
const prefOptions = { const prefOptions = {
pluginID: config.addonID, pluginID: config.addonID,
src: this._Addon.rootURI + "chrome/content/preferences.xhtml", src: this._Addon.rootURI + "chrome/content/preferences.xhtml",
label: "Template", label: this._Addon.locale.getString("prefs.title"),
image: `chrome://${config.addonRef}/content/icons/favicon.png`, image: `chrome://${config.addonRef}/content/icons/favicon.png`,
extraDTD: [`chrome://${config.addonRef}/locale/overlay.dtd`], extraDTD: [`chrome://${config.addonRef}/locale/overlay.dtd`],
defaultXUL: true, defaultXUL: true,

19
src/locale.ts Normal file
View File

@ -0,0 +1,19 @@
import Addon from "./addon";
import AddonModule from "./module";
class AddonLocale extends AddonModule {
private stringBundle: any;
constructor(parent: Addon) {
super(parent);
this.stringBundle = Components.classes['@mozilla.org/intl/stringbundle;1']
.getService(Components.interfaces.nsIStringBundleService)
.createBundle('chrome://addontemplate/locale/addontemplate.properties');
}
public getString(localString: string): string {
return this.stringBundle.GetStringFromName(localString);
}
}
export default AddonLocale;

View File

@ -24,7 +24,7 @@ class AddonViews extends AddonModule {
this._Addon.toolkit.UI.insertMenuItem("item", { this._Addon.toolkit.UI.insertMenuItem("item", {
tag: "menuitem", tag: "menuitem",
id: "zotero-itemmenu-addontemplate-test", id: "zotero-itemmenu-addontemplate-test",
label: "Addon Template: Menuitem", label: this._Addon.locale.getString("menuitem.label"),
oncommand: "alert('Hello World! Default Menuitem.')", oncommand: "alert('Hello World! Default Menuitem.')",
icon: menuIcon, icon: menuIcon,
}); });
@ -33,11 +33,11 @@ class AddonViews extends AddonModule {
"item", "item",
{ {
tag: "menu", tag: "menu",
label: "Addon Template: Menupopup", label: this._Addon.locale.getString("menupopup.label"),
subElementOptions: [ subElementOptions: [
{ {
tag: "menuitem", tag: "menuitem",
label: "Addon Template", label: this._Addon.locale.getString("menuitem.submenulabel"),
oncommand: "alert('Hello World! Sub Menuitem.')", oncommand: "alert('Hello World! Sub Menuitem.')",
}, },
], ],
@ -53,7 +53,7 @@ class AddonViews extends AddonModule {
// menu->File menuitem // menu->File menuitem
this._Addon.toolkit.UI.insertMenuItem("menuFile", { this._Addon.toolkit.UI.insertMenuItem("menuFile", {
tag: "menuitem", tag: "menuitem",
label: "Addon Template: File Menuitem", label: this._Addon.locale.getString("menuitem.filemenulabel"),
oncommand: "alert('Hello World! File Menuitem.')", oncommand: "alert('Hello World! File Menuitem.')",
}); });