From 80ac36ccf0703e0ca6cb751b172d079f1672b84b Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 15 Sep 2021 13:41:58 -0700 Subject: [PATCH] misc(proto): add i18n.icuMessagePaths --- lighthouse-core/lib/proto-preprocessor.js | 15 +++++---------- proto/lighthouse-result.proto | 7 ++++++- types/lhr/lhr.d.ts | 6 +++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lighthouse-core/lib/proto-preprocessor.js b/lighthouse-core/lib/proto-preprocessor.js index 6e0fdd836bab..62893724eb71 100644 --- a/lighthouse-core/lib/proto-preprocessor.js +++ b/lighthouse-core/lib/proto-preprocessor.js @@ -16,10 +16,10 @@ const fs = require('fs'); */ /** - * Transform an LHR into a proto-friendly, mostly-compatible LHR. - * @param {LH.Result} lhr - * @return {LH.Result} - */ + * Transform an LHR into a proto-friendly, mostly-compatible LHR. + * @param {LH.Result} lhr + * @return {LH.Result} + */ function processForProto(lhr) { /** @type {LH.Result} */ const reportJson = JSON.parse(JSON.stringify(lhr)); @@ -68,13 +68,8 @@ function processForProto(lhr) { }); } - // Drop the i18n icuMessagePaths. Painful in proto, and low priority to expose currently. - if (reportJson.i18n && reportJson.i18n.icuMessagePaths) { - delete reportJson.i18n.icuMessagePaths; - } - - // Remove any found empty strings, as they are dropped after round-tripping anyway /** + * Remove any found empty strings, as they are dropped after round-tripping anyway * @param {any} obj */ function removeStrings(obj) { diff --git a/proto/lighthouse-result.proto b/proto/lighthouse-result.proto index ae6f84e97190..09e268d8dcf9 100644 --- a/proto/lighthouse-result.proto +++ b/proto/lighthouse-result.proto @@ -505,8 +505,13 @@ message I18n { string show_relevant_audits = 48; } - // The message holding all formatted strings + // The message holding all formatted strings used in the renderer. RendererFormattedStrings renderer_formatted_strings = 1; + + // Holds all message paths used. The locale of the report has already be used to translated + // the strings in this LighthouseResult, but this field can be used to translate into another + // language. + map icu_message_paths = 2; } // Message containing Stack Pack information. diff --git a/types/lhr/lhr.d.ts b/types/lhr/lhr.d.ts index bd20aebd4ee0..3fdc4a6acf59 100644 --- a/types/lhr/lhr.d.ts +++ b/types/lhr/lhr.d.ts @@ -41,7 +41,11 @@ interface Result { /** Execution timings for the Lighthouse run */ timing: Result.Timing; /** Strings for the report and the record of all formatted string locations in the LHR and their corresponding source values. */ - i18n: {rendererFormattedStrings: Record, icuMessagePaths?: Result.IcuMessagePaths}; + i18n: { + rendererFormattedStrings: Record; + /** Optional because LR has many old LHRs that return nothing for this property. */ + icuMessagePaths?: Result.IcuMessagePaths; + }; /** An array containing the result of all stack packs. */ stackPacks?: Result.StackPack[]; }