github.com/lyeb/hugo@v0.47.1/docs/content/en/functions/lang.Merge.md (about)

     1  ---
     2  title: lang.Merge
     3  description: "Merge missing translations from other languages."
     4  godocref: ""
     5  workson: []
     6  date: 2018-03-16
     7  categories: [functions]
     8  keywords: [multilingual]
     9  menu:
    10    docs:
    11      parent: "functions"
    12  toc: false
    13  signature: ["lang.Merge FROM TO"]
    14  workson: []
    15  hugoversion:
    16  relatedfuncs: []
    17  deprecated: false
    18  draft: false
    19  aliases: []
    20  comments:
    21  ---
    22  
    23  As an example:
    24  
    25  ```bash
    26  {{ $pages := .Site.RegularPages | lang.Merge $frSite.RegularPages | lang.Merge $enSite.RegularPages }}
    27  ```
    28  
    29  Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English.
    30  
    31  
    32  A more practical example is to fill in the missing translations for the "minority languages" with content from the main language:
    33  
    34  
    35  ```bash
    36   {{ $pages := .Site.RegularPages }}
    37   {{ .Scratch.Set "pages" $pages }}
    38   {{ $mainSite := .Sites.First }}
    39   {{ if ne $mainSite .Site }}
    40      {{ .Scratch.Set "pages" ($pages | lang.Merge $mainSite.RegularPages) }}
    41   {{ end }}
    42   {{ $pages := .Scratch.Get "pages" }} 
    43   ```
    44  
    45  {{% note %}}
    46  Note that the slightly ugly `.Scratch` construct will not be needed once this is fixed: https://github.com/golang/go/issues/10608
    47  {{% /note %}}