Browse Source

Merge pull request #25684 from abpframework/maliming/fix-localization-missing-separator-warn

Stop warning for plain strings without the localization separator
pull/25693/head
sumeyye 3 months ago
committed by GitHub
parent
commit
4b86359fa6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  2. 25
      npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts

3
npm/ng-packs/packages/core/src/lib/services/localization.service.ts

@ -230,7 +230,8 @@ export class LocalizationService {
}; };
if (keys.length < 2) { 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); return defaultValue || (key as string);
} }
if (!state.localization) return defaultValue || keys[1]; if (!state.localization) return defaultValue || keys[1];

25
npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts

@ -28,6 +28,7 @@ describe('LocalizationService', () => {
provide: ConfigStateService, provide: ConfigStateService,
useValue: { useValue: {
getOne: vi.fn(), getOne: vi.fn(),
getAll: vi.fn(() => ({})),
refreshAppState: vi.fn(), refreshAppState: vi.fn(),
getDeep: vi.fn(), getDeep: vi.fn(),
getDeep$: vi.fn(() => new Subject()), getDeep$: vi.fn(() => new Subject()),
@ -70,4 +71,28 @@ describe('LocalizationService', () => {
expect(result).toBeDefined(); 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();
});
});
}); });

Loading…
Cancel
Save