ngx-translate-cut
TypeScript icon, indicating that this package has built-in type declarations

19.0.2 • Public • Published

✂️🌍 NgxTranslateCut Pipe

npm version Package License Build & Publish NPM Downloads codecov

Angular pipe for cutting translations ✂️ 🌍 (plugin for @ngx-translate)

Angular 19, Angular Universal (SSR) and Zoneless compatible

Here's the demo or stackblitz live preview

Install

  1. Make sure you have @ngx-translate library installed, because this is its plugin

  2. Use npm (or yarn) to install the package

npm install ngx-translate-cut # For Angular 19. See compatibility table

Choose the version corresponding to your Angular version:

Angular ngx-translate-cut Install
ng19 19.x npm install ngx-translate-cut
ng18 18.x npm install ngx-translate-cut@18
ng17 17.x npm install ngx-translate-cut@17
ng16 5.x npm install ngx-translate-cut@5
ng15 4.x npm install ngx-translate-cut@4
ng14 3.x npm install ngx-translate-cut@3
ng13 3.x npm install ngx-translate-cut@3
ng12 (ivy only) 2.x npm install ngx-translate-cut@2
>= 5 =< 12 1.x npm install ngx-translate-cut@1
  1. Add NgxTranslateCutModule into your module imports.

File app.module.ts

  import { NgxTranslateCutModule } from 'ngx-translate-cut';

  @NgModule({
   // ...
   imports: [
     // ...
     NgxTranslateCutModule
   ]
  })

Usage

Definition

Strings are separated with | (pipe sign) ...but you can choose your own symbol

File assets/i18n/en.json

{
  "demo": "This is only one 'translate string' with | strong text | and | links"
}

Example code

In your template use translateCut:<number> pipe right after translate pipe from @ngx-translate library.

{{ 'demo' | translate | translateCut:0 }}

<strong> {{ 'demo' | translate | translateCut:1 }} </strong>

{{ 'demo' | translate | translateCut:2 }}

<a href="#"> {{ 'demo' | translate | translateCut:3 }} </a>

Result

This is only one 'translate string' with strong text and links

Options

Separator

If you are not satisfied with the basic settings of the separator (which is |), you can choose your own separator

  import { NgxTranslateCutModule } from 'ngx-translate-cut';

  @NgModule({
   // ...
   imports: [
     // ...
     NgxTranslateCutModule.forRoot({
      // Your separator in translation strings will be `*`
      separator: '*'
    }),
   ]
  })

Trim

If you do not want to trim your translation strings before cutting you can set trim to false (default is true). See this explanation...

  import { NgxTranslateCutModule } from 'ngx-translate-cut';

  @NgModule({
   // ...
   imports: [
     // ...
     NgxTranslateCutModule.forRoot({
      trim: false
    }),
   ]
  })

Dependencies

@ngx-translate/core

FAQ

Older Angular

Error

Failed to compile.

./node_modules/ngx-translate-cut/fesm2015/ngx-translate-cut.mjs 17:18-28 Can't import the named export 'Injectable' from non EcmaScript module (only default export is available)

Solution

You are probably trying to use this library with an older version of Angular (Angular 5 – 11).

Install copmatibility version instead:

yarn add ngx-translate-cut@1 # for angular 5 – 11

Development (notes for me)

Publish Stable

yarn release:patch
# yarn release:minor
# yarn release:major

Publish next channel

  1. Bump version -next.0 in package.json
  2. yarn publish:next

License

Copyright © 2024 Lukas Bartak

Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)

All contents are licensed under the MIT license.

Donation

If this project have helped you save time please consider making a donation for some 🍺 or 🍵 ;)

Thanks to

Original idea comes from: @yuristsepaniuk in this thread.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.0-beta.30ng12
1.7.43compat
18.1.0-next.10next
19.0.211latest

Version History

VersionDownloads (Last 7 Days)Published
19.0.211
19.0.154
19.0.07
18.1.0142
18.1.0-next.10
18.1.0-next.00
18.0.05
17.0.084
5.0.0148
4.0.25
4.0.10
4.0.00
4.0.0-next.00
3.2.041
3.1.122
3.1.00
3.0.00
3.0.0-next.10
2.0.055
1.7.43
1.7.30
2.0.0-beta.30
2.0.0-beta.20
2.0.0-beta.10
2.0.0-beta.00
1.7.25
1.7.10
1.7.00
1.7.0-beta.10
1.7.0-beta.00
1.6.30
1.6.20
1.6.10
1.6.1-rc.10
1.6.00
1.6.0-rc.20
1.6.0-rc.10
1.5.00
1.5.0-beta.10
1.4.20
1.4.10
1.4.00
1.3.00
1.3.0-rc.10
1.2.10
1.2.00
1.1.00
0.9.10
0.9.00

Package Sidebar

Install

npm i ngx-translate-cut

Weekly Downloads

437

Version

19.0.2

License

MIT

Unpacked Size

19.8 kB

Total Files

12

Last publish

Collaborators

  • bartholomej