Editing Module:Dictionary/docGive feedback
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
= Overview = | =Overview= | ||
See | See [[Template: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= | ||
Translates a given key | ==translate== | ||
Translates a given key using [[Data:Dictionary]]. | |||
===Parameters=== | |||
*'''key''' - key to translate | |||
*'''lang_code_override''' (OPTIONAL, Named parameter) - language code that overrides current language. See supported list at [[Data:LangCodes.json]]. | |||
*'''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. | |||
*'''show_needs_translation''' (OPTIONAL, Named parameter) - boolean that determines if the {{NeedsTranslationTooltip}} is appended when its unable to be translated. Defaults to 'true' | |||
=== | ===Example=== | ||
Example where translation does exist<br> | |||
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=en}}</nowiki></code> | |||
Outputs | |||
{{#invoke:Dictionary|translate|Update history|lang_code_override=en}} | |||
<code><nowiki>{{#invoke:Dictionary|translate|Update history|fallback_str= | |||
< | 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|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. | |||