Module:Dictionary/doc: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m now includes show_needs_translation and better examples
Sur (talk | contribs)
m →‎Examples: example updated for embedment
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Overview=
=Overview=
See [[Template:Translate]] for how/when to use and more documentation.
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=
=Functions=
Line 9: Line 10:
*'''key''' - key to translate
*'''key''' - key to translate
*'''lang_code_override''' (OPTIONAL, Named parameter) - language code that overrides current language. See supported list at [[Data:LangCodes.json]].
*'''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'
*'''show_needs_translation''' (OPTIONAL, Named parameter) - boolean that determines if the {{NeedsTranslationTooltip}} is appended when its unable to be translated. Defaults to 'true'


Line 29: Line 31:


Example where translation does not yet exist but displaying the tooltip is off<br>
Example where translation does not yet exist but displaying the tooltip is off<br>
<code><nowiki>{{#invoke:Dictionary|translate|Update history|show_needs_translation=false}}</nowiki></code>
<code><nowiki>{{#invoke:Dictionary|translate|Update history|lang_code_override=es|show_needs_translation=false}}</nowiki></code>


Outputs
Outputs


{{#invoke:Dictionary|translate|Update history|show_needs_translation=false}}
{{#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==
==translate_embed==
Line 46: Line 63:


===Examples===
===Examples===
Without embedment:
Without embedment:
<code><nowiki>{{#invoke:Dictionary|translate|TranscludedNotesFrom}}</nowiki></code>
<code><nowiki>{{#invoke:Dictionary|translate|NeedsTranslationTooltip}}</nowiki></code>


Outputs
Outputs


{{#invoke:Dictionary|translate|TranscludedNotesFrom}}
{{#invoke:Dictionary|translate|NeedsTranslationTooltip}}


With embedment:
With embedment:
<pre>{{#invoke:Dictionary|translate_embed
<pre>{{#invoke:Dictionary|translate_embed
|1=TranscludedNotesFrom
|1=NeedsTranslationTooltip
|2=https://en.wikipedia.org/wiki/Help:Transclusion
|2=Template:Translate
|3=[[Source_Page/notes]]
|4=https://deadlocked.wiki/index.php?title=Source_Page/notes&action=edit
}}</pre>
}}</pre>


Line 64: Line 80:


{{#invoke:Dictionary|translate_embed
{{#invoke:Dictionary|translate_embed
|1=TranscludedNotesFrom
|1=NeedsTranslationTooltip
|2=https://en.wikipedia.org/wiki/Help:Transclusion
|2=Template:Translate
|3=[[Source_Page/notes]]
|4=https://deadlocked.wiki/index.php?title=Source_Page/notes&action=edit
}}
}}


Line 73: Line 87:
* 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.
* 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.
* Ensure the number of passed variables (other than the key) matches the number of %s used in the translated string.
=Important translations=
<i>Note: these are not yet important, as most translations are only used for in-development pages right now.<br></i>
Page/subpage names that can't exist without translation and whose existence is relied on by other pages:
* '''Notes''' - for <code><nowiki>[[<ability_name>/Notes]]</nowiki></code> being transcluded to [[Abrams#Abilities]]
*
Other:
* '''NeedsTranslationTooltip''' - {{NeedsTranslationTooltip}} is displayed when something can't be localized, so the tooltip being localized is quite helpful for guiding potential translators
* '''MissingValveTranslationTooltip''' - {{MissingValveTranslationTooltip}} is displayed... same reason as above

Latest revision as of 01:21, 16 October 2024

Overview[edit source]

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[edit source]

translate[edit source]

Translates a given key using Data:Dictionary.

Parameters[edit source]

  • 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 [nt] is appended when its unable to be translated. Defaults to 'true'

Example[edit source]

Example where translation does exist
{{#invoke:Dictionary|translate|Update history|lang_code_override=en}}

Outputs

Update history


Example where translation does not yet exist
{{#invoke:Dictionary|translate|Update history|lang_code_override=es}}

Outputs

Update history[nt]


Example where translation does not yet exist but displaying the tooltip is off
{{#invoke:Dictionary|translate|Update history|lang_code_override=es|show_needs_translation=false}}

Outputs

Update history

Example where translation does not yet exist and the fallback is an empty string
{{#invoke:Dictionary|translate|Update history|lang_code_override=es|fallback_str=}}

Outputs



Example where translation does not yet exist and the fallback is another text
{{#invoke:Dictionary|translate|Update history|lang_code_override=es|fallback_str=My custom fallback text}}

Outputs

My custom fallback text[nt]

translate_embed[edit source]

Translates a given key then replaces %s in the string with extra parameters

Parameters[edit source]

  • 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 %s in the translated string.

Examples[edit source]

Without embedment: {{#invoke:Dictionary|translate|NeedsTranslationTooltip}}

Outputs

This needs translation to English. To help translate it, visit %s.

With embedment:

{{#invoke:Dictionary|translate_embed
|1=NeedsTranslationTooltip
|2=Template:Translate
}}

Outputs

This needs translation to English. To help translate it, visit Template:Translate.

Notes[edit source]

  • 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 (=) 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.