stefalda / react-localization

Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module.
MIT License
373 stars 58 forks source link

Cannot use Localized strings in array - undefined #95

Open moyoteg opened 5 years ago

moyoteg commented 5 years ago

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

Larsrdev commented 4 years ago

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.