ngx-translate-testing
Version:
A library of utilities for testing with the ngx-translate i18n Angular library
146 lines • 6.8 kB
TypeScript
import { ModuleWithProviders } from '@angular/core';
import { TranslateDefaultParser, TranslateService, TranslateCompiler } from '@ngx-translate/core';
import { LanguageTranslations, Translations } from './translations.model';
import * as i0 from "@angular/core";
import * as i1 from "@ngx-translate/core";
/**
* The TranslateTestingModule provides the {TranslateModule} as well as a
* {TranslateService} configured to return translations specific for the
* test environment.
*
* @export
*/
export declare class TranslateTestingModule implements ModuleWithProviders<TranslateTestingModule> {
private _translations;
private _defaultLanguage;
private _compiler;
private _parser;
/**
* Creates a new instance of the {TranslateTestingModule} with translations for the specified language.
*
* @example
*
* const ENGLISH_TRANSLATIONS = { greeting: 'Hello' };
* const translateModule = TranslateTestingModule.withTranslations('en', ENGLISH_TRANSLATIONS);
*
* @example
*
* TranslateTestingModule.withTranslations('en', require('../../assets/i18n/en.json'));
*
* @static
* @param {string} language the language for the translations.
* @param {Translations} translations the translations to be used in the tests.
* @returns the new instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
static withTranslations(language: string, translations: LanguageTranslations): TranslateTestingModule;
/**
* Creates a new instance of the {TranslateTestingModule} with the provided translations.
*
* @example
*
* const TRANSLATIONS = { en: { greeting: 'Hello' }, es: { greeting: 'Hola' } };
* const translateModule = TranslateTestingModule.withTranslations(TRANSLATIONS);
*
* @example
*
* TranslateTestingModule.withTranslations(require('./test.i18n.json'));
*
* @static
* @param {Translations} the language translations the translations to be used in the tests.
* @returns the new instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
static withTranslations(translations: Translations): TranslateTestingModule;
get ngModule(): typeof TranslateTestingModule;
get providers(): {
provide: typeof TranslateService;
useValue: TranslateService;
}[];
/**
* Updates the {TranslateTestingModule} instance with additional translations. The
* translations will be shallowly merged with any existing translations.
*
* @example
*
* const ENGLISH_TRANSLATIONS = { en: { greeting: 'Hello' } };
* const SPANISH_TRANSLATIONS = { en: { greeting: 'Hola' } };
* const translateModule = TranslateTestingModule.withTranslations(ENGLISH_TRANSLATIONS)
* .withTranslations(SPANISH_TRANSLATIONS);
*
* @param {Translations} translations the additional translations to add to the testing service.
* @returns the instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
withTranslations(translations: Translations): TranslateTestingModule;
/**
* Updates the {TranslateTestingModule} instance with additional translations for a
* specified language. The translations will be shallowly merged with any existing translations.
*
* @example
*
* const ENGLISH_TRANSLATIONS = { greeting: 'Hello' };
* const SPANISH_TRANSLATIONS = { greeting: 'Hola' };
* const translateModule = TranslateTestingModule.withTranslations('en', ENGLISH_TRANSLATIONS)
* .withTranslations('es', SPANISH_TRANSLATIONS);
*
* @example
*
* TranslateTestingModule.withTranslations('en', require('../../assets/i18n/en.json'))
* .withTranslations('es', require('../../assets/i18n/es.json'));
*
* @param {string} language the language for which the new translations are being added.
* @param {LanguageTranslations} translations the translations for the specified language.
* @returns the instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
withTranslations(language: string, translations: LanguageTranslations): TranslateTestingModule;
/**
* Updates the {TranslationTestingModule} to provide a {TranslateService} that will
* use the provided {TranslateCompiler} to translate the test translations.
*
* @example
*
* TranslateTestingModule.withTranslations('en', {people: '{gender, select, male{He is} female{She is} other{They are}} {how})'})
* .withCompiler(new TranslateMessageFormatCompiler());
*
* @param compiler the compiler to use to compile the test translations.
* @returns the instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
withCompiler(compiler: TranslateCompiler): TranslateTestingModule;
/**
* Updates the {TranslateTestingModule} to provide a {TranslateService} that will
* use the provided {TranslateParser} to parse the test translations.
*
* @example
*
* TranslateTestingModule.withTranslations('en', {key: 'content'})
* .withParser(new CustomTranslateDefaultParser());
*
* @param parser the parser to use to parse the test translations.
* @returns the instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
withParser(parser: TranslateDefaultParser): TranslateTestingModule;
/**
* Updates the {TranslateTestingModule} to use the provided language as the default language.
* By default, the default language will be set to the first language provided.
*
* @example
*
* TranslateTestingModule.withTranslations('es', SPANISH_TRANSLATIONS)
* .withTranslations('en', ENGLISH_TRANSLATIONS)
* .withDefaultLanguage('en');
*
* @param language the new default language for translations.
* @returns the instance that can be used to chain additional configuration.
* @memberof TranslateTestingModule
*/
withDefaultLanguage(language: string): TranslateTestingModule;
private addTranslations;
static ɵfac: i0.ɵɵFactoryDeclaration<TranslateTestingModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<TranslateTestingModule, never, [typeof i1.TranslateModule], [typeof i1.TranslateModule]>;
static ɵinj: i0.ɵɵInjectorDeclaration<TranslateTestingModule>;
}
//# sourceMappingURL=testing.module.d.ts.map