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

@libs-ui/services-translate

v0.2.356-1

Published

Dịch vụ quản lý đa ngôn ngữ (i18n) cho project, mở rộng từ `@ngx-translate/core` với các tính năng đặc thù:

Readme

LibsUiTranslateService

Dịch vụ quản lý đa ngôn ngữ (i18n) cho project, mở rộng từ @ngx-translate/core với các tính năng đặc thù:

  • Tích hợp MessageFormat: Hỗ trợ plural rules, select statements phức tạp.
  • Global Interpolation: Biến {value} dùng chung không cần truyền thủ công.
  • Merge từ source: Tự động merge chuỗi dịch nội bộ(data-translation.ts) khi gọi use().
  • Lưu ngôn ngữ: Tích hợp UtilsCache để lưu lựa chọn ngôn ngữ vào localStorage.

Cài đặt

// app.config.ts
import { getConfigTranslate } from '@libs-ui/services-translate';

export const appConfig: ApplicationConfig = {
  providers: [
    getConfigTranslate(), // Load từ /i18n/*.json
    getConfigTranslate('/assets/translations/'), // Đường dẫn tùy chỉnh
  ],
};

Cấu trúc file ngôn ngữ

Đặt các file JSON tại public/i18n/ (hoặc đường dẫn tùy chỉnh truyền vào getConfigTranslate):

public/
└── i18n/
    ├── vi.json
    └── en.json

Ví dụ vi.json:

{
  "i18n_hello": "Xin chào",
  "i18n_greeting": "Xin chào, {name}!",
  "i18n_item_count": "{value} {value,plural, =0 {mục} =1 {mục} other {mục}}"
}

Inject translation từ Object (không cần file .json)

Phù hợp khi muốn đặt translation trực tiếp trong code (ví dụ: cho các key của thư viện dùng chung):

import { TranslateService } from '@ngx-translate/core';

constructor() {
  this.translate.setTranslation('vi', {
    i18n_welcome: 'Chào mừng đến với hệ thống',
    i18n_role: 'Vai trò: {role}',
  }, true); // true = merge, không ghi đè keys từ file JSON

  this.translate.setTranslation('en', {
    i18n_welcome: 'Welcome to the system',
    i18n_role: 'Role: {role}',
  }, true);

  this.translate.use('vi');
}

Sử dụng trong Template

<!-- Dùng pipe -->
<span>{{ 'i18n_search' | translate }}</span>

<!-- Có interpolation params -->
<span>{{ 'i18n_greeting' | translate: { name: 'Admin' } }}</span>

<!-- Plural (MessageFormat) -->
<span>{{ 'i18n_item_count' | translate: { value: 5 } }}</span>

Sử dụng trong Component

import { TranslateService } from '@ngx-translate/core';

export class MyComponent {
  private translate = inject(TranslateService);

  // Sync
  get label() {
    return this.translate.instant('i18n_search');
  }

  // Async (reactive)
  label$ = this.translate.get('i18n_search');

  // Chuyển ngôn ngữ
  switchLang(lang: string) {
    this.translate.use(lang);
  }
}

Global Interpolation

Dùng để inject biến dùng chung (tên thương hiệu, hotline...) vào tất cả chuỗi dịch:

import { setInterpolateParamDefault } from '@libs-ui/services-translate';

// Thường đặt ở app.component.ts
setInterpolateParamDefault({
  brand: 'Mobio CRM',
  hotline: '1900 1234',
});

Trong file dịch:

{
  "i18n_contact": "Liên hệ {brand} qua hotline {hotline}"
}

Kết quả: "Liên hệ Mobio CRM qua hotline 1900 1234" — không cần | translate: { brand: '...', hotline: '...' }.

MessageFormat — Plural & Select

{
  "i18n_items": "{value} {value,plural, =0 {mục} =1 {mục} other {mục}}",
  "i18n_status": "Trạng thái: {status,select, active {Hoạt động} inactive {Không hoạt động} other {Không xác định}}"
}

Demo

Xem chi tiết và test interactive tại: http://localhost:4500/services/translate