From e1385d3bdf20c6728121f99e2e912f4388f8b8e8 Mon Sep 17 00:00:00 2001
From: Ebrahim Byagowi
Date: Thu, 16 May 2024 21:39:52 +0330
Subject: 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
---
tests/parser/parserTests.txt | 83 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
(limited to 'tests/parser')
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
العربية
!! 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
+Persian: rtl
+
English: ltr
+
Persian (with space): rtl
+
Tajik: ltr
+
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'
+- ltr
+- Directionality of internal code 'eml'
+- ltr == ltr
+!! html/parsoid+integrated
+Persian: rtl
+English: ltr
+Persian (with space): rtl
+Tajik: ltr
+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'
+- ltr
+- Directionality of internal code 'eml'
+- ltr == ltr
+
+!! end
+
+!! test
+Dir parser function (target language)
+!! options
+language=fa
+cat
+!! metadata
+!! wikitext
+These are all equivalent:
+
+{{#dir}} / {{#dir:}} / {{#dir:{{PAGELANGUAGE}}}}
+!! html/php
+These are all equivalent:
+
rtl / rtl / rtl
+
+!! html/parsoid+integrated
+These are all equivalent:
+rtl / rtl / rtl
+!! end
+
+!! test
+Dir parser function (invalid code)
+!! options
+cat
+!! wikitext
+{{#dir:blahltr
+
+!! html/parsoid+integrated
+ltr
+!! end
+
!!test
Padleft and padright (default 0-padding)
!! wikitext
--
cgit v1.2.3