Template:Pg/doc

{{TemplateBox |1       = 1  |1label-en= target |1d-en   = 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. |1type   = line |1def    = |1stat   = required

|2       = 2  |2label-en= display name |2d-en   = Override link text. By default the link text is the localized title of the linked page (except for Category, File and Special namespaces). |2type   = line |2def    = |2stat   = optional

|3       = anchor |3label-en= anchor |3d-en   = 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. |3type   = line |3def    = |3stat   = deprecated

|4       = lang |4label-en= language |4d-en   = 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. |4type   = line |4def    = |4stat   = optional-

|name              = pg  |desc               = Render localized link to Commons/Help page name |namespace         = Commons |usergroup         = All |placement         = |example-value     = |mustbesubst       = |relieson          = Module:Pg |usage-notes       =   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,  renders
 * If the current page language is e.g. French and there is a French version of the target page, renders e.g.
 * Otherwise renders e.g. 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  renders e.g.
 * or
 * or

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,
 * renders

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 File types as:

A link to this anchor on a Spanish language page could be coded as:

which would render:

If there was no Spanish version of the target page, it would render:

|shorthand         = |setscats          = |seealso           =
 * 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,  ,   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. |type              = |i18n-desc         = |i18n-subpage      = |i18n-mediawiki-msg = |i18n-method       = - |example           = |print             = |useTemplateData   = only }}