Module:Dictionary/doc: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m Examples: example updated for embedment
New version.
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.
See [[Data:Dictionary/sources]] for list of where each translation is used. This may be particularly helpful for reading on the context of the phrase that needs translation.


=Functions=
== p.translate ==
==translate==
Translates a given key from [[Data:Dictionary]]. '''Manual invocation should only be used for special cases''', such as {{tl|Update link}}. For normal usage, use the basic template.
Translates a given key using [[Data:Dictionary]].


===Parameters===
=== Function parameters ===
*'''key''' - key to translate
* '''key''' – translation key (required).
*'''lang_code_override''' (OPTIONAL, Named parameter) - language code that overrides current language. See supported list at [[Data:LangCodes.json]].
* Language-specific:
*'''fallback_str''' (OPTIONAL, Named parameter) - string to return if '''key''' cannot be translated. Defaults to the english translation. Use a blank string or nil for easier catching of missed translations, where the needs translation tooltip will also not be added.
** '''lang_code_override''' (optional, named parameter) language code overriding the automatic detection. See [[Data:LangCodes.json]].
*'''show_needs_translation''' (OPTIONAL, Named parameter) - boolean that determines if the {{NeedsTranslationTooltip}} is appended when its unable to be translated. Defaults to 'true'
** '''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).


===Example===
=== Examples ===
Example where translation does exist<br>
<code><nowiki>{{#invoke:Dictionary|translate|Update history}}</nowiki></code> Output: {{#invoke:Dictionary|translate|Update history}}
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=en}}</nowiki></code>


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


{{#invoke:Dictionary|translate|Update history|lang_code_override=en}}
<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.}}
 
<includeonly>[[Category:Modules]]</includeonly><noinclude>[[Category:Module documentation]]</noinclude>
 
Example where translation does not yet exist<br>
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=es}}</nowiki></code>
 
Outputs
 
{{#invoke:Dictionary|translate|Update history|lang_code_override=es}}
 
 
Example where translation does not yet exist but displaying the tooltip is off<br>
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=es|show_needs_translation=false}}</nowiki></code>
 
Outputs
 
{{#invoke:Dictionary|translate|Update history|lang_code_override=es|show_needs_translation=false}}
 
Example where translation does not yet exist and the fallback is an empty string<br>
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=es|fallback_str=}}</nowiki></code>
 
Outputs
 
{{#invoke:Dictionary|translate|Update history|lang_code_override=es|fallback_str=}}
 
 
Example where translation does not yet exist and the fallback is another text<br>
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=es|fallback_str=My custom fallback text}}</nowiki></code>
 
Outputs
 
{{#invoke:Dictionary|translate|Update history|lang_code_override=es|fallback_str=My custom fallback text}}
 
==translate_embed==
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|NeedsTranslationTooltip}}</nowiki></code>
 
Outputs
 
{{#invoke:Dictionary|translate|NeedsTranslationTooltip}}
 
With embedment:
<pre>{{#invoke:Dictionary|translate_embed
|1=NeedsTranslationTooltip
|2=Template:Translate
}}</pre>
 
Outputs
 
{{#invoke:Dictionary|translate_embed
|1=NeedsTranslationTooltip
|2=Template:Translate
}}
 
===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.

Revision as of 02:57, 6 June 2026

Overview

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

p.translate

Translates a given key from Data:Dictionary. Manual invocation should only be used for special cases, such as {{Update link}}. For normal usage, use the basic template.

Function parameters

  • 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

{{#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]