Module:Lang/doc: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
initial
 
Sur (talk | contribs)
m documentation updates for new combined get_string
Line 1: Line 1:
==Overview==
=Overview=
overview
overview


==Functions==
=Functions=
===get_string===
==get_string==
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.


====Parameters====
===Parameters===
* '''string''' - String to localize
* '''key''' - Key string to localize
* '''lang_code_override''' (OPTIONAL) - Overrides the current language to a specific language code
* '''fallback_str''' (OPTIONAL) - Passing <code>en</code> causes 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. Use this very often as some keys are not yet localized in every language by the game.
* '''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%.


====Examples====
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.
From wikitext:<br>


<pre>{{#invoke:Lang|get_string|hero_atlas}}</pre>
===Examples===
{{#invoke:Lang|get_string|hero_atlas}}
Invokes from wikitext:<br>


<code><nowiki>{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff}}</nowiki></code>


<pre>{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff}}</pre>
{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff}}
{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff}}


===search_string===
Searches for the unlocalized key corresponding to a given english string, then localizes it to the current language


====Parameters====
<code><nowiki>{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff|lang_code_override=es}}</nowiki></code>
 
{{#invoke:Lang|get_string|CitadelHeroStats_Weapon_Falloff|lang_code_override=es}}
 
 
===Examples for fallback_str===
<code><nowiki>{{#invoke:Lang|get_string|hero_atlas|lang_code_override=es}}</nowiki></code>
 
{{#invoke:Lang|get_string|hero_atlas|lang_code_override=es}}
 
 
<code><nowiki>{{#invoke:Lang|get_string|hero_atlas|lang_code_override=es|fallback_str=en}}</nowiki></code>
 
{{#invoke:Lang|get_string|hero_atlas|lang_code_override=es|fallback_str=en}}
 
===Examples for remove_var_index===
<code><nowiki>{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild}}</nowiki></code>
 
{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild}}
 
<i>TODO: Debug why is =0 still removing that extra space? Doesn't matter yet I suppose, no use cases for 0 yet</i>
<code><nowiki>{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild|remove_var_index=0}}</nowiki></code>
 
{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild|remove_var_index=0}}
 
 
<code><nowiki>{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild|remove_var_index=-1}}</nowiki></code>
 
{{#invoke:Lang|get_string|Citadel_HeroBuilds_DefaultHeroBuild|remove_var_index=-1}}
 
 
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 <code>nil</code>. Such as, <code>.get_string('hero_atlas', nil, 'en')</code>
 
==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
* '''string''' - English string to search for


====Examples====
===Examples===
From wikitext:<br>
From wikitext:<br>


<pre>{{#invoke:Lang|get_string|Abrams}}</pre>
<pre>{{#invoke:Lang|search_string|Abrams}}</pre>
{{#invoke:Lang|search_string|Abrams}}
{{#invoke:Lang|search_string|Abrams}}

Revision as of 03:54, 11 October 2024

Overview

overview

Functions

get_string

Localizes a given string to the current language, i.e. Data:Lang_en.json for english.

Parameters

  • key - Key string to localize
  • lang_code_override (OPTIONAL) - Overrides the current language to a specific language code
  • fallback_str (OPTIONAL) - Passing en causes 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. Use this very often as some keys are not yet localized in every language by the game.
  • 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


Examples for fallback_str

{{#invoke:Lang|get_string|hero_atlas|lang_code_override=es}}

Abrams


{{#invoke:Lang|get_string|hero_atlas|lang_code_override=es|fallback_str=en}}

Abrams

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