Requests for comment/Scoped language converter

The current language converter contains a rule-based engine. Rules are applied from the point of definition on. See Writing systems/Syntax for more information.

This has a number of disadvantages. Rules defined in a template can unexpectedly leak into the body of an article. Changes to a template require the entire page to be re-rendered from the point of inclusion on. Finally, it exposes unnecessary complexity to the author/editor of an article, who would like to edit language converter rules on a global basis (in a page properties dialog, for example) without having to worry about exactly *where* in the article the rules are defined.

There are some advantages to the system, which should be preserved. First, by allowing rules to leak out of templates it is possible to write templates which contain a number of useful rules. All articles in a given topic area can include that template at the top of the page.

This RFC proposes to add syntax for scoped rules to the language converter. These rules would provide better encapsulation and more efficient rendering. In order to provide a migration path, we propose to first add new syntax. Existing rules using the old point-of-definition semantics can then be incrementally migrated to the new syntax (with the aid of bots or other tools in most cases). The old syntax could then be deprecated and removed.

It is proposed to add the new syntax at the same time bug 52661 is fixed.

= Proposals = There are two proposals for new language converter syntax/semantics. Both proposals maintain the basic syntax of the language converter unchanged. The following flags are also unchanged:
 * no flag : a one-off conversion that does not modify the rule table
 * R : disable conversion
 * D : describe conversion
 * T : override language conversion in title

The T flag might be deprecated if  can be made to work after bug 52661 is fixed.

The two proposals differ on how to support the existing use case where common groups of rules are defined in templates in order to be used by the including page.

Proposal A
This proposal adds "category rules" to handle common groups of rules. Pages inherit the category rules defined by all categories they are member of. The new flags are:


 * S : scoped rule. Regardless of where in the document this rule occurs, it applies to all text in the document.  It does *not* apply to text included from templates.  If the document is included (as a template or page transclusion) the rule applies to the included text but does not leak out to the including document.
 * C : category rule. If this rule is included in a document in the Category namespace, then this rule will apply to all pages in the category.  It does *not* apply to the text on the category page itself. (Similarly, rules with the S flag will affect the category page but will not affect pages in the category.)
 * S- : scoped rule removal. The given rule is disabled (regardless of whether it was a S or C rule) in the same scope as an S rule.  This allows the page author to disable a few rules which would otherwise be active due to the page's category, for example.  (S- rules override any S rules in the same scope.)

''Possibly S rules should also apply to text included from templates, although this complicates template caching. If they are, then the S- rules allow the template to disable rules which might be inherited from the including scope.''

Proposal B
This proposal adds "global rules" which deliberately leak from templates into the entire page scope. The new flags are:
 * G : global rule. Regardless of whether this comes from a (possibly nested) inclusion or where in the document this rule occurs, it applies to all text on the page.
 * C : child rule. This rule applies to the current page and any pages it includes, but not to any pages which include it.
 * L : local rule. This rule applies to the current page, but *not* to any included pages or pages which include it.
 * L-: local rule removal. The given rules is disabled (regardless of whether it was a G or L rule) in the same scope as an L rule. (L- rules override any L rules in the same scope.)

One of C or L might be removed as unnecessary.

= Examples = In our examples, we are writing pages about the en:Premier League. We use  to define useful rules for the (fictional) en-uk and en-us variants, as well as to provide an appropriate info box and categories.

Proposal A
Template:Premier League:

-{S-|en-uk:football; en-us:soccer;}-

Category:Premier League: -{C|en-uk:football; en-us:soccer;}- -{C|en-uk:pitch; en-us:field;}-

The main article for this category is Premier League.

Game 39 (article):

The top football league in England, the Premier League is currently played on a double round robin basis... ...It needed the support only of the -{R|Football}- Association (FA)...

Proposal B
Template:Premier League:

-{G|en-uk:football; en-us:soccer;}- -{G|en-uk:pitch; en-us:field;}-

-{L-|en-uk:football; en-us:soccer;}-

Game 39 (article):

The top football league in England, the Premier League is currently played on a double round robin basis... ...It needed the support only of the -{R|Football}- Association (FA)...