Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Localize data-l10n-id attributes in renderer process window
Browse files Browse the repository at this point in the history
Fix #2638

Auditors: @aekeus
  • Loading branch information
bbondy committed Aug 13, 2016
1 parent 227a83c commit 23037df
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/extensions/brave/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<meta name="availableLanguages" content="en-US">
<meta name="availableLanguages" content="">
<meta name="defaultLanguage" content="en-US">
<!-- TODO: Don't allow img-src *, needed for favicons -->
<!-- TODO: Refactor away all unsafe-inline content -->
Expand Down
4 changes: 2 additions & 2 deletions app/extensions/brave/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html>
<head>
<meta charset="utf-8">
<meta name="availableLanguages" content="">
<meta name="defaultLanguage" content="en-US">
<!-- TODO: Don't allow img-src *, needed for favicons -->
<!-- TODO: Refactor away all unsafe-inline content -->
<!-- TODO: Replace suggestqueries.google.com and ac.duckduckgo.com and other search engines with a single config search engine -->
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; form-action 'none'; referrer no-referrer; script-src 'self'; img-src * data:; style-src 'self' 'unsafe-inline'; font-src 'self'; connect-src 'self' https://s3.amazonaws.com/adblock-data/ https://s3.amazonaws.com/safe-browsing-data/ https://s3.amazonaws.com/tracking-protection-data/ https://s3.amazonaws.com/https-everywhere-data/ https://suggestqueries.google.com https://ac.duckduckgo.com https://completion.amazon.com https://search.yahoo.com https://api.bing.com https://brave-download.global.ssl.fastly.net https://brave-laptop-updates.global.ssl.fastly.net https://laptop-updates-pre.brave.com https://brave-laptop-updates-pre.brave.com; object-src 'self'; plugin-types application/browser-plugin"/>
<meta name="availableLanguages" content="en-US"/>
<meta name="defaultLanguage" content="en-US"/>
<title>Brave</title>
<script src="gen/app.entry.js" async></script>
<script src="ext/l20n.min.js" async></script>
Expand Down
3 changes: 3 additions & 0 deletions js/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const appStoreRenderer = require('./stores/appStoreRenderer')
const messages = require('./constants/messages')
const Immutable = require('immutable')
const patch = require('immutablepatch')
const l10n = require('./l10n')

// don't allow scaling or zooming of the ui
webFrame.setPageScaleLimits(1, 1)
Expand Down Expand Up @@ -65,3 +66,5 @@ ipc.on(messages.APP_STATE_CHANGE, (e, action) => {
window.addEventListener('beforeunload', function () {
ipc.send(messages.LAST_WINDOW_STATE, windowStore.getState().toJS())
})

l10n.init()
9 changes: 9 additions & 0 deletions js/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const ipcRenderer = require('electron').ipcRenderer
const locale = require('../app/locale')
const {LANGUAGE, REQUEST_LANGUAGE} = require('./constants/messages')

// rendererTranslationCache stores a hash containing the entire set of menu translations
// for the currently selected language
Expand All @@ -26,3 +27,11 @@ exports.translation = (token) => {
return locale.translation(token)
}
}

exports.init = () => {
ipcRenderer.on(LANGUAGE, (e, detail) => {
document.l10n.requestLanguages([detail.langCode])
document.getElementsByName('availableLanguages')[0].content = detail.languageCodes.join(', ')
})
ipcRenderer.send(REQUEST_LANGUAGE)
}
2 changes: 1 addition & 1 deletion js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const doAction = (action) => {
activeFrameKey))
let totalOpenTabs = windowState.get('frames').filter((frame) => !frame.get('pinnedLocation')).size

// If we reach the limit of opened tabs per page while closing tabs, switch to
// If we reach the limit of opened tabs per page while closing tabs, switch to
// the active tab's page otherwise the user will hang on empty page
if ((totalOpenTabs % getSetting(settings.TABS_PER_PAGE)) === 0) {
updateTabPageIndex(FrameStateUtil.getActiveFrame(windowState))
Expand Down

2 comments on commit 23037df

@luixxiul
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix #2929 too?

@aekeus
Copy link
Member

@aekeus aekeus commented on 23037df Aug 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.