diff --git a/build/commands/lib/l10nUtil.js b/build/commands/lib/l10nUtil.js index aad786bdf8a..4be0627825a 100644 --- a/build/commands/lib/l10nUtil.js +++ b/build/commands/lib/l10nUtil.js @@ -150,31 +150,51 @@ 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())) -// ethereum-remote-client path relative to the Brave paths -module.exports.ethereumRemoteClientPaths = [ - '../../../ethereum-remote-client/app/_locales/en/messages.json', - '../../../ethereum-remote-client/brave/app/_locales/en/messages.json' -] +// Helper function to retrieve ethereum-remote-client paths relative +// to the Brave paths +module.exports.getEthereumRemoteClientPaths = function (extensionPath) { + let basePath = extensionPath + if (!basePath) { + basePath = '../../../ethereum-remote-client' + } + + return [ + `${basePath}/app/_locales/en/messages.json`, + `${basePath}/brave/app/_locales/en/messages.json` + ] +} // Helper function to retrieve Greaselion script paths relative to the // Brave paths. -module.exports.getGreaselionScriptPaths = function () { - const jsonContent = fs.readFileSync('../../../brave-site-specific-scripts/Greaselion.json', 'utf8') +// +// Greaselion.json consists of an array of Greaselion rules, +// specifying scripts to inject into given sites based on certain +// preconditions. If the rule contains a "messages" key, then the +// script contains user-visible strings that require translation. This +// helper function gathers those messages.json files for transmission +// to Transifex. +module.exports.getGreaselionScriptPaths = function (extensionPath) { + let basePath = extensionPath + if (!basePath) { + basePath = '../../../brave-site-specific-scripts' + } + + const jsonContent = fs.readFileSync(`${basePath}/Greaselion.json`, 'utf8') if (!jsonContent) { console.error('Missing Greaselion.json') return [] } - const jsonObject = JSON.parse(jsonContent) - if (!jsonObject) { + const greaselionRules = JSON.parse(jsonContent) + if (!greaselionRules) { console.error('Malformed Greaselion.json') return [] } let paths = [] - jsonObject.forEach((item) => { - if (item.messages) { - paths.push(`../../../brave-site-specific-scripts/${item.messages}/en_US/messages.json`) + greaselionRules.forEach((rule) => { + if (rule.messages) { + paths.push(`${basePath}/${rule.messages}/en_US/messages.json`) } }) diff --git a/build/commands/lib/pullL10n.js b/build/commands/lib/pullL10n.js index 2d1198f1451..0cc4688da8b 100644 --- a/build/commands/lib/pullL10n.js +++ b/build/commands/lib/pullL10n.js @@ -1,19 +1,20 @@ const path = require('path') const config = require('../lib/config') const util = require('../lib/util') -const {braveTopLevelPaths, ethereumRemoteClientPaths, getGreaselionScriptPaths} = require('./l10nUtil') +const {braveTopLevelPaths, getEthereumRemoteClientPaths, getGreaselionScriptPaths} = require('./l10nUtil') const pullL10n = (options) => { const cmdOptions = config.defaultOptions cmdOptions.cwd = config.braveCoreDir if (options.extension) { + const extensionPath = options.extension_path if (options.extension === 'ethereum-remote-client') { - ethereumRemoteClientPaths.forEach((sourceStringPath) => { + getEthereumRemoteClientPaths(extensionPath).forEach((sourceStringPath) => { util.run('python', ['script/pull-l10n.py', '--source_string_path', sourceStringPath], cmdOptions) }) return } else if (options.extension === 'greaselion') { - getGreaselionScriptPaths().forEach((sourceStringPath) => { + getGreaselionScriptPaths(extensionPath).forEach((sourceStringPath) => { util.run('python', ['script/pull-l10n.py', '--source_string_path', sourceStringPath], cmdOptions) }) return diff --git a/build/commands/lib/pushL10n.js b/build/commands/lib/pushL10n.js index 2c4fde5512a..927f7ad815a 100644 --- a/build/commands/lib/pushL10n.js +++ b/build/commands/lib/pushL10n.js @@ -1,20 +1,21 @@ const path = require('path') const config = require('../lib/config') const util = require('../lib/util') -const {braveTopLevelPaths, ethereumRemoteClientPaths, getGreaselionScriptPaths} = require('./l10nUtil') +const {braveTopLevelPaths, getEthereumRemoteClientPaths, getGreaselionScriptPaths} = require('./l10nUtil') const pushL10n = (options) => { const runOptions = { cwd: config.srcDir } const cmdOptions = config.defaultOptions cmdOptions.cwd = config.braveCoreDir if (options.extension) { + const extensionPath = options.extension_path if (options.extension === 'ethereum-remote-client') { - ethereumRemoteClientPaths.forEach((sourceStringPath) => { + getEthereumRemoteClientPaths(extensionPath).forEach((sourceStringPath) => { util.run('python', ['script/push-l10n.py', '--source_string_path', sourceStringPath], cmdOptions) }) return } else if (options.extension === 'greaselion') { - getGreaselionScriptPaths().forEach((sourceStringPath) => { + getGreaselionScriptPaths(extensionPath).forEach((sourceStringPath) => { util.run('python', ['script/push-l10n.py', '--source_string_path', sourceStringPath], cmdOptions) }) return diff --git a/build/commands/scripts/commands.js b/build/commands/scripts/commands.js index 9693048d6c3..26daf46e10f 100755 --- a/build/commands/scripts/commands.js +++ b/build/commands/scripts/commands.js @@ -152,6 +152,7 @@ program program .command('push_l10n') .option('--extension ', 'Scope this command to localize a Brave extension such as ethereum-remote-client') + .option('--extension_path ', 'Local path for extension') .option('--grd_path ', `Relative path to match end of full GRD path, e.g: 'generated_resources.grd'.`) .action(pushL10n) diff --git a/script/lib/transifex.py b/script/lib/transifex.py index b3e807b1871..77b756c1061 100644 --- a/script/lib/transifex.py +++ b/script/lib/transifex.py @@ -30,12 +30,14 @@ allowed_html_tags = [ 'a', 'abbr', 'b', 'b1', 'b2', 'br', 'code', 'h4', 'learnmore', 'li', 'ol', 'p', 'span', 'strong', 'ul' ] + def transifex_name_from_greaselion_script_name(script_name): match = re.search('brave-site-specific-scripts/scripts/(.*)/_locales/en_US/messages.json$', script_name) if match: return 'greaselion_' + match.group(1).replace('-', '_').replace('/', '_') return '' + def transifex_name_from_filename(source_file_path, filename): ext = os.path.splitext(source_file_path)[1] if 'brave_components_strings' in source_file_path: diff --git a/script/pull-l10n.py b/script/pull-l10n.py index d45b0f8fd74..2973551ffc7 100644 --- a/script/pull-l10n.py +++ b/script/pull-l10n.py @@ -21,8 +21,8 @@ def check_args(): transifex_info = (get_env_var('TRANSIFEX_USERNAME') and get_env_var('TRANSIFEX_PASSWORD') or get_env_var('TRANSIFEX_API_KEY')) - message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or ' - 'TRANSIFEX_API_KEY must be set' + message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or '\ + 'TRANSIFEX_API_KEY must be set' assert transifex_info, message diff --git a/script/push-l10n.py b/script/push-l10n.py index f24dac157cd..4930c6f9ff6 100644 --- a/script/push-l10n.py +++ b/script/push-l10n.py @@ -27,8 +27,8 @@ def check_args(): transifex_info = (get_env_var('TRANSIFEX_USERNAME') and get_env_var('TRANSIFEX_PASSWORD') or get_env_var('TRANSIFEX_API_KEY')) - message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or ' - 'TRANSIFEX_API_KEY must be set in npm config' + message = 'TRANSIFEX_USERNAME and TRANSIFEX_PASSWORD or '\ + 'TRANSIFEX_API_KEY must be set in npm config' assert transifex_info, message @@ -58,9 +58,8 @@ def main(): check_for_chromium_upgrade(SOURCE_ROOT, source_string_path) check_missing_source_grd_strings_to_transifex(source_string_path) upload_source_strings_desc(source_string_path, filename) - if 'ethereum-remote-client' in source_string_path: - upload_missing_json_translations_to_transifex(source_string_path) - if 'brave-site-specific-scripts' in source_string_path: + if ('ethereum-remote-client' in source_string_path or + 'brave-site-specific-scripts' in source_string_path): upload_missing_json_translations_to_transifex(source_string_path)