Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the text of the FooterCount (i18n)? #354

Open
djalmajr opened this issue Mar 7, 2020 · 4 comments
Open

How to change the text of the FooterCount (i18n)? #354

djalmajr opened this issue Mar 7, 2020 · 4 comments

Comments

@djalmajr
Copy link

djalmajr commented Mar 7, 2020

Steps to reproduce the behavior:

My snippet of code is this:

image

Actual behavior:

I would like to change only this part of the text

image

Expected behavior:

To this:

image

How can I achieve this? I tried using formatters but no luck :/

Would be nice if we have i18n... By the way, thanks for this awesome lib

@martinjuhasz
Copy link

martinjuhasz commented Mar 9, 2020

I had the same requirement. There is no way to just translate the of part of the footer.
You need to add a custom Component and replace it with the default FooterCount one.

What i did:

const CustomModalFooter = ({ currentIndex, views }) => {
	const activeView = currentIndex + 1
	const totalViews = views.length

	if (!activeView || !totalViews) return null
	return (
		<span>
			{activeView} de {totalViews}
		</span>
	)
}
<Carousel
    components={{ FooterCount: CustomModalFooter }}
    views={[...]}
/>

@anhtran
Copy link

anhtran commented Mar 10, 2020

I agree with @martinjuhasz, you should re-write the component to get that.

@djalmajr
Copy link
Author

So, where this is used:

image

I thought it would be used for this kind of problem. Re-writting the code breaks the DRY for a simple thing. :/

Anyway, thanks for response :)

@martinjuhasz
Copy link

These props are not used for the FooterCount component. The FooterCount component does not use the formatters feature as you can see here, although adding support for it would be fairly easy.

The formatters you highlighted above are used for alt-texts on the buttons for next and previous images. When you hover your mouse on those buttons the text will appear.

I gave the formatters props a try and somehow it only works when declaring ALL formatters, not just a single one. From a quick look at the code it should be merged, but it only worked for me when delcaring all formatter like:

<Carousel
    formatters={{
        getAltText: () => 'a',
        getNextLabel: () => 'b',
        getPrevLabel: () => 'c',
        getNextTitle: () => 'd',
        getPrevTitle: () => 'e',
        getCloseLabel: () => 'f',
        getFullscreenLabel: () => 'g',
    }}
    ...
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants