New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lakea/gravity-translate-adapter-transloco

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lakea/gravity-translate-adapter-transloco

An adapter for `GrTranslate` using [`Transloco`](https://ngneat.github.io/transloco/) as implementation.

  • 3.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-64.71%
Maintainers
3
Weekly downloads
 
Created
Source

@lakea/gravity-translate-adapter-transloco

An adapter for GrTranslate using Transloco as implementation.

Installation

Install the library using NPM:

npm install @lakea/gravity-translate-adapter-transloco @ngneat/transloco --save

Next, create a new file, translate-adapter-root.module.ts which exposes an Angular's module with a default configuration.

import {NgModule} from '@angular/core';
import {GrTranslateAdapterTranslocoModule} from '@lakea/gravity-translate-adapter-transloco';

@NgModule({
  imports: [
    GrTranslateAdapterTranslocoModule.forRoot({
      availableLangs: ['en', 'es'],
      defaultLang: 'en',
      reRenderOnLangChange: true,
      prodMode: false, // get from your environments file
    }),
  ],
})
export class TranslateAdapterRootModule {}

Import TranslateAdapterRootModule to application root module like app.module.ts.

You should import the TranslateAdapterRootModule once in your root module.

The TranslateAdapterRootModule file imports the GrTranslateAdapterTranslocoModule which has all Transloco initial configs.

To configure transloco library, read the docs here.

Going forward, you need to provide a global app config injector with baseUrl property.

Add it to you app root module (maybe app.module.ts):

  providers: [
    {
      provide: 'APP_CONFIG',
      useValue: {
        // change for your app baseUrl
        // (don't miss to deal with prod url)
        baseUrl: 'http://localhost:4200'
      },
    },
  ]

baseUrl is used by TranslocoLoader to load translations file from assets.


Creating your own adapter

Create your adapter implementation class extending GrTranslate abstraction:

import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';

import {HashMap} from '@lakea/gravity/cdk';
import {GrTranslate} from '@lakea/gravity/translate';

@Injectable()
export class GrTranslateAdapter extends GrTranslate {
  constructor() {
    super();
  }

  public activeLanguageChanges$(): Observable<string> {
    // YOUR IMPLEMENTATION
  }

  public changeActiveLanguage(lang: string): void {
    // YOUR IMPLEMENTATION
  }

  public getActiveLanguage(): string {
    // YOUR IMPLEMENTATION
  }

  public getAvailableLanguages(): string[] {
    // YOUR IMPLEMENTATION
  }

  public translate<T = string | string[]>(key: T, options?: HashMap): Observable<T> {
    // YOUR IMPLEMENTATION
  }
}

So, provide it on your application root module (maybe app.module.ts), like this:

  providers: [
    {
      provide: GrTranslate,
      useClass: GrTranslateAdapter,
    }
  ]

FAQs

Package last updated on 19 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc