Skip to content

Commit

Permalink
Merge pull request #1 from brave/chrome-i18n
Browse files Browse the repository at this point in the history
Use chrome.i18n
  • Loading branch information
bbondy authored Nov 27, 2017
2 parents 70dd343 + 8936f39 commit 70b10a2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"appName": {
"message": "The Brave Extension"
},
"newTab": {
"message": "New Tab"
}
}
13 changes: 13 additions & 0 deletions app/background/api/localeAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
* Gets the locale message specified in messages.json
* @param {string} The locale string
*/
export const getMessage = (message) => {
if (chrome.i18n) {
return chrome.i18n.getMessage(message)
}
}
3 changes: 2 additions & 1 deletion app/containers/newTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as newTabPageActions from '../actions/newTabPageActions'
import {getMessage} from '../background/api/localeAPI'

class NewTab extends Component {
render () {
// const { newTabPage, actions } = this.props
const { actions } = this.props
return <div data-test-id='new-tab-page'>
<div>Brave New Tab!</div>
<div>Hello, {getMessage('newTab')} world!</div>
<div onClick={actions.settingsIconClicked}>Settings</div>
</div>
}
Expand Down
3 changes: 2 additions & 1 deletion app/manifest.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"version": "1.0.0",
"name": "Brave",
"manifest_version": 2,
"description": "Brave UI",
"description": "__MSG_appName__",
"default_locale": "en_US",
"browser_action": {
"default_title": "Brave Shields",
"default_popup": "braveShieldsPanel.html"
Expand Down
3 changes: 2 additions & 1 deletion app/manifest.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"version": "1.0.0",
"name": "Brave",
"manifest_version": 2,
"description": "Brave UI",
"description": "__MSG_appName__",
"default_locale": "en_US",
"browser_action": {
"default_title": "Brave Shields",
"default_popup": "braveShieldsPanel.html"
Expand Down
1 change: 1 addition & 0 deletions scripts/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exports.copyAssets = (type) => {
rm('-rf', type)
mkdir(type)
cp(`app/manifest.${env}.json`, `${type}/manifest.json`)
cp('-R', 'app/_locales/', type)
cp('-R', 'app/assets/*', type)
exec(`pug -O "{ env: '${env}' }" -o ${type} app/views/`)
}
25 changes: 25 additions & 0 deletions test/app/background/api/localeAPITest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* global describe, it, before, after */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import sinon from 'sinon'
import assert from 'assert'
import * as localeAPI from '../../../../app/background/api/localeAPI'

describe('locale API', () => {
describe('getMessage', function () {
before(function () {
this.spy = sinon.spy(chrome.i18n, 'getMessage')
this.message = 'NESPRESS YOURSELF'
localeAPI.getMessage(this.message)
})
after(function () {
this.spy.restore()
})
it('calls chrome.i18n.getMessage with the message', function () {
assert(this.spy.calledOnce)
assert.deepEqual(this.spy.getCall(0).args[0], this.message)
})
})
})
4 changes: 4 additions & 0 deletions test/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export const getMockChrome = () => {
})
}
}
},
i18n: {
getMessage: function (message) {
}
}
}
}
Expand Down

0 comments on commit 70b10a2

Please sign in to comment.