summaryrefslogtreecommitdiffstats
path: root/docs/content/functions/lang.Merge.md
blob: 6e1d41c0f832481eb680668b9cf0efd34437f8d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
title: lang.Merge
description: "Merge missing translations from other languages."
godocref: ""
workson: []
date: 2018-03-16
categories: [functions]
keywords: [multilingual]
menu:
  docs:
    parent: "functions"
toc: false
signature: ["lang.Merge FROM TO"]
workson: []
hugoversion:
relatedfuncs: []
deprecated: false
draft: false
aliases: []
comments:
---

As an example:

```bash
{{ $pages := .Site.RegularPages | lang.Merge $frSite.RegularPages | lang.Merge $enSite.RegularPages }}
```

Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English.


A more practical example is to fill in the missing translations for the "minority languages" with content from the main language:


```bash
 {{ $pages := .Site.RegularPages }}
 {{ .Scratch.Set "pages" $pages }}
 {{ $mainSite := .Sites.First }}
 {{ if ne $mainSite .Site }}
    {{ .Scratch.Set "pages" ($pages | lang.Merge $mainSite.RegularPages) }}
 {{ end }}
 {{ $pages := .Scratch.Get "pages" }} 
 ```

{{% note %}}
Note that the slightly ugly `.Scratch` construct will not be needed once this is fixed: https://github.com/golang/go/issues/10608
{{% /note %}}