npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spscommerce/document-view-auto-localization

v1.6.0

Published

An automatic localization tool for the FEDS.

Downloads

179

Readme

@spscommerce/document-view-auto-localization

An automatic localization tool for the Document View FF functionality. Processes XSL stylesheets and replaces hardcoded text with localization calls.

Requirements

  • Node.js >=24

Installation

pnpm add @spscommerce/document-view-auto-localization

Usage

import { autoLocalization } from '@spscommerce/document-view-auto-localization';

const xslText = `
  <xsl:stylesheet version="1.0">
    <p id="FieldLabel">Total Volume :</p>
  </xsl:stylesheet>
`;

const result = await autoLocalization(xslText);

console.log(result.xslText);
// <p id="FieldLabel">
//   <xsl:call-template name="translate">
//     <xsl:with-param name="id" select="'totalVolume'"/>
//     <xsl:with-param name="default" select="'Total Volume'"/>
//   </xsl:call-template> :
// </p>

console.log(result.foundTextTokens);
// [{ text: 'Total Volume :', key: 'totalVolume', textType: 'text', performedAction: 'canonical', quantityUsing: 1 }]

API

autoLocalization(xslText, options)

Processes an XSL stylesheet and replaces hardcoded text nodes with <xsl:call-template name="translate"> localization calls.

Signature:

async function autoLocalization(
  xslText: string,
  options?: AutoLocalizationOptions,
): Promise<ProcessingResults>

Parameters

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | xslText | string | Yes | The XSL stylesheet source text to process. Must be a valid non-empty XSL string. | | options | AutoLocalizationOptions | No | Configuration options for the localization process. |

AutoLocalizationOptions

| Property | Type | Default | Description | |----------|------|--------|-------------| | useConsoleLog | boolean | false | Enables verbose debug logging to the console. | | env | 'test' \| 'prod' | test | Specifies the runtime environment. Affects which canonical keys are loaded. | | ownCanonicalKeys | CanonicalKeys | — | Custom set of canonical keys to use instead of the built-in ones. |

Return value: ProcessingResults

| Property | Type | Description | |----------|------|-------------| | xslText | string | The processed XSL stylesheet with hardcoded text replaced by localization calls. | | foundTextTokens | FoundTextToken[] | List of all text tokens found and processed during transformation. |

FoundTextToken

| Property | Type | Description | |----------|------|-------------| | text | string | The original text found in the XSL. | | key | string | The translation key assigned to this text. | | textType | TextType | Whether the token is a plain text node ('text') or a legacy localization call ('legacy'). | | performedAction | PerformedAction | The action taken when resolving the key (see below). | | quantityUsing | number | How many times this text token was encountered in the XSL. |

PerformedAction values

| Value | Description | |-------|-------------| | 'canonical' | Text was matched exactly to an existing canonical key. | | 'canonical_normalized' | Text was matched to a canonical key after normalization (e.g. removing punctuation). | | 'new' | No canonical match found; a new key was generated from the text. | | 'unparsed_key' | A legacy $translate[@id='...'] call had an invalid or unparseable format. | | 'unresolved_key' | A legacy key was found but could not be resolved in the canonical keys. |

CanonicalKeys

See the full format specification in the https://support.phrase.com/hc/en-us/articles/20038313421468--JSON-Phrase-Strings.

In the package we use the following format:

type CanonicalKeys = Record<string, CanonicalKey>;

interface CanonicalKey {
  key: {
    plural?: boolean;
    max_characters_allowed?: number;
    description?: string;
    tags?: string[];
  };
  translations: {
    locale?: string;
    locale_code?: string;
    content: string;
  }[];
}

Errors

The function throws an error if xslText is an empty string.

How it works

  1. Parses the XSL source text into a DOM tree.
  2. Recursively walks all nodes looking for text content.
  3. For each text node, attempts to resolve a translation key using three strategies in order:
    • Exact match against canonical keys.
    • Normalized match — strips punctuation/separators and tries again.
    • New key — generates a camelCase key from the text.
  4. Replaces the text node with an <xsl:call-template name="translate"> element.
  5. Handles legacy <xsl:value-of select="$translate[@id='...']"/> calls and transforms them into the new format.
  6. Serializes the DOM back to an XSL string and returns it together with the token metadata.

Note: The new keys (PerformedAction = 'new') are not saving to any place, so you have to collect it and store to the Phrase.com project.