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

@fullerstack/ngx-i18n

v0.0.9

Published

A Translation Library for Angular

Downloads

29

Readme

@fullerstack/ngx-i18n

A simple translation library for Angular applications

status-image version-image coverage-image download-image

Overview

Description

Dealing with translation can be very hard especially if you don't want to publish different version of your application for each language you support. In that case ngx-translate is a great library to use. This packages encapsulates the ngx-translate library and make it a bit easier to deploy.

@fullerstack/ngx-i18n attempts to streamline the translation of your application, while promoting DRY DRY.

How to install

npm i @fullerstack/ngx-i18n |OR| yarn add @fullerstack/ngx-i18n

How to use

// In your environment{prod,staging}.ts

import { ApplicationCfg } from '@fullerstack/ngx-config';

export const environment: ApplicationCfg = {
  production: false,
  i18n: {
    // available languages
    availableLanguages: {
      en: {
        name: 'English',
        locale: '@angular/common/locales/en',
        localeExtra: '@angular/common/locales/extra/en',
      },
      fr: {
        name: 'Français',
        locale: '@angular/common/locales/fr',
        localeExtra: '@angular/common/locales/extra/fr',
      },
      de: {
        name: 'Deutsch',
        locale: '@angular/common/locales/de',
        localeExtra: '@angular/common/locales/extra/de',
      },
    },
    // enabled languages
    enabledLanguages: [
      // order is important
      'en',
      'fr',
    ],
    // cache busting hash
    // bump when you change any file in /assets/i18n/*.json
    cacheBustingHash: 'v0.0.1',
  },
};
// In your app.component.ts

import { ConfigModule } from '@fullerstack/ngx-config';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    ConfigModule.forRoot(environment), // make the environment injectable
    I18nModule.forRoot(), // use forChild() for lazy loaded modules
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}
// In your app.component.ts
import { Component } from '@angular/core';
import { I18nService } from '@fullerstack/ngx-i18n';

@Component({
  selector: 'fullerstack-root',
  template: `<h1>{{ 'COMMON.WELCOME' | translate }} to {{ title }}!</h1>`,
})
export class AppComponent {
  title = 'Fullerstack';
  constructor(i18n: I18nService) {}
}

Supported language translations in the /assets/ngx-i18n directory of your application.

/assets/ngx-i18n/en.json

{
  "COMMON.WELCOME": "Welcome",
  "COMMON.ABOUT": "About"
}

/assets/ngx-i18n/fr.json

{
  "COMMON.WELCOME": "Bienvenue",
  "COMMON.ABOUT": "Sur"
}

Advanced usage:

// In your app.component.ts
import { Component } from '@angular/core';
import { I18nService } from '@fullerstack/ngx-i18n';

@Component({
  selector: 'fullerstack-root',
  template: `<h1>{{ 'COMMON.WELCOME' | translate }} to {{ title }}!</h1>`,
})
export class AppComponent {
  direction = 'ltr';
  title = 'Fullerstack';
  constructor(public i18n: I18nService) {
    // translate in ts files
    i18n.xlate.get('COMMON.WELCOME').subscribe((res: string) => {
      console.log.info(res);
    });

    // check if language is Right2Left `rtl`
    if (i18n.isLanguageRTL('he')) {
      this.direction = 'rtl';
    }

    // change the language
    i18n.setCurrentLanguage('fr');

    // available properties
    // direction
    // currentLanguage
    // defaultLanguage
    // enabledLanguages

    // available methods
    // isCurrentLanguage(iso)
    // getLanguageName(iso)
    // getLanguageDirection(iso)
    // isLanguageEnabled(iso)
  }
}

License

Released under a (MIT) license.

Version

X.Y.Z Version

`MAJOR` version -- making incompatible API changes
`MINOR` version -- adding functionality in a backwards-compatible manner
`PATCH` version -- making backwards-compatible bug fixes