mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
#3753 Item label/description: Fall back to non-empty language - attempt to read labels by language or the first one in the list (#3759)
This commit is contained in:
parent
de3377c0fe
commit
384afa6c44
3 changed files with 7 additions and 4 deletions
|
|
@ -75,7 +75,7 @@ class DepictsClient @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEntities(ids: String): Single<Entities> {
|
fun getEntities(ids: String): Single<Entities> {
|
||||||
return depictsInterface.getEntities(ids, Locale.getDefault().language)
|
return depictsInterface.getEntities(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toDepictions(sparqlResponse: Observable<SparqlResponse>): Observable<List<DepictedItem>> {
|
fun toDepictions(sparqlResponse: Observable<SparqlResponse>): Observable<List<DepictedItem>> {
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,5 @@ public interface DepictsInterface {
|
||||||
Single<DepictSearchResponse> searchForDepicts(@Query("search") String query, @Query("limit") String limit, @Query("language") String language, @Query("uselang") String uselang, @Query("continue") String offset);
|
Single<DepictSearchResponse> searchForDepicts(@Query("search") String query, @Query("limit") String limit, @Query("language") String language, @Query("uselang") String uselang, @Query("continue") String offset);
|
||||||
|
|
||||||
@GET("/w/api.php?format=json&action=wbgetentities")
|
@GET("/w/api.php?format=json&action=wbgetentities")
|
||||||
Single<Entities> getEntities(@Query("ids")String ids, @Query("languages")String language);
|
Single<Entities> getEntities(@Query("ids") String ids);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import fr.free.nrw.commons.wikidata.WikidataProperties.*
|
||||||
import org.wikipedia.wikidata.DataValue
|
import org.wikipedia.wikidata.DataValue
|
||||||
import org.wikipedia.wikidata.Entities
|
import org.wikipedia.wikidata.Entities
|
||||||
import org.wikipedia.wikidata.Statement_partial
|
import org.wikipedia.wikidata.Statement_partial
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model class for Depicted Item in Upload and Explore
|
* Model class for Depicted Item in Upload and Explore
|
||||||
|
|
@ -25,8 +26,8 @@ data class DepictedItem constructor(
|
||||||
|
|
||||||
constructor(entity: Entities.Entity) : this(
|
constructor(entity: Entities.Entity) : this(
|
||||||
entity,
|
entity,
|
||||||
entity.labels().values.firstOrNull()?.value() ?: "",
|
entity.labels().byLanguageOrFirstOrEmpty(),
|
||||||
entity.descriptions().values.firstOrNull()?.value() ?: ""
|
entity.descriptions().byLanguageOrFirstOrEmpty()
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor(entity: Entities.Entity, place: Place) : this(
|
constructor(entity: Entities.Entity, place: Place) : this(
|
||||||
|
|
@ -73,3 +74,5 @@ private val List<Statement_partial>?.primaryImageValue: DataValue.ValueString?
|
||||||
operator fun Entities.Entity.get(property: WikidataProperties) =
|
operator fun Entities.Entity.get(property: WikidataProperties) =
|
||||||
statements?.get(property.propertyName)
|
statements?.get(property.propertyName)
|
||||||
|
|
||||||
|
private fun Map<String, Entities.Label>.byLanguageOrFirstOrEmpty() =
|
||||||
|
let { it[Locale.getDefault().language] ?: it.values.firstOrNull() }?.value() ?: ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue