@colsen1991/ngx-translate-extract-marker

中文文档
3.0.1发布于 2024/11/08MITTypeScriptES Module近 30 天下载 5.4万

Function, pipe and directive to manually mark strings to be extracted using ngx-translate-extract

原始使用文档
文档目录8 节
  1. Installation
  2. Important notice
  3. Mark strings for extraction using the marker function
  4. Mark strings for extraction using the marker pipe
  5. Mark strings for extraction using the marker directive
  6. ngx-translate-extract-marker module
  7. ngx-translate-extract
  8. Credits

ngx-translate-extract-marker

This is a fork of a great library by Kim Biesbjerg, but as far as I can tell the original library is unfortunately no longer being developed

Installation

$ npm install @colsen1991/ngx-translate-extract-marker

Important notice

The marker pipe and directive is not supported in Kim's ngx-translate-extract package. Please use Vendure's instead: $ npm install @colsen1991/ngx-translate-extract.

Mark strings for extraction using the marker function

If, for some reason, you want to extract strings not passed directly to ngx-translate/TranslateService's get(), instant() or stream() methods, you can wrap them in a custom marker function to let ngx-translate-extract know you want to extract them.

Import and use the marker function:

import { marker } from '@colsen1991/ngx-translate-extract-marker';

marker('Extract me');

Or you can alias the marker() method:

import { marker as _ } from '@colsen1991/ngx-translate-extract-marker';

_('Extract me');

Then run the extract script: $ ngx-translate-extract

Mark strings for extraction using the marker pipe

If, for some reason, you want to extract strings not passed directly to ngx-translate/TranslatePipe, you can pass them into a custom marker pipe to let ngx-translate-extract know you want to extract them.

Import and use the marker pipe in your @NgModule:

import { MarkerPipe } from '@colsen1991/ngx-translate-extract-marker/extras';

@NgModule({ declarations: [MarkerPipe] })
export class YourModule {}

Or use the standalone pipe in your standalone component (careful not to use both methods):

import { MarkerPipeStandalone } from '@colsen1991/ngx-translate-extract-marker/extras';

@Component({ imports: [MarkerPipeStandalone], standalone: true })
export class StandaloneComponent {}

Then mark strings in your templates:

<your-component [yourInput]="'Hello world' | marker"></your-component>

Mark strings for extraction using the marker directive

If, for some reason, you want to extract strings not passed directly to ngx-translate/TranslateDirective, you can wrap them in a custom marker directive to let ngx-translate-extract know you want to extract them.

Import and use the marker directive in your @NgModule:

import { MarkerDirective } from '@colsen1991/ngx-translate-extract-marker/extras';

@NgModule({ declarations: [MarkerDirective] })
export class YourModule {}

Or use the standalone directive in your standalone component (careful not to use both methods):

import { MarkerDirectiveStandalone } from '@colsen1991/ngx-translate-extract-marker/extras';

@NgModule({ imports: [MarkerDirectiveStandalone], standalone: true })
export class StandaloneComponent {}

Then mark strings in your templates:

<p marker>Hello World</p>

Then run the extract script: $ ngx-translate-extract

ngx-translate-extract-marker module

You may also import the marker pipe and directive as a module:

import { MarkerModule } from '@colsen1991/ngx-translate-extract-marker/extras';

@NgModule({ imports: [MarkerModule] })
export class YourModule {}

ngx-translate-extract

See ngx-translate-extract and ngx-translate for more details.

Credits

Original library, idea and code: @biesbjerg/ngx-translate-extract-marker ❤️

版本与发布记录

@colsen1991/ngx-translate-extract-marker 共发布 11 个版本,首次发布于 2023/01/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.1latest2024/11/082 年前
3.0.02024/11/082 年前
2.0.82023/03/143 年前
2.0.72023/01/273 年前
2.0.62023/01/263 年前
2.0.52023/01/193 年前

关于 @colsen1991/ngx-translate-extract-marker 的常见问题

@colsen1991/ngx-translate-extract-marker 是什么?

Function, pipe and directive to manually mark strings to be extracted using ngx-translate-extract

如何安装 @colsen1991/ngx-translate-extract-marker?

在项目目录运行 npm install @colsen1991/ngx-translate-extract-marker,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(>=14.2.0)、@angular/core(>=14.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@colsen1991/ngx-translate-extract-marker 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@colsen1991/ngx-translate-extract-marker 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@colsen1991/ngx-translate-extract-marker 可以商用吗?

@colsen1991/ngx-translate-extract-marker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@colsen1991/ngx-translate-extract-marker 的下载量有多少?

根据 npm 官方下载统计,@colsen1991/ngx-translate-extract-marker 在 2026/10/11 – 2026/11/09 这 30 天内被下载 54,121 次,日均约 1,804 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@colsen1991/ngx-translate-extract-marker 还在维护吗?

最新版本 3.0.1 发布于 2024/11/08(2 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/01/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。