Templat:Pagelang/doc
[[Category:Languages pages{{#translation:}}]]
| Ini adalah sebuah subhalaman dokumentasi untuk Templat:Pagelang. Templat ini berisi informasi penggunaan, kategori dan konten lainnya yang bukan merupakan bagian dari templat halaman. |
| Templat ini digunakan pada sekitar 50.000 halaman dan perubahannya kemungkinan dipantau. Uji cobalah di subhalaman /bak pasir atau /kasus uji templat, atau subhalaman pengguna Anda. Pertimbangkan untuk mendiskusikan perubahan di halaman pembicaraan sebelum mengimplementasikannya. |
| Templat ini menggunakan Lua: |
Usage
[sunting sumber]<templatedata> { "description": { "en": "This stuff template for check language of translated subpage (for translatable pages). Used for automate substitution localized values that will match the language of the current page. Also used to help defining text direction (with using with ltr). It is designed to be called from other templates.", "cs": "Tato šablona pro kontrolu jazyka přeložené podstránky (pro přeložitelné stránky). Používá se k automatickému nahrazování lokalizovaných hodnot, které budou odpovídat jazyku aktuální stránky. Také se používá k definování směru textu (s použitím s ltr). Je navržen pro volání z jiných šablon.", "tr": "Çevrilen alt sayfanın kontrol dili için malzeme şablonu (çevrilebilir sayfalar için). Geçerli sayfanın diliyle eşleşecek yerelleştirilmiş değiştirme değerlerini otomatikleştirmek için kullanılır. Ayrıca metin yönünü tanımlamaya yardımcı olmak için de kullanılır (ltr ile birlikte). Diğer şablonlardan çağrılmak üzere tasarlanmıştır.", "fr": "Ce modèle sert à contrôler la langue de la sous-page traduite (pour les pages traductibles). Il est utilisé pour la substitution automatique des valeurs localisées correspondant à la langue de la page actuelle. Il est également utilisé pour aider à définir la direction du texte (par l'utilisation de ltr). Il est conçu pour être appelé à partir d'autres modèles." }, "format": "inline", "params": { "1": { "label": { "en": "Page title", "cs": "Název stránky", "tr": "Sayfa başlığı", "fr": "Titre de la page" }, "description": { "en": "Page title to get language for. By default the title of the current page.", "cs": "Název stránky pro získání jazyka. Ve výchozím nastavení název aktuální stránky.", "tr": "Dili alınacak sayfa başlığı. Varsayılan olarak mevcut sayfanın başlığı.", "fr": "Titre de la page dont on veut connaître la langue. " }, "type": "wiki-page-name", "default": { "fr": "valeur du titre de la page courante." } } } } </templatedata>
Examples
[sunting sumber]{{pagelang}}
Galat skrip: tidak ada modul tersebut "Template translation".
{{pagelang|Page name}}
Galat skrip: tidak ada modul tersebut "Template translation".
{{pagelang|Page name/ja}}
Galat skrip: tidak ada modul tersebut "Template translation".
Examples of common use in translated pages or templates:
<syntaxhighlight lang="html5"> {{#language:Templat:1|Galat skrip: tidak ada modul tersebut "Template translation".
</syntaxhighlight>
Technical note
[sunting sumber]When a subpage page contains any (single or double) quotes or ampersands, it is not a valid language code; PAGENAME and SUBPAGENAME normally HTML-encodes these characters in their return value, so they are safe to use as input of #language. But #titleparts restores these quotes or ampersands by HTML-decoding them.
But then #language will produce a fatal server error when it is used with "language codes" with single quotes.
- Proof
This still works: <syntaxhighlight lang="html5">
français
</syntaxhighlight>
This does not work either: <syntaxhighlight lang="html5">
français
</syntaxhighlight>
Nor does this: <syntaxhighlight lang="html5">
français
</syntaxhighlight>
This is a critical bug of the #language parser function, and apparently a severe security issues that could be caused by some clever insertion of code in PHP after the quote.
This bug only occurs in the second parameter of #language (the target language into which to give the name of the language specified by the code in the first parameter). Only the first parameter is checked for validity, but not the second one. Here, where #language cannot find the name of the language, in any target language, it should return the native language name, as in:
<syntaxhighlight lang="html5">
français
</syntaxhighlight>
- français
- Word-around used in this template
To avoid this severe bug, we want to detect quotes (or ampersands) in subpage names, as they are invalid anyway in any language code, in order to return an empty string and not the subpage name: such subpage name cannot be a language code anyway.
One way to detect subpages that cannot be safe language codes is to check if their value filtered by #titleparts is equal to their value filtered by PAGENAME: if they aren't equal that's because they contained "ampersands", or quotes.
- Why we use
#titlepartsand not justSUBPAGENAME?
#titleparts is used in this template instead of using SUBPAGENAME, but using SUBPAGENAME would not avoid the bug either, because it could as well return the full page name containing the quotes (SUBPAGENAME only works in namespaces where subpages have been activated, so it does not work in the main namespace to see if it has been translated using a language code suffix).
See also
[sunting sumber]- REDIRECT Template:Localized link