Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use ngx-translate in Angular 17, Knowing that AppModule is not implemented? #1459

Open
red1code opened this issue Nov 28, 2023 · 2 comments

Comments

@red1code
Copy link

Current behavior

Expected behavior

How do you think that we should fix this?

Minimal reproduction of the problem with instructions

Environment


ngx-translate version: X.Y.Z
Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@inunotaisho
Copy link

This one needs major attention because if it's not dealt with, I'm gonna have to look for a new translator package

@shahmaulik1991
Copy link

shahmaulik1991 commented Apr 23, 2024

//app.config.ts
import { ApplicationConfig, importProvidersFrom } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideAnimations } from '@angular/platform-browser/animations';
import { HttpBackend, HttpClient, HttpClientModule, provideHttpClient } from '@angular/common/http';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

export const provideTranslation = () => ({
defaultLanguage: 'en',
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient],
},
});

export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes),provideAnimations(),provideHttpClient(),importProvidersFrom(HttpClientModule), importProvidersFrom([TranslateModule.forRoot(provideTranslation())
]),],

};

//home.ts
import { TranslateModule, TranslateService } from '@ngx-translate/core';

@component({
selector: 'app-home',
standalone: true,
imports: [CommonModule, RouterModule, ViewallschemeComponent,LibrariesModule,TranslateModule],
templateUrl: './home.component.html',
styleUrl: './home.component.scss'
})
export class HomeComponent implements OnInit {
constructor(
public translate: TranslateService
) {
}

ngOnInit(): void {
this.translate.setDefaultLang('en'); //hi,ta,fr any language
}
}

//Home Html

{{'login.title' | translate }}
//json file like (assets/i18n/en.json)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants