From 3e0889a6508b3c238405c980cece4794509a12cc Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 24 Jun 2026 10:57:35 +0800 Subject: [PATCH] Stop warning for plain strings without localization separator --- .../src/lib/services/localization.service.ts | 3 ++- .../lib/tests/localization.service.spec.ts | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts index 0e27973a90..ec3844c018 100644 --- a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts @@ -230,7 +230,8 @@ export class LocalizationService { }; if (keys.length < 2) { - warn('The localization source separator (::) not found.'); + // A plain string without the `::` separator is a valid passthrough value + // (e.g. text piped through `abpLocalization`), so it must not warn here. return defaultValue || (key as string); } if (!state.localization) return defaultValue || keys[1]; diff --git a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts index dee26425ea..e9fc91e288 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts @@ -28,6 +28,7 @@ describe('LocalizationService', () => { provide: ConfigStateService, useValue: { getOne: vi.fn(), + getAll: vi.fn(() => ({})), refreshAppState: vi.fn(), getDeep: vi.fn(), getDeep$: vi.fn(() => new Subject()), @@ -70,4 +71,28 @@ describe('LocalizationService', () => { expect(result).toBeDefined(); }); }); + + describe('#instant (missing :: separator)', () => { + const separatorWarning = 'The localization source separator (::) not found.'; + + it('should not warn for a plain string used as a passthrough value', () => { + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + const result = service.instant('Plain text'); + + expect(result).toBe('Plain text'); + expect(warnSpy).not.toHaveBeenCalledWith(separatorWarning); + warnSpy.mockRestore(); + }); + + it('should return the default value without warning', () => { + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + const result = service.instant({ key: 'Plain text', defaultValue: 'Fallback' }); + + expect(result).toBe('Fallback'); + expect(warnSpy).not.toHaveBeenCalledWith(separatorWarning); + warnSpy.mockRestore(); + }); + }); });