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

fix(TranslatePipe): handle non string input #893

Merged
merged 1 commit into from
Feb 5, 2020

Conversation

jrolheiser
Copy link
Contributor

@jrolheiser jrolheiser commented Jul 13, 2018

I didn't see a contributing guideline and I wasn't sure if I sure file a bug for this/wanted to start more of a discussion about how TranslatePipe should handle non-string input.

Preface

I write shared components for other teams to use (think asset kit), and don't have strict control over inputs. We can put in arg validation as needed but I did run into a case that IMO the TranslatePipe should handle on its own.

Problem

TranslatePipe throws a Parameter "key" required error for number type input. IMO this could just return back the number that was passed in, curious on others' opinions?

Example

We have a shared filtering/searching component that displays a list of filter labels the user can select from such as:

image

The basic replication code boils down to:

<span>{{ 2018 | translate }}</span>

Which throws the Parameter "key" required error.

Solution

Return back the original query arg if it is falsey or the .length call is falesy.

Discussion

Curious if others agree if this should be the functionality or if I have to resort to coercing all inputs to strings in my components.


@ocombe

@ocombe ocombe merged commit d535df3 into ngx-translate:master Feb 5, 2020
ocombe pushed a commit that referenced this pull request Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants