Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    Thank you @shaharkazaz - The library looks super cool :) - however I was wondering if it is possible to do this in a user.component.spec.ts file. Let's say I have the user.component.html with the tag below:
    <label for="firstName">{{ t('firstNameqqq') }}</label>
    When I run the ng test, the following is displayed in the browser console: "Missing translation for 'userRegistration.firstNameqqq'"
    I want a unit test like this to tell me if any keys is missing or changed:
    it('should check if translation in component is missing', () => {
    // var consoleData = check if translation is missing
    expect(consoleData).not.toContain('missing translation ...');
    Is this feasible?
    Shahar Kazaz
    @avifox I'm not sure what you are trying to test here, if it's missing keys you are looking for the keys manager as part of your pipeline is the way to go.
    What's the benefit of testing it at a component level? texts are things that change.

    @avifox spectator is not necessary, but it really makes everything easier. My examples are below.
    For missing keys, I agree with @shaharkazaz , if you want to check for missing keys, just run transloco-keys-manager find and look for the missing and unused keys. If you wanted it automated, maybe there is a way to parse the output and make it a pass/fail step in your build process.

    i pulled out my setLanguage promise into a function that i can call:

      /** setting the language does not happen immediately. It must first load,
       * then change detection must fire.
       * This method will set the lang, and wait for it to load and detect changes. */
      async function setLang(lang: string) {
        await new Promise(resolve => {
            filter((t: TranslocoEvents) => t.type === 'translationLoadSuccess')
          ).subscribe(t => resolve());
        }).then(() => spectator.detectChanges());

    here is my beforeEach:

    beforeEach(() => {
        // tests were written for the case that spanish is the default language
        TranslocoConfigProvider.useValue.defaultLang = 'es';
        spectator = createSpectator();
        translocoService = spectator.inject(TranslocoService);
        // set lang here so we can make sure it is loaded before running tests

    make sure to also use the TranslocoTestingModule, here's what I used, borrowed from Transloco:

    export const languageMap = {
      'i18nTest/en': admin,
      'i18nTest/es': adminSpanish,
      'lazyPage/en': lazy,
      'lazyPage/es': lazySpanish,
      'mf/en': transpilersMessageFormat,
      'mf/es': transpilersMessageFormatSpanish
    export function getTranslocoTestModule(config: Partial<TranslocoConfig> = {}) {
      return TranslocoTestingModule.withLangs(
          availableLangs: ['es', 'en'],
          defaultLang: 'es',
          fallbackLang: 'en',
    I should note that I'm able to unit test Structural and Pipe translations, but not attribute translations. I'm also not able to test ICU message format translations, they appear to take longer to render and I'm not sure what to wait for. All of them work in practice in my project, just not in unit tests.
    Hi All, I'm looking to get started with this library for my project. I remember there used to be a feature comparison table between ngx-translate, transloco and a few other libraries. Is that removed?
    Shahar Kazaz
    @siddharth1903 We decided to remove the comparison table, but out of curiosity what interests you there?
    @seadonk no need to parse the output, if you have missing keys the process exits with code 1, this one done so you can integrate it easily as part of your pipeline.
    @seadonk Thanks a lot :)
    @shaharkazaz Thank you very much. I have installed the key manager. It is awesome. However I am getting an issue. I have added this to my package.json:
    "i18n:find": "transloco-keys-manager find --translations-path assets/i18n"
    Then I run: npm run i18n:find
    If there are no missing translations, it runs fine. But when there are missing translation, it gives me a table with the missing translations plus some errors
    Shahar Kazaz
    @avifox glad to hear, as I stated before, the error thrown at the end is ok.
    We throw it intentionally, so you can integrate it as part of you CI pipeline and if a key is missing the pipeline will fail (and prevent deployment or whatever you do after it).
    @shaharkazaz Thanks a lot.
    Shahar Kazaz
    @avifox sure thing, that's what this gitter is for, so we can help each other :grin:
    @/all There is a new disscusions tab on Github, feel free to use it as well!

    Hey everyone! Curious question about providing params to a json array with just the template.

    For example, consider the following language file

        "LISTS": [
            "List Item 1 {{param}}",
            "List Item 2",
            "List Item 3 {{param}}"

    Does anyone have a solution to provide the parameter while using the above in a *ngFor?

    Doing it like such does not work, which is expected:

        <li *ngFor="let item of ('LISTS' | transloco: { param: 'Hello World'})">item</li>

    I was able to achieve this by using selectTranslationObject in the respected component file and change my json array to an object of objects but it would be pretty cool if I can accomplish this just in the template

    Shahar Kazaz
    @smmarrocco Hey! you are right, that could be cool and actually pretty easy to support since we already support translation objects.
    I'll find the time to add this ability where given an array, each value will be transpiled :thumbsup:
    So keep an eye out for the next version :wink:
    @shaharkazaz too cool!! Fantastic, glad it’s doable. Will keep an :eyes: out! Thank you
    Shahar Kazaz
    @smmarrocco released in v2.20.0 :slight_smile:
    @shaharkazaz way too excited for this! thank you for the quick delivery, going update now
    Dale Nguyen

    Question on translocoDate PIPE. How can I display day & month only? (E.g. Dec 12). In the documentation, the guide is limited.


       * date | translocoDate: {} : en-US // 9/10/2019
       * date | translocoDate: { dateStyle: 'medium', timeStyle: 'medium' } : en-US // Sep 10, 2019, 10:46:12 PM
       * date | translocoDate: { timeZone: 'UTC', timeStyle: 'full' } : en-US // 7:40:32 PM Coordinated Universal Time
       * 1 | translocoDate: { dateStyle: 'medium' } // Jan 1, 1970
       * '2019-02-08' | translocoDate: { dateStyle: 'medium' } // Feb 8, 2019
    Shahar Kazaz

    @dalenguyen Transloco L10N uses the native Intl, you can read more about date formatting here.
    The following code should produce the output you want:

    new Intl.DateTimeFormat('en-US', {month: 'short', day: 'numeric'}).format(Date.now())

    This means that {month: 'short', day: 'numeric'} is the config you are looking for :smile:

    1 reply
    Victor Diaz

    Hello. I'm trying to follow the example here https://ngneat.github.io/transloco/docs/inline-loaders but I'm lacking clarity. I have the following JSON:

      "generalSettings": {
        "title": "General Settings",
        "header": "Edit the configuration for your store.",
        "clientInformation": {
          "sectionLbl": "Client Information"

    In my features module, I have:

    imports: [
    declarations: [
      ...all components
    providers: [
        provide: TRANSLOCO_SCOPE,
        useValue: {
          scope: 'shopSettings',

    The template works well. I have the following:

    <div *transloco="let t; read: 'shopSettings.generalSettings'">
      <h2>{{ t('title') }}</h2>
      {{ t('header') }}

    However, in the component file, I can't seem to load the translation. Each of the following queries logs error:

      private translocoService: TranslocoService,
    ) {}
    ngOnInit() {
      let result = this.translocoService.translateObject('shopSettings.generalSettings.clientInformation');
      result = this.translocoService.translateObject('generalSettings.clientInformation');
      result = this.translocoService.translateObject('clientInformation');
    // outputs:
    // Missing translation for 'shopSettings.generalSettings.clientInformation'
    // Missing translation for 'generalSettings.clientInformation'
    // Missing translation for 'clientInformation'

    What am I missing? Thanks!

    Shahar Kazaz
    @vdiaz1130 Have you seen this section in our docs? I think that's the answer to your question :slight_smile:
    Methods prefixed with translate are synchronous and will only work if your translation is already loaded.
    You can use selectTranslateObject
    Victor Diaz

    @shaharkazaz Thanks for the reply. I've tried selectTranslateObject as you suggested and I get the same error message. To be clear, the en.json file is in a directory within the feature module:

    and I have a loader function in the feature module:

    export const loader = ['en', 'es'].reduce((acc, lang) => {
      acc[lang] = () => import(`./_i18n/${lang}.json`);
      return acc;
    }, {});

    The template markup sees the translations but I can't get it to show up in the component logic.

    Victor Diaz
    I figured it out - had to add this.scope (reference to @Inject(TRANSLOCO_SCOPE) private scope):
    let result = this.translocoService
          title: { value: 100 },
        this.scope, // added this...
    Shahar Kazaz
    Hi what is the purpose of "transloco.config.js"
    if I delete this file it's still working, thanks!!!

    Hello, I'm using the TranslocoService in a pipe and I would like to access a lazy loaded scope when I do :

    this.transloco.translate('key', {}, 'scopeName')

    I've got Missing translation for scopeName.key. I tried to provide the TRANSLOCO_SCOPE in the module in which the pipe is declared, but it didn't help. Anyone has an idea how to fix that ?

    the component using the pipe already load another scope unfortunately.
    In the end I used the load. I'm not sure it's the right way to do though as it triggers load on every pipe instance (event with shareReplay).
    Patrick Zhong
    @shaharkazaz Does transloco support multiple fallback language for missing translation key and missing whole language? For example, the fallbacks are "fr-CA -> fr -> en" for language AND for missing translation keys.
    Shahar Kazaz
    @GrandSchtroumpf as the docs states, when using the synchronous translation methods (prefixed with translate) you need to make sure the translations are loaded.
    I don't think you have much of a performance issue regarding the load since it's cached, why not use selectTranslate with take(1)?
    @pookdeveloper It's a configuration file mostly used by our plugins & tools (keys manager, scoped lib extractor, etc), that's why the core functionality works without it :thumbsup:
    Shahar Kazaz
    @zhongsp If a translation file fails to load, all the keys you will try to translate will be taken from the fallback, did I understand your question correctly?
    Patrick Zhong
    @shaharkazaz I defined a custom LanguageFallbackStrategy in my app to try a set of fallback languages, e.g. fr-CA / fr / en. I think it works for a translation file fails to load.
    But, if it can load fr-CA.json, but missing a key in fr-CA.json. Does transloco can try fr-CA / fr / en for the missing translation key?
    Patrick Zhong
    @shaharkazaz I enter an issue for language fallbacks, please help to look at it when u are free. Thanks. ngneat/transloco#389
    Shahar Kazaz
    @zhongsp :thumbsup:
    Yaza Wainakh
    Hello all,
    I have a problem with translations showing in production. I have created an issue ngneat/transloco#387, but I was directed to this channel. Any idea what the problem could be?
    Already tried to use the relative path for the JSON files as mentioned as a note here.
    Shahar Kazaz
    @YazaWainakh have you tried following the official guide?
    if you start a new project and install the library using the schematics do you still have issues? try it and see what's the difference.
    Nicola Toledo

    Schermata 2020-12-29 alle 16.56.46.png

    hi everyone, i hava. a problem, i can't get the translation in the scope 'countries'

    the default language is 'it' so should get countries/it.json right?

    i use nx

    i tried also with inject the
    providers: [ { provide: TRANSLOCO_SCOPE, useValue: 'countries', }, ],

    inside the component and use the translate method but don't work 😕