(обновление данных) |
м (Защитил страницу Шаблон:Localization/register: критический шаблон/модуль ([Редактирование=Разрешено только администраторам] (бессрочно) [Переименование=Разрешено только администраторам] (бессрочно))) |
||
(не показаны 4 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
<includeonly><!-- |
<includeonly><!-- |
||
+ | -->{{#dplvar:set<!-- |
||
− | trim: |
||
− | --> |
+ | -->|l10n:reg:namespace|{{{1|}}}<!-- |
+ | -->|l10n:reg:lang|{{{2|en}}}<!-- |
||
− | each namespace+lang register only once: |
||
+ | -->}}<!-- |
||
− | -->{{#if:{{#dplvar:{{#var:l10n:reg:_p}}:1}}||<!-- if not flag |
||
+ | |||
+ | ========================================================================================= |
||
+ | If autoloading was triggered, we only load the information for the language that {{l10n|}} currently needs, from the /l10n subtemplate. The registrations of the other languages in the /l10n subtemplate will be skipped, and instead only an "exists" flag for their language will be set. When {{l10n|}} needs another language's information, it will already know if that language exists in the /l10n subtemplate (thanks to the "exists" flag), and will only load the /l10n subtemplate again if that language does exist there. |
||
+ | |||
+ | Example (assuming autoload was triggered): |
||
+ | (Template:Test/l10n contains l10n registrations for en, fr, and de) |
||
+ | We call {{l10n|test|foo|en}}, so the /l10n subtemplate (Template:Test/l10n) will be loaded. Only {{l10n/register|test|en|foo=...}} will be registered; {{l10n/register|test|fr|foo=...}} and {{l10n/register|test|de|foo=...}} will be ignored (though both will be set to "exists"). |
||
+ | Now we call {{l10n|test|foo|fr}} sometime later, and {{l10n|}} realizes that there is no relevant l10n information available about fr. Hence it checks the "exists" for fr and sees that there is a registration for fr in the /l10n subtemplate. Consequently, it will load the /l10n subtemplate again, now with the intention to register {{l10n/register|test|fr|foo=...}} (so the de registration will be ignored again). |
||
+ | Lastly, we call {{l10n|test|foo|zh}}, and {{l10n|}} again realizes it has no l10n information for zh. It finds that the "exists" flag for zh is not set, however, so it concludes there is no {{l10n/register|test|zh|foo=...}} in the /l10n subtemplate, and will not load it again. ({{l10n|}} will then fallback to using the en information.) |
||
+ | |||
+ | Thanks to this method, we can avoid processing numerous {{l10n/register}} calls for languages that are never used on a page, thus save a lot of runtime resources. |
||
+ | ========================================================================================= |
||
+ | |||
+ | {{#var:l10n:autoloading}} is the important link to {{l10n|}}, the langcode it currently wants to autoload. If it is empty, this registration is transcluded manually (not on an /l10n subtemplate). |
||
+ | |||
+ | // autoloaded flag: this namespace has been autoloaded. |
||
+ | -->{{#dplvar:set|l10n:autoloaded:{{#dplvar:l10n:reg:namespace}}|{{#var:l10n:autoloading}}}}<!-- |
||
+ | |||
+ | // skip this registration? |
||
+ | -->{{#if:{{#switch:{{#dplvar:l10n:reg:lang}}|{{#var:l10n:autoloading}}|en=y|#default={{#if:{{#var:l10n:autoloading}}||y}}}}|<!-- |
||
+ | don't skip if: (checks performed in this order) |
||
+ | * the language of this registration matches the language {{l10n|}} currently wants to autoload, or |
||
+ | * the language of this registration is en (en should always be available for fallback), or |
||
+ | * we are not autoloading (i.e. this {{l10n/register}} is not on an /l10n subtemplate). |
||
+ | // actual registration: |
||
-->{{#forargs:|l10n:reg:_key|l10n:reg:_value|<!-- |
-->{{#forargs:|l10n:reg:_key|l10n:reg:_value|<!-- |
||
− | -->{{#dplvar:set|{{# |
+ | -->{{#dplvar:set|l10n:{{#dplvar:l10n:reg:namespace}}:{{#dplvar:l10n:reg:lang}}:{{#var:l10n:reg:_key}}|{{#var:l10n:reg:_value}}}}<!-- |
-->}}<!-- |
-->}}<!-- |
||
+ | -->|<!-- |
||
+ | skip if: |
||
+ | * we are autoloading, and |
||
+ | * the language of this registration is not en, and |
||
+ | * the language of this registration does not match the language {{l10n|}} currently wants to autoload. |
||
+ | // only set the "exists" flag |
||
+ | -->{{#dplvar:set|l10n:{{#dplvar:l10n:reg:namespace}}:{{#dplvar:l10n:reg:lang}}:2|y}}<!-- |
||
-->}}<!-- |
-->}}<!-- |
||
+ | |||
+ | Results now (assuming we are autoloading): |
||
+ | * {{#dplvar:l10n:<namespace>:<lang>:1}} will now be non-empty if the l10n info for this language has been loaded and is readily available in full. |
||
+ | * {{#dplvar:l10n:autoloaded:<namespace>}} will always be non-empty now – the /l10n subtemplate for this namespace has been loaded at least once now. |
||
+ | * {{#dplvar:l10n:<namespace>:<lang>:2}} will now be non-empty if there is an l10n registration in the /l10n subtemplate for this lang, but the l10n info has not been loaded. |
||
+ | |||
+ | This information is used by {{l10n|}}. |
||
+ | |||
--></includeonly><noinclude>{{doc}}</noinclude> |
--></includeonly><noinclude>{{doc}}</noinclude> |
Текущая версия от 04:49, 8 сентября 2020
Документация
[обновить]
См. также этот шаблон на английском языке: Template:Localization/register. В нём может содержаться более полная или подробная информация.
Документация для этого шаблона отсутствует. Создайте её.