Skip to content

Commit 2886949

Browse files
Merge branch 'main' into v15/add-maximumpayload-bytes-settings
2 parents dcf8a9c + edba11d commit 2886949

File tree

12 files changed

+649
-193
lines changed

12 files changed

+649
-193
lines changed

10/umbraco-cms/tutorials/multilanguage-setup.md

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
---
2-
meta.Title: Multilanguage setup in Umbraco
3-
product: CMS
42
description: A guide to multilanguage setup in Umbraco
53
---
64

75
# Creating a Multilingual Site
86

9-
You can use **language variants** to setup a multilingual site. **Language Variants** allow you to have variants of the same content all under the same project. So, if you open a page and a language variant is enabled, you will see the option to switch the language from the drop-down list. Additionally, you can view or input the translated content.
7+
You can use **language variants** to set up a multilingual site. **Language Variants** allow you to have variants of the same content all under the same project. So, if you open a page and a language variant is enabled, you will see the option to switch the language from the drop-down list. Additionally, you can view or input the translated content.
108

11-
This tutorial explains how to set-up a basic multilingual website.
9+
This tutorial explains how to set up a basic multilingual website.
1210

1311
## Adding a New language
1412

@@ -226,3 +224,108 @@ For viewing purposes, I've added a stylesheet to my website. The final result sh
226224
**German Version:**
227225

228226
<figure><img src="images/final-result-da.png" alt=""><figcaption></figcaption></figure>
227+
228+
## Using Multiple languages across APIs
229+
230+
When requesting content over an API, the culture will fall back to the default, unless explicitly set.
231+
232+
To do this, you can use the IVariationContextAccessor.
233+
234+
```csharp
235+
public class ExampleController : SurfaceController
236+
{
237+
private readonly ILocalizationService _localizationService;
238+
private readonly IVariationContextAccessor _variationContextAccessor;
239+
240+
public ExampleController(IUmbracoContextAccessor umbracoContextAccessor, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider, ILocalizationService localizationService, IVariationContextAccessor variationContextAccessor) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
241+
{
242+
_localizationService = localizationService;
243+
_variationContextAccessor = variationContextAccessor;
244+
}
245+
246+
public IActionResult Index(string culture = null)
247+
{
248+
IEnumerable<ILanguage> UmbracoLanguages = _localizationService.GetAllLanguages(); //a helpful method to get all configured languages
249+
var requestedCulture = UmbracoLanguages.FirstOrDefault(l => l.IsoCode == culture);
250+
251+
if (requestedCulture != null)
252+
{
253+
_variationContextAccessor.VariationContext = new VariationContext(requestedCulture.IsoCode);
254+
}
255+
256+
//this will now be in the requested culture
257+
var content = UmbracoContext.Content.GetAtRoot();
258+
259+
//Content requested in this View Component will now be in the requested culture
260+
return ViewComponent();
261+
}
262+
}
263+
```
264+
265+
### Creating a Language Switching Navigation
266+
267+
To navigate between languages, we need to do two key things:
268+
269+
1. Get all the languages that the site can provide
270+
2. Identify the language used on the current page
271+
272+
Once you have these, you need to loop through the languages and provide links to each home node.
273+
274+
### Getting all the languages for a site
275+
276+
There are two ways to achieve this. One is to use `localizationService.GetAllLanguages();` to call the database, which is expensive and ideally includes caching.
277+
278+
The alternative is to get the Home node and find all 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.
279+
280+
### Identify the language for the current page
281+
282+
This is achieved in `cs.html` files using `umbracoHelper.AssignedContentItem.GetCultureFromDomains();`.
283+
284+
#### Steps
285+
286+
Now that you have what you need, take the following steps to create a working example.
287+
288+
1. Create a new view called `Navigation.cshtml`
289+
2. Paste in the following code:
290+
291+
```cshtml
292+
@using Umbraco.Cms.Web.Common
293+
@inject IUmbracoHelperAccessor _umbracoHelperAccessor;
294+
295+
@{
296+
_umbracoHelperAccessor.TryGetUmbracoHelper(out var umbracoHelper);
297+
298+
var homePage = umbracoHelper.ContentAtRoot().FirstOrDefault(c => c.ContentType.Alias == "{{homeNodeContentAlias}}");
299+
var cultures = homePage?.Cultures;
300+
}
301+
302+
@if (cultures.Count > 1)
303+
{
304+
<ul aria-label="Language switcher">
305+
@foreach (var cult in cultures)
306+
{
307+
//get the settings for this culture
308+
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo(cult.Key);
309+
//if the current page has a language variant, otherwise link to the homepage language variant
310+
string langUrl = umbracoHelper.AssignedContentItem.Url(cult.Key, UrlMode.Relative) ?? homePage.Url(cult.Key, UrlMode.Relative);
311+
312+
<li>
313+
@if (cult.Key.ToLower() == umbracoHelper.AssignedContentItem.GetCultureFromDomains().ToLower())
314+
{
315+
<span aria-current="true" >@culture.NativeName</span>
316+
}
317+
else
318+
{
319+
<a href="@langUrl" hreflang="@cult.Key" lang="@cult.Key" >@culture.NativeName</a>
320+
}
321+
</li>
322+
}
323+
</ul>
324+
}
325+
```
326+
327+
3. Replace `{{homeNodeContentAlias}}` with the Document Type alias of your Home node.
328+
329+
This will render links to either the language variant of the current page or the home node for the language variant.
330+
331+
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.

14/umbraco-cms/customizing/extending-overview/extension-types/section-view.md

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,116 @@ This page is a work in progress and may undergo further revisions, updates, or a
1212

1313
<figure><img src="../../../.gitbook/assets/section-views.svg" alt=""><figcaption><p>Section View</p></figcaption></figure>
1414

15-
**Manifest**
15+
## Creating a custom Section View
16+
17+
In this section, you can learn how to register and create a custom Section View for the Umbraco backoffice.
18+
19+
### Manifest
20+
21+
The manifest file can be created using either JSON or Typescript. Both methods are shown below.
22+
23+
{% tabs %}
24+
25+
{% tab title="Json" %}
26+
27+
We can create the manifest using json in the `umbraco-package.json`.
1628

1729
```json
1830
{
1931
"type": "sectionView",
2032
"alias": "My.SectionView",
2133
"name": "My Section View",
34+
"element": "./my-section.element.js",
2235
"meta": {
23-
"sections": ["My.Section"],
2436
"label": "My View",
25-
"pathname": "/my-view"
26-
}
37+
"icon": "icon-add",
38+
"pathname": "my-view"
39+
},
40+
"conditions": [
41+
{
42+
"alias": "Umb.Condition.SectionAlias",
43+
"match": "My.Section",
44+
}
45+
]
2746
}
2847
```
48+
49+
{% endtab %}
50+
51+
{% tab title="Typescript" %}
52+
53+
54+
The manifest can also be written in TypeScript.
55+
56+
For this typescript example we used a [Backoffice Entry Point](../../extending-overview/extension-types/backoffice-entry-point) extension to register the manifests.
57+
58+
```typescript
59+
import { ManifestSectionView } from "@umbraco-cms/backoffice/extension-registry";
60+
61+
const sectionViews: Array<ManifestSectionView> = [
62+
{
63+
type: "sectionView",
64+
alias: "My.SectionView",
65+
name: "My Section View",
66+
element: () => import('./my-section.element.ts'),
67+
meta: {
68+
label: "My View",
69+
icon: "icon-add",
70+
pathname: "my-view",
71+
},
72+
conditions: [
73+
{
74+
alias: 'Umb.Condition.SectionAlias',
75+
match: 'My.Section',
76+
}
77+
]
78+
}
79+
]
80+
```
81+
82+
{% endtab %}
83+
84+
{% endtabs %}
85+
86+
87+
### Lit Element
88+
89+
Creating the Section View Element using a Lit Element.
90+
91+
92+
**my-section.element.ts:**
93+
```typescript
94+
import { UmbLitElement } from "@umbraco-cms/backoffice/lit-element";
95+
import { css, html, customElement, property } from '@umbraco-cms/backoffice/external/lit';
96+
97+
@customElement('my-sectionview-element')
98+
export class MySectionViewElement extends UmbLitElement {
99+
100+
render() {
101+
return html`
102+
<uui-box headline="Sectionview Title goes here">
103+
Sectionview content goes here
104+
</uui-box>
105+
`
106+
}
107+
108+
static override styles = [
109+
css`
110+
:host {
111+
display: block;
112+
padding: 20px;
113+
}
114+
`,
115+
];
116+
117+
}
118+
119+
export default MySectionViewElement;
120+
121+
declare global {
122+
interface HTMLElementTagNameMap {
123+
'my-sectionview-element': MySectionViewElement;
124+
}
125+
}
126+
127+
```

14/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ Umbraco CMS currently ships with two Block Editors: the Block List and the Block
1313
## [Block Grid](block-grid-editor.md)
1414

1515
## Customizing Block Editors
16-
17-
### [Build custom views for blocks](build-custom-view-for-blocks.md)
16+
### [Creating custom views for blocks](https://docs.umbraco.com/umbraco-cms/tutorials/creating-custom-views-for-blocklist)
1817

1918
Learn how to create custom views for the blocks used in your Block Grid or Block List property editors.
20-
2119
### [Configure Block Editor label properties](label-property-configuration.md)
2220

2321
Get an overview of available configurations for the label properties.

0 commit comments

Comments
 (0)