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 using the site default culture. 

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 using the CultureRegion class. 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. To do this, you create a new scope where you activate the required language or culture. Inside this scope, you assign the new values of the Lstring-backed properties using the syntax. Internally, Lstring ensures that the proper culture is persisted. The following sample demonstrates how to use a different culture:

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 culture to be the desired one. This way the Sitefinity CMS API that is responsible for URL generation will persist the Url property in the correct language. To avoid forgetting to set back the original culture once you are done saving your changes, simply use a using scope with CultureRegion class.

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?