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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tnet-i18n/i18n

v1.332.0

Published

> Shared **i18n package** cho hệ thống web & mobile apps của Trinity Net Technology. > Dùng để đồng bộ key/value translations (multi-language) và cung cấp API/React hook để thao tác thuận tiện.

Downloads

12,713

Readme

@tnet-i18n/i18n

Shared i18n package cho hệ thống web & mobile apps của Trinity Net Technology.
Dùng để đồng bộ key/value translations (multi-language) và cung cấp API/React hook để thao tác thuận tiện.


✨ Tính năng

  • 📦 Centralized translations: dùng chung locales/*.json cho cả web (React) và app (React Native).
  • 🔑 Type-safe keys: auto-generate type từ en.json → autocomplete khi gọi t().
  • React hooks: có sẵn useT() để dễ dùng trong component.
  • 🔄 Hot language switch: hỗ trợ i18next.changeLanguage() runtime.
  • 🚀 CI/CD ready: publish tự động qua GitHub Actions khi release.

📥 Cài đặt

Package được publish public trên npm:

yarn add @tnet-i18n/i18n
# hoặc npm
npm install @tnet-i18n/i18n

🛠 Cách dùng

1. Khởi tạo i18n

Trong entry file của app (ví dụ main.tsx với React, App.tsx với React Native):

import { initI18n } from "@tnet-i18n/i18n";

// Khởi tạo với ngôn ngữ mặc định
initI18n({ lng: "en" });

2. Dùng hàm t()

import { t } from "@tnet-i18n/i18n";

function Example() {
  return <h1>{t("button.viewQuotes")}</h1>;
}

3. Dùng hook useT()

import { useT } from "@tnet-i18n/i18n";

export function Example() {
  const { t, i18n, lng } = useT();

  return (
    <>
      <p>Current language: {lng}</p>
      <p>{t("common.loading")}</p>
      <button onClick={() => i18n.changeLanguage(lng === "en" ? "cn" : "en")}>
        Switch Language
      </button>
    </>
  );
}

🌍 Cấu trúc locales/

locales/
 ├─ en.json   # English
 └─ cn.json   # Chinese

Ví dụ en.json:

{
  "button": {
    "login": "Login",
    "logout": "Logout",
    "viewQuotes": "View Quotes"
  },
  "common": {
    "loading": "Loading..."
  }
}

🔑 Type-safe Keys

Sau mỗi lần build, file dist/keys.d.ts sẽ được sinh tự động từ en.json.

import { t } from "@tnet-i18n/i18n";
import type { TranslationKey } from "@tnet-i18n/i18n/dist/keys";

function safeT<K extends TranslationKey>(key: K) {
  return t(key);
}

safeT("button.login");     // ✅
safeT("button.notExists"); // ❌ lỗi compile

🚀 Release quy trình

1. Tự động (qua GitHub Actions)

  • Bump version trong package.json (ví dụ "1.0.1").
  • Commit & tạo tag theo format:
    git commit -am "chore(release): v1.0.1"
    git tag i18n-v1.0.1
    git push origin main --tags
  • GitHub Actions sẽ tự build & publish lên npm.

2. Thủ công (Run workflow)

  • Push code với version mới trong package.json.
  • Vào tab Actions → Publish to npm → Run workflow.
  • CI sẽ build & publish version mới.

📦 Scripts có sẵn

  • yarn build – build TypeScript → dist/
  • yarn check:placeholders – check placeholders giữa các file locale
  • yarn gen:keys – generate type keys từ en.json
  • yarn prepublishOnly – chạy full build + check + gen trước khi publish

📜 License

MIT © Trinity Net Technology