Skip to content

Commit

Permalink
only translations
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Dec 30, 2023
1 parent 9ac1aa8 commit 14c0917
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
"never"
],
"prefer-arrow/prefer-arrow-functions": [
"error",
"warn",
{
"allowStandaloneDeclarations": true
}
Expand Down
6 changes: 3 additions & 3 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const fs = require('fs')
const esbuild = require('esbuild')
const rmrf = require('rimraf')
const { parse: ftl } = require('@fluent/syntax')
const { parse: parseftl } = require('@fluent/syntax')

rmrf.sync('gen')

Expand All @@ -21,8 +21,8 @@ const ftl = {
const text = await fs.promises.readFile(args.path, 'utf-8')

const l10n = {}
for (const message of ftl(text).body) {
l10n[message.id.name] = message.value.elements.map{|element| element.value}.join('')
for (const message of parseftl(text).body) {
l10n[message.id.name] = message.value.elements.map(element => element.value).join('')
}

return {
Expand Down
35 changes: 18 additions & 17 deletions lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare const Zotero: any

Check failure on line 1 in lib.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find module './locale/en-US/zotero-edtechhub.ftl' or its corresponding type declarations.
declare const Components: any
declare const Services: any

import l10n = require('./locale/en-US/zotero-edtechhub.ftl')

Expand Down Expand Up @@ -153,8 +154,8 @@ function zotero_itemmenu_popupshowing() {
// bluebird promise has status
const pending = (EdTechHub.ready as any).isPending()
const hidden = pending || !selected.find(item => item.isRegularItem()) // eslint-disable-line @typescript-eslint/no-unsafe-return
for (const elt of Array.from(doc.getElementsByClassName('edtechhub-zotero-itemmenu-regularitem'))) {
(elt as any).hidden = hidden
for (const elt of Array.from(doc.getElementsByClassName('edtechhub-zotero-itemmenu-regularitem') as HTMLElement[])) {
elt.hidden = hidden
}

doc.getElementById('edtechhub-duplicate-attachment').hidden =
Expand Down Expand Up @@ -238,14 +239,14 @@ class EdTechHubMain {
XUL: 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
HTML: 'http://www.w3.org/1999/xhtml',
}
function create(name: string, attrs: Record<string, number | string | Handler | HTMLElement[]> = {}): HTMLElement {
function create(name: string, attrs: Record<string, number | string | Function | HTMLElement[]> = {}): HTMLElement {

Check warning on line 242 in lib.ts

View workflow job for this annotation

GitHub Actions / release

Use const or class constructors instead of named functions

Check warning on line 242 in lib.ts

View workflow job for this annotation

GitHub Actions / release

Don't use `Function` as a type. Avoid using the `Function` type. Prefer a specific function type, like `() => void`
const children: HTMLElement[] = (attrs.$ as unknown as HTMLElement[]) || []
delete attrs.$

const namespace = name.startsWith('html:') ? NAMESPACE.HTML : NAMESPACE.XUL
name = name.replace('html:', '')

const elt: HTMLElement = is7
const elt: HTMLElement = Zotero.platformMajorVersion >= 102 // eslint-disable-line @typescript-eslint/no-magic-numbers
? doc[ namespace === NAMESPACE.XUL ? 'createXULElement' : 'createElement' ](name) as HTMLElement
: doc.createElementNS(namespace, name) as HTMLElement
attrs.class = `edtechhub ${attrs.class || ''}`.trim()
Expand Down Expand Up @@ -283,7 +284,7 @@ class EdTechHubMain {

win.addEventListener('unload', _event => {
doc.getElementById('zotero-itemmenu').removeEventListener('popupshowing', zotero_itemmenu_popupshowing, false)
for (const elt of Array.from(doc.getElementsByClassName('edtechhub'))) {
for (const elt of Array.from(doc.getElementsByClassName('edtechhub') as HTMLElement[])) {
elt.remove()
}
}, false)
Expand All @@ -292,37 +293,37 @@ class EdTechHubMain {
itemmenu.appendChild(create('menuseparator'))
itemmenu.appendChild(create('menuitem', {
class: 'edtechhub-zotero-itemmenu-regularitem',
label: l10n['edtechhub_Bjoern2A_BjoernCitationStringTagged'],
oncommand: () => Zotero.EdTechHub.run('copyToClipboard', '4ec4a50b-e979-448f-af4c-e5b46d1a3b03')
label: l10n.edtechhub_Bjoern2A_BjoernCitationStringTagged,
oncommand: () => void Zotero.EdTechHub.run('copyToClipboard', '4ec4a50b-e979-448f-af4c-e5b46d1a3b03'),
}))
itemmenu.appendChild(create('menuitem', {
class: 'edtechhub-zotero-itemmenu-regularitem',
label: l10n['edtechhub_Bjoern2C_BjoernCitationStringTagged'],
oncommand: () => Zotero.EdTechHub.run('copyToClipboard', 'fe1c68d8-aa8e-11eb-85c1-1799e2c1b06e')
label: l10n.edtechhub_Bjoern2C_BjoernCitationStringTagged,
oncommand: () => void Zotero.EdTechHub.run('copyToClipboard', 'fe1c68d8-aa8e-11eb-85c1-1799e2c1b06e'),
}))
itemmenu.appendChild(create('menuitem', {
class: 'edtechhub-zotero-itemmenu-regularitem',
label: l10n['edtechhub_Bjoern7_ETHref'],
oncommand: () => Zotero.EdTechHub.run('copyToClipboard', 'ba5f8764-3966-11ea-9cd5-5b52329a4e4c')
label: l10n.edtechhub_Bjoern7_ETHref,
oncommand: () => void Zotero.EdTechHub.run('copyToClipboard', 'ba5f8764-3966-11ea-9cd5-5b52329a4e4c'),
}))
itemmenu.appendChild(create('menuitem', {
class: 'edtechhub-zotero-itemmenu-regularitem',
label: l10n['edtechhub_assign-key'],
oncommand: () => Zotero.EdTechHub.run('assignKey')
oncommand: () => void Zotero.EdTechHub.run('assignKey'),
}))
itemmenu.appendChild(create('menuitem', {
class: 'edtechhub-zotero-itemmenu-regularitem',
class: 'edtechhub-zotero-itemmenu-regularitem',
label: l10n['edtechhub_save-to-note'],
oncommand: () => Zotero.EdTechHub.run('saveToNote')
oncommand: () => void Zotero.EdTechHub.run('saveToNote'),
}))
itemmenu.appendChild(create('menuitem', {
id: 'edtechhub-duplicate-attachment',
label: l10n['edtechhub_duplicate-attachment'],
oncommand: () => Zotero.EdTechHub.run('duplicateAttachment')
oncommand: () => void Zotero.EdTechHub.run('duplicateAttachment'),
}))
}

startup() {
async startup() {
const ready = Zotero.Promise.defer()
this.ready = ready.promise

Expand Down Expand Up @@ -435,7 +436,7 @@ class EdTechHubMain {
const doc = win.document

doc.getElementById('zotero-itemmenu').removeEventListener('popupshowing', zotero_itemmenu_popupshowing, false)
for (const elt of Array.from(doc.getElementsByClassName('edtechhub'))) {
for (const elt of Array.from(doc.getElementsByClassName('edtechhub') as HTMLElement[])) {
elt.remove()
}
}
Expand Down

0 comments on commit 14c0917

Please sign in to comment.