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

@cyia/localize

v1.2.3

Published

Angular 本地化独立版本;Angular localize standalone version

Downloads

7

Readme

| 中文 | English | | --------------------------- | ---------------------- |


简介

  • @angular/localize独立版本,允许用于任何 node/前端 项目
  • 通过命令i18n/l10n提取/合并/转换翻译文件

来源

  • Angular 17.3.1

使用方法

import { $localize } from '@cyia/localize';
$localize`one`;
  • 使用i18n ./src 提取src下所有$localize标签模板内容生成extract.json元数据

    @angular/localize 生成 id 一致

  • 复制extract.json自定义语言翻译,将翻译内容写入到target字段
  • 使用i18n convert ./i18n-merge ./i18n将翻译元数据转换为key-value格式用于引用
  • 自定义引用格式导入翻译,如
// node环境演示
import path from 'path';
import fs from 'fs';
import { loadTranslations } from '@cyia/localize';
export const LanguageMap: Record<string, string> = {
  zh_cn: 'zh-Hans',
  cn: 'zh-Hans',
  en: 'en-US',
  en_us: 'en-US',
};
export function loadI18n() {
  let lang = process.env['CR_LANG']?.toLowerCase();
  if (!lang) {
    if (process.env['LANGUAGE']) {
      lang = process.env['LANGUAGE'].split(':')[0].toLowerCase();
    } else if (process.env['LANG']) {
      lang = process.env['LANG'].split('.')[0].toLowerCase();
    }
  }
  let cache;
  const filePath = path.join(__dirname, `./i18n/${LanguageMap[lang!] || lang || 'zh-Hans'}.json`);
  if (ENV === 'test') {
    cache = {};
  } else {
    if (!fs.existsSync(filePath)) {
      cache = __non_webpack_require__('./i18n/zh-Hans.json');
    } else {
      cache = __non_webpack_require__(filePath);
    }
  }

  loadTranslations(cache);
}

loadI18n();

合并其他翻译

  • 如果其他依赖包也使用了@cyia/localize并且发布包中含有翻译文本/元数据文本,可以使用i18n merge ./output ./pkg1 ./pkg2将多个合并,然后再导入

更新已有翻译

  • i18n ./src ./i18n-meta --update --name zh-Hans提取内容后以zh-Hans为原始文件(不需要翻译),其他语言的文件会添加/删除相应文本