Skip to content

Add support for arrays of strings in package.nls.json files#188

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-187
Draft

Add support for arrays of strings in package.nls.json files#188
Copilot wants to merge 3 commits intomainfrom
copilot/fix-187

Conversation

Copy link

Copilot AI commented Jul 10, 2025

This PR implements support for arrays of strings as message values in package.nls.json files, addressing the pain point of maintaining multiline strings with explicit \n characters.

Problem

Previously, multiline strings in package.nls.json had 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

  • Type Extension: Extended l10nJsonMessageFormat to support string[] in addition to existing string and complex object formats
  • Normalization Functions: Added normalizeMessage() and normalizeL10nJsonFormat() utilities that join arrays with \n characters
  • Comprehensive Integration: Updated all processing pipelines:
    • Pseudo-localization (generate-pseudo)
    • Azure translation (generate-azure)
    • XLF generation and import (generate-xlf, import-xlf)
  • Backwards Compatibility: All existing functionality remains unchanged

Key Features

Exact Equivalence: Array format produces identical output to original \n format
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-dev commands
Backwards Compatible: Existing package.nls.json files continue to work unchanged

Testing

Added comprehensive tests covering:

  • Array string normalization
  • Integration with pseudo-localization
  • Type safety and edge cases
  • Validation that output matches original format exactly

Fixes #187.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 10, 2025 06:57
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 package.nls.json Add support for arrays of strings in package.nls.json files Jul 10, 2025
Copilot AI requested a review from TylerLeonhardt July 10, 2025 07:01
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow using arrays of strings as messages in package.nls.json

2 participants