Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Kristoffer Lindén
Dec 30, 2021
  1924
(0 votes)

Handle translations in ViewConfiguration for CMS 12

In CMS 11 I had a view configuration that looked like this:

[ServiceConfiguration(typeof(ViewConfiguration))]
public class SendToTranslationView : ViewConfiguration<IContentData>
{
    public SendToTranslationView()
    {
        var localization = ServiceLocator.Current.GetInstance<LocalizationService>();
        Key = "SendToTranslationView";
        Name = localization.GetString("/Translations/ContentView/Name");
        Description = localization.GetString("/Translations/ContentView/Description");
        ControllerType = "epi-cms/widget/IFrameController";
        ViewType = "/MyPlugin/ContentTranslationHistory/Index";
        IconClass = "epi-iconCatalog epi-icon--medium";
    }
}

And after upgrading to CMS 12, the menu option no longer was translated even though the Thread.CurrentThread.CurrentUICulture was updated when changing the users UI language.
For some reason Name and Descrption no longer works in CMS 12 so the solution is to use LanguagePath instead.

This is how it should look:

[ServiceConfiguration(typeof(ViewConfiguration))]
public class SendToTranslationView : ViewConfiguration<IContentData>
{
    public SendToTranslationView()
    {
        Key = "SendToTranslationView";
        ControllerType = "epi-cms/widget/IFrameController";
        ViewType = "/MyPlugin/ContentTranslationHistory/Index"; 
        IconClass = "epi-iconCatalog epi-icon--medium";
        LanguagePath = "/Translations/ContentView";
    }
}

To get your menu option translated to English your language file then needs to contain:

<language name="English" id="en">
  <Translations>
    <ContentView>
      <Name>Translate content</Name>
      <Description>Choose what properties you want to translate and then mark your content</Description>
    </ContentView>
  </Translations>
</language>

So from now on, use LanguagePath instead of Name and Description in you ViewConfigurations

Dec 30, 2021

Comments

Please login to comment.
Latest blogs
How to Reset or Complete a Stuck Optimizely DXP Integration Deployment using the Optimizely Deployment API

If you’ve deployed to Optimizely’s Integration environment without specifying the DirectDeploy parameter in your PowerShell command, your deploymen...

Johnny Mullaney | Mar 31, 2025 |

Transitioning to Application Insights Connection Strings: Essential Insights for Optimizely CMS

Transitioning to Application Insights Connection Strings: Essential Insights for Optimizely CMS As part of Microsoft's ongoing modernization effort...

Stefan Johansson | Mar 27, 2025

Save The Date - London 2025 Summer Meetup

Following last years very succesful meetup in London July 2024 https://world.optimizely.com/blogs/scott-reed/dates/2024/7/optimizely-london-dev-mee...

Scott Reed | Mar 25, 2025

Revalidate Page in Next.js after Publishing Content in Headless Optimizely PaaS CMS.

Headless CMS implementations are becoming increasingly popular. In this approach, the CMS and the front-end application are decoupled and can use...

Tomek Juranek | Mar 25, 2025

Getting 404 when expecting 401

A short story about the mysterious behavior of an API in headless architecture.

Damian Smutek | Mar 25, 2025 |

A Free Course for Building Headless Applications with Next.js and Optimizely SaaS CMS

I am excited to announce the transformation of Optimizely Headless CMS webinar into a comprehensive, completely free self-paced course that's...

Szymon Uryga | Mar 24, 2025