How to get content type translations in spfx webpart

Antti Mikkonen 96 Reputation points
2023-12-13T07:11:52.6133333+00:00

Hi!

We have created multiple SharePoint Online sites with Finnish default language. Also English and Swedish languages are enabled. We have imported content type translations for Swedish and English as an XML. Everything is working fine in the user interface.

We have a spfx webpart that needs translated names of the content types. Is there any way to get this information to be used in this webpart (CSOM/REST etc.)? Translation for specific content type should be able to be fetched by lcid, not based on the current user's language settings.

Any ideas is this even possible?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,229 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,603 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Martin Laplante 326 Reputation points
    2023-12-14T15:27:12.9233333+00:00

    Hi Antti,

    There are two ways to get this. One is to get the contentType object from the web or the list, then call get_nameResource().getValueForUICulture(lang). This get_nameResource method is not well documented. The value of "lang" is a string, for example "en-US" or "sv-SE".

    The other way is to put a fake "Accept-Language" http header in your API call, essentially fooling the API into thinking that your browser is configured for that language. This only works if the user doesn't have a preferred language in their profile, which overrides the browser language setting.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.