Module:Dictionary/doc: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
initial
 
mNo edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Overview=
= Overview =
See [[Template:Translate]] for how/when to use and more documentation.
See {{tl|Translate}} for how/when to use and more documentation.


=Functions=
== p.translate ==
==translate==
Translates a given key from [[Data:Dictionary]]. '''Manual invocation should only be used when additional parameters are required''', such as {{tl|Update layout}}, where the DISPLAYTITLE is generated using a translation key with expected parameters.
Translates a given key using [[Data:Dictionary]].


===Parameters===
For normal usage, use the basic template.
*'''key''' - key to translate
*'''lang_code_override''' (OPTIONL) - language code that overrides current language. See supported list at [[Data:LangCodes]].


===Example===
=== Function parameters ===
<code><nowiki>{{#invoke:Dictionary|translate|Update history|es}}</nowiki></code>
* '''key''' – translation key (required).
* Language-specific:
** '''lang_code_override''' (optional, named parameter) – language code overriding the automatic detection. See [[Data:LangCodes.json]].
** '''fallback_str''' (optional, named parameter) – value returned '''only if translation is missing'''. If set to empty string or nil, fallback will be empty (useful for detecting missing translations).


Outputs
=== Examples ===
<code><nowiki>{{#invoke:Dictionary|translate|Update history}}</nowiki></code> Output: {{#invoke:Dictionary|translate|Update history}}


{{#invoke:Dictionary|translate|Update history|es}}
<code><nowiki>{{#invoke:Dictionary|translate|Updates|lang_code_override=pt-br}}</nowiki></code> Output: {{#invoke:Dictionary|translate|Updates|lang_code_override=pt-br}}


 
<code><nowiki>{{#invoke:Dictionary|translate|Update history|fallback_str=Custom fallback text.}}</nowiki></code> Output: {{#invoke:Dictionary|translate|Updates|lang_code_override=xx<!-- invalid language code to force fallback. -->|fallback_str=Custom fallback text.}}
==translate_embed==
<includeonly>[[Category:Modules]]</includeonly><noinclude>[[Category:Module documentation]]</noinclude>
Translates a given key then replaces %s in the string with extra parameters
 
===Parameters===
*'''key''' - key to translate
*'''var1''' - first variable to embed in the string
*'''var2''' - second
*'''varN''' - Nth
Ensure the number of variables passed matches the number of instances of <code>%s</code> in the translated string.
 
===Examples===
Without embedment:
<code><nowiki>{{#invoke:Dictionary|translate|TranscludedNotesFrom}}</nowiki></code>
 
Outputs
 
{{#invoke:Dictionary|translate|TranscludedNotesFrom}}
 
With embedment:
<pre>{{#invoke:Dictionary|translate_embed
|1=TranscludedNotesFrom
|2=https://en.wikipedia.org/wiki/Help:Transclusion
|3=[[Source_Page/notes]]
|4=https://deadlocked.wiki/index.php?title=Source_Page/notes&action=edit
}}</pre>
 
Outputs
 
{{#invoke:Dictionary|translate_embed
|1=TranscludedNotesFrom
|2=https://en.wikipedia.org/wiki/Help:Transclusion
|3=[[Source_Page/notes]]
|4=https://deadlocked.wiki/index.php?title=Source_Page/notes&action=edit
}}
 
===Notes===
* The parameters do not need to be prefixed with "1=", "2=", etc., they are used in the above example because the 4th parameter contains an equal sign (<code>=</code>) in it, where it would be read as a named parameter rather than a ordinal parameter.
* Ensure the number of passed variables (other than the key) matches the number of %s used in the translated string.

Latest revision as of 21:03, 6 June 2026

Overview

[edit source]

See {{Translate}} for how/when to use and more documentation.

p.translate

[edit source]

Translates a given key from Data:Dictionary. Manual invocation should only be used when additional parameters are required, such as {{Update layout}}, where the DISPLAYTITLE is generated using a translation key with expected parameters.

For normal usage, use the basic template.

Function parameters

[edit source]
  • key – translation key (required).
  • Language-specific:
    • lang_code_override (optional, named parameter) – language code overriding the automatic detection. See Data:LangCodes.json.
    • fallback_str (optional, named parameter) – value returned only if translation is missing. If set to empty string or nil, fallback will be empty (useful for detecting missing translations).

Examples

[edit source]

{{#invoke:Dictionary|translate|Update history}} Output: Update history

{{#invoke:Dictionary|translate|Updates|lang_code_override=pt-br}} Output: Atualizações

{{#invoke:Dictionary|translate|Update history|fallback_str=Custom fallback text.}} Output: Custom fallback text.[nt]