0

I'm adding multilingual support to an existing webpart. Easy enough with the different locale string files and testing with the --locale pararmeter on gulp serve.

What I don't understand though is how the locale is picked up in production, I have a site, created in English. I have tried:

  • Adding a translation for Spanish and publishing the new page - still English
  • Changing my user account default language to Spanish - web part still shows in English.

I was hoping the webpart would display differently based on the user or the page translation, not the site language? Also, is it possible to change the locale of the webpart at runtime? Potentially with a webpart prop or reading the user's preferred language? I have tried settng the cultureInfo on the context to 'es-ES', pre-render (I know it's supposed to be read only!), which did nothing.

Any ideas? Thanks

1 Answer 1

0

The locale is typically defined by the language in the user's profile, as long as that language is one of the main or alternate languages of the site.

To change the user profile language, in your personal menu, click on My Profile, click on Update Profile under your name, scroll down to "How can I change language and regional settings?" and click on it, click on the word "here", click on the ellipsis (...) and then choose Language and Region, under Language/Language Preference/My Display Languages, pick a new language and make it the first, scroll to the bottom, and click "Save all and close", then wait about 10 to 15 minutes.

The account language is not the same thing as the profile language. Usually changing the account language changes the profile language, but not always.

If there is no language in your profile, then the browser's language setting is used instead. The page translation language plays no part in this, that language toggle is not a real language toggle, it's just a page redirection.

It is possible to change the locale of SPFx webparts and several other aspects of the page UI at runtime by adding "?forceLocale=es-ES" (case-sensitive) to the URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.