Localization (l10n) : Set Default Language for my mozilla addon

天涯浪子 提交于 2019-12-02 11:29:08

问题


I am developing a mozilla addon and implementing l10n. My questions are ,

  • How to set default language to my addon?(This works when my addon doesn't support a language, it switches to default language)

  • Will addon change its locale language when the language of the Mozilla Firefox changes?

  • How to change my firefox browser language?


回答1:


Classic Bootstrap

In classic bootstrap addons, you don't set a default. Firefox automatically figures out the closest locale between the users browser and from whatever locales your addon has.

JPM

Are you doing a JPM/SDK addon? If you are localizing the preferences, you have to initially set a string in the package.json:

"preferences": [
    {
        "name": "imagePath",
        "type": "file",
        "value": "",
        "title": "Image File Path",
        "description": "A path to an image on your computer that the dock icon should be set to"
    },
    {
        "name": "restoreDefault",
        "type": "control",
        "title": "default locale:Restore Default",
        "description": "this is from package.json:: If you have changed your icon, and want to restore the default Firefox icon, click this button",
        "label": "this is from package.json:: Restore"
    }
]

So the default is whatever you set there. If firefox cannot find a match to the locales provided it will use the string from package.json.

So for exmaple to localize the restoreDefault strings you would create a en-US.properties file and drop it in a folder named locale like this:

restoreDefault_title=blah Restore Default blah
restoreDefault_description=blahIf you have changed your icon, and want to restore the default Firefox icon, click this buttonblah
restoreDefault_label=blahRestoreblah

So now set your browser locale to english by going to about:config and then change the preference general.useragent.locale to something other then en-US (change it to es) for this example then load your preferences page (may need to restart browser after changing general.useragent.locale). Now because your addon does not have es.properties you will see the strings from package.json. Set your general.useragent.locale back to en-us and then restart your browser, and go back to your addon pref page, and you will see the strings from the properties file.



来源:https://stackoverflow.com/questions/33168163/localization-l10n-set-default-language-for-my-mozilla-addon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!