expressive-date icon indicating copy to clipboard operation
expressive-date copied to clipboard

Add ability to set custom units for ->getRelativeDate

Open Anahkiasen opened this issue 11 years ago • 8 comments

Currently the getRelativeDate method only ouputs in english, it would be nice to be able to set a custom $units array and the ago string to allow manual translation of the date.

Anahkiasen avatar Feb 14 '13 00:02 Anahkiasen

Yeah nice one mate, will get onto it when I'm home. On Feb 14, 2013 11:25 AM, "Maxime Fabre" [email protected] wrote:

Currently the getRelativeDate method only ouputs in english, it would be nice to be able to set a custom $units array and the ago string to allow manual translation of the date.

— Reply to this email directly or view it on GitHubhttps://github.com/jasonlewis/expressive-date/issues/3.

jasonlewis avatar Feb 14 '13 01:02 jasonlewis

I know this is an old issue but I really want to implement something for i18n. The problem is working with dates and especially with relative dates like Expressive Date it becomes quite complex. It's okay for some languages, but others, like Russian, can have 3 plural forms. Russian also requires that the "from now" suffix be placed in front of the date as a prefix, not a suffix.

I'm thinking of using the Symfony translator for this but that does add a dependency to what is currently a lightweight package.

For anyone that's using this I'd be interested to hear your thoughts.

jasonlewis avatar Apr 20 '13 07:04 jasonlewis

+1 localization would be awesome although it seems quite complex to do.

TomClarkson avatar Jul 15 '13 01:07 TomClarkson

What if for i18n support, you return back an array or something:

array(
    "number": "4",
    "unit": "day",
    "direction": "future"
}

So "4 days ago" would be

array(
    "number": "4",
    "unit": "day",
    "direction": "past"
}

And "3 weeks from now" would be

array(
    "number": "3",
    "unit": "week",
    "direction": "future"
}

Then leave it up to the implementer to translate that to actual language?

kalenjordan avatar Oct 03 '13 22:10 kalenjordan

:+1: For localization, any update?

ludo237 avatar Nov 28 '13 14:11 ludo237

+1

punkeel avatar Dec 04 '13 17:12 punkeel

It would also read better in some situations to change future dates to use a prefix instead, e.g. on an event page:

echo 'Event starting ' . $dt->getRelativeDate();

Would become:

Event starting in 4 hours

Rather than

Event starting 4 hours from now

@kalenjordan's suggestion would allow for this, though passing in a custom message format would be good too, e.g.

echo $dt->getRelativeDate('in %s', '%s ago');

zeropingheroes avatar Feb 15 '14 17:02 zeropingheroes

I have added Laravel Localization support and added a pull-request

denvers avatar May 13 '14 12:05 denvers