Set lang
and dir
attributes on tweet bodies
#170
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tweets can be written in various languages. Language metadata is essential for browsers to correctly render multilingual texts because the different language uses different shapes of glyphs for the same Unicode codepoints, and the browsers must select fonts based on the intended language1.
Twitter API infers the primary language of each tweet, and this patch sets the
lang
attribute to the inferred language for the tweet bodies.dir="auto"
is also necessary for proper rendering of texts in the right-to-left languages, such as Arabic, Hebrew, and Persian.This test tweet in Japanese contains several Han characters which present regional variation (See 1 for details): https://twitter.com/k_hanazuki/status/1803451841684111591
Footnotes
Regarding font selection in CJK languages: https://heistak.github.io/your-code-displays-japanese-wrong/ ↩ ↩2