Add Language.LanguageName

Fixes #2435
This commit is contained in:
Bjørn Erik Pedersen 2016-09-12 20:57:52 +02:00
parent a7dc3c082e
commit 69a97823c4
3 changed files with 35 additions and 19 deletions

View file

@ -24,11 +24,12 @@ import (
) )
type Language struct { type Language struct {
Lang string Lang string
Title string LanguageName string
Weight int Title string
params map[string]interface{} Weight int
paramsInit sync.Once params map[string]interface{}
paramsInit sync.Once
} }
func (l *Language) String() string { func (l *Language) String() string {

View file

@ -271,9 +271,10 @@ func doTestMultiSitesBuild(t *testing.T, configContent, configSuffix string) {
require.Len(t, homeEn.Translations(), 3) require.Len(t, homeEn.Translations(), 3)
require.Equal(t, "fr", homeEn.Translations()[0].Lang()) require.Equal(t, "fr", homeEn.Translations()[0].Lang())
require.Equal(t, "nn", homeEn.Translations()[1].Lang()) require.Equal(t, "nn", homeEn.Translations()[1].Lang())
require.Equal(t, "Nynorsk", homeEn.Translations()[1].Title) require.Equal(t, "På nynorsk", homeEn.Translations()[1].Title)
require.Equal(t, "nb", homeEn.Translations()[2].Lang()) require.Equal(t, "nb", homeEn.Translations()[2].Lang())
require.Equal(t, "Bokmål", homeEn.Translations()[2].Title) require.Equal(t, "På bokmål", homeEn.Translations()[2].Title, configSuffix)
require.Equal(t, "Bokmål", homeEn.Translations()[2].Language().LanguageName, configSuffix)
sectFr := frSite.getNode("sect-sect-0") sectFr := frSite.getNode("sect-sect-0")
require.NotNil(t, sectFr) require.NotNil(t, sectFr)
@ -626,7 +627,8 @@ tag = "tags"
[Languages] [Languages]
[Languages.en] [Languages.en]
weight = 10 weight = 10
title = "English" title = "In English"
languageName = "English"
[Languages.en.blackfriday] [Languages.en.blackfriday]
angledQuotes = false angledQuotes = false
[[Languages.en.menu.main]] [[Languages.en.menu.main]]
@ -636,13 +638,15 @@ weight = 0
[Languages.fr] [Languages.fr]
weight = 20 weight = 20
title = "Français" title = "Le Français"
languageName = "Français"
[Languages.fr.Taxonomies] [Languages.fr.Taxonomies]
plaque = "plaques" plaque = "plaques"
[Languages.nn] [Languages.nn]
weight = 30 weight = 30
title = "Nynorsk" title = "På nynorsk"
languageName = "Nynorsk"
[Languages.nn.Taxonomies] [Languages.nn.Taxonomies]
lag = "lag" lag = "lag"
[[Languages.nn.menu.main]] [[Languages.nn.menu.main]]
@ -652,7 +656,8 @@ weight = 1
[Languages.nb] [Languages.nb]
weight = 40 weight = 40
title = "Bokmål" title = "På bokmål"
languageName = "Bokmål"
[Languages.nb.Taxonomies] [Languages.nb.Taxonomies]
lag = "lag" lag = "lag"
` `
@ -679,7 +684,8 @@ Taxonomies:
Languages: Languages:
en: en:
weight: 10 weight: 10
title: "English" title: "In English"
languageName: "English"
blackfriday: blackfriday:
angledQuotes: false angledQuotes: false
menu: menu:
@ -689,12 +695,14 @@ Languages:
weight: 0 weight: 0
fr: fr:
weight: 20 weight: 20
title: "Français" title: "Le Français"
languageName: "Français"
Taxonomies: Taxonomies:
plaque: "plaques" plaque: "plaques"
nn: nn:
weight: 30 weight: 30
title: "Nynorsk" title: "På nynorsk"
languageName: "Nynorsk"
Taxonomies: Taxonomies:
lag: "lag" lag: "lag"
menu: menu:
@ -704,7 +712,8 @@ Languages:
weight: 1 weight: 1
nb: nb:
weight: 40 weight: 40
title: "Bokmål" title: "På bokmål"
languageName: "Bokmål"
Taxonomies: Taxonomies:
lag: "lag" lag: "lag"
@ -731,7 +740,8 @@ var multiSiteJSONConfig = `
"Languages": { "Languages": {
"en": { "en": {
"weight": 10, "weight": 10,
"title": "English", "title": "In English",
"languageName": "English",
"blackfriday": { "blackfriday": {
"angledQuotes": false "angledQuotes": false
}, },
@ -747,14 +757,16 @@ var multiSiteJSONConfig = `
}, },
"fr": { "fr": {
"weight": 20, "weight": 20,
"title": "Français", "title": "Le Français",
"languageName": "Français",
"Taxonomies": { "Taxonomies": {
"plaque": "plaques" "plaque": "plaques"
} }
}, },
"nn": { "nn": {
"weight": 30, "weight": 30,
"title": "Nynorsk", "title": "På nynorsk",
"languageName": "Nynorsk",
"Taxonomies": { "Taxonomies": {
"lag": "lag" "lag": "lag"
}, },
@ -770,7 +782,8 @@ var multiSiteJSONConfig = `
}, },
"nb": { "nb": {
"weight": 40, "weight": 40,
"title": "Bokmål", "title": "På bokmål",
"languageName": "Bokmål",
"Taxonomies": { "Taxonomies": {
"lag": "lag" "lag": "lag"
} }

View file

@ -96,6 +96,8 @@ func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) {
switch loki { switch loki {
case "title": case "title":
language.Title = cast.ToString(v) language.Title = cast.ToString(v)
case "languagename":
language.LanguageName = cast.ToString(v)
case "weight": case "weight":
language.Weight = cast.ToInt(v) language.Weight = cast.ToInt(v)
} }