ngx-translate-testing 5.0.1
Install from the command line:
Learn more about npm packages
$ npm install @safe-fleet/ngx-translate-testing@5.0.1
Install via package.json:
"@safe-fleet/ngx-translate-testing": "5.0.1"
About this version
Unit testing utilities for the ngx-translate internationalization (i18n) library for Angular.
Currently, ngx-translate-testing
is compatible with Angular 6+ and @ngx-translate/core
10+. Prior versions of Angular and ngx-translate
are not supported. See the version table below for more details.
Angular | @ngx-translate/core | ngx-translate-testing |
---|---|---|
6.0.0 | 10.0.0 | 1.0.0 |
7.0.0 | 11.0.0 | 2.0.0 |
8.0.0 | 11.0.0 | 3.0.0 |
9.0.0 | 12.0.0 | 4.0.0 |
10.0.0 | 13.0.0 | 5.0.0 |
11.0.0 | 13.0.0 | 5.1.0 |
12.0.0 | 13.0.0 | 5.2.0 |
The ngx-translate-testing
module needs to be installed as a test dependency using your favorite NPM client.
npm install ngx-translate-testing --save-dev
or
yarn add ngx-translate-testing --dev
The TranslateTestingModule
class can provide all of the capabilities of the ngx-translate
TranslateModule
(translation directives, pipes,and services) and easily be configured with translations for your test cases.
The module can easily be imported into your test cases:
import { TranslateTestingModule } from 'ngx-translate-testing';
The first way to configure the testing module is with hard-coded JavaScript objects for translations. At the root of the object you provide language codes, with any structures nested underneath representing the translations keys or values.
const ENGLISH_LANGUAGE = 'en';
const ENGLISH_TRANSLATIONS = {
pleasantries: {
greeting: 'Hello',
appreciation: 'Thank You!'
}
};
const SPANISH_LANGUAGE = 'es';
const SPANISH_TRANSLATIONS = {
pleasantries: {
greeting: 'Hola',
appreciation: 'Gracias'
}
};
const TRANSLATIONS = {
[ENGLISH_LANGUAGE]: ENGLISH_TRANSLATIONS,
[SPANISH_LANGUAGE]: SPANISH_TRANSLATIONS
};
The TranslateTestingModule is initialized using the static withTranslations()
method. The method can either accept a complete
translations structure
TranslateTestingModule.withTranslations(TRANSLATIONS)
or the individual language translations separately
TranslateTestingModule.withTranslations(ENGLISH_LANGUAGE, ENGLISH_TRANSLATIONS)
The module also provides withTranslations()
instance methods that can be chained to add additional languages or additional translations for a language (via a shallow merge).
TranslateTestingModule.withTranslations(ENGLISH_LANGUAGE, ENGLISH_TRANSLATIONS)
.withTranslations(SPANISH_LANGUAGE, SPANISH_TRANSLATIONS)
.withTranslations(ENGLISH_LANGUAGE, require('../../assets/i18n/en.json'))
The TranslateTestingModule will set the default language to the first language it is provided. If withTranslations()
is called with an explicit language (e.g. withTranslations('en', ENGLISH)
) then the default language will be set to that language code. If a complete translations object is provided (e.g. withTranslations({en: ENGLISH, es: SPANISH})
) then the first language key will be used.
The default language can be overridden using the withDefaultLanguage()
instance method to explicitly define the default language.
TranslateTestingModule
.withTranslations({en: ENGLISH, es: SPANISH})
.withDefaultLanguage('es')
Be default, the TranslateTestingModule
will use the TranslateFakeCompiler
instance. If your translations use a custom compiler, such as the ngx-translate-messageformat-compiler, you can specify the compiler with the withCompiler()
instance method.
TranslateTestingModule
.withTranslations('en', require('../../assets/i18n/en_msgfmt.json'))
.withCompiler(new TranslateMessageFormatCompiler())
Licensed under MIT
- Michael Wooten (@mwootendev)
- Paulo Soares (@7jpsan)
- Paul Iannello (paul-kr)
- Arnaud Tiérant (@atierant)
Details
- ngx-translate-testing
- safe-fleet
- 8 months ago
- MIT
- 5 dependencies
Assets
- ngx-translate-testing-5.0.1.tgz
Download activity
- Total downloads 1
- Last 30 days 0
- Last week 0
- Today 0