Skip to content

Commit

Permalink
Exclude unnecessary messages from the standard localization files
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 committed Jan 19, 2024
1 parent ffdc981 commit ada3e49
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extension/.parcelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"transformers": {
"filename:*": ["./tools/transformers/filename", "..."],
"locale:*": ["./tools/transformers/locale", "@parcel/transformer-json", "@parcel/transformer-js"],
"raw:messages.json": ["./tools/transformers/locale"]
"raw:messages.json": ["./tools/transformers/locale", "./tools/transformers/treeshake"]
}
}
9 changes: 9 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
"plus-lg",
"trash"
],
"messages": [
"appName",
"appShortName",
"appDescription",
"actionInstallSite",
"actionLaunchSite",
"updateNotificationTitle",
"updateNotificationMessage"
],
"alias": {
"process": false
}
Expand Down
3 changes: 1 addition & 2 deletions extension/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
],
"browser_action": {
"default_icon": "images/browser-action.svg",
"default_popup": "sites/manage.html",
"default_title": "__MSG_appShortName__"
"default_popup": "sites/manage.html"
},
"page_action": {},
"permissions": [
Expand Down
21 changes: 21 additions & 0 deletions extension/tools/transformers/treeshake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { Transformer } = require('@parcel/plugin')

const allowed = require('../../package.json').messages

module.exports = new Transformer({
async transform ({ asset }) {
const messages = JSON.parse(await asset.getCode())

// Remove all messages except ones used by the standard localization system
for (const key in messages) {
if (!allowed.includes(key)) {
delete messages[key]
}
}

asset.setCode(JSON.stringify(messages))
asset.type = 'json'

return [asset]
}
})

0 comments on commit ada3e49

Please sign in to comment.