You can switch languages, but there is no content available in, for example, German or Japanese yet. Refresh the rendered site ( to see your changes. Add the following code in the view: (var culture in ( = the Views/_ViewImports.cshtml View, add the following line to enable the use of custom View Components from this project as Tag Helpers: *, MyProjectĪdd the language switcher to Views/Default/Index.cshtml (the default View) under the Sitecore logo: This view renders our language switcher using the model. Create a Razor View within the folder called Default.cshtml. Icons, Illustrations, Patterns, Textures. In the rendering project, create a new folder path for the component's view, Views/Shared/Components/LanguageSwitcher. Go ProFor DesignersPortfolio creation made easyFor FreelancersFresh leads in your inbox every dayFor TeamsBuild your team’s pipeline or profile. SupportedCultures = _(),ĬurrentUICulture = ,ĬurrentSitecoreRoute = ?.ToString() ? "" Var languageSwitcherModel = new LanguageSwitcherModel _localizationOptions = localizationOptions Public LanguageSwitcherViewComponent(IOptions localizationOptions) Private readonly IOptions _localizationOptions Public class LanguageSwitcherViewComponent : ViewComponent Add the following code in the class: using MyProject.Models ![]() This class populates the model based on the configured languages, current language, and the current route. Var supportedCultures = new List Ĭreate a new folder in the rendering project called ViewComponents, and create a new View Component class inside the folder. Text links are a great way to offer your website or app in other languages. If you add languages in Sitecore that this site/rendering host should support, then add them here. Language Switcher as part of the Main Navigation. In the ConfigureServices method, add the following localization configuration registration, which enables three languages, in this example, German, English, and Japanese, as well as the Sitecore URL-based culture resolution: // You need to configure localization options here so you can access them in your language switcher component Some changes are required in this class to make the ASP.NET Core RequestLocalizationOptions available to our language switcher through dependency injection. Note: This topic explains how to change the display language in the VS Code UI via Language Packs such as French or Chinese.
0 Comments
Leave a Reply. |