npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-translate-testing

v7.0.0

Published

A library of utilities for testing with the ngx-translate i18n Angular library

Downloads

185,796

Readme

ngx-translate-testing

Unit testing utilities for the ngx-translate internationalization (i18n) library for Angular.

Table of Contents

Installation

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 | | 13.0.0 | 14.0.0 | 6.0.0 | | 15.0.0 | 14.0.0 | 6.1.0 | | 16.0.0 | 15.0.0 | 7.0.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

Usage

TranslateTestingModule

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';

JavaScript Translation Objects

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'))

Default Language

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')

Custom Compiler

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())

Custom Parser

The default parser used in the TranslateTestingModule it is an instance of TranslateDefaultParser. If your translations use a custom parser, you can specify the parser with the withParser() instance method.

TranslateTestingModule
  .withTranslations("en", require("../../assets/i18n/en.json"))
  .withParser(new CustomTranslateDefaultParser())

License

Licensed under MIT

Contributors