expressive-date
expressive-date copied to clipboard
Add ability to set custom units for ->getRelativeDate
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.
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.
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.
+1 localization would be awesome although it seems quite complex to do.
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?
:+1: For localization, any update?
+1
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');
I have added Laravel Localization support and added a pull-request