question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow $translate service to return objects & arrays

See original GitHub issue

Hi, 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:closed
  • Created 10 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bdurrercommented, Apr 23, 2016

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?

1reaction
Zemkecommented, Mar 7, 2016

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Objects and Arrays - i18next documentation
You can return objects or arrays to be used by third party modules localization: · keys · sample · The returned value supports...
Read more >
ANGULAR 5 : translate.get with array of String returns keys ...
You can use the Object.keys function along with .map , like so: let result = Object.keys(this.headers).map((key) => this.headers[key]).
Read more >
Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >
Array methods - The Modern JavaScript Tutorial
Returns the array of removed elements. This method is easy to grasp by examples. Let's start with the deletion: let arr = ["I",...
Read more >
Objects - Manual - PHP
So I wrote an improved_var_export() function to convert instances of stdClass to (object) array () calls. If you choose to export objects of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found