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

ng-trans

v1.5.0

Published

package for build a translate angular project

Downloads

1

Readme

transApp

@ng-trans [

The internationalization (i18n) compiler for Angular.

Simple example using ng-trans: https://stackblitz.com/github/ngx-translate/example

Get the complete changelog here: https://www.npmjs.com/package/ng-trans

Table of Contents

Installation

First you need to install the npm module:

npm i ng-trans --save

Usage

1. Build node server :

You should create simple server trans-server.js file in angular project root or any project using the following options

Option | Usage | Required ----------- | ------------------- | -------------------------- src | the source files path | required dest | if you need translate output in other directory not in same files (not src)| optional prefix | if have multiple projects | optional transPath | trans json files path | required compName | if you need to trans single component | optional ext | file extensions like ['js', 'ts'] | optional


after using npm i ng-trans --save to install package create the simple file

var trans = require('ng-trans');  
trans({  
  src: 'src/app',  
  transPath: 'src/assets/trans'  
});

2. Create HTML and TS files :

Now you should customize your component files like as the following example

<p>{{'%WelcomePage.HelloWorld.{"en":"Hello World","fr":"Bonjour le monde"}%@trans' | translate}}</p>

Notes: 1- the line should start with % and end with %@trans 2- important: the translate line should ended with object with translated types for example en and fr or en and ar and you make sure add . in between object and last key in translate levels .{"en":""} . 3- you can use multiple levels levelOne.LevelTwo.LevelThree. ....... 4- you can write object keys camel case welcomePage or upper letter WELCOME_PAGE or welcome_page or any typing ways and output will be WELCOME_PAGE. 5. you can add trans value in en as same as last key in object WelcomePage.HelloWorld.{"en":"HelloWorld"} and compiler will rewrite it as human writes Hello wold.

import {Component} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';

@Component({
    selector: 'app',
   .....
})
export class AppComponent {
    validation = {isRequeried: '%welcomePAge.validation{"en":"%this field is required%@trans","fr":"Ce champ est requis"'};

    constructor(translate: TranslateService) {
    }
}

3. Run:

When you run node trans-server.js in project root then open project files you will found % %@trans removed and last object also.

import {Component} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';

@Component({
    selector: 'app',
   .....
})
export class AppComponent {
    validation = {isRequeried: 'WELCOME_PAGE.VALIDATION';

    constructor(translate: TranslateService) {
    }
}

and HTML

<p>{{'WELCOME_PAGE.HELLO_WORLD' | translate}}</p>

and you can find new files in translate files path en.json and fr.json and map

{
	WELCOME_PAGE:{
		HELLO_WORLD:"Hello World",
		VALIDATION:"this field is required"
		
	}
}

If you need add more translate item do it without write old items or if you need update old one you need only set it in trans mode % .... %@trans and it will overwrite in translated files.

3. Cli:

Also you can use commend lines to build translate files without install it in project package use the following commend to download project in your workspace:

git clone https://gitlab.com/ahmedharby9/transapp.git

after download project copy your source files in src in project and create trans directory and then run commend line node app.js src 'src' transPath 'trans' you can also use node app.js -h or node app.js --help to know more about options.

Finally, this package used to reducing translation time during development work and providing you with the ideal solution in creating an integrated translation in many languages in the simplest way.