Repository navigation
feat: right-to-left language support for the modern template and search - #11234
Open
soroshsabz wants to merge 4 commits into
Open
soroshsabz wants to merge 4 commits into
soroshsabz wants to merge 4 commits into
Conversation
Contributor
Author
|
@vicancy Can you please review this PR thanks :) |
Contributor
Author
|
Contributor
Author
Contributor
Author
2 of 3 tasks
Contributor
Author
|
@vicancy Can you please review this PR thanks :) |
vicancy
reviewed
Dec 3, 2026
Pages in a right-to-left language such as Arabic, Hebrew or Persian are rendered right-to-left. Docfx derives the text direction from `_lang`, or from the new `_dir` metadata, writes `dir="rtl"` and the modern template loads a mirrored stylesheet. Code and API member names stay left-to-right, the directional icons point the other way, and the "In this article" title no longer breaks the letter joining of cursive scripts. Search finds the words of every language. lunr's ASCII-only trimmer is replaced by a Unicode-aware one, the Arabic and Hebrew language packs are patched so that they work in the ES module bundle and keep their state apart, and an unsupported `lunrLanguages` entry no longer disables search. The strings of the modern template that were hard-coded in English are taken from token.json, and the view model snapshots follow. Fixes dotnet#11227 Fixes dotnet#11228 Fixes dotnet#11229 Fixes dotnet#11230 Fixes dotnet#11231 Fixes dotnet#11232 Fixes dotnet#11233
The direction was determined once for the docset and written to its global metadata as an explicit `_dir`. A page of a Persian docset that set `_lang` to a left-to-right language was still rendered right-to-left. The direction is now determined from the metadata of each page, after its file metadata and YAML header are merged with the global metadata. The global metadata is only checked for an invalid `_dir`, which is reported once and removed.
The default template had been given the `dir` attribute too, without the styles that keep code left-to-right on right-to-left pages: the code blocks of existing sites with a right-to-left `_lang` were rendered incorrectly. Only the modern template lays out right-to-left languages. The default template is not changed.
The snapshots gain the tokens that this pull request adds to `__global`.
soroshsabz
force-pushed
the
fix/rtl-languages
branch
from
December 3, 2026 06:58
7146ee3 to
e6aaf7a
Compare
Contributor
Author
|
@vicancy Thanks for review this PR, I try to resolve all of your comments Can you please review this PR again? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #11227, fixes #11228, fixes #11229, fixes #11230, fixes #11231, fixes #11232, fixes #11233
Summary
Pages in a right-to-left language are now rendered right-to-left, and search finds the words of every language.
Text direction (#11233)
_lang: pages in a right-to-left language such as Arabic, Hebrew and Persian getdir="rtl". The new_dirmetadata sets the direction explicitly (rtlorltr), e.g. for a language docfx doesn't know._langand_dircan also be set for a single file with file metadata or in the YAML header of a page, so an English page in a Persian docset is left-to-right. An invalid_diris reported once per docset.dirattribute broke the code blocks of existing sites.public/docfx.rtl.min.css. The template build derives it from the left-to-right stylesheet with rtlcss, as Bootstrap does for its own RTL stylesheet, and appends the few rules that must not be mirrored. Left-to-right pages load the same stylesheet as before.Code and member names stay left-to-right (#11230)
dir="auto"in the templates,unicode-bidi: plaintextfor links.Calculator()andobject.GetType()keep their parentheses, and a name in a right-to-left script is still laid out right-to-left.Letter joining of cursive scripts (#11231)
letter-spacingwhen it is written in a cursive script such as Arabic, whose letters are only joined without it.Search (#11227, #11228, #11229)
[A-Za-z0-9_]only and turned every Persian, Cyrillic, … word into an empty string. It is replaced by a Unicode-aware trimmer. The multi-language trimmer dropped every word outside the configured languages in the same way, so it is replaced too.this. In a classic script that is the global object: in the ES module bundle, wherethisisundefined, they threwCannot set properties of undefined (setting 'result'), and loading both packs made them overwrite each other's state. The template build now keeps the state in an object per pack.lunrLanguagesentry such asfais reported in the console instead of disabling search. A language pack that fails to load no longer disables the other languages.Translated strings (#11232)
aria-labels of the search box, of the anchors and of the search pagination come fromtoken.json.Left-to-right sites are not affected: their pages get the same HTML (no
dir), the same stylesheet and the same strings.Tests
Unit tests:
TextDirectionTest: the direction from_dir, from_langand from its script, and invalid values.search-index.test.ts: the trimmer keeps every script, the default pipeline finds Persian, Cyrillic and CJK words, English stemming and stop words still apply, and an index can be saved and loaded.search-languages.test.ts: the Arabic and Hebrew packs need the global object as their state and fail in strict mode; the patched packs work in strict mode and keep their state apart; unsupported languages are skipped with a warning; a pack that fails to load doesn't disable the other languages; the index analyzes the words of every loaded language and keeps the words of other languages.helper.test.ts: right-to-left pages and cursive scripts.System tests:
RtlLanguageTestdrives a headless Chromium, likeVersionLocaleSelectorTestdoes. It builds a Persian site and an English site from the same content, with an API page and a page whose file name is Persian, and checks in the browser:dir="rtl", the right stylesheet, code left-to-right with the braces in place, icons at the start of their inputs, joined letters, the bar of blockquotes, translated strings, the direction of previous/next, member names left-to-right and right-aligned, the inheritance chain and the table of contents. It also checks that the English site is unchanged. A second test searches Persian, Arabic and Hebrew in sites with differentlunrLanguages.TextDirectionBuildTestbuilds docsets for 12 language and direction combinations and checks the generated HTML, including pages that override the language or the direction, the warning for an invalid_dir, and that the default template is not changed.BrowserTestServerto be shared. It now decodes URL-encoded paths, which pages with a Persian file name need.Follow-ups from the review
_langto a left-to-right language inside a Persian docset was still rendered right-to-left.dirattribute. Only the modern template has the styles for right-to-left pages, so the automatic direction broke code blocks on existing default-template sites.main.Notes for reviewers
templates/modern/publicis build output and is not committed.rtlcssis a new devDependency oftemplates, the same range Bootstrap uses (^4.3.0).CultureInfo.*.html.view.verified.jsonfiles are the view model snapshots ofSamplesTest, which usesAutoVerify: each gains the new tokens in__global. This also adds the three tokenschangeVersion,changeLocaleandchangeMonikerthat feat: Built-in version, locale and moniker selectors for multi-version sites #11212 introduced intoken.jsonbut that were missing from the snapshots, and covers the 9 snapshots added by chore: Add samples of csharp15 syntax metadata extraction #11224. The*.pdf.verified.jsonsnapshots are not changed.mainand with this branch: all 202 pages have the same content, apart from three newloc:meta tags, thedir="auto"spans around API names and the "View Source" tooltip that now comes fromtoken.json.