You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Content requested in this View Component will now be in the requested culture
299
+
returnViewComponent();
300
+
}
301
+
}
302
+
```
303
+
304
+
##Creating a Language Switching Navigation
305
+
306
+
To navigate between languages, we need to do two key things:
307
+
308
+
1. Get all the languages that the site can provide
309
+
2. Identify the language used on the current page
310
+
311
+
Once we have these, we need to loop through the languages, and provide links to each home node.
312
+
313
+
#Getting all the languages for a site
314
+
315
+
There are two ways to achive this. One is to use ```localizationService.GetAllLanguages();``` to call the database, which is expensive and ideally includes caching.
316
+
317
+
The alternative is to get the Home node, and find all of the cultures associated to it. This has a few benifits including speed and easily providing us with a link to show the user. It is the process we will use.
318
+
319
+
#Identify the language for the current page
320
+
321
+
This is easily achived in ```cs.html``` files using ```umbracoHelper.AssignedContentItem.GetCultureFromDomains();```
322
+
323
+
#Steps
324
+
325
+
Now we have what we need, create a view called ```Navigation.cshtml``` , and paste in the following:
You will need to replace ```{{homeNodeContentAlias}}``` with the Document Type alias of your Home node.
364
+
365
+
This will look at all the cultures available on the home node, and render links to either the language variant of the current page, or the home node for the language variant. If the home node for a language variant is removed, it will not appear in the list.
366
+
Additionally, ```System.Globalization.CultureInfo``` is used to obtain the native name of the language being rendered. This is useful if a user does not speak the default language of the site.
0 commit comments