Having some problems with lookup() function when trying to build a multi-language supported App. I have a data source that has 3 columns, Title, English, and French. When I change the user language from French to English or vice versa I am seeing the desired results. See examples below.
The following code will return just "English" or "French", into the text label.
LookUp(
Table2,
Text(Dropdown1.Selected.Value) = Text(Column1),
varUserLanguage
)
Where this code, returns the proper message or title text from the datasource
LookUp(
Table2,
Text(Dropdown1.Selected.Value) = Text(Column1),
English
)
Yes, I have tried wrapping the varUSerLanguage in Text().
I am sure this is a super simple thing I am not seeing.
I would recommend 1 collection with a field to indicate the language. This allows you to reference a simple & short LookUp function (without If / Switch statements). Additionally, this approach is easily scalable with a third language by just adding records (no need to create an additional collection).
One thing to take into account is that using 1 collection expects the list length to not exceed your Data Row Limit (Max 2000 records). Otherwise you may need a workaround to create collections that exceed 2000 records.
I hope this helps!
Thanks for the notes, I did not realize lookup() did not support dynamic references.
As a follow-up question. Would you suggest I build two collections? One for each language? Or just build a single one that references a language field? Does it make a difference?
Cheers
Hi @Hack-7,
Dynamic column references are currently not supported within Power Apps. A workaround would be using a Switch statement:
With(
{
wRecord: LookUp(
Table2,
Dropdown1.Selected.Value = Column1
)
},
Switch(
varUserLanguage,
"English",
wRecord.English,
"French",
wRecord.French
)
)
This will make the code rather long. What I would recommend is using a record for each language instead of 1 record with 2 language columns:
Title | Language | Translation |
Title 1 | English | English value |
Title 1 | French | French value |
This will allow you to use the following approach instead:
LookUp(
Table2,
Dropdown1.Selected.Value = Column1 && varUserLanguage = Language,
Translation
)
Additionally, I would not recommend using direct table / list look-ups for translations. Each label would result in an API call and will have a noticable delay within the app (e.g. when navigating screens the text may not be visible yet). You could ClearCollect() all records in e.g. the OnStart to make sure they are accessible in memory and use the collection as your datasource - individual lookups will no longer result in API calls to your datasource.
If this solves your question, would you be so kind as to accept it as a solution.
Thanks!
WarrenBelz
146,645
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,997
Most Valuable Professional