core icon indicating copy to clipboard operation
core copied to clipboard

Incomplete migration guide v16 → v17

Open szape89 opened this issue 6 months ago • 3 comments

I found some missing breaking changes which are not mentioned in Migration guide v16 → v17:

I advise to include these in the migration guide because they are part of the public API.

szape89 avatar Aug 12 '25 12:08 szape89

Is missing also the unit testing migration?

After following the migration, if I launch npm test I have the following error

npm test

> [email protected] test
> ng test --code-coverage --browsers=ChromeHeadless --no-progress --no-watch

Application bundle generation failed. [0.968 seconds]

✘ [ERROR] No matching export in "node_modules/@ngx-translate/core/fesm2022/ngx-translate-core.mjs" for import "TranslateFakeCompiler"

    node_modules/ngx-translate-testing/fesm2022/ngx-translate-testing.mjs:1:44:
      1 │ ...er, TranslateService, TranslateFakeCompiler, TranslateDefaultPar...
        ╵                          ~~~~~~~~~~~~~~~~~~~~~                             

My dependencies are

    "@ngx-translate/core": "17.x",
    "@ngx-translate/http-loader": "17.x",
    "ngx-translate-testing": "7.x",

And here a sample test

import { TestBed } from '@angular/core/testing';

import { I18nService } from './i18n.service';
import { LookupService } from './lookup.service';
import { TranslateTestingModule } from 'ngx-translate-testing';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import enTranslations from '../../../../public/i18n/en-gb.json';

describe('I18nService', () => {
  let service: I18nService;

  beforeEach(() => {
    TestBed.configureTestingModule({
    imports: [NoopAnimationsModule,
        TranslateTestingModule.withTranslations('en', enTranslations)],
    providers: [
        LookupService,
        I18nService,
        provideHttpClient(withInterceptorsFromDi()),
        provideHttpClientTesting()
    ]
});
    service = TestBed.inject(I18nService);
  });

  it('should be created', () => {
    expect(service).toBeTruthy();
  });
});

classicPintus avatar Aug 15 '25 00:08 classicPintus

Today I have tried and following the documentation I have completed with this code.

import { Injectable } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core';
import { Observable, of } from 'rxjs';

import enTranslations from '../../../../public/i18n/en-gb.json';

@Injectable()
export class JsonTranslateFileLoader implements TranslateLoader {
    private readonly translations: { [key: string]: any } = {
        'en-gb': enTranslations,
    };

    getTranslation(lang: string): Observable<any> {
        const translation = this.translations[lang];

        if (translation) {
            return of(translation);
        }

        // Fallback to default language
        return of(this.translations['en-gb']);
    }
}

and in the providers of my test I have the following

provideTranslateService({
    fallbackLang: 'en-gb',
    loader: provideTranslateLoader(JsonTranslateFileLoader)
})

classicPintus avatar Sep 14 '25 11:09 classicPintus

i use translateService.getParsedResult(translateService.translation["en"], "MY_KEY", placeholderValues); to get my text in english to log some info in english while the app is running in another language. v17 breaks that:

  • .translation does not exist anymore
  • getParsedResult() does not accept placeholder values anymore

grafanauser avatar Oct 30 '25 15:10 grafanauser

Updated the documentation.

About ngx-translate-testing - we can't do much here - it's not our code... sorry.

CodeAndWeb avatar Dec 10 '25 13:12 CodeAndWeb