【问题标题】:Firefox Web Extension Internationalization ErrorFirefox Web 扩展国际化错误
【发布时间】:2017-08-23 18:52:44
【问题描述】:

我昨天开始在 55.0.2 版本上开发我的第一个 Firefox Web 扩展。我想为那个扩展添加不同的语言,所以我在官方网站上阅读了这个主题:https://developer.mozilla.org/fr/Add-ons/WebExtensions/Internationalization

但是,事情并没有按预期进行,因为现在每当我尝试使用 about:debugging 加载我的应用程序时,它都会不断弹出此错误消息“安装期间出现错误:扩展程序无效”。

我已经搜索了一些可能导致此问题的原因,但我发现完全奇怪。每当我的 _locales 文件夹中有“en”或“fr”之类的文件夹时,Firefox 就会不断向我显示该错误消息。

我尝试在 manifest.json 中添加一个默认语言环境来修复它,但没有运气,它不起作用。我已经尝试通过更改扩展名和扩展描述来使我的messages.json 尽可能简单,但没有运气。

由于我不明白的原因,这些子文件夹阻止我添加不同的语言。

这是我的 manifest.json:

{
    "manifest_version": 2,
    "default_locale": "en",
    "name": "__MSG_extensionName__",
    "description": "__MSG_extensionDescription__",
    "version": "1.0",
    "applications": {
        "gecko":{

        }
    },

    "permissions": [
        "contextMenus",
        "activeTab"
    ],

    "background": {
        "scripts": ["ddo.js"]
    },

    "browser_action": {
        "default_title": "Download Destination Organizer"
    }
}

这是我在 _locales 内的“en”子文件夹中的 messages.json:

{
  "extensionName": {
    "message": "DDO",
    "description": "Name of the extension."
  },

  "extensionDescription": {
    "message": "Insert description here",
    "description": "Description of the extension."
  }

}

这是 _locales 中“fr”子文件夹中的 messages.json:

{
  "extensionName": {
    "message": "DDO",
    "description": "Name of the extension."
  },

  "extensionDescription": {
    "message": "Insérer la description ici.",
    "description": "Description of the extension."
  }

}

【问题讨论】:

  • 如何安装扩展?你使用 web-ext 命令行吗?
  • 我使用 about:debugging 页面并将应用程序加载为临时应用程序。
  • 你确定你已经为_locales文件夹命名了吗?

标签: firefox-addon-webextensions


【解决方案1】:

使用来自 Mozilla 存储库的官方 web-ext 工具:https://github.com/mozilla/web-ext

当我使用此命令运行您的示例时(在 MacOS 上),它适用于我:

web-ext run --firefox

您也可以使用以下命令在 Firefox 开发者版中运行它:

web-ext run --firefox /Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox

此外,您可以使用详细选项 (-v) 运行它,以查看失败问题的确切位置:

web-ext run --firefox -v

这是我的架构(我没有更改您提供的任何内容,我只添加了清单中描述的 ddo.js 文件——ddo.js 文件包含console.log):

|- _locales
|  |- en
|  |  |- messages.json
|  |
|  |- fr
|  |  |- messages.json
|
|- ddo.js
|- manifest.json

【讨论】:

    【解决方案2】:

    您是否正在加载压缩的 webextension?

    你是如何压缩它的?

    您必须使用 "compatible" 程序对其进行压缩,例如,当我通过 powershell 命令行使用 Compress-Archive 对其进行压缩时会出现该错误,但如果我使用 Windows send to -> Compressed (zipped) folder 菜单或默认 7z 压缩它zip的选项,然后它就可以通过了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-04
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 2019-05-24
      相关资源
      最近更新 更多