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

@ubs-platform/translator-ngx

v4.0.0

Published

A translator library for Angular, based [Translator Core](https://www.github.com/ubs-platform/translator-core)

Downloads

34

Readme

UBS Translator NGX (a16-c1.0.7)

A translator library for Angular, based Translator Core

Importante Resultante :d

Installation

npm install rxjs @ubs-platform/translator-core @ubs-platform/translator-ngx

⚠️ Currently natively working on Angular 16. If you have newer angular version, you can install by passing --legacy-peer-deps It should work on Angular 17. However it not tested yet and i don't recommend this way either. We are working at the new upgrade for Angular 17

How to use

Before start

  • Create directory named lang in application path/assets/
  • And then; Create 3 json files in the lang directory

en.json:

[
  {
    "stringMap": {
      "hello": "Hello, Welcome!"
    }
  },
  {
    "prefix": "languages",
    "stringMap": {
      "tr": "Turkish",
      "en": "English",
      "de": "German"
    }
  }
]

de.json

[
  {
    "stringMap": {
      "hello": "Hallo, Willkommen!"
    }
  },
  {
    "prefix": "languages",
    "stringMap": {
      "tr": "Türkisch",
      "en": "Englisch",
      "de": "Deutsch"
    }
  }
]

tr.json:

[
  {
    "stringMap": {
      "hello": "Merhaba, Hoş Geldiniz"
    }
  },
  {
    "prefix": "languages",
    "stringMap": {
      "tr": "Türkçe",
      "en": "İngilizce",
      "de": "Almanca"
    }
  }
]

Fun fact: In json files, you can define TranspationPart array or one translation part if you need just a TranspationPart

In modular library/or application

  • In app.module.ts or your library

    • Import UbsTranslatorNgxModule to use translate pipe and HttpClientModule to import required json files via HttpClient.

    • Provide TranslatorRepositoryService to keep translations and LANGUAGE_JSON_URL to load translation files as desired

import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { UbsTranslatorNgxModule, TranslatorRepositoryService, LANGUAGE_JSON_URL, EnvironmentController } from '@ubs-platform/translator-ngx';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';

// Initialize the environment controller
// and start in default language
// and you can call it first at `main.ts` before module get bootstrapped
EnvironmentController.getEnvironmentController('en');

@NgModule({
  imports: [UbsTranslatorNgxModule, HttpClientModule, BrowserModule],
  providers: [
    TranslatorRepositoryService,
    {
      provide: LANGUAGE_JSON_URL,
      useValue: [(language: string) => `assets/lang/${language}.json`],
    },
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}
  • In component:
import { Component } from '@angular/core';
import { EnvironmentController, LANGUAGE_JSON_URL, TranslatorRepositoryService, UbsTranslatorNgxModule } from '@ubs-platform/translator-ngx';
import { HttpClientModule } from '@angular/common/http';

@Component({
  selector: 'translator-ngx-example-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  /**
   * Changes the language
   */
  changeLanguage(arg0: string) {
    EnvironmentController.getEnvironmentController().setLanguage(arg0);
  }
  title = 'translator-ngx-example';
}
  • And the component template, you can use translate pipe to translating these texts
<button (click)="changeLanguage('en')">{{ 'languages.en' | translate }}</button>
<button (click)="changeLanguage('tr')">{{ 'languages.tr' | translate }}</button>
<button (click)="changeLanguage('de')">{{ 'languages.de' | translate }}</button>
<h1>{{ 'hello' | translate }}</h1>

In standalone components

In standalone components, there is similar operations in Angular modules.

  • Import UbsTranslatorNgxModule to use translate pipe and HttpClientModule to import required json files via HttpClient.

  • Provide TranslatorRepositoryService to keep translations and LANGUAGE_JSON_URL to load translation files as desired

  • You can use same template and json files at in The section: In modular library/or application

// Initialize the environment controller and start in default language
EnvironmentController.getEnvironmentController('en');

import { Component } from '@angular/core';
import { EnvironmentController, LANGUAGE_JSON_URL, TranslatorRepositoryService, UbsTranslatorNgxModule } from '@ubs-platform/translator-ngx';
import { HttpClientModule } from '@angular/common/http';

@Component({
  standalone: true,
  imports: [UbsTranslatorNgxModule, HttpClientModule],
  providers: [
    TranslatorRepositoryService,
    {
      provide: LANGUAGE_JSON_URL,
      useValue: [(language: string) => `assets/lang/${language}.json`],
    },
  ],
  selector: 'translator-ngx-example-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  changeLanguage(arg0: string) {
    EnvironmentController.getEnvironmentController('en').setLanguage(arg0);
  }
  title = 'translator-ngx-example';
}

Passing parameters in translate pipe

In translate part, some parameter definitions can be made with curly parentheses.

{
  "stringMap": {
    "person-saved": "The person named {name} has been saved"
  }
}

Extra paramaters can be passed via

{{ "person-saved" | translate: {name: 'Jason'} }}

After the render, you will see as:

The person named Jason has been saved

Roadmap

We are planning to making documentation more detailed and upgrade the angular version at soon.

If you have any questions, improvements or any issue, you can open a issue or pull request without hesitation.

Changelog

2.0.2

  • Version of Translator Core library has been upgraded to 1.0.7

2.0.1

  • Upgraded to Angular 16

1.0.7

  • Readme.md file is edited

1.0.6

  • Worked on getting runnable

Contact

Hüseyin Can Gündüz