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

Default language cached in sessionStorage from HTML can have messed up line breaks #1

Open
tomyo opened this issue Oct 18, 2022 · 2 comments

Comments

@tomyo
Copy link
Owner

tomyo commented Oct 18, 2022

Trying to debug this myself, found the problem in the innerText specs, quoting:

If the element itself is not being rendered (for example, is detached from the document or is hidden from view), the returned value is the same as the Node.textContent property.

I can't think of a workaround for this without making assumptions about the text content itself (for example, only preserving newlines after a period).

  • Is storing the default language in the html itself a good idea?
    Motivation was/is some basic SEO without needing SSR, otherwise the default content will need to be retrieved from a json and added to the HTML in runtime.
@tomyo
Copy link
Owner Author

tomyo commented Oct 18, 2022

I think making sure served HTML default translatable content respects desired visual line breaks is the easiest workaround for now.
Will add a note in README for now.

@tomyo tomyo closed this as completed in 6ef0d9e Oct 18, 2022
@tomyo
Copy link
Owner Author

tomyo commented Oct 18, 2022

What about using innerHTML instead of innerText?
This way we could get closer to React's <Trans></Trans> component functionality, that is, respect markup inside translations.

Downside is the danger of inserting HTML from json files...

Will reopen to try this out, or give more thoughts to it.

@tomyo tomyo reopened this Oct 18, 2022
@tomyo tomyo changed the title Default language cached in sessionStorage from HTML has messed up line breaks Default language cached in sessionStorage from HTML can have messed up line breaks Oct 18, 2022
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

No branches or pull requests

1 participant