Add support for arrays of strings in package.nls.json files#188
Draft
Add support for arrays of strings in package.nls.json files#188
Conversation
Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Allow using arrays of strings as messages in
Add support for arrays of strings in package.nls.json files
Jul 10, 2025
package.nls.json
Comment on lines
+16
to
+48
| /** | ||
| * @public | ||
| * Normalizes a message format to a string by joining arrays with newlines | ||
| * @param value The message format to normalize | ||
| * @returns The normalized message string | ||
| */ | ||
| export function normalizeMessage(value: l10nJsonMessageFormat): string { | ||
| if (typeof value === 'string') { | ||
| return value; | ||
| } | ||
| if (Array.isArray(value)) { | ||
| return value.join('\n'); | ||
| } | ||
| return value.message; | ||
| } | ||
|
|
||
| /** | ||
| * @public | ||
| * Normalizes all messages in an l10nJsonFormat object | ||
| * @param data The l10nJsonFormat object to normalize | ||
| * @returns A normalized l10nJsonFormat object with all arrays converted to strings | ||
| */ | ||
| export function normalizeL10nJsonFormat(data: l10nJsonFormat): l10nJsonFormat { | ||
| const normalized: l10nJsonFormat = {}; | ||
| for (const [key, value] of Object.entries(data)) { | ||
| if (Array.isArray(value)) { | ||
| normalized[key] = value.join('\n'); | ||
| } else { | ||
| normalized[key] = value; | ||
| } | ||
| } | ||
| return normalized; | ||
| } |
Member
There was a problem hiding this comment.
I was really expecting these to be implementation details of the existing functionality and that the only API change is just adding string[] to l10nJsonMessageFormat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements support for arrays of strings as message values in
package.nls.jsonfiles, addressing the pain point of maintaining multiline strings with explicit\ncharacters.Problem
Previously, multiline strings in
package.nls.jsonhad to be written as single-line strings with explicit newline characters:{ "configuration.markdown.editor.filePaste.videoSnippet": "Snippet used when adding videos to Markdown. This snippet can use the following variables:\n- `${src}` — The resolved path of the video file.\n- `${title}` — The title used for the video. A snippet placeholder will automatically be created for this variable." }This format is difficult to read and maintain, especially for longer multiline messages.
Solution
Now you can use arrays of strings which are automatically joined with newline characters:
{ "configuration.markdown.editor.filePaste.videoSnippet": [ "Snippet used when adding videos to Markdown. This snippet can use the following variables:", "- `${src}` — The resolved path of the video file.", "- `${title}` — The title used for the video. A snippet placeholder will automatically be created for this variable." ] }Implementation Details
l10nJsonMessageFormatto supportstring[]in addition to existingstringand complex object formatsnormalizeMessage()andnormalizeL10nJsonFormat()utilities that join arrays with\ncharactersgenerate-pseudo)generate-azure)generate-xlf,import-xlf)Key Features
✅ Exact Equivalence: Array format produces identical output to original
\nformat✅ Flexible Support: Handles single-item arrays, empty arrays, and multi-line arrays
✅ Type Safety: Full TypeScript support with proper type definitions
✅ CLI Integration: Works with all existing
vscode-l10n-devcommands✅ Backwards Compatible: Existing
package.nls.jsonfiles continue to work unchangedTesting
Added comprehensive tests covering:
Fixes #187.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.