Jarekt added a comment.

I am testing new code in Module:Wikidata label/sandbox. The label selection code becomes

	userLang = mw.getCurrentFrame():callParserFunction( "int", "lang" )
	
	-- try easy way to get label (visible part of the link)
	-- call if requesting label in user's language, but skip if we already have entity
	if (userLang==lang) and (not entity) then
		label, language = mw.wikibase.getLabelWithLang( item )
	end

	-- hard way to get label
	-- used if requesting label in language different than user's, or if we already have entity
	if not label then
		entity = entity or mw.wikibase.getEntity(item) -- load entity if we do not have it yet
		for _, language in ipairs(langList) do -- loop over language fallback list
			label = entity:getLabel(language)
			if label then break end -- label found and we are done
		end
	end
	if not label then -- no labels found so just show the q-code
		label = item
	end

The language loop over getLabel() in the second block will be executed only in a rare cases when one of following things happen:

  1. someone called the template while specifying language other than user's language. For example see Template:City Examples where name of Beijing is displayed in English, Chinese and in Arabic. That should be a rare case mostly used for template testing
  2. We already fetched the whole entity for something else and there is no need for another call to get the label
  3. getLabelWithLang returned nul label

Would that fix the code in your view?

If getLabelWithLang was modified to take second language input parameter we could skip if (userLang==lang) test and let getLabelWithLang handle first case as well.

I assume that the second block is more efficient if we already have entity and are just parsing it, as oppose to fetching data again from wikidata. But if it does not make much of a difference, with second parameter to getLabelWithLang we could get rid of the second block and rely only on that function.


TASK DETAIL
https://phabricator.wikimedia.org/T173194

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Jarekt
Cc: Izno, daniel, Multichill, Aklapper, Ricordisamoa, JeanFred, Jarekt, ValterVB, Elitre, Jheald, Daniel_Mietchen, Nemo_bis, Aschroet, zhuyifei1999, Steinsplitter, Matanya, RP88, El_Grafo, Revent, Sjoerddebruin, Jane023, Susannaanas, Mike_Peel, Lydia_Pintscher, Micru, intracer, Poyekhali, Nizil, PokestarFan, hoo, E1presidente, Ramsey-WMF, Jmmuguerza, SandraF_WMF, GoranSMilovanovic, QZanden, Acer, Vali.matei, Volker_E, Wong128hk, Wikidata-bugs, PKM, Base, matthiasmullie, aude, GWicke, Fabrice_Florin, Raymond, Mbch331, Jay8g
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to