diff options
author | Ebrahim Byagowi <ebrahim@gnu.org> | 2024-05-16 21:39:52 +0330 |
---|---|---|
committer | C. Scott Ananian <cscott@cscott.net> | 2024-07-19 16:57:48 -0400 |
commit | e1385d3bdf20c6728121f99e2e912f4388f8b8e8 (patch) | |
tree | 26dadcb1201865035be2f6f025c09d743b38e08c /tests/parser | |
parent | c2b2f2ebb1215a7a3d33677aa2cbb90b8cab2c11 (diff) | |
download | mediawikicore-e1385d3bdf20c6728121f99e2e912f4388f8b8e8.tar.gz mediawikicore-e1385d3bdf20c6728121f99e2e912f4388f8b8e8.zip |
Add {{#dir}} parser function
Template:Dir is one of the most used templates in Wikimedia Commons,
this tries to provide parts of its functionality in hope we can
perhaps simplify or get rid of the template eventually for clarity and
performance reasons.
As a convenience, `{{#dir}}` and `{{#dir:}}` are synonyms for
`{{#dir:{{PAGELANGUAGE}}}}`: they return the direction of the target
language. For articles, the target language is the content language;
for messages, the target language is the user language.
In addition, to avoid confusion between BCP-47 language codes and
MediaWiki-internal language codes, an optional second parameter can be
supplied. If the second parameter is the (localizable) string
'bcp47', the language code given in the first parameter will be
treated as a BCP-47 code. For example: `{{#dir:sr-Cyrl|bcp47}}`.
(See LanguageCode::bcp47ToInternal() for a description of the
differences and overlaps between MediaWiki internal and BCP-47
codes. These overlaps *so far* don't result in any case where
encouraging editors to be precise about which set of enumerated
string values they are using for consistency with other
language-related functions, and because MediaWiki internally
differentiates between BCP-47 codes and internal codes.)
Bug: T359761
Change-Id: I19c3e91a924e080f37dc95a0d4e61493583b533e
Diffstat (limited to 'tests/parser')
-rw-r--r-- | tests/parser/parserTests.txt | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 07d90e4ef1d8..9626fab124dd 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -12938,6 +12938,89 @@ Language parser function <p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:ar","function":"language"},"params":{},"i":0}}]}'>العربية</span></p> !! end +!! test +Dir parser function (valid codes) +!! wikitext +Persian: {{#dir:fa}} + +English: {{#dir:en}} + +Persian (with space): {{#dir: fa}} + +Tajik: {{#dir:tg}} + +The string 'egl' is a valid internal code; however when used as a +BCP-47 code it refers to the internal code 'eml'. Unfortunately, +both of these have ltr directionality which makes this test case +less useful than it could be. + +Ambiguous BCP-47 code: +;Directionality of internal code 'egl':{{#dir:egl}} +;Directionality of internal code 'eml':{{#dir:egl|bcp47}} == {{#dir:eml}} +!! html/php +<p>Persian: rtl +</p><p>English: ltr +</p><p>Persian (with space): rtl +</p><p>Tajik: ltr +</p><p>The string 'egl' is a valid internal code; however when used as a +BCP-47 code it refers to the internal code 'eml'. Unfortunately, +both of these have ltr directionality which makes this test case +less useful than it could be. +</p><p>Ambiguous BCP-47 code: +</p> +<dl><dt>Directionality of internal code 'egl'</dt> +<dd>ltr</dd> +<dt>Directionality of internal code 'eml'</dt> +<dd>ltr == ltr</dd></dl> +!! html/parsoid+integrated +<p>Persian: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:fa","function":"dir"},"params":{},"i":0}}]}'>rtl</span></p> +<p>English: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:en","function":"dir"},"params":{},"i":0}}]}'>ltr</span></p> +<p>Persian (with space): <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir: fa","function":"dir"},"params":{},"i":0}}]}'>rtl</span></p> +<p>Tajik: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:tg","function":"dir"},"params":{},"i":0}}]}'>ltr</span></p> +<p>The string 'egl' is a valid internal code; however when used as a BCP-47 code it refers to the internal code 'eml'. Unfortunately, both of these have ltr directionality which makes this test case less useful than it could be.</p> +<p>Ambiguous BCP-47 code:</p> +<dl> +<dt>Directionality of internal code 'egl'</dt> +<dd><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:egl","function":"dir"},"params":{},"i":0}}]}'>ltr</span></dd> +<dt>Directionality of internal code 'eml'</dt> +<dd><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:egl","function":"dir"},"params":{"1":{"wt":"bcp47"}},"i":0}}]}'>ltr</span> == <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:eml","function":"dir"},"params":{},"i":0}}]}'>ltr</span></dd> +</dl> +!! end + +!! test +Dir parser function (target language) +!! options +language=fa +cat +!! metadata +!! wikitext +These are all equivalent: + +{{#dir}} / {{#dir:}} / {{#dir:{{PAGELANGUAGE}}}} +!! html/php +<p>These are all equivalent: +</p><p>rtl / rtl / rtl +</p> +!! html/parsoid+integrated +<p>These are all equivalent:</p> +<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir","function":"dir"},"params":{},"i":0}}]}'>rtl</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:","function":"dir"},"params":{},"i":0}}]}'>rtl</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:{{PAGELANGUAGE}}","function":"dir"},"params":{},"i":0}}]}'>rtl</span></p> +!! end + +!! test +Dir parser function (invalid code) +!! options +cat +!! wikitext +{{#dir:blah<blah}} +!! metadata +cat=Pages_with_invalid_language_codes sort= +!! html/php +<p>ltr +</p> +!! html/parsoid+integrated +<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:blah<blah","function":"dir"},"params":{},"i":0}}]}'>ltr</span></p> +!! end + !!test Padleft and padright (default 0-padding) !! wikitext |