-
Notifications
You must be signed in to change notification settings - Fork 444
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(comments): align locale resource names, improve i18n usage #5665
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
No changes to documentation |
Component Testing Report Updated Feb 5, 2024 6:26 PM (UTC)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this cleanup Espen! This makes a lot of sense (and is a lot more clean), so this is noted for next time 👍
I think it could be very beneficial to add some of your comments in the description to the internal docs. I used those docs a lot when working with this and maybe it can prevent some similar mistakes to happen
...ages/sanity/src/structure/comments/src/components/reactions/CommentReactionsUsersTooltip.tsx
Outdated
Show resolved
Hide resolved
Thanks for pointing that out @ninaandal - will add it.
This is caused by the span not rendering leading/trailing whitespace. I have added
Thanks for catching this and the above issue @hermanwikner ! 28118e0 addresses them both by introducing a smarter logic based on the segmentation: While iterating over the elements, checks whether or not the next element is a literal (
If you still see issues with incorrect wrapping of literals, we could use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great – thanks @rexxars!
Description
Apologies for bigger PR than anticipated. I will outline the main changes I have done below:
This started off as wanting to remove the
comments.
prefix from comments locale resources - since there is already an explicitcomments
namespace, the extra layer is unnecessary. It means the full resource names are actuallycomments:comments.some-resource-key
. This should be done asap, as we want to get locale packs up to date and include comment resources in their translations.The comments that are located above resources were lacking some clarity on what their purpose was, which makes it hard for translators to actually figure out what to translate them as without diving deep into the code. I made an attempt of improving the ones that I thought were the hardest to reason about.
There was a
Strong
component passed down to a few resources, which looked to take children, but actually always rendered the field name. In these cases we should either:<strong>
directly (do not need to pass a component, but do need to use the<Translate>
component), and pass the field name as a title (I went for this approach)<FieldName/>
The list of user names is indeed non-trivial to render in an internationalized way. If you add resource strings that are "words"/"parts of a sentence", such as
and
, it is usually a sign that the approach does not necessarily fit in all languages. For lists, this plays out like this:A, B, and C
A, B and C
A, B og C
A、B、C
Because of these differences, we introduced a
useListFormat
hook, which exposes the browsers' underlying Intl.ListFormat API with the users' chosen locale. This can be used to either format lists straight up:useListFormat().format(['A', 'B', 'C'])
, or by using theformatToParts
, we can get access to each "token" - either an element (A
) or a literal (,
,and
).I refactored the code that displays use names to utilize this API, removing the need for and
and
resource. Additionally, I changed the logic around theYou
handling. Capitalization is not the same in all languages, so I found it cleaner to refer to it as "leading" (eg you are the first user) or not. It somehow still doesn't feel too clean, but at least this allows people to customize the strings as before. I also decided to pass it the actual username, should some language prefer/mandate that you do not refer to "You" but rather an actual name. Altered the story for this component to more easily be able to test this.Found a difference between "fieldName" and "fieldTitle", so decided to unify these and simply name them "field".
The timestamps that we show for creation date did not use the localization API. I introduced the
useDateFormat
hook and made these match the old timestamps in style/length, but still be locale aware. Also used a<time>
element with the full iso timestamp for a potential improvement to screen readers etc.There was a warning being printed about a
t
prop being passed to a button element - I tracked it down to acloneElement
call, and removed it.Found a placeholder that was not yet localized, added a resource for it
Grouped together and renamed resources to be more in line with the rest of the Sanity codebase
Sorted some imports and added type-only declarations in some locations
What to review
Please thoroughly test the comments feature for any broken strings. Glossing over the HTML for aria-labels that are broken is probably wise too. Note that since the studio defaults to
en-US
, you'll now have oxford commas (A, B, and C
instead ofA, B and C
) - this is intentional and in line with the Intl APIs.Testing
No new surfaces introduced, so no change in testing here.
I did add a few expansions to the reactions story to more easily test the "you" logic.
Notes for release