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

@studiohyperdrive/ngx-i18n

v17.0.0

Published

Install the package first: ```shell npm install @studiohyperdrive/ngx-i18n ```

Downloads

202

Readme

Angular Tools: NgxI18nModule (@studiohyperdrive/ngx-i18n)

Install the package first:

npm install @studiohyperdrive/ngx-i18n

1. Concept

ngx-1i8n is a layer on top of ngx-translate that allows for a lazy-loaded modular approach to translations. This approach allows the user to split up the translations into several independent files, which can be lazy-loaded whenever they're needed.

This approach only works for module-based projects. There is currently no support for standalone-components.

2. Modular

In order for a modular translation system, we provide a TranslationLoader to each forChild method of the NgxI18nModule. This loader uses a similar approach as @rbalet's MultiTranslateHttpLoader.

Using an array of source paths, the translation loader loads in only the provided translations. If one of the assets has previously been loaded by a different module, the translation will be fetched from the cache.

import { MultiTranslationHttpLoader } from '@studiohyperdrive/ngx-i18n'

export function ExampleTranslationLoader(http: HttpBackend) {
	return new MultiTranslationHttpLoader(http, ['./path-to-translation/']);
}

If no custom TranslationLoader is provided, than the module will use a fall-back loader which has a default array of paths that can be set in the config file.

3. Lazy-loaded

In order to provide a lazy loaded translation system, the translations only get loaded when routing to a specific route.

For this purpose we've provided a TranslationLoaderGuard which will automatically fetch all translations when the application routes to this route.

At any given time you can query the I18nLoadingService to see whether the translations have been loaded into the application. There are two Observables provided, being translationsLoading$ and translationsFailed$;

4. I18nGuard

The @studiohyperdrive/ngx-i18n package also provides us with a I18nGuard which will automatically prefix the routes of your application with a language parameter.

The name of the route parameter is language by default, but can be overwritten in the config file. The same config file will also provide the opportunity to define a set of permitted languages and a default language for when no language is provided.

5. Setup

In this simple example we'll provide the basic setup for the NgxI18nModule approach.

First off, in our root module we provide the NgxI18nModule in which we'll configure our basic settings.

 @NgModule({
    imports: [
        NgxI18nModule.forRoot({
            defaultLanguage: 'nl',
            availableLanguages: ['nl', 'fr'],
            defaultAssetPaths: ['./assets/i18n/shared/', './assets/i18n/ui/']
        })
    ]
 })
 export class AppModule{}

Next up, we'll take a look at the lazy loaded feature module. In order to then lazy load our translations, we provide a routing module with the TranslationResolverGuard on our root path.

 import {TranslationLoaderGuard} from '@studiohyperdrive/ngx-i18n';

 const routes = [
    {
        path: '',
        component: FeatureComponent,
        canActivate: [TranslationLoaderGuard]
    }
 ];

 export const FeatureRoutingModule = RoutingModule.forChild(routes);

Afterwards, we setup a translation loader for our feature module we'll lazy load.

import { MultiTranslationHttpLoader } from '@studiohyperdrive/ngx-i18n'

export function FeatureTranslationLoader(http: HttpBackend) {
	return new MultiTranslationHttpLoader(http, ['./assets/i18n/shared/', './assets/i18n/feature']);
}

Which we'll then provide to the NgxI18nModule in our feature module

 @NgModule({
    imports: [
        NgxI18nModule.forRoot(FeatureTranslationLoader),
        FeatureRoutingModule
    ]
 })
 export class FeatureModule{}

With this setup, the translations will be loaded only when navigating to the FeatureModule.

build information

This project has been build with:

  • Angular CLI : 16.1.4
  • Angular: 16.1.5
  • nodejs: 18.17.0
  • npm: 9.6.7

For a complete list of packages and version check out the package.json file.

Team

This bundle of tools has been created and is maintained by Studio Hyperdrive.

Contributors: