Module:Translate/doc
This module detects the languages a translated SVG file is available in (via the Translate extension / SVG language-switching system) and can output either a human-readable list or ready-to-use category wikitext.
It relies on mw.title.new(fileName, 'File').file.languages, which MediaWiki
populates for SVG files that use systemLanguage/switch elements
(the format produced by tools such as Commons' SVG translation feature). Files without
language variants will simply return an empty list.
Usage
From wikitext:
Kannada (kn), Tulu (tcy) Category:Tulu-language SVGCategory:Kannada-language SVG
From another module:
local Translate = require('Module:Translate')
local langs, err = Translate.getLanguages('Tulunadu.svg')
Functions
getLanguages(fileName)
Returns an array of language codes (e.g. { 'en', 'fr', 'de' }) available for
the given file, or nil, errorMessage if the file can't be found.
- fileName
- The file name, with or without the
File:/Image:prefix.
This function is intended for use by other modules, not for direct #invoke.
listLanguages(frame)
Usage: {{#invoke:Translate|listLanguages|<file name>}}
Returns a comma-separated, alphabetically sorted list of language names and codes, e.g.:
English (en), French (fr), German (de)
If the file doesn't exist or has no language variants, returns an error message or "No language versions found" respectively.
getCategories(frame)
Usage: {{#invoke:Translate|getCategories|<file name>}}
Returns wikitext categories, one per available language, in the form:
Category:English-language SVG Category:French-language SVGReturns an empty string if the file doesn't exist or has no language variants (so it's safe to use unconditionally on a file page without producing visible errors).
Parameters
Both listLanguages and getCategories take a single positional
parameter: the file name. It can be passed directly to the invoke, or, if this module is
called from a wrapper template, will fall back to the parent frame's first argument.
both work identically.
Examples
| Input | Output |
|---|---|
| {{#invoke:Translate|listLanguages|File:Tulunadu.svg}} | Kannada (kn), Tulu (tcy) |
| {{#invoke:Translate|getCategories|File:Tulunadu.svg}} | [[Category:Kannada-language SVG]] [[Category:Tulu-language SVG]] |
Errors
No file name provided— no argument was passed.Invalid file name: ...— the title couldn't be parsed.File does not exist: ...— no such file on this wiki.
getCategories suppresses these and returns an empty string instead, so it can
be embedded directly in file page templates without breaking rendering.