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

ngx-transloco-markup-router-link

v4.0.0

Published

Link renderer for ngx-tranlate-markup that supports router links

Downloads

2,055

Readme

Build Status NPM Version

ngx-transloco-markup-router-link

A plugin for ngx-transloco-markup that supports router links. The support for such links has intentionally been excluded from the ngx-transloco-markup core library, as this would introduce a dependency to @angular/router. Not all applications using Transloco will be using the Angular router. For those that do, and which also need for router links in translations, this plugin delivers that support.

Installation

This library is a plugin for ngx-transloco-markup, so first make sure that package is installed and your application has been configured to use it.

The next step is to install the ngx-transloco-markup-router-link package from NPM:

npm install --save ngx-transloco-markup-router-link

After having installed the NPM package the final step is to make the router link renderer available to the link markup transpilers of ngx-transloco-markup. This is as simple as including translocoMarkupRouterLinkRenderer() in the providers array of your application's root module (usually called AppModule):

import { translocoMarkupRouterLinkRenderer } from 'ngx-transloco-markup-router-link';

@NgModule({
  providers: [
    translocoMarkupRouterLinkRenderer() // <-- Add this line to the providers array
  ]
})
export class AppModule { }

Usage

If you followed the installation instructions above, then your application now supports router links wherever you make use of one of the link markup transpilers. A router link is defined as an object should conform to the following interface:

import { NavigationExtras } from '@angular/router';

export interface RouterLink extends NavigationExtras {
    route: string | NavigationCommand[];
    target?: string;
}

export type NavigationCommand = any;

The route property defines the Angular router target, which can either be defined as string or as a sequence of navigation commands (similar to the input of Angular's router link directive). Like normal links you can also specify a target window or frame using the target property.

Since the RouterLink model is an extension of the NavigationExtras interface you can also specify optional properties such a query parameters, the fragment and whether the route is relative to a certain ActivatedRoute.

An example of how to use the RouterLink model in a component is shown below:

import { Component } from '@angular/core';
import { RouterLink } from 'ngx-transloco-markup-router-link';

@Component({
  selector: 'app-router-link-example'
  template: `
    <transloco
      [key]="'EXAMPLE_WITH_LINK'"
      [params]="{ moreDetailsLink: projectLink }"
    ></transloco>
  `
})
export class RouterLinkExampleComponent {
  @Input() public projectId: string = '7357-C453';

  public get projectLink(): RouterLink {
    return {
      route: ['projects', this.projectId, 'details'],
      queryParams: { soundEffects: 'on' }
    };
  }
}

The corresponding English translation file for the example above could look like the following:

{
  "EXAMPLE_WITH_LINK": "Show [link:moreDetailsLink]more details[/link] of the project."
}