Module talk:Template translation

Fallback

edit

This module is getting more and more important and useful for the translation of the template through {{Translatable template}} or my experiment of auto-translatable templates. Thanks Verdy p for your modifications in adding a proper fallback to English when there is no translation (and checking if the /en subpage really exists since it is not always the case).

This can still go a step forward: since gerrit:101910 Lua has access to mw.language.getFallbacksFor(code), so this can be used to properly degrade the translation given the translated pages. A minor point to be warned is the last language in the fallback sequence is always 'en' since this fallback sequence is constructed for the translation of MediaWiki messages; on a wiki the last language of the fallback sequence must be the site-wide content language (yes, on multilingual Wikimedia wikis, the default language is always English, in for the sake of generality it cannot be assumed it is always that).

When such a function will be added, I guess it can replace {{Fallback}}, and particularly the Commons version, much more developed and used.

Additionnally, the internal fallback sequences of MediaWiki and the fallback sequences of commons:Template:Fallback should be compared and reconciliated, probably by opening bugs for MediaWiki and discuss about the better fallback sequences for each languages.

~ Seb35 [^_^] 17:46, 17 January 2014 (UTC)Reply

I wrote a such a thing on a test wiki, mainly by splitting this.renderTranslatedTemplate into smaller private functions:
  • getTranslatablePage (which guesses the translatable "main" page depending of the arguments supplied to the module call; corresponds to the first third of renderTranslatedTemplate)); and
  • getTranslationFor (which constructs the fallback languages sequence and test if a translation exists for each one until one exists; corresponds to the second third of renderTranslatedTemplate).
I polish a bit my code before submitting it to avoid too much refreshing of pages on Meta.
~ Seb35 [^_^] 09:26, 18 January 2014 (UTC)Reply
It’s on Module:Template translation/sandbox2 for now. ~ Seb35 [^_^] 16:56, 18 January 2014 (UTC)Reply

Uses in the "Category" namespace

edit

See Template_talk:Translatable_template#Template is not worked at the "Category:" namespace. --Kaganer (talk) 15:51, 18 January 2014 (UTC)Reply

Upgrade getLanguage functions to use PAGELANGUAGE magic word

edit

Please replace

function this.getLanguage()
    local subpage = mw.title.getCurrentTitle().subpageText
    return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode())
end

--[[Get the language of the current frame. Not used locally.
--]]
function this.getFrameLanguage(frame)
    local titleparts = mw.text.split(frame:getParent():getTitle(), '/')
    local subpage = titleparts[#titleparts]
    return this.checkLanguage(subpage, mw.language.getContentLanguage():getCode())
end

with

function this.getLanguage()
	return this.getFrameLanguage( mw.getCurrentFrame() )
end

--[[Get the language of the given frame.
--]]
function this.getFrameLanguage(frame)
	return frame:preprocess("{{PAGELANGUAGE}}")
end

Because these both functions were added in 2014 whereas {{PAGELANGUAGE}} has been added in 2017. This magic word is stronger than subpage name parsing because it works with pages which are not written in English (and which are not translations made with Translate extension). -- Pols12 (talk) 22:26, 30 January 2022 (UTC)Reply

@Pols12: I've raised this on RFH. —MarcoAurelio (talk) 11:03, 11 April 2022 (UTC)Reply
Thank you MarcoAurelio, I just have updated the LuaDoc comment which wasn’t really exact. --Pols12 (talk) 12:17, 11 April 2022 (UTC)Reply

┌──────┘
If there is any chance of this edit request being noticed by (future) admins, I would like to add that this change is completely fine as far as I'm concern. NguoiDungKhongDinhDanh 14:35, 25 May 2022 (UTC)Reply

I think we're all hesitant about breaking anything on this module :) Pings to @Verdy p and Guillom: - do you have any comments on this? If there is no other response to this in a few days I'll push it forward. — xaosflux Talk 14:53, 13 June 2022 (UTC)Reply
This is OK as long as the page language is now properly set in the meta-data of each page (unfortunately, this interface is frequently blocked and not easily accessible; many page have been made also when this UI feature (now in the sidebar) diod not even exist, so these pages are still marked by default as having the site's default language name.
Before this change can be made, a survey of existing pages should be made to fix the metadata of these pages when they do not match their "/code" suffix (and when this suffix matches a supported language code). Note also that there are also some pages using language codes that are technically correct, but still not supported by the magic keyword. For such cases, there's a helper template that can fix missing names, and which should then default to the magic keyword otherwise; that list is quite long and their support in Mediawiki lags a lot behind, or just uses some weakly defined names coming from CLDR, which were actually not fully vetted but provided "provisionally", waiting for a future CLDR vetting period; CLDR survey and vetting occurs only once or twice a year, in a very short period, and many additions cannot be fully vetted in that short time, so many are left to be fully vetted for later; remember that there are tons of language names, and the CLDR survey is still unable to manage so many translations, including for all variants that wikiemdia already documents and use; frequently Wikimedia has MORE data existing than CLDR, and it is used as a default provisional source for CLDR in many cases where researches about these languages is still not enough complete! As well many names may have been made by a couple of major CLDR vetters, Apple and Google, based mostly on their existing search engine and their own commerical interests and this is problematic for many minority languages; other interesting sources provide alternate names, notably the LinguistList and Glottolog; and sometimes there are errors caused by incorrect early classification or confusion with one of their dialects or because a dialect name is sometimes a different language; so CLDR language names must be considered with care;, notably provional ones, and they are still not complete enough, not even for their autonym or names in English, which can also just use the autonym instead of the actual names with their attested English orthography).
So as long as you do not want to use the magic keyword only but use the support helper tempalte, and as long as you check the pages' metadata, and you check the validity of language codes detected, such change may be fine. verdy_p (talk) 16:43, 13 June 2022 (UTC).Reply
@Pols12 ^----- — xaosflux Talk 17:28, 13 June 2022 (UTC)Reply
I found an example: User:Tangotango/Whatredirectshere/sv. {{PAGELANGUAGE}} gives en (expand) while {{TNT|User groups}} gives the Swedish version of the template (expand). NguoiDungKhongDinhDanh 17:30, 13 June 2022 (UTC)Reply
According to this timed-out unprecise query we have at least 300 of such pages. NguoiDungKhongDinhDanh 17:37, 13 June 2022 (UTC)Reply
@NguoiDungKhongDinhDanh that page isn't a translated page (it is not in 'sv', it is a normal default language page) - so the pagelanguage should be 'en' (the metawiki project default). What am I missing? — xaosflux Talk 15:24, 13 January 2023 (UTC)Reply
@Xaosflux: Exactly, it is not a translated page and therefore the English version of the template should be displayed. However, since {{TNT}} saw the sv suffix, it outputs the Swedish version instead. (I hardly remember the reason led to my half-a-year-old comment above, so this might not be what I was trying to say back then.) NguoiDungKhongDinhDanh 10:36, 14 January 2023 (UTC)Reply

I’m closing the edit request for now, since we can improve Meta-Wiki content before, in order to make this change consensual. We need a bot to list all pages with inconsistent page language and langcode subpage suffix; then we will need help from translators to review those pages; finally we’ll need to fix all concerned pages (a bot should be able to proceed). If a bot owner is able to provide some support, they would be much welcome. 🙂 --Pols12 (talk) 16:11, 31 January 2023 (UTC)Reply

Same issue with getTranslatedTemplate() (called by {{TNTN}}): we need to use getLanguage() as fallback for args['uselang'] rather than getCurrentLanguageSubpage() which does not work when source language page is not in English. --Pols12 (talk) 17:24, 14 January 2024 (UTC)Reply

Return to "Template translation" page.