Localize taxonomies and taxa

To localize taxonomies or their taxa using the Sitefinity CMS you must set a desired value in the culture you want for the properties that are localizable. These properties are of type Lstring, which enables you to persist different value for different culture, and Sitefinity CMS will automatically resolve the correct value based on the current culture in the context where the taxonomy or taxa is used.

Create a taxonomy in a specified language

By default, when using the Sitefinity CMS API to create items, they are created in the current culture of the thread your request is executed in. If you are not running your code on a page where you are explicitly selecting a different language, the current culture of the thread is usually the default culture of your Sitefinity CMS website.

To create a taxonomy in a specific culture, you need to set the desired culture to be the current thread culture. Once you take care of that, you proceed by using the API to create the item. The following example demonstrates creating a taxonomy in a specified culture:

Add a translation of a taxon in a specified language

You can use the Sitefinity CMS API to add a translation to a taxon, that already exists. You must get the taxon and set the desired values for the taxon properties in the desired language. This is done via the SetString method  of the Lstring class, which enables you to pass a string value and a culture, for which that value should be persisted. The following sample demonstrates using the SetString method to add a translation to an existing taxon properties:

Notice that some of the taxon properties are not localizable, for example Name. When adding a translation to an existing taxon you can choose whether to skip setting values to the non-localizable properties, since this will override the value in all languages.

Additionally, when the Urls for localizable content are generated, you must take care of setting the CurrentThread culture to be the desired one. This way the Sitefinity CMS API that is responsible for URL generation will persist the Url in the correct language. Don't forget to set back the original culture once you are done saving your changes. Omitting this might affect any code that runs afterwards in the same thread.

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?