allow $translate service to return objects & arrays
See original GitHub issueHi, I was wondering whether it’s possible to not only ‘translate’ strings but also objects & arrays.
Here’s what I mean: I’m using a calendar, namely this one http://arshaw.com/fullcalendar/ Configuration happens in a controller using an object for configuration. Configuring the title format would look something like this:
titleFormat : {
"month": "MMMM yyyy",
"day": "ddd, d. MMM, yyyy"
}
now these formats should depend on the selected language. Therefore I hoped I could just write
titleFormat: $translate('TITLE_FORMAT');
and provide the appropriate config in my translation. Unfortunately this doesn’t achieve what I was hoping. I thought I could bypass this by writing a custom interpolator, but that didn’t seem to work either.
What do you think? - Is this something you might include in future releases, or is there another way to achieve this, which I just haven’t figured out yet?
Issue Analytics
- State:
- Created 10 years ago
- Comments:16 (7 by maintainers)
I got here because I wanted to put list of available formats of an datepicker into an array. But the workaround is actually really easy enough: Just put the list of date formats into a single string, separate them with something (eg semicolon) and split them after loading.
$scope.dateFormats = $translate.instant('datepicker.dateFormats').split(';');
For lists you’ll be repeating over them anyway, so you can just use
{{'myEnumNames.' + value | translate}}
inside the repeated part. I can’t imagine all too many cases where the absence of this feature would be a big pain?I don’t see why this was closed. The array syntax to translate multiple keys is nothing like getting a whole translation object. I think the feature request is still valid, isn’t it?