Skip to content

Commit de69e6e

Browse files
authored
Merge pull request #27 from adambullmer/locales
Added basic support for internationalization through browser APIs.
2 parents 4cefafc + e592c49 commit de69e6e

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ module.exports = {
201201
}
202202
```
203203

204+
## Internationalization
205+
206+
Some boilerplate for internationalization has been added. This follows the i18n ([chrome](https://developer.chrome.com/extensions/i18n)|[WebExtention](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/i18n)) spec.
207+
Provided for you is the `default_locale` option in the manifest, and a `_locales` directory.
208+
There is some basic usage of it in the manifest, as well as in some of the boilerplate files.
209+
Since this is largely an out of the box solution provided by the browsers, it is heavily encouraged to utilize it.
210+
If you do not want to translate your app, simply delete the `public/_locales` directory, and no longer use the `browser.i18n` methods.
211+
204212
## Testing
205213
This library is following the standard styling of vue projects, and those are really the only tests to perform.
206214

generator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = (api, _options) => {
2525
}
2626

2727
const appRootPath = process.cwd()
28-
const { name } = require(path.join(appRootPath, 'package.json'))
28+
const { name, description } = require(path.join(appRootPath, 'package.json'))
2929
const eslintConfig = { env: { webextensions: true } }
3030
const pkg = {
3131
private: true,
@@ -57,7 +57,7 @@ module.exports = (api, _options) => {
5757
}
5858

5959
api.extendPackage(pkg)
60-
api.render('./template/base-app', { name, ...options })
60+
api.render('./template/base-app', { name, description, ...options })
6161

6262
if (options.components.background) {
6363
api.render('./template/background', { name, ...options })
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extName": {
3+
"message": "<%- name %>",
4+
"description": "<%- description %>"
5+
}
6+
}

generator/template/base-app/src/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"manifest_version": 2,
3-
"name": "<%- name %>",
3+
"name": "__MSG_extName__",
44
"homepage_url": "http://localhost/",
55
"description": "A Vue Browser Extension",
6+
"default_locale": "en",
67
"icons": {
78
"16": "icons/16.png",
89
"48": "icons/48.png",
@@ -25,7 +26,7 @@
2526
<%_ if (options.components.popup) { -%>
2627
"default_popup": "popup/popup.html",
2728
<%_ } -%>
28-
"default_title": "<%- name %>",
29+
"default_title": "__MSG_extName__",
2930
"default_icon": {
3031
"19": "icons/19.png",
3132
"38": "icons/38.png"

generator/template/options/src/options/App.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<template>
22
<div>
3-
<p>Hello world!</p>
3+
<p>{{ defaultText }}</p>
44
</div>
55
</template>
66

77
<script>
88
export default {
9-
name: 'App'
9+
name: 'App',
10+
computed: {
11+
defaultText() {
12+
return <%- options.api %>.i18n.getMessage('extName');
13+
}
14+
}
1015
}
1116
</script>
1217

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<p>Hello world!</p>
2+
<h1>{{ defaultText }}</h1>
33
</template>
44

55
<script>
@@ -13,12 +13,11 @@ export default {
1313
},
1414
mounted () {
1515
<%- options.api %>.runtime.sendMessage({})
16+
},
17+
computed: {
18+
defaultText() {
19+
return <%- options.api %>.i18n.getMessage('extName');
20+
}
1621
}
1722
}
1823
</script>
19-
20-
<style scoped>
21-
p {
22-
font-size: 20px;
23-
}
24-
</style>

generator/template/standalone/src/standalone/router/pages/Index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<p>Hello world!</p>
2+
<p>{{ defaultText }}</p>
33
</template>
44

55
<script>
@@ -13,6 +13,11 @@ export default {
1313
},
1414
mounted () {
1515
<%- options.api %>.runtime.sendMessage({});
16+
},
17+
computed: {
18+
defaultText() {
19+
return <%- options.api %>.i18n.getMessage('extName');
20+
}
1621
}
1722
}
1823
</script>

0 commit comments

Comments
 (0)