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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@intl/t

v1.1.0

Published

This package provides a function `t()` which serves as a way to mark user-facing strings for translation. These strings are not translated at runtime but can be [statically extracted](https://github.com/gilbsgilbs/babel-plugin-i18next-extract) for transla

Downloads

1,831

Readme

@intl/t

This package provides a function t() which serves as a way to mark user-facing strings for translation. These strings are not translated at runtime but can be statically extracted for translation offline.

The only thing t() does at runtime is string interpolation. This is well typed using TypeScript.

The first parameter to t() should always be a string literal, it should never be a variable or expression. Protip: Use eslint-plugin-t to enforce this.

Examples:

// ✅ Correct Usage
t('Good morning!');

// ✅ Correct Usage
t('Hello {name}!', { name: 'Alice' });

// 🚫 TypeScript Error - Wrong property name
t('Hello {name}!', { firstName: 'Bob' });

// 🚫 TypeScript Error - Missing property `name`
t('Hello {name}!', {});

Installation

  1. Install using your favorite package manager

    npm install @intl/t
    # -- or --
    yarn add @intl/t
  2. Optionally make t() a global

    (TODO: Add instructions for this, including adding to global.d.ts and eslint config, jest)

  3. Consider installing the eslint plugin eslint-plugin-t

React

In React (or React Native) apps you might have special styling that needs to be applied to a portion of a sentence or phrase. You don't want to break up a sentence into multiple t() calls [^1] so we provide a special syntax for this.

Examples:

// Be sure to import the React version of `t()`
import { t } from '@intl/t/react';

// Wrap spans of text in an html-style tag (of any name), then provide a
// resolver for each tag name
t('Hello <b>world</b>!', {
  b: (content) => <span class="bold">{content}</span>,
});

// You can use value placeholders as well as tags
t('Hello <b>{name}</b>, click <a>here</a> to continue!', {
  name: currentUser.name,
  a: (content) => <a href="/next">{content}</a>,
  b: (content) => <strong>{content}</strong>,
});

// You can use any name for the html-like tags
t('Please <loginLink>login</loginLink> to to continue.', {
  loginLink: (content) => <a href="/login">{content}</a>,
});

// In React Native, all strings must be wrapped in a <Text> element, so we have
// a "fallback resolver" denoted by "_"
t('Hello <b>world</b>!', {
  b: (content) => <Text style={styles.bold}>{content}</Text>,
  _: (content) => <Text>{content}</Text>,
});

// The above is rendered as:
<>
  <Text>Hello </Text>
  <Text style={styles.bold}>world</Text>
  <Text>!</Text>
</>;

Footnotes

[^1]: Breaking up a sentence into multiple t() calls will essentially hard-code a specific word order to the sentence, however word order can be different in different languages, so we want to avoid this.