SOLVED

Programmatically receive the title of the list in the language of the browser in the SPFx

%3CLINGO-SUB%20id%3D%22lingo-sub-2779154%22%20slang%3D%22en-US%22%3EProgrammatically%20receive%20the%20title%20of%20the%20list%20in%20the%20language%20of%20the%20browser%20in%20the%20SPFx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2779154%22%20slang%3D%22en-US%22%3E%3CP%3EDear%20Ladies%20and%20Gentlemen%2C%3C%2FP%3E%3CP%3EI%20would%20like%20to%20programmatically%20receive%20the%20title%20of%20the%20list%20in%20the%20language%20of%20the%20browser%20in%20the%20SPFx.%3C%2FP%3E%3CP%3EI%20have%20the%20source%20language%20of%20the%20site%20collection%20in%20SharePoint%20Online%20%22English%22.%3C%2FP%3E%3CP%3EI've%20made%20a%20list.%3C%2FP%3E%3CP%3EThen%20I%20set%20the%20language%20to%20%22German%22%20and%20renamed%20the%20list.%3C%2FP%3E%3CP%3EWith%20the%20following%20method%20I%20get%20the%20object%20of%20the%20list%20in%20the%20variable%20%22list%22.%3C%2FP%3E%3CP%3EThe%20%22listTitle%22%20parameter%20is%20set%20with%20the%20title%20of%20the%20list%20in%20the%20source%20language%20%22English%22.%3C%2FP%3E%3CP%3EHow%20can%20I%20get%20the%20title%20of%20the%20list%20in%20German%20from%20the%20%22list%22%20object%3F%3C%2FP%3E%3CP%3EThe%20property%20%22list.Title%22%20contains%20the%20title%20of%20the%20list%20in%20the%20source%20language%20and%20not%20in%20the%20current%20language%20of%20the%20browser.%20(In%20the%20server%20object%20model%2C%20the%20%22list.Title%22%20property%20always%20contains%20the%20title%20of%20the%20list%20in%20the%20current%20display%20language.)%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Epublic%20GetListTitleBrowserLanguage(listTitle%3A%20string)%3A%20Promise%3CSTRING%3E%20%7B%3C%2FSTRING%3E%3C%2FP%3E%3CP%3Econsole.log(%22listTitle%3A%22)%3B%3CBR%20%2F%3Econsole.log(listTitle)%3B%3C%2FP%3E%3CP%3Ereturn%20new%20Promise%3CSTRING%3E(async(resolve%2C%20reject)%20%3D%26gt%3B%20%7B%3C%2FSTRING%3E%3C%2FP%3E%3CP%3Eawait%20sp.web.lists.getByTitle(listTitle).get().then((list%3A%20any)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(list)%20%7B%3C%2FP%3E%3CP%3Econsole.log(%22list%3A%22)%3B%3CBR%20%2F%3Econsole.log(list)%3B%3CBR%20%2F%3E%3CBR%20%2F%3Elet%20listTitleBrowserLanguage%20%3D%20list.Title%3B%3C%2FP%3E%3CP%3Eif%20(listTitleBrowserLanguage)%20%7B%3C%2FP%3E%3CP%3Eresolve(listTitleBrowserLanguage)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D).catch(()%20%3D%26gt%3B%20%7B%3C%2FP%3E%3CP%3Ereject(%22Error%20occured%20in%20method%20GetListTitleBrowserLanguage.%22)%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20help.%3C%2FP%3E%3CP%3EWith%20best%20regards%3CBR%20%2F%3ELadislav%20Stupak%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2781341%22%20slang%3D%22en-US%22%3ERe%3A%20Programmatically%20receive%20the%20title%20of%20the%20list%20in%20the%20language%20of%20the%20browser%20in%20the%20SPFx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2781341%22%20slang%3D%22en-US%22%3EToday%20I%20have%20changed%20the%20titles%20of%20the%20fields%20in%20this%20list%20in%20German%20language.%3CBR%20%2F%3EAfter%20that%20also%20the%20title%20of%20the%20list%20changed%20in%20the%20property%20%22list.Title%22%20to%20the%20list%20title%20in%20German%20language%2C%20when%20I%20have%20selected%20the%20German%20language%20for%20my%20user%20account.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2786418%22%20slang%3D%22en-US%22%3ERe%3A%20Programmatically%20receive%20the%20title%20of%20the%20list%20in%20the%20language%20of%20the%20browser%20in%20the%20SPFx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2786418%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F824507%22%20target%3D%22_blank%22%3E%40LadislavStupak%3C%2FA%3E%26nbsp%3B%26nbsp%3BIt's%20better%20to%20retrieve%20the%20list%20by%20its%20GUID.%26nbsp%3B%20After%20you%20look%20it%20up%20you%20can%20use%20calls%20like%3CBR%20%2F%3E_api%2Fweb%2Flists('%3CLIST%20guid%3D%22%22%3E')%3CBR%20%2F%3E%3CBR%20%2F%3EOtherwise%2C%20if%20you%20use%26nbsp%3B%2F_api%2Fweb%2Flists%2Fgetbytitle('%3CLIST%20title%3D%22%22%3E')%20the%20list%20title%20depends%20on%20the%20current%20language%20of%20the%20user%20that%20is%20executing%20the%20code.%26nbsp%3B%20That%20can%20depend%20on%20the%20user's%20profile%2C%20or%20if%20the%20profile%20is%20blank%20it%20depends%20on%20the%20user's%20browser%20language%20setting.%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20CSOM%20you%20can%20often%20retrieve%20the%20title%20in%20another%20language%20by%20using%26nbsp%3B%3CBR%20%2F%3Esplist.TitleResource.GetValueForUICulture(culture)%3B%3CBR%20%2F%3E%3CBR%20%2F%3EThere%20is%20no%20complete%20solution%20yet%2C%20any%20time%20that%20you%20use%20the%20list%20title%2C%20you%20are%20taking%20a%20risk%20that%20it%20will%20only%20work%20in%20one%20language%3C%2FLIST%3E%3C%2FLIST%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fblog.icefire.ca%2Fblogs%2Fpost%2Fhow-to-make-sharepoint-api-calls-language-independent%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EMore%20details%20here%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Dear Ladies and Gentlemen,

I would like to programmatically receive the title of the list in the language of the browser in the SPFx.

I have the source language of the site collection in SharePoint Online "English".

I've made a list.

Then I set the language to "German" and renamed the list.

With the following method I get the object of the list in the variable "list".

The "listTitle" parameter is set with the title of the list in the source language "English".

How can I get the title of the list in German from the "list" object?

The property "list.Title" contains the title of the list in the source language and not in the current language of the browser. (In the server object model, the "list.Title" property always contains the title of the list in the current display language.)


public GetListTitleBrowserLanguage(listTitle: string): Promise<string> {

console.log("listTitle:");
console.log(listTitle);

return new Promise<string>(async(resolve, reject) => {

await sp.web.lists.getByTitle(listTitle).get().then((list: any) => {

if (list) {

console.log("list:");
console.log(list);

let listTitleBrowserLanguage = list.Title;

if (listTitleBrowserLanguage) {

resolve(listTitleBrowserLanguage);
}
}
}).catch(() => {

reject("Error occured in method GetListTitleBrowserLanguage.");
});
});
}

Thank you for your help.

With best regards
Ladislav Stupak

5 Replies
Today I have changed the titles of the fields in this list in German language.
After that also the title of the list changed in the property "list.Title" to the list title in German language, when I have selected the German language for my user account.

@LadislavStupak  It's better to retrieve the list by its GUID.  After you look it up you can use calls like
_api/web/lists('<list GUID>')

Otherwise, if you use /_api/web/lists/getbytitle('<list title>') the list title depends on the current language of the user that is executing the code.  That can depend on the user's profile, or if the profile is blank it depends on the user's browser language setting.

In CSOM you can often retrieve the title in another language by using 
splist.TitleResource.GetValueForUICulture(culture);

There is no complete solution yet, any time that you use the list title, you are taking a risk that it will only work in one language

 

More details here

@Martin Laplante  thank you for your message.

 

You are right about to better work with the ID of the list than with the title.

I have changed the language of my Office 365 account from English to German.

Then I have changed the title of the list.

Then I have changed the language of my Office 365 account back to Englisch.

The title of the list has been changed also in the Englisch language to the title like I have set in the German language.

But the Link in the vertical navigation remained in the English language.

So the behavior of changing the language of a list in SharePoint Online is different than in SharePoint On Premise.

I would say it is a bug.

@LadislavStupak I think the difference that you saw has to do with the order in which the steps were carried out, not a difference between on premise and online.  Both the list name and the Navigation node support MUI, but they are separate objects, updating one does not update the other.  If you add a list to the navigation then provide a German translation of the list name, that German translation is not automatically applied to the navigation entry.  You have to edit the navigation entry as well while your language is German.

best response confirmed by LadislavStupak (Contributor)
Solution

@Martin Laplante thank you for your answer.

I can change the list title in the navigation so, that I remove the navigation and set it back again.

But the list title changes in both languages after the change of the list title in one language.

So I can not set a different list title for a list just through changing the language and changing the list title.

Through this action I change the list title in all languages.

This is different behavior to SharePoint On Premise.

And in my point of view it is a bug.