Add Language.LanguageName
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Sep 2016 18:57:52 +0000 (20:57 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Sep 2016 18:59:03 +0000 (20:59 +0200)
Fixes #2435

helpers/language.go
hugolib/hugo_sites_test.go
hugolib/multilingual.go

index a64809f9f5ce7f47ea94638dd087c5f2cea5598e..c822dedd0cb1bffd7c268ba18174b4e5a804c9e6 100644 (file)
@@ -24,11 +24,12 @@ import (
 )
 
 type Language struct {
-       Lang       string
-       Title      string
-       Weight     int
-       params     map[string]interface{}
-       paramsInit sync.Once
+       Lang         string
+       LanguageName string
+       Title        string
+       Weight       int
+       params       map[string]interface{}
+       paramsInit   sync.Once
 }
 
 func (l *Language) String() string {
index 41535fdf80863b24bb17b06cd1e136be0117ff94..3b5bf1cfc46992f23869d92da541340812f91ceb 100644 (file)
@@ -271,9 +271,10 @@ func doTestMultiSitesBuild(t *testing.T, configContent, configSuffix string) {
        require.Len(t, homeEn.Translations(), 3)
        require.Equal(t, "fr", homeEn.Translations()[0].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, "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")
        require.NotNil(t, sectFr)
@@ -626,7 +627,8 @@ tag = "tags"
 [Languages]
 [Languages.en]
 weight = 10
-title = "English"
+title = "In English"
+languageName = "English"
 [Languages.en.blackfriday]
 angledQuotes = false
 [[Languages.en.menu.main]]
@@ -636,13 +638,15 @@ weight = 0
 
 [Languages.fr]
 weight = 20
-title = "Français"
+title = "Le Français"
+languageName = "Français"
 [Languages.fr.Taxonomies]
 plaque = "plaques"
 
 [Languages.nn]
 weight = 30
-title = "Nynorsk"
+title = "På nynorsk"
+languageName = "Nynorsk"
 [Languages.nn.Taxonomies]
 lag = "lag"
 [[Languages.nn.menu.main]]
@@ -652,7 +656,8 @@ weight = 1
 
 [Languages.nb]
 weight = 40
-title = "Bokmål"
+title = "På bokmål"
+languageName = "Bokmål"
 [Languages.nb.Taxonomies]
 lag = "lag"
 `
@@ -679,7 +684,8 @@ Taxonomies:
 Languages:
     en:
         weight: 10
-        title: "English"
+        title: "In English"
+        languageName: "English"
         blackfriday:
             angledQuotes: false
         menu:
@@ -689,12 +695,14 @@ Languages:
                   weight: 0
     fr:
         weight: 20
-        title: "Français"
+        title: "Le Français"
+        languageName: "Français"
         Taxonomies:
             plaque: "plaques"
     nn:
         weight: 30
-        title: "Nynorsk"
+        title: "På nynorsk"
+        languageName: "Nynorsk"
         Taxonomies:
             lag: "lag"
         menu:
@@ -704,7 +712,8 @@ Languages:
                   weight: 1
     nb:
         weight: 40
-        title: "Bokmål"
+        title: "På bokmål"
+        languageName: "Bokmål"
         Taxonomies:
             lag: "lag"
 
@@ -731,7 +740,8 @@ var multiSiteJSONConfig = `
   "Languages": {
     "en": {
       "weight": 10,
-      "title": "English",
+      "title": "In English",
+      "languageName": "English",
       "blackfriday": {
         "angledQuotes": false
       },
@@ -747,14 +757,16 @@ var multiSiteJSONConfig = `
     },
     "fr": {
       "weight": 20,
-      "title": "Français",
+      "title": "Le Français",
+      "languageName": "Français",
       "Taxonomies": {
         "plaque": "plaques"
       }
     },
     "nn": {
       "weight": 30,
-      "title": "Nynorsk",
+      "title": "På nynorsk",
+      "languageName": "Nynorsk",
       "Taxonomies": {
         "lag": "lag"
       },
@@ -770,7 +782,8 @@ var multiSiteJSONConfig = `
     },
     "nb": {
       "weight": 40,
-      "title": "Bokmål",
+      "title": "På bokmål",
+      "languageName": "Bokmål",
       "Taxonomies": {
         "lag": "lag"
       }
index 493a8e8a385022483f41123cd323fe8e8cc4172f..2b0214e10c0396ffcfa5de8a963905ef645c44a9 100644 (file)
@@ -96,6 +96,8 @@ func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) {
                        switch loki {
                        case "title":
                                language.Title = cast.ToString(v)
+                       case "languagename":
+                               language.LanguageName = cast.ToString(v)
                        case "weight":
                                language.Weight = cast.ToInt(v)
                        }