hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

integration_test.go (2069B)

    1 // Copyright 2021 The Hugo Authors. All rights reserved.
    2 //
    3 // Licensed under the Apache License, Version 2.0 (the "License");
    4 // you may not use this file except in compliance with the License.
    5 // You may obtain a copy of the License at
    6 // http://www.apache.org/licenses/LICENSE-2.0
    7 //
    8 // Unless required by applicable law or agreed to in writing, software
    9 // distributed under the License is distributed on an "AS IS" BASIS,
   10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   11 // See the License for the specific language governing permissions and
   12 // limitations under the License.
   13 
   14 package templates_test
   15 
   16 import (
   17 	"testing"
   18 
   19 	"github.com/gohugoio/hugo/hugolib"
   20 )
   21 
   22 func TestExecuteAsTemplateMultipleLanguages(t *testing.T) {
   23 	t.Parallel()
   24 
   25 	files := `
   26 -- config.toml --
   27 baseURL = "http://example.com/blog"
   28 defaultContentLanguage = "fr"
   29 defaultContentLanguageInSubdir = true
   30 [Languages]
   31 [Languages.en]
   32 weight = 10
   33 title = "In English"
   34 languageName = "English"
   35 [Languages.fr]
   36 weight = 20
   37 title = "Le Français"
   38 languageName = "Français"
   39 -- i18n/en.toml --
   40 [hello]
   41 other = "Hello"
   42 -- i18n/fr.toml --
   43 [hello]
   44 other = "Bonjour"
   45 -- layouts/index.fr.html --
   46 Lang: {{ site.Language.Lang }}
   47 {{ $templ := "{{T \"hello\"}}" | resources.FromString "f1.html" }}
   48 {{ $helloResource := $templ | resources.ExecuteAsTemplate (print "f%s.html" .Lang) . }}
   49 Hello1: {{T "hello"}}
   50 Hello2: {{ $helloResource.Content }}
   51 LangURL: {{ relLangURL "foo" }}
   52 -- layouts/index.html --
   53 Lang: {{ site.Language.Lang }}
   54 {{ $templ := "{{T \"hello\"}}" | resources.FromString "f1.html" }}
   55 {{ $helloResource := $templ | resources.ExecuteAsTemplate (print "f%s.html" .Lang) . }}
   56 Hello1: {{T "hello"}}
   57 Hello2: {{ $helloResource.Content }}
   58 LangURL: {{ relLangURL "foo" }}
   59 
   60 	`
   61 
   62 	b := hugolib.NewIntegrationTestBuilder(
   63 		hugolib.IntegrationTestConfig{
   64 			T:           t,
   65 			TxtarString: files,
   66 		}).Build()
   67 
   68 	b.AssertFileContent("public/en/index.html", `
   69 		Hello1: Hello
   70 		Hello2: Hello
   71 		`)
   72 
   73 	b.AssertFileContent("public/fr/index.html", `
   74 		Hello1: Bonjour
   75 		Hello2: Bonjour
   76 		`)
   77 }