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-translate-routes

v1.4.1

Published

A package to translate title and route path

Downloads

797

Readme

NgxTranslateRoutes

pipeline status Quality Gate Status Coverage Vulnerabilities

Features

  • This service translate title and route path.

Dependencies

Latest version available for each version of Angular

| ngx-translate | Angular | |---------------|---------------| | 1.4.0 | 13.x to 9.x | | 1.3.0 | 11.x to 8.x | | 1.2.0 | 9.x 8.x 7.x | | 1.1.0 | 9.x 8.x 7.x | | 1.0.2 | 9.x 8.x 7.x | | 1.0.0 | 9.x 8.x 7.x | | 0.1.0 | 9.x 8.x 7.x |

Live Example

You can check how these library work in the next link, on live example: https://stackblitz.com/edit/ngx-translate-routes-example

Install

  npm install ngx-translate-routes --save

@ngx-translate package is a required dependency

  npm install @ngx-translate/core --save
  npm install @ngx-translate/http-loader --save

Follows this link for more information about ngx-translate: https://github.com/ngx-translate/core

Setup

step 1: Add NgxTranslateRoutesModule to appModule, make sure you have configured ngx-translate as well

  import { BrowserModule } from '@angular/platform-browser';
  import { HttpClientModule, HttpClient } from '@angular/common/http';
  import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
  import { TranslateHttpLoader } from '@ngx-translate/http-loader';

  import { NgxTranslateRoutesModule } from 'ngx-translate-routes';

  // part of configuration ngx translate loader function
  export function HttpLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http); // make sure your assets files are in default assets/i18n/*
  }

  @NgModule({
    declarations: [
      AppComponent
    ],
    imports: [
      BrowserModule,
      HttpClientModule, // required module for ngx-translate
      // required ngx-translate module
      TranslateModule.forRoot({
        defaultLanguage: 'en',
        useDefaultLang: true,
        loader: {
          provide: TranslateLoader,
          useFactory: (HttpLoaderFactory),
          deps: [HttpClient]
        }
      }),
      NgxTranslateRoutesModule.forRoot(),//NgxTranslateRoutesModule added
    ],
    providers: [],
    bootstrap: [AppComponent]
  })
  class MainModule {}

In app module when import the module can configure if we don want to to translate routes or title for default the service will translate both features. We can pass to forRoot the following object if dont want to translate titles.

 NgxTranslateRoutesModule.forRoot({
      enableTitleTranslate: false
    })

Configuration Object

  NgxTranslateRoutesConfig {
    enableRouteTranslate?: boolean,
    enableTitleTranslate?: boolean
  }

step 2 Add error message configuration in JSON file Ngx-translate and others internationalizations packages manage json files for each idiom thant manage. For example is your application manage english langague you must create in assets/i18n/en.jsone all the titles and routes you need to translate in your application. Every property in the json will be named as we want to discribe route, by example:

  // assets/i18n/en.json
  {
    "titles": {
        "about": "About Us",
        "users": {
            "root": "Users",
            "profile": "User Profile",
            "myaccount": "List Users"
        }
    },
    "routes": {
        "about": "aboutUs",
        "myaccount": "myAccount"
    }
  }

You must respect titles and routes key. If you change some of these keys, the library does not work for you to change.

Use

After configuration you can use the service customizing your routes object as follow example

  // app.routing.modules.ts 
  const routes: Routes = [
    { path: 'about', component: AboutComponent, data: {title: 'titles.about'} },
    { path: 'profile', component: MyprofileComponent, data: {title: 'titles.profile'} },
    { path: 'myaccount', component: MyaccountComponent, data: {title: 'titles.myaccount'} },
    { path: 'dashboard', component: DashboardComponent, data: {title: 'Dashboard'} }
  ];

For translate titles we need to add in data object title value respecting the tree we create for translate titles for example title: 'titles.about', will be replace with about value inside json translation file, follow the json in step 2 of cofiguration it title will replace with About Us. If we dont add translate for some title we will follow Dashboard example only add for title the final value.

For translate routes is litle easy we only need to create the route object inside translation follow the json in step 2 of configuration. The route key in translate file must be the same as path string.

License

MIT


GitLab @darioegb  ·