Skip to content

Commit

Permalink
Merge pull request #365 from brave/grd-strings
Browse files Browse the repository at this point in the history
Provide a script to do GRD string upgrades for Chromium rebasing
  • Loading branch information
bbondy authored Jun 15, 2018
2 parents c1dd13e + edac596 commit e366b5d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/chromiumRebaseL10n.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/. */

const config = require('../lib/config')
const util = require('../lib/util')
const {rebaseBraveStringFilesOnChromiumL10nFiles} = require('./l10nUtil')

const chromiumRebaseL10n = (options) => {
rebaseBraveStringFilesOnChromiumL10nFiles()
}

module.exports = chromiumRebaseL10n
45 changes: 39 additions & 6 deletions lib/l10nUtil.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
/* 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/. */

const path = require('path')
const fs = require('fs')

const srcDir = path.resolve(path.join(__dirname, '..', 'src'))

// Brave string paths
const braveStringsPath = path.resolve(path.join(srcDir, 'brave', 'app', 'brave_strings.grd'))
const braveSettingsPartPath = path.resolve(path.join(srcDir, 'brave', 'app', 'settings_brave_strings.grdp'))
const braveComponentsStringsPath = path.resolve(path.join(srcDir, 'brave', 'app', 'components_brave_strings.grd'))
const braveExtensionMessagesPath = path.resolve(path.join(srcDir, 'brave', 'vendor', 'brave-extension', 'app', '_locales', 'en_US', 'messages.json'))
const braveGeneratedResourcesPath = path.resolve(path.join(srcDir, 'brave', 'app', 'brave_generated_resources.grd'))
const braveComponentsResourcesPath = path.resolve(path.join(srcDir, 'brave', 'components', 'resources', 'brave_components_resources.grd'))

// Chromium string paths
const chromiumStringsPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'chromium_strings.grd'))
const chroimumSettingsPartPath = path.resolve(path.join(srcDir, 'chrome', 'app', 'settings_chromium_strings.grdp'))
const chromiumComponentsStringsPath = path.resolve(path.join(srcDir, 'components', 'components_chromium_strings.grd'))

module.exports.getSourceStringPaths = () => {
return [
path.resolve(path.join(srcDir, 'brave', 'vendor', 'brave-extension', 'app', '_locales', 'en_US', 'messages.json')),
path.resolve(path.join(srcDir, 'brave', 'app', 'brave_strings.grd')),
path.resolve(path.join(srcDir, 'brave', 'app', 'brave_generated_resources.grd')),
path.resolve(path.join(srcDir, 'brave', 'app', 'components_brave_strings.grd')),
path.resolve(path.join(srcDir, 'brave', 'components', 'resources', 'brave_components_resources.grd'))
braveStringsPath,
braveComponentsStringsPath,
braveExtensionMessagesPath,
braveGeneratedResourcesPath,
braveComponentsResourcesPath,
// No strings for now, uncomment if strings are added
// path.resolve(path.join(srcDir, 'brave', 'browser', 'resources', 'brave_extension.grd')),
// path.resolve(path.join(srcDir, 'brave', 'common', 'extensions', 'api', 'brave_api_resources.grd')),
]

}

module.exports.rebaseBraveStringFilesOnChromiumL10nFiles = (path) =>
Object.entries({
[chromiumStringsPath]: braveStringsPath,
[chroimumSettingsPartPath]: braveSettingsPartPath,
[chromiumComponentsStringsPath]: braveComponentsStringsPath
}).forEach(([sourcePath, destPath]) =>
fs.writeFileSync(destPath,
fs.readFileSync(sourcePath, 'utf8')
.replace(/settings_chromium_strings.grdp/g, 'settings_brave_strings.grdp')
.replace(/The Chromium Authors/g, 'Brave Software Inc')
.replace(/Google Chrome/g, 'Brave')
.replace(/Chromium/g, 'Brave')
.replace(/Chrome/g, 'Brave')
.replace(/Google/g, 'Brave'), 'utf8'))
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"start": "node ./scripts/commands.js start",
"push_l10n": "node ./scripts/commands.js push_l10n",
"pull_l10n": "node ./scripts/commands.js pull_l10n",
"chromium_rebase_l10n": "node ./scripts/commands.js chromium_rebase_l10n",
"test": "node ./scripts/commands.js test",
"web-ui": "webpack --config src/brave/components/webpack/prod.config.js --progress --profile --colors",
"web-ui-dev": "webpack --config src/brave/components/webpack/dev.config.js --progress --profile --colors"
Expand Down
9 changes: 9 additions & 0 deletions scripts/commands.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* 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/. */

const program = require('commander');
const path = require('path')
const fs = require('fs-extra')
Expand All @@ -9,6 +13,7 @@ const start = require('../lib/start')
const updatePatches = require('../lib/updatePatches')
const pullL10n = require('../lib/pullL10n')
const pushL10n = require('../lib/pushL10n')
const chromiumRebaseL10n = require('../lib/chromiumRebaseL10n')
const createDist = require('../lib/createDist')
const upload = require('../lib/upload')
const test = require('../lib/test')
Expand Down Expand Up @@ -73,6 +78,10 @@ program
.command('push_l10n')
.action(pushL10n)

program
.command('chromium_rebase_l10n')
.action(chromiumRebaseL10n)

program
.command('update_patches')
.action(updatePatches)
Expand Down

0 comments on commit e366b5d

Please sign in to comment.