react-localization icon indicating copy to clipboard operation
react-localization copied to clipboard

Cannot use Localized strings in array - undefined

Open moyoteg opened this issue 6 years ago • 1 comments

I have: mainViews = ['Home', 'Providers', 'Carts']

I want: mainViews = [LocalizedStrings.home, LocalizedStrings.providers, LocalizedStrings.carts]

so that I can: mainView.map( (text, index) => { // code goes here })...

result: undefined

moyoteg avatar Oct 08 '19 23:10 moyoteg

You are not using it correct. As mentioned in the documentation: https://github.com/stefalda/react-localization#typescript-support you can do something like this:

export interface IStrings extends LocalizedStringsMethods{
    home_header: string;
    home_title: string;

    provider_header: string;
    provider_title: string;

    carts_header: string;
    carts_title: string;
}

public strings: IStrings;
this.strings = new LocalizedStrings({
            it: {
                home_header: "Punti",
                home_title: "Tempo"

                provider_header: "Uno",
                provider_title: "Roma"

                carts_header: "Prova",
                carts_title: "Testo"
            },
            en: {
                home_header: "Score",
                home_title: "Time"

                provider_header: "One",
                provider_title: "Rome"

                carts_header: "Check",
                carts_title: "Test"
            }
        });

And try to do some stuff or add logic to match the view depending strings.

Larsrdev avatar Jul 10 '20 21:07 Larsrdev