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 🙏

© 2025 – Pkg Stats / Ryan Hefner

translate-localization

v0.0.5

Published

Install: npm i [email protected]

Downloads

7

Readme

TranslateLocalization

Install: npm i [email protected]

Guide basic

📦src
 ┣ 📂app
 ┣  ...
 📦assets
 ┣ 📂i18n
 ┣ ┣ 📜vi.json
 ┣ ┣ 📜en.json
 
{
  "form_user": {
    "name" : "Name user",
    "email": "Email user",
    "exp_Job": "Exp job",
    "name_job" : "Name Job",
    "name_company": "Name company",
    "position": "Position",
    "income": "Income",
    "other_job" : "Other job",
    "list_address": "List address",
    "introduce": "introduce",
    "level": "level",
    "list_tech": "List tech",
    "info": "Info CV"
  },
  "title": "Form user",
  "info": "Information user",
  "button_add": "Add",
  "required": "Required",
  "minlength_4": "Lest 4 chat",
  "maxlength_8": "Not more 8 chat",
  "email": "Required email",
  "message": "Do you want to delete this {{name}} and {{job}}?"
}
import {II18nConfig, Lang} from "translate-localization";
import {I18nModule} from "translate-localization";

const CONFIG_I18N : II18nConfig<Lang> ={
  folders: ['root'], // load file langauges in i18n
  defaultLanguage: 'vi'
}

@NgModule({
declarations: [
  AppComponent,
  TestDialogComponent
],
imports: [
  I18nModule.forRoot(CONFIG_I18N)
],
providers: providerRoot,
bootstrap: [AppComponent]
})
export class AppModule { }
import {I18nService} from "translate-localization";

@Component({
  selector: 'app-root',
  template: `
    <p>
      <span>
        {{'title' | asyncTranslate | async}} // recommand asyncTranslate
      </span>
    </p>
  `
})
export class AppComponent {

  constructor(private i18nService : I18nService) {
    i18nService.useDefaultLang();
  }
}
import {I18nService, Lang} from "translate-localization";

@Component({
  selector: 'app-index',
  template: `
      <button (click)="handleChangeLang(item.lang)" *ngFor="let item of languages" >
        <img [src]="item.flag" alt="" style="width: 12px; height: 12px" />
        {{item.label}}
      </button>
  `
  changeDetection: ChangeDetectionStrategy.OnPush,
})

export class IndexComponent {

  //Lang: 'en' | 'fr' | 'de' | 'es' | 'af' | 'sq' | 'am' | 'ar' | 'hy' | 'az' | 'eu' | 'be' | 'bn' | 'bs' | 'bg' | 'ca' | 'ceb' | 'ny' | 'zh' | 'co' | 'hr' | 'cs' | 'da' | 'nl' | 'eo' | 'et' | 'tl' | 'fi' | 'fy' | 'gl' | 'ka' | 'el' | 'gu' | 'ht' | 'ha' | 'haw' | 'iw' | 'hi' | 'hmn' | 'hu' | 'is' | 'ig' | 'id' | 'ga' | 'it' | 'ja' | 'jw' | 'kn' | 'kk' | 'km' | 'ko' | 'ku' | 'ky' | 'lo' | 'la' | 'lv' | 'lt' | 'lb' | 'mk' | 'mg' | 'ms' | 'ml' | 'mt' | 'mi' | 'mr' | 'mn' | 'my' | 'ne' | 'no' | 'or' | 'ps' | 'fa' | 'pl' | 'pt' | 'pa' | 'ro' | 'sm' | 'gd' | 'sr' | 'st' | 'sn' | 'sd' | 'si' | 'sk' | 'sl' | 'so' | 'su' | 'sw' | 'sv' | 'tg' | 'ta' | 'te' | 'th' | 'tr' | 'uk' | 'ur' | 'ug' | 'uz' | 'vi' | 'cy' | 'xh' | 'yi' | 'yo' | 'zu'
  readonly languages: Language<Lang>[] =  [
      {
        label: 'Tiếng việt',
        lang: 'vi',
        flag: 'assets/svgs/vietnam-flag-icon.svg'
      },
      {
        label: 'English',
        lang: 'en',
        flag: 'assets/svgs/united-kingdom-flag-icon.svg'
      },
  ]

  constructor(private i18: I18nService) {}

  handleChangeLang(lang: Lang){
    if (this.i18.lang != lang)
      this.i18.use(lang)
  }
}

Guide advanced

If you load multiple folders then your array is ['root', 'buttons', 'users'] and you can ignore root : ['buttons', 'users'].

const CONFIG_I18N : II18nConfig ={
  folders: ['root', 'buttons', 'users'], // load file langauges in i18n
  defaultLanguage: 'vi', // default language
}
📦src
 ┣ 📂app
 ┣  ...
 📦assets
 ┣  📂i18n
 ┣  ┣  📂buttons
 ┣  ┣  ┣ 📜 vi.json
 ┣  ┣  ┣ 📜 en.json
 ┣  ┣  📂users
 ┣  ┣  ┣ 📜 vi.json
 ┣  ┣  ┣ 📜 en.json
 ┣  ┣  📜 vi.json
 ┣  ┣  📜 en.json
template: `
  <p>
    <span>
      {{'buttons.title' | asyncTranslate | async}} // recommand asyncTranslate
    </span>
    <span>
      {{'users.title' | asyncTranslate | async}} // recommand asyncTranslate
    </span>
  </p> `
📦assets
┣  📂i18n
┣  ┣  📂buttons
┣  ┣  ┣ 📜 vi.json
┣  ┣  ┣ 📜 en.json
//en.json
{
  "button_add": "Add",
  "message": "Do you want to delete this {{name}} and {{job}}?"
} 

//app.component.ts
constructor(private i18: I18nService) {}

ngOnInit(){
  console.log(this.i18.translate('buttons.button_add')) output >> Add

  console.log(this.i18.translate('buttons.message', {name: 'ABC', job: 'CDF'})) output >> Do you want to delete this ABC and CDF?
}
constructor(private i18: I18nService) {}
ngOnInit(){
  console.log(this.i18.lang) // output vi or en ...
}
 //en.json
{
  "button_add": "Add",
  "message": "Do you want to delete this {{name}} and {{job}}?"
} 

<div>
  {{'users.message' | asyncTranslate: param | async}} output >> Do you want to delete this ABC and CDF?

  {{'users.button_add' | asyncTranslate}} output >> Add
</div>

API

  • I18nService
    • lang: The return value is the national language. ('en' | 'fr' | 'de' | 'es' | 'af' | 'sq'....)
    • translate(key: string, params): Return language and use in file your.ts;
    • useDefaultLang(): Init language in app.component.
    • use(lang: Lang): Change language. (Lang: 'en' | 'fr' | 'de' | 'es' | 'af' | 'sq'....)
  • pipe
    • asyncTranslate: async translate lang