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

just now with formatter + buildFormatter #164

Closed
MichaelKheel opened this issue Jun 9, 2021 · 3 comments
Closed

just now with formatter + buildFormatter #164

MichaelKheel opened this issue Jun 9, 2021 · 3 comments

Comments

@MichaelKheel
Copy link

MichaelKheel commented Jun 9, 2021

you can create your formatter function which has to returns string
as example:

<TimeAgo date={timeAgo}
formatter={(value, unit) => {
                  if (unit === 'second' && value < 15) return "just now";
                  if (unit === "second") return "few seconds ago";
                  if (unit  === "minute") return `${value} ${value === 1 ? "minute" : "minutes"} ago`;
                  ...
                }}
/>

How can I do this if I use localization?

import React from "react";

import TimeAgo from 'react-timeago';
import LocaleRU from 'react-timeago/lib/language-strings/ru';
import buildFormatter from 'react-timeago/lib/formatters/buildFormatter';
const formatter = buildFormatter(LocaleRU);
import {Box} from '@material-ui/core';

export default ({date, title}) => {
	return(
		<Box component="small" color="text.disabled" fontWeight="bold">
			<TimeAgo
			date={date}
			formatter={formatter}
			title={title} />
		</Box>
	);
}

Originally posted by @mara1esh in #130 (comment)

@nmn
Copy link
Owner

nmn commented Jun 10, 2021

Since formatters are a functions you can wrap a localization function with your function to customize it however you need to.

@nmn nmn closed this as completed Jun 10, 2021
@MichaelKheel
Copy link
Author

I would be grateful if you could show a simple example, since I tried different options.

@dmatora
Copy link

dmatora commented Nov 18, 2021

Same question. How can it be wrapped?
I tried and couldn't get it working

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