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

@dysporium/polyglot-dom

v2.0.0

Published

DOM integration for Dysporium Polyglot

Readme

@dysporium/polyglot-dom

Declarative DOM translation for vanilla JavaScript applications. This package automatically translates HTML elements using data attributes, with no framework required.

Overview

The DOM package bridges the Dysporium Polyglot core engine with the browser DOM. It scans your HTML for specially-marked elements and applies translations based on the current locale. When the locale changes, all translated elements update automatically.

This package is designed for projects that do not use React or other UI frameworks. For React applications, use @dysporium/polyglot-react instead.

Features

Attribute-Based Translation

Elements are marked for translation using data attributes. The primary attribute holds the translation key, while optional attributes provide pluralization counts, interpolation values, and context.

Default attributes:

  • data-i18n - The translation key to look up
  • data-i18n-count - A number for plural form selection
  • data-i18n-values - JSON object containing interpolation variables
  • data-i18n-context - Contextual hint for translation disambiguation
  • data-i18n-default - Fallback text when translation is missing
  • data-i18n-attr - Target attribute name instead of text content

Automatic DOM Observation

A MutationObserver watches for changes to the DOM tree. When new elements with translation attributes are added, they are translated immediately without manual intervention. This works seamlessly with dynamically generated content and single-page application navigation.

Reactive Locale Changes

The translator subscribes to locale change events from the core engine. When a user switches languages, every translated element on the page updates to reflect the new locale.

Attribute Translation

Beyond text content, translations can target element attributes. This is useful for translating placeholder text in inputs, title attributes for tooltips, aria-label values for accessibility, and other attribute-based content.

Scoped Translation

Translations can be scoped to a specific root element rather than the entire document body. This allows multiple independent translation contexts on a single page or limits the observation scope for performance optimization.

Installation

npm

npm install @dysporium/polyglot-dom

pnpm

pnpm add @dysporium/polyglot-dom

yarn

yarn add @dysporium/polyglot-dom

Package Exports

  • DOMTranslator - Main class for DOM translation management
  • createDOMTranslator - Factory function that creates and initializes a translator
  • translateDOM - Convenience function that returns a cleanup callback
  • DOMTranslatorConfig - TypeScript interface for configuration options

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | attribute | string | data-i18n | Primary attribute for translation keys | | countAttribute | string | data-i18n-count | Attribute for plural count values | | valuesAttribute | string | data-i18n-values | Attribute for interpolation variables | | root | Element | document.body | Root element to observe and translate | | observe | boolean | true | Whether to watch for DOM mutations |

Dependencies

This package includes @dysporium/polyglot-core as a dependency. The core package provides the translation engine, locale management, and formatting capabilities. You do not need to install it separately.

Related Packages

  • @dysporium/polyglot-core - Core translation engine
  • @dysporium/polyglot-react - React hooks and components
  • @dysporium/polyglot-ai - AI-powered translation with LLM providers

Browser Support

Requires browsers with MutationObserver support. All modern browsers are supported. Internet Explorer is not supported.

License

MIT