Files
react-native-devtools-frontend/scripts/build/generate_devtools_ui_strings.py
T
Mandy Chen e64996c39e DevTools: Add scripts to generate id mapping for localizable strings
The backend changes[1] for localizing devtools leverage the existing
webui functionalities, which consume a list of id mappings from the id
of a string used in the frontend (i.e. the English string) to the IDS_
key of the string in the corresponding grdp file. Example:

const LocalizedString kLocalizedStrings[] = {
  ...
  {"Editable", IDS_DEVTOOLS_2c09e798bf8c5a82d211331c82893a0f},
  ...
}

This patch adds scripts that generate the structure. The output will be
two files, devtools_ui_strings_map.h and .cc, under
<generated files root directory>/chrome/browser/ui/webui
(e.g. D:/chromium/src/out/Release/gen/chrome/browser/ui/webui).

The design is to create a build step that calls generate_devtools_ui_strings.py,
which then calls generate_devtools_ui_strings.js. Integration into the build
system will come as a another patch, because it depends on the first set of
changes[2].

Example arguments to generate_devtools_ui_strings.js to generate output
files (invoke under '--root_gen_dir', e.g. D:/chromium/src/out/release/gen
in the example below):

['D:/chromium/src/third_party/node/win/node.exe',
'D:/chromium/src/third_party/blink/renderer/devtools/scripts/build/generate_devtools_ui_strings.js',
'--root_gen_dir', 'D:/chromium/src/out/release/gen',
'--output_header', 'chrome/browser/ui/webui/devtools_ui_strings_map.h',
'--output_cc', 'chrome/browser/ui/webui/devtools_ui_strings_map.cc']

[1]: https://crrev.com/c/1672628
[2]: https://crrev.com/c/1628927

Bug: 941561
Change-Id: Ic03dae24cd074219790c6eec5df3183c24bf15a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1671848
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Mandy Chen <mandy.chen@microsoft.com>
Cr-Original-Commit-Position: refs/heads/master@{#699370}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 3927e5494ba1866261dc577d8f93660fd9f04b5d
2019-09-24 16:12:59 +00:00

54 lines
1.9 KiB
Python

# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import optparse
import os
import subprocess
import sys
_HERE_PATH = os.path.abspath(os.path.dirname(__file__))
_JS_SCRIPT_PATH = os.path.join(_HERE_PATH, 'generate_devtools_ui_strings.js')
_SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..', '..', '..', '..'))
sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'node'))
# pylint: disable=wrong-import-position
import node # pylint: disable=import-error
_NODE_PATH = node.GetBinaryPath()
def main():
parser = optparse.OptionParser(description=__doc__)
parser.add_option(
'--root_gen_dir',
action='store',
metavar='ROOT_GEN_DIR',
help='The root directory where the header and cc will be generated.')
parser.add_option('--output_header', action='store', metavar='OUTPUT_HEADER', help='Generated output .h file for pairs of IDs')
parser.add_option(
'--output_cc',
action='store',
metavar='OUTPUT_CC',
help='Generated output .cc file that contains pairs of {front-end string key, IDS_ key}')
options, _ = parser.parse_args()
if not options.root_gen_dir:
parser.error('--root_gen_dir was not specified.')
if not options.output_header:
parser.error('--output_header was not specified.')
if not options.output_header:
parser.error('--output_cc was not specified.')
cmd_parts = [
_NODE_PATH, _JS_SCRIPT_PATH, '--root_gen_dir',
os.path.abspath(options.root_gen_dir), '--output_header', options.output_header, '--output_cc', options.output_cc
]
process = subprocess.Popen(cmd_parts, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = process.communicate()
if process.returncode != 0:
return out
if __name__ == '__main__':
sys.exit(main())