Template:Pg
Render localized link to Commons/Help page name
Usage
{{pg |1= |2= }}
{{pg|pagename|displayname}}
Renders a link to a version of a target page in the Commons or Help namespace in the most suitable language that is available.
Target page selection
If the user is viewing a page in a language other than English and selects a link, they will be taken to a version of the target page in the same language if available, failing that in their preference language, and failing that in English.
- If the current page language is English,
{{pg|pagename}}
renders[[pagename]]
- If the current page language is e.g. French and there is a French version of the target page, renders e.g.
[[pagename/fr|pagename]]
- Otherwise renders e.g.
[[Special:MyLanguage/pagename|pagename]]
This will link to a version of the target page in the user's preferred language if available, or in English otherwise.
Display name
A display name will be used if provided. So {{pg|pagename|displayname}}
renders e.g.
[[pagename|displayname]]
or[[pagename/fr|displayname]]
or[[Special:MyLanguage/pagename|displayname]]
If no display name is provided and the link is to a non-English page, the translated title of that page will be used if available. E.g., on a Spanish language page,
{{pg|Commons:Copyright rules by territory/Argentina}}
renders[[Commons:Copyright rules by territory/Argentina/es|Commons:Reglas de derechos de autor por territorio/Argentina]]
Anchor
The name of a section usually varies from one language to another, and may be changed. A link to a short capitalized {{Anchor}} on the target page will be more stable. The anchor can be placed outside the translatable part of the page to ensure that it is the same for all language versions, for example on Commons:File types as:
</translate>{{anchor|UNSUPP}}<translate>
===Unsupported file types===
A link to this anchor on a Spanish language page could be coded as:
{{pg|Commons:File types#UNSUPP|Tipos de archivo no soportados}}
which would render:
If there was no Spanish version of the target page, it would render:
Template parameters
- TemplateData
TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.
Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either useTemplateData=1
or useTemplateData=only
on the /doc
subpage and transcluding it with {{Documentation}} into the template. <nowiki>
-tags can be wrapped around the arguments, if required, to avoid templates being expanded.
Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw <templatedata>
-tags into the Wikitext of the template, as described in various Wikipediae.
Wikipedia's help about TemplateData • Commons-specific information
Render localized link to Commons/Help page name
Parameter | Description | Type | Status | |
---|---|---|---|---|
target | 1 | Target page name, optionally including an anchor (i.e. “Page#Anchor”). Note that the anchor may be different in translations; either add an untranslatable anchor (see usage notes), or use the legacy parameter. | Line | required |
display name | 2 | Override link text. By default the link text is the localized title of the linked page (except for Category, File and Special namespaces). | Line | optional |
anchor | anchor | Name of anchor (or section) in the target page. Has the same effect as providing the anchor in page name, this parameter exists only for historical reasons. | Line | deprecated |
language | lang | Language to link for. It’s needed only when using this template in other templates, it can automatically detect the language in Commons and Help namespaces. By default the page language for links to the Commons and Help namespaces, user language for other namespaces. | Line | optional |
Additional information
The template is intended to be used in the following namespaces: the Commons namespace
The template is intended to be used by the following user groups: all users
Relies on:
Module:Pg
See also
- Commons:Project page translation:Links to other pages
- {{Localized link}}. More suitable for other namespaces. Links to a target page in the user's preferred language if available, or in English if not.
When a user is browsing through Commons or Help documentation, {{Pg}} tries to keep them on pages in their current selection of language as long as possible, falling back if needed to their preferred language and then to English. Thus a user who prefers a poorly supported language such as Asturian may choose to browse documentation in Spanish. {{Pg}} will link them from page to page in Spanish, while {{Localized link}} would repeatedly try to link to an Asturian version, fail, and fall back to English.
On the other hand, when a user is looking at a file description, they will see it in their preferred language if available, or English otherwise, because file descriptions and license templates are typically localized to preferred language using {{int:}}
, {{De}}
, {{PD-old-70}}
etc. When the user clicks on a link in the file description it makes sense to take them to a target page in their preferred language if available, or English otherwise.
Localization
This template is not intended to be localized.