Line 46: |
Line 46: |
| args = normalize_input_args(frame:getParent().args, args) | | args = normalize_input_args(frame:getParent().args, args) |
| args = normalize_input_args(frame.args, args) | | args = normalize_input_args(frame.args, args) |
− |
| |
− | -- get language fallback list
| |
− | if not args.lang or not mw.language.isSupportedLanguage(args.lang) then
| |
− | args.lang = frame:callParserFunction( "int", "lang" ) -- get user's chosen language
| |
− | end
| |
− | local langList = mw.language.getFallbacksFor(args.lang)
| |
− | table.insert(langList,1,args.lang)
| |
| | | |
| -- find base page | | -- find base page |
Line 62: |
Line 55: |
| end | | end |
| | | |
− | -- find base template language subpage
| + | |
− | local page = args.default -- default page if provided or nil otherwise
| |
− | for _, language in ipairs(langList) do
| |
− | if mw.title.new(base .. '/' .. language).exists then
| |
− | page = base .. '/' .. language -- returns only the page
| |
− | break
| |
− | end
| |
− | end
| |
− | assert(page, string.format('No fallback page found for autotranslate (base=[[%s]], lang=%s)', base, args.lang))
| |
− |
| |
| -- Transclude {{page |....}} with template arguments the same as the ones passed to {{autotranslate}} template. | | -- Transclude {{page |....}} with template arguments the same as the ones passed to {{autotranslate}} template. |
| return frame:expandTemplate{ title = page, args = args} | | return frame:expandTemplate{ title = page, args = args} |