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

@insanetlabs/translate

v1.0.1

Published

You can install the package with yarn or npm `yarn add @insanetlabs/translate` or `npm i @insanetlabs/translate`

Downloads

4

Readme

Installation

You can install the package with yarn or npm yarn add @insanetlabs/translate or npm i @insanetlabs/translate

Usage

1.Import the module

Add TranslationModule to your root module.

import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {TranslationModule} from '@insanetlabs/translate';

@NgModule({
    imports: [
        BrowserModule,
        TranslationModule,
        ...
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

2. Initialize TranslationService

You usually want to initialize the TranslationSerice in the root component of your application.

import { Component } from '@angular/core';
import { TranslationService } from '@insanetlabs/translate';

@Component({
})
export class AppComponent {
    constructor(private _translationService: TranslationService) {
        ...
    }
}

In here you can provide the application with the translation files.

import { TranslationService, Translation } from '@insanetlabs/translate';
    ...
     constructor(private _translationService: TranslationService) {
        const englishTranslation = new Translation('path/to/file.json', 'en');
        this._translationService.addTranslation(englishTranslation);

        this._translationService.setLanguage('en');
    }

It's import the function setLanguage() is called after the files have been added to the service. The TranslationService will include the files from the assets folder. In this case the path of where file.json would be loaded from is src/assets/path/to

3. Defining the translations

path/to/file.json An example of the translation file.

{
    "messages": {
        "hello": "Hello world!"
    }
}

4. Retrieving the translation

If you want to display Hello world! you can get the translation by navigating to the translation using the '.' notation. In this case 'messages.hello'. You can retrieve the translation using either the function translate('messagess.hello') from the TranslationService, or using the translate pipe: {{ 'messages.hello' | translate }}

Multiple language files

If you want to seperate your translations in multiple file, you can provide multiple files for a single lanugage. The name of the file will be used as the first object in the tree. Lets say you have provided two files in the root component of your app named projects and orders.

projects

{
    "title": "Projects"
}

order

{
    "title": "Orders"
}

If you want to get the title of the projects file they key would look like this {{ 'projects.title' | translate }}