mwootendev / ngx-translate-plugins

Utilities plugins for the @ngx-translate translation library.
MIT License
15 stars 10 forks source link

Support arrays in ngx-translate-testing #62

Open GrumpyMeow opened 2 years ago

GrumpyMeow commented 2 years ago

Is your feature request related to a problem? Please describe. We use your ngx-translate-testing package for Storybook and unit-tests to mock our translations. The TranslateTestingModule does not support arrays for translations. The following error is given during build:

    Type 'string[]' is not assignable to type 'LanguageTranslation'.
    Type 'string[]' is not assignable to type '{ [translationKey: string]: LanguageTranslation; }'.
    Index signature for type 'string' is missing in type 'string[]'.

This error is given when we try:

TranslateTestingModule.withTranslations({
          'lifecycle': {
            'customer-profile': {
              'profiles': ["profile1","profile2"]      
            },
          },
        })

Arrays are supported by the TranslateModule.

In our template we do this:

<button
      *ngFor="let profile of 'lifecycle.customer-profile.profiles' | translate; let i = index" >
      {{ profile | translate }}
    </button>
"profiles": ["profile1", "profile2", "profile3"],

Describe the solution you'd like Allow to specify arrays just like our translation which comes from a json file.

export declare type LanguageTranslation = string | string[] | {
    [translationKey: string]: LanguageTranslation;
};
mwootendev commented 2 years ago

I believe this should be supported in version 6.1.0. Have you updated to the lastest version?

GrumpyMeow commented 2 years ago

V6.1.0 needs Angular v14. I’ll retry it when we arrive at Angular v14. We are currently still at Angular v13. thanks

GrumpyMeow commented 1 year ago

We've arrived at Angular v14 and using v6.1.0. Unfortunately arrays still don't seem to work.

const translations = {
    dummyData: {
      header: {
        breadcrumbs: ['dummy1','dummy2'],
      },
    },
  };