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

soon-i18n-common

v2.0.0

Published

utils for soon-i18n

Readme

soon-i18n-common v2.0

Shared core utilities and type definitions for soon-i18n ecosystem. This package contains the common logic used by all framework-specific adapters.

Purpose

This package provides:

  • 🧩 Core Utilities: Shared functions like formatString, flatTreeKey, mergeLocales
  • 🎯 Type Definitions: Advanced TypeScript types for type-safe translations
  • Loading Logic: Universal async/sync loading mechanisms
  • 🔧 Framework Agnostic: Can be used standalone for custom integrations

Installation

npm install soon-i18n-common

Core APIs

Utility Functions

formatString(str, obj)

Format a string with placeholders.

import { formatString } from "soon-i18n-common";

const result = formatString("Hello {name}!", { name: "World" });
// Returns: "Hello World!"

flatTreeKey(obj)

Flatten nested object to dot-notation keys.

import { flatTreeKey } from "soon-i18n-common";

const flat = flatTreeKey({
  button: {
    submit: "Submit",
    cancel: "Cancel"
  }
});
// Returns: { "button.submit": "Submit", "button.cancel": "Cancel" }

mergeLocales(target, ...sources)

Safely merge multiple locale objects.

import { mergeLocales } from "soon-i18n-common";

const result = mergeLocales(
  {},
  { welcome: "Welcome" },
  { button: { submit: "Submit" } }
);
// Returns: { welcome: "Welcome", button: { submit: "Submit" } }

formatObjKey(messages, id, ...args)

Get formatted translation from messages object.

import { formatObjKey } from "soon-i18n-common";

const messages = { greeting: "Hello {name}!" };
const result = formatObjKey(messages, "greeting", { name: "World" });
// Returns: "Hello World!"

loadLocale(rawData, onSuccess, onFail)

Load locale resource (sync or async).

import { loadLocale } from "soon-i18n-common";

loadLocale(
  () => import("./locales/en"),
  (locale) => console.log("Loaded:", locale),
  (error) => console.error("Failed:", error)
);

loadSyncLocales(rawLocales)

Load synchronous locales and initialize loading states.

import { loadSyncLocales } from "soon-i18n-common";

const [locales, loadings] = loadSyncLocales({
  zh: { hello: "你好" },
  en: () => import("./locales/en")
});

yi(locale)

Create standalone translator without state.

import { yi } from "soon-i18n-common";

const t = yi({
  hello: "Hello {name}!"
});

console.log(t("hello", { name: "World" })); // "Hello World!"

Type Definitions

AllPaths<T>

Extract all nested paths from an object type.

type Paths = AllPaths<{
  button: {
    submit: string;
    cancel: string;
  }
}>;
// Returns: "button.submit" | "button.cancel"

GetValue<data, path>

Get value type at specific path.

type Value = GetValue<
  { button: { submit: string } },
  "button.submit"
>;
// Returns: string

GetParams<T>

Extract parameters needed for translation.

type Params = GetParams<"Hello {name}, welcome to {city}!">;
// Returns: [{ name: string | number; city: string | number }]

SafeLocales<T>

Get intersection of translation keys across all languages.

type SafeKeys = SafeLocales<{
  zh: { common: { title: string } };
  en: { common: { title: string } };
}>;
// Ensures only keys that exist in ALL languages

LoadingStatus

Type for loading status: undefined | true | false | null

  • undefined: Waiting to load
  • true: Loading in progress
  • false: Loaded successfully
  • null: Load failed

Usage Examples

Custom Integration

You can use these utilities to build your own i18n solution:

import { 
  formatString, 
  flatTreeKey, 
  mergeLocales,
  loadLocale 
} from "soon-i18n-common";

class MyI18n {
  private locales = {};
  
  async load(lang: string, loader: () => Promise<any>) {
    await loadLocale(loader, (locale) => {
      this.locales[lang] = flatTreeKey(locale);
    });
  }
  
  translate(key: string, params?: any) {
    const message = this.locales[currentLang][key];
    return params ? formatString(message, params) : message;
  }
}

Type-Safe Translation Function

import { yi, AllPaths, GetValue, GetParams } from "soon-i18n-common";

type Locale = {
  greeting: "Hello {name}!";
  button: {
    submit: "Submit";
  };
};

const t = yi<Locale>({
  greeting: "Hello {name}!",
  button: {
    submit: "Submit"
  }
});

// Full type safety
t("greeting", { name: "World" }); // ✅
t("button.submit");               // ✅
// t("invalid.key");              // ❌ Type error

For Framework Authors

If you're building a framework-specific adapter, you'll need:

import {
  formatString,
  flatTreeKey,
  mergeLocales,
  loadLocale,
  loadSyncLocales,
  formatObjKey,
  yi,
  type AllPaths,
  type GetValue,
  type GetParams,
  type SafeLocales,
  type LoadingStatus
} from "soon-i18n-common";

// Then add your framework's reactivity system

See the source code of soon-i18n-react, soon-i18n-vue, etc. for examples.

Documentation

License

MIT