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
263
+
returnViewComponent();
264
+
}
265
+
}
266
+
```
267
+
268
+
##Creating a Language Switching Navigation
269
+
270
+
To navigate between languages, we need to do two key things:
271
+
272
+
1. Get all the languages that the site can provide
273
+
2. Identify the language used on the current page
274
+
275
+
Once we have these, we need to loop through the languages, and provide links to each home node.
276
+
277
+
#Getting all the languages for a site
278
+
279
+
There are two ways to achive this. One is to use ```localizationService.GetAllLanguages();``` to call the database, which is expensive and ideally includes caching.
280
+
281
+
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 providing us with a link to show the user. It is the process we will use.
282
+
283
+
#Identify the language for the current page
284
+
285
+
This is achived in ```cs.html``` files using ```umbracoHelper.AssignedContentItem.GetCultureFromDomains();```
286
+
287
+
#Steps
288
+
289
+
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.
328
+
329
+
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.
330
+
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.
@@ -312,7 +312,9 @@ Once we have these, we need to loop through the languages, and provide links to
312
312
313
313
#Getting all the languages for a site
314
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.
315
+
There are three ways to achive this. The best one is to use ```languageService.GetAllAsync();``` which retrives items from the cache.
316
+
317
+
Another is to use ```localizationService.GetAllLanguages();``` to call the database, which is expensive and ideally includes caching. This should only be done if you cannot use the ILanguage service. This service is marked as obsolete.
316
318
317
319
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 providing us with a link to show the user. It is the process we will use.
0 commit comments