-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Angular] Format values of i18n attributes #5875
Comments
Not an Angular user, so take this with a grain of salt, but how about this? <h1
i18n="
This is a very long internationalization description text, exceeding the
configured print width, but could easily be formatted
"
>
Hello!
</h1>
<my-custom-component
customAttr="meep"
i81n-customAttr="
This is a very long attribute-based internationalization
description text, which also exceeds the configured print width
"
>
</my-custom-component> |
That should work fine as well - basically, any kind of auto-formatting would be better than the current behavior (which does nothing). Does Prettier already have a precedent of treating attribute values that way? If so, that should be fine - otherwise, I think I'd prefer the first example (with the continuation indent). |
Just to confirm, does this sound good as-is (i.e. is it ready for a PR) or does it need more discussion? |
Feel free to open a PR! |
Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes prettier#5875.
Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes prettier#5875.
Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes prettier#5875.
Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes prettier#5875.
Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes prettier#5875.
Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes prettier#5875.
* Add formatting for i18n attributes. Previously, Prettier would largely ignore i18n attributes, not even wrapping their content, which wasn't ideal since i18n descriptive text can sometimes get long. After this, Prettier will auto-wrap the contents of i18n attributes once they exceed the line length. Fixes #5875.
Hi, we recently started using prettier in our project and I think that this PR is missing a key point... If you for example already have a translation for something like:
Then the result translation would be something like:
But with this change, running prettier would format my translation to something like:
And my resulting translation id would now be changed to:
Beasure this is not the same translation id anymore, the xi18n angular cli command will remove my old translation (because there is no reference to it anymore) and insert the new translation id with an empty value. I think that everything that has to do with translations should be left "as is" to prevent falsy results like this. Any chance we can change this back to not break the ending (result could be something like this?)
|
Thanks for the fix! I'm wondering, though, if this is a bug in the Angular compiler? Intuitively, I wouldn't expect the |
Prettier 1.16.4
Playground link
Input:
Output:
Expected behavior:
Currently, Prettier doesn't wrap the
i18n
attribute content. Based on discussions in #5479 and #5482, I think this would be a good candidate for formatting, since thei18n
content is well-known, and tends to be long (and thus is more of a pain when unformatted).Documentation on Angular's
i18n
attributes, for reference: https://angular.io/guide/i18nIdeally, I'd want output similar to either this (with a continuation indent):
Or this (with an alignment to the opening quote,
"
):I'd somewhat prefer the continuation indent instead of the quote alignment, as it minimizes wasted horizontal space and seems to be more consistent with how Prettier formats long sequences of attributes.
Does this sound reasonable? If so, I may try sending a PR.
The text was updated successfully, but these errors were encountered: