diff --git a/build/lib/chromiumRebaseL10n.js b/build/lib/chromiumRebaseL10n.js index bc3e0a5b2c9f..20cf3ea56326 100644 --- a/build/lib/chromiumRebaseL10n.js +++ b/build/lib/chromiumRebaseL10n.js @@ -6,8 +6,8 @@ const config = require('../lib/config') const util = require('../lib/util') const {rebaseBraveStringFilesOnChromiumL10nFiles, braveAutoGeneratedPaths} = require('./l10nUtil') -const chromiumRebaseL10n = (options) => { - rebaseBraveStringFilesOnChromiumL10nFiles() +const chromiumRebaseL10n = async (options) => { + await rebaseBraveStringFilesOnChromiumL10nFiles() braveAutoGeneratedPaths.forEach((sourceStringPath) => { const cmdOptions = config.defaultOptions cmdOptions.cwd = config.projects['brave-core'].dir diff --git a/build/lib/l10nUtil.js b/build/lib/l10nUtil.js index 1448a4117570..5d77cdc686c6 100644 --- a/build/lib/l10nUtil.js +++ b/build/lib/l10nUtil.js @@ -104,18 +104,38 @@ module.exports.allBravePaths = module.exports.braveNonGeneratedPaths.concat(modu // This is because only 1 xtb is created per grd per locale even if it has multiple grdp files. module.exports.braveTopLevelPaths = module.exports.allBravePaths.filter((x) => ['grd', 'json'].includes(x.split('.').pop())) + // This simply reads Chromium files that are passed to it and replaces branding strings // with Brave specific branding strings. // Do not use this for filtering XML, instead use chromium-rebase-l10n.py. // Only add idempotent replacements here (i.e. don't append replace A with AX here) -module.exports.rebaseBraveStringFilesOnChromiumL10nFiles = (path) => - Object.entries(chromiumToAutoGeneratedBraveMapping).forEach(([sourcePath, destPath]) => - fs.writeFileSync(destPath, - fs.readFileSync(sourcePath, 'utf8') - .replace(/Automatically send usage statistics and crash reports to Google/g, 'Automatically send crash reports to Google') - .replace(/Automatically sends usage statistics and crash reports to Google/g, 'Automatically sends crash reports to Google') - .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')) +module.exports.rebaseBraveStringFilesOnChromiumL10nFiles = async function (path) { + const ops = Object.entries(chromiumToAutoGeneratedBraveMapping).map(async ([sourcePath, destPath]) => { + let contents = await new Promise(resolve => fs.readFile(sourcePath, 'utf8', (err, data) => resolve(data))) + for (const replacement of defaultReplacements) { + contents = contents.replace(replacement[0], replacement[1]) + } + await new Promise(resolve => fs.writeFile(destPath, contents, 'utf8', resolve)) + }) + await Promise.all(ops) +} + +// Straight-forward string replacement list. +// Consider mapping chromium resource ID to a new brave resource ID +// for whole-message replacements, instead of adding to this list. +const defaultReplacements = [ + [/Automatically send usage statistics and crash reports to Google/g, 'Automatically send crash reports to Google'], + [/Automatically sends usage statistics and crash reports to Google/g, 'Automatically sends crash reports to Google'], + [/The Chromium Authors/g, 'Brave Software Inc'], + [/Google Chrome/g, 'Brave'], + [/Chromium/g, 'Brave'], + [/Chrome/g, 'Brave'], + [/Google/g, 'Brave'], + [/You're incognito/g, 'This is a private window'], + [/an incognito/g, 'a private'], + [/an Incognito/g, 'a Private'], + [/incognito/g, 'private'], + [/Incognito/g, 'Private'], + [/inco\&\;gnito/g, '&private'], + [/Inco\&\;gnito/g, '&Private'], +]