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
298
+
returnViewComponent();
299
+
}
300
+
}
301
+
```
302
+
303
+
### Creating a Language Switching Navigation
304
+
305
+
To navigate between languages, you need to do two key things:
306
+
307
+
1. Get all the languages that the site can provide
308
+
2. Identify the language used on the current page
309
+
310
+
Once you have these, you need to loop through the languages and provide links to each home node.
311
+
312
+
### Getting all the languages for a site
313
+
314
+
There are three ways to achieve this. The best one is to use `languageService.GetAllAsync();` which retrieves items from the cache.
315
+
316
+
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.
317
+
318
+
The alternative is to get the Home node and find all of the cultures associated with it. This has a few benefits including speed and providing us with a link to show the user. It is the process you will use when following this guide.
319
+
320
+
### Identify the language for the current page
321
+
322
+
This is achieved in `cs.html` files using `umbracoHelper.AssignedContentItem.GetCultureFromDomains();`
323
+
324
+
#### Steps
325
+
326
+
Now that you have what you need, take the following steps to create a working example.
3. Replace `{{homeNodeContentAlias}}` with the Document Type alias of your Home node.
364
+
365
+
This will render links to either the language variant of the current page or the home node for the language variant.
366
+
367
+
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.
0 commit comments