Module:Lang/doc: Difference between revisionsGive feedback
Gammaton32 (talk | contribs) |
No edit summary |
||
| Line 6: | Line 6: | ||
Localizes a given string to the current language, i.e. [[Data:Lang_en.json]] for english. | Localizes a given string to the current language, i.e. [[Data:Lang_en.json]] for english. | ||
Note: If you need to get a string that uses a value referenced from another Data page, | Note: If you need to get a string that uses a value referenced from another Data page, pass the <code>item_name</code> parameter to <code>get_string</code>. | ||
===Parameters=== | ===Parameters=== | ||
| Line 27: | Line 27: | ||
{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff|lang_code_override=es}} | {{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff|lang_code_override=es}} | ||
==== Strings with Variables ==== | |||
For strings containing <code>{s:variable}</code>, provide the <code>item_name</code>: | |||
'''Example:''' | |||
<code><nowiki>{{#invoke:Lang|get_string|upgrade_target_stun_desc|item_name=Knockdown}}</nowiki></code> | |||
→ {{#invoke:Lang|get_string|upgrade_target_stun_desc|item_name=Knockdown}} | |||
Without <code>item_name</code>, variables won't be filled: | |||
<code><nowiki>{{#invoke:Lang|get_string|upgrade_target_stun_desc}}</nowiki></code> | |||
→ {{#invoke:Lang|get_string|upgrade_target_stun_desc}} | |||
Revision as of 20:38, 15 May 2025
Overview
overview
Functions
get_string
Localizes a given string to the current language, i.e. Data:Lang_en.json for english.
Note: If you need to get a string that uses a value referenced from another Data page, pass the item_name parameter to get_string.
Parameters
- key - Key string to localize
- lang_code_override (OPTIONAL) - Overrides the current language to a specific language code
- fallback_str (OPTIONAL) - Passing
encauses it to return the english localization if it can't be localized to the current language. Passing any other string causes it to return that string if it can't be localized. Both have Template:MissingValveTranslationTooltip appended. Use this very often as some keys are not yet localized in every language by the game. Passingdictionarycauses it to return the translation via Data:Dictionary if it can't be localized. If parsing the fallback_str from lua and is computationally expensive (i.e. add_space_before_cap), consider using fallback outside this function so it only computes when needed. - remove_var_index (OPTIONAL) - Removes %variables% from the resulting string. -1 also removes the character prefixing %variables%, while 1 removes the postfixed character, and 0 removes only the %variables%.
NOTE: Optional parameters are ideally named when not all parameters are provided, though named parameters can only be passed by invoke, and not internal lua calls.
Examples
Invokes from wikitext:
{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff}}
Falloff Range
{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff|lang_code_override=es}}
Distancia de caída
Strings with Variables
For strings containing {s:variable}, provide the item_name:
Example:
{{#invoke:Lang|get_string|upgrade_target_stun_desc|item_name=Knockdown}}
→ Apply a Stun after 2s. Stun duration is increased against airborne targets.
Increases the target's gravity for the duration of the stun.
Without item_name, variables won't be filled:
{{#invoke:Lang|get_string|upgrade_target_stun_desc}}
→ Apply a Stun after {s:StunDelay}s. Stun duration is increased against airborne targets.
Increases the target's gravity for the duration of the stun.
Examples for fallback_str
{{#invoke:Lang|get_string|StatDesc_CritDamageBonusScale|lang_code_override=es}}
Escala de críticos adicional
{{#invoke:Lang|get_string|StatDesc_CritDamageBonusScale|lang_code_override=es|fallback_str=en}}
Escala de críticos adicional
{{#invoke:Lang|get_string|StatDesc_CritDamageBonusScale|lang_code_override=es|fallback_str=Crit Damage Bonus Scale}}
Escala de críticos adicional
{{#invoke:Lang|get_string|Tech Items|fallback_str=dictionary}}
Key 'Tech Items' is not in Data:Dictionary
Examples for remove_var_index
{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild}}
Default %hero_name% Build
TODO: Debug why is =0 still removing that extra space? Doesn't matter yet I suppose, no use cases for 0 yet
{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild|remove_var_index=0}}
Default Build
{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild|remove_var_index=-1}}
Default Build
When calling by internal modules, the parameters cannot be named, and therefore have to be in order. Unused parameters before the last used parameter should be nil. Such as, .get_string('hero_atlas', nil, 'en')
search_string
Searches for the unlocalized key corresponding to a given english string, then localizes it to the current language. NOTE: Use sparingly, always use get_string instead where plausible, as it has time complexity O(1) compared to search_string's O(10,000).
Parameters
- string - English string to search for
Examples
From wikitext:
{{#invoke:Lang|search_string|Abrams}}
Abrams
get_lang_code
Output the language subpage of the current page
{{#invoke:Lang|get_lang_code}}
en