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

koto-react

v1.1.0

Published

Koto - React translation library with IndexedDB caching

Readme

Koto React

Koto (言) — Japanese for "word." Every translation starts with a single word. Koto bridges languages one word at a time.

A React translation library with IndexedDB caching for optimal performance.

Installation

npm install koto-react
# or
yarn add koto-react

Usage

Basic Setup with Provider

import React from 'react';
import { KotoProvider } from 'koto-react';

function App() {
  return (
    <KotoProvider
      apiKey="your-api-key"
      defaultLocale="en"
      apiUrl="https://your-api-endpoint.com/translations" // optional
    >
      <YourApp />
    </KotoProvider>
  );
}

Using the Translation Hook

import React from 'react';
import { useTranslation } from 'koto-react';

function MyComponent() {
  const { t, locale, loading } = useTranslation();

  if (loading) {
    return <div>Loading translations...</div>;
  }

  return (
    <div>
      <h1>{t('checkout.payment.title')}</h1>
      <p>{t('checkout.payment.description', 'Default fallback text')}</p>
      <p>Current locale: {locale}</p>
    </div>
  );
}

Using the Standalone Translation Function

For non-React contexts or utility functions:

import { t, initTranslations } from 'koto-react';

// Initialize once in your app
await initTranslations('en');

// Use anywhere
const title = t('checkout.payment.title');
const notFound = t('some.missing.key'); // Returns 'some.missing.key'
const withFallback = t('some.missing.key', 'Fallback text'); // Returns 'Fallback text'

Translation with Interpolation

import { ti } from 'koto-react';

// If translation is: "Hello, {{name}}! You have {{count}} items."
const message = ti('greeting.message', {
  name: 'John',
  count: 5
});
// Returns: "Hello, John! You have 5 items."

Pluralization

import { tp } from 'koto-react';

// Translations:
// "items.zero": "No items"
// "items.one": "One item"
// "items.other": "{{count}} items"

tp('items', 0);  // "No items"
tp('items', 1);  // "One item"
tp('items', 5);  // "5 items"

Features

  • Automatic Caching: Translations are cached in IndexedDB for offline access and faster loads
  • Background Updates: Cached translations are served immediately while fresh data is fetched in the background
  • Nested Keys: Support for nested translation keys using dot notation
  • TypeScript Support: Full TypeScript support with type definitions
  • Offline Support: Works offline using cached translations
  • Flexible API: Use with React hooks or standalone functions

API Reference

KotoProvider

The main provider component that manages translations.

Props:

  • apiKey (string, required): Your API key for fetching translations
  • defaultLocale (string, required): The default locale to use
  • apiUrl (string, optional): Custom API endpoint URL
  • children (ReactNode, required): Your app components

useTranslation()

Hook that returns translation utilities.

Returns:

  • t(key: string, fallback?: string): string - Translation function
  • locale: string - Current locale
  • loading: boolean - Loading state

t(key: string, fallback?: string): string

Standalone translation function.

Parameters:

  • key: The translation key (supports dot notation)
  • fallback: Optional fallback value if translation not found

Returns: The translated string or the key if not found

Storage

Translations are automatically cached in IndexedDB with:

  • 1-hour cache duration (configurable)
  • Automatic cleanup of expired entries
  • Per-locale storage

License

MIT