Sep 23 2021 09:25 AM
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
Sep 24 2021 02:34 AM
Sep 26 2021 09:06 AM
@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
Sep 28 2021 09:59 AM
@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.
Sep 28 2021 02:22 PM
@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.
Sep 29 2021 12:55 AM
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.
Nov 30 2022 12:57 AM
Sep 29 2021 12:55 AM
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.