angular-i18next
Version:
i18next module for Angular
155 lines (150 loc) • 4.52 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, inject, provideAppInitializer } from '@angular/core';
import { jest } from '@jest/globals';
import { defaultInterpolationFormat, I18NextEvents, I18NEXT_SERVICE, interpolationFormat, makeI18NextFeature, I18NextFeatureKind } from 'angular-i18next';
import * as i18next from 'i18next';
class MockI18NextService {
i18next;
get isInitialized() {
return this.i18next.isInitialized;
}
get modules() {
return this.i18next.modules;
}
get services() {
return this.i18next.services;
}
get store() {
return this.i18next.store;
}
get resolvedLanguage() {
return this.i18next.resolvedLanguage;
}
constructor() {
this.i18next = i18next.default;
}
t = jest.fn((key, optionsOrDefault, options) => {
if (key instanceof Array) {
return key.length > 0 ? key[0] : '';
}
return key;
});
format = jest.fn((value, format, lng, options) => defaultInterpolationFormat(value, format, lng));
getFixedT(lng, ns, keyPrefix) {
throw new Error('Method not implemented.');
}
loadLanguages(lngs, callback) {
throw new Error('Method not implemented.');
}
loadResources(callback) {
throw new Error('Method not implemented.');
}
getDataByLanguage(lng) {
throw new Error('Method not implemented.');
}
reloadResources(lngs, ns, callback) {
throw new Error('Method not implemented.');
}
addResource(lng, ns, key, value, options) {
throw new Error('Method not implemented.');
}
addResources(lng, ns, resources) {
throw new Error('Method not implemented.');
}
addResourceBundle(lng, ns, resources, deep, overwrite) {
throw new Error('Method not implemented.');
}
removeResourceBundle(lng, ns) {
throw new Error('Method not implemented.');
}
events = new I18NextEvents();
language = '';
languages = [];
get options() {
return {
keySeparator: '.',
nsSeparator: ':',
};
}
use(plugin) {
return this;
}
init(options) {
options = options || {};
return new Promise((resolve, reject) => {
resolve(null);
});
}
changeLanguage(lng) {
return new Promise((resolve, reject) => {
this.language = lng;
resolve(this.language);
});
}
loadNamespaces(namespaces) {
return new Promise((resolve, reject) => {
resolve();
});
}
exists(key, options) {
return true;
}
setDefaultNamespace(ns) { }
dir(lng) {
return 'ltr';
}
getResource(lng, ns, key, options) {
return null;
}
hasResourceBundle(lng, ns) {
return true;
}
getResourceBundle(lng, ns) {
return null;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.1", ngImport: i0, type: MockI18NextService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.1", ngImport: i0, type: MockI18NextService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.1", ngImport: i0, type: MockI18NextService, decorators: [{
type: Injectable
}], ctorParameters: () => [] });
/**
* Initializes i18next with mock settings for testing
*/
function mockAppInit() {
const i18next = inject(I18NEXT_SERVICE);
let promise = i18next.init({
lng: 'cimode',
interpolation: {
format: interpolationFormat(),
},
});
return promise;
}
const provideI18NextMockAppInitializer = () => provideAppInitializer(mockAppInit);
/**
* Provides a mock implementation of I18NEXT_SERVICE for testing purposes.
* Also initializes i18next with mock settings.
*
* @returns An I18NextFeature that configures the service to use MockI18NextService
*
* Example:
* ```typescript
* providers: [
* provideI18Next(withMock())
* ]
* ```
*/
function withMock() {
return makeI18NextFeature(I18NextFeatureKind.Mock, [
{
provide: I18NEXT_SERVICE,
useClass: MockI18NextService,
},
]);
}
/**
* Generated bundle index. Do not edit.
*/
export { MockI18NextService, mockAppInit, provideI18NextMockAppInitializer, withMock };
//# sourceMappingURL=angular-i18next-testing.mjs.map