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

Get multiple strings with same parameter name #123

Open
OasisLiveForever opened this issue May 17, 2016 · 7 comments
Open

Get multiple strings with same parameter name #123

OasisLiveForever opened this issue May 17, 2016 · 7 comments

Comments

@OasisLiveForever
Copy link

Hi,

translate.instant allows to pass an array of keys to get multiple strings at the same time. If the strings have the same parameter name, there is no way no pass a different value for each string.

This is a sample json:
{
"string1": "test {{name}}",
"string2": "test2 {{name}}"
}

let strings = translate.instant(['string1', 'string2'], { name: 'sample' });

Is there a way to pass a different value for name parameter to string1 and string2?

@ocombe
Copy link
Member

ocombe commented May 17, 2016

Good point, looks like a design flow :)

@OasisLiveForever
Copy link
Author

OasisLiveForever commented May 17, 2016

Maybe we need two different methods, one for getting a single string and one for getting multiple strings. When getting multiple strings, we should pass an array of objects for parameters.
Maybe we can also change the names of methods:

// Old instant method
getString(key: string, interpolateParams?: Object): string
// Old get method
getStringAsync(key: string, interpolateParams?: Object): Observable<string>
// New method for getting multiple strings
getStrings(keys: Array<string>, interpolateParams?: Array<Object>): any
// New method for getting multiple strings async
getStringsAsync(keys: Array<string>, interpolateParams?: Array<Object>): Observable<any>

What do you think?

@ocombe
Copy link
Member

ocombe commented May 17, 2016

Yes, that'd probably be a better idea

@Lukec1
Copy link

Lukec1 commented Jan 9, 2017

Is it possible now?

@sabbynair
Copy link

Any updates on this? Is this possible in any way now? This would be a really useful feature.

@revenz
Copy link

revenz commented Aug 31, 2018

bump. im too after this feature. my use case is

"DateRange": { "Today": "Today", "Yesterday": "Yesterday", "LastDays": "Last {num} days", "ThisMonth": "This Month", "LastMonth": "Last Month" },

translate.get(['DateRange.Today', 'DateRange.Yesterday', 'DateRange.LastDays', 'DateRange.LastDays', 'DateRange.ThisMonth', 'DateRange.LastMonth'])

I want the first "LastDays" to be passed 7 and the second one passed "30", so my calendar input shows "Last 7 Days" and "Last 30 Days". The work around is to you have 2 separate translations, but it would be nice to just have the one and use a variable.

@rmckeel
Copy link

rmckeel commented Jan 20, 2021

I'm also interested in this feature. It seems like a design flaw that an array can be passed for the first argument, but the second has to be an object. I'd expect the interpolateParams to allow an array of interpolateParams, which applies to each key.

My use case:

[ 'FAVORITE_NUMBER', 'FAVORITE_NUMBER' ] where the translation key/value pair is "FAVORITE_NUMBER": "Favorite {{number}}" and the desired parameters are [ { number: 1}, { number: 2 } ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants