Skip to content

Getting Cannot read properties of null (reading 'preSaveTranslation') issue while trying to load a language. #847

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

Open
patilsiddhesh794 opened this issue Apr 7, 2025 · 0 comments

Comments

@patilsiddhesh794
Copy link

I am trying to use Transloco but its giving this issue. My file path is correct and the json files are returning data as well in get request, but still getting this error. Below is my transloco module code which I am using:

`import {
DefaultFallbackStrategy,
DefaultTranspiler,
Translation,
TRANSLOCO_CONFIG,
TRANSLOCO_FALLBACK_STRATEGY,
TRANSLOCO_INTERCEPTOR,
TRANSLOCO_LOADER,
TRANSLOCO_MISSING_HANDLER,
TRANSLOCO_TRANSPILER,
translocoConfig,
TranslocoLoader,
TranslocoModule
} from '@ngneat/transloco';
import { Injectable, isDevMode, NgModule } from '@angular/core';
// import { TranslocoHttpLoader } from './transloco-loader';
import { HttpClient } from '@angular/common/http';

@Injectable({ providedIn: 'root' })
export class TranslocoHttpLoader implements TranslocoLoader {
constructor(private http: HttpClient) { }

getTranslation(lang: string) {
return this.http.get(/assets/i18n/${lang}.json);
}
}

@NgModule({
exports: [TranslocoModule],
providers: [
{
provide: TRANSLOCO_CONFIG,
useValue: translocoConfig({
availableLangs: ['en', 'fr', 'hi'],
defaultLang: 'en',
fallbackLang: 'en',
reRenderOnLangChange: true,
prodMode: true,
}),
},
{ provide: TRANSLOCO_LOADER, useClass: TranslocoHttpLoader },
{
provide: TRANSLOCO_TRANSPILER,
useClass: DefaultTranspiler // Use an empty object if you don't have a custom transpiler
},
{
provide: TRANSLOCO_MISSING_HANDLER,
useValue: (key: string) => {
console.warn(Missing translation for ${key});
return key; // You can return the key as a fallback
}
},
{
provide: TRANSLOCO_INTERCEPTOR,
useValue: null
},
// Provide Fallback Strategy
{
provide: TRANSLOCO_FALLBACK_STRATEGY,
useClass: DefaultFallbackStrategy,
},
],
})
export class TranslocoRootModule { }
`

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

1 participant