Преглед на файлове

Add internationalization (i18n) support (#12)

George Cushen преди 8 години
родител
ревизия
31f9ce5f94

+ 11 - 1
exampleSite/config.toml

@@ -1,7 +1,6 @@
 baseurl = "https://example.com"
 title = "Academic Theme"
 copyright = "© 2016 Your Name"
-languageCode = "en-us"
 theme = "academic"
 enableEmoji = true
 footnotereturnlinkcontents = "<sup>^</sup>"
@@ -12,6 +11,10 @@ disqusShortname = ""
 # Enable analytics by entering your Google Analytics tracking ID
 googleAnalytics = ""
 
+# Default language to use (if you setup multilingual support)
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = false
+
 [blackfriday]
   hrefTargetBlank = true
 
@@ -119,3 +122,10 @@ googleAnalytics = ""
   name = "Contact"
   url = "#contact"
   weight = 6
+
+# Languages
+#   Create a [languages.X] block for each language you want, where X is the language ID.
+
+# Configure the English version of the website.
+[languages.en]
+  languageCode = "en-us"

+ 0 - 4
exampleSite/content/home/about.md

@@ -11,7 +11,6 @@ weight = 0
 
 # List your academic interests.
 [interests]
-  title = "Interests"
   interests = [
     "Artificial Intelligence",
     "Computational Linguistics",
@@ -19,9 +18,6 @@ weight = 0
   ]
 
 # List your qualifications (such as academic degrees).
-[education]
-  title = "Education"
-
 [[education.courses]]
   course = "PhD in Artificial Intelligence"
   institution = "Stanford University"

+ 0 - 4
exampleSite/content/home/posts.md

@@ -18,9 +18,5 @@ tags = []
 # Number of posts to list.
 count = 5
 
-# Links.
-str_all = "More Posts"
-str_read_more = "CONTINUE READING"
-
 +++
 

+ 0 - 3
exampleSite/content/home/publications.md

@@ -18,8 +18,5 @@ count = 10
 # Show publication details (such as abstract)? (true/false)
 detailed_list = false
 
-# Link.
-str_all = "More Publications"
-
 +++
 

+ 86 - 0
i18n/en.yaml

@@ -0,0 +1,86 @@
+# Navigation
+
+- id: toggle_navigation
+  translation: Toggle navigation
+
+# Buttons
+
+- id: btn_details
+  translation: Details
+
+- id: btn_pdf
+  translation: PDF
+
+- id: btn_slides
+  translation: Slides
+
+- id: btn_video
+  translation: Video
+
+- id: btn_code
+  translation: Code
+
+- id: btn_dataset
+  translation: Dataset
+
+- id: btn_project
+  translation: Project
+
+# About widget
+
+- id: interests
+  translation: Interests
+
+- id: education
+  translation: Education
+
+# Publications widget
+
+- id: more_publications
+  translation: More Publications
+
+# Posts widget
+
+- id: continue_reading
+  translation: CONTINUE READING
+
+- id: more_posts
+  translation: More Posts
+
+# Talks widget
+
+- id: more_talks
+  translation: More Talks
+
+# Publication/Talk details
+
+- id: abstract
+  translation: Abstract
+
+- id: publication
+  translation: Publication
+
+- id: date
+  translation: Date
+
+- id: links
+  translation: Links
+
+- id: event
+  translation: Event
+
+# Project details
+
+- id: open_project_site
+  translation: Go to Project Site
+
+# Section titles
+
+- id: posts
+  translation: Posts
+
+- id: publications
+  translation: Publications
+
+- id: talks
+  translation: Talks

+ 1 - 1
layouts/partials/navbar.html

@@ -5,7 +5,7 @@
     <div class="navbar-header">
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
               data-target=".navbar-collapse" aria-expanded="false">
-        <span class="sr-only">Toggle navigation</span>
+        <span class="sr-only">{{ i18n "toggle_navigation" }}</span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>
         <span class="icon-bar"></span>

+ 1 - 1
layouts/partials/post_li.html

@@ -23,7 +23,7 @@
   </div>
   <p class="read-more">
     <a href="{{ $post.Permalink }}" class="btn btn-primary btn-outline">
-      {{ with $page.Params.str_read_more }}{{ . | markdownify }}{{ end }}
+      {{ i18n "continue_reading" }}
     </a>
   </p>
 </div>

+ 7 - 7
layouts/partials/publication_links.html

@@ -3,37 +3,37 @@
 
 {{ if $is_list }}
 <a class="btn btn-primary btn-outline btn-xs" href="{{ $.Permalink }}">
-  Details
+  {{ i18n "btn_details" }}
 </a>
 {{ end }}
 {{ with $.Params.url_pdf }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  PDF
+  {{ i18n "btn_pdf" }}
 </a>
 {{ end }}
 {{ with $.Params.url_slides }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Slides
+  {{ i18n "btn_slides" }}
 </a>
 {{ end }}
 {{ with $.Params.url_video }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Video
+  {{ i18n "btn_video" }}
 </a>
 {{ end }}
 {{ with $.Params.url_code }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Code
+  {{ i18n "btn_code" }}
 </a>
 {{ end }}
 {{ with $.Params.url_dataset }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Dataset
+  {{ i18n "btn_dataset" }}
 </a>
 {{ end }}
 {{ with $.Params.url_project }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Project
+  {{ i18n "btn_project" }}
 </a>
 {{ end }}
 {{ range $.Params.url_custom }}

+ 4 - 4
layouts/partials/talk_links.html

@@ -3,22 +3,22 @@
 
 {{ if $is_list }}
 <a class="btn btn-primary btn-outline btn-xs" href="{{ $.Permalink }}">
-  Details
+  {{ i18n "btn_details" }}
 </a>
 {{ end }}
 {{ with $.Params.url_pdf }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  PDF
+  {{ i18n "btn_pdf" }}
 </a>
 {{ end }}
 {{ with $.Params.url_slides }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Slides
+  {{ i18n "btn_slides" }}
 </a>
 {{ end }}
 {{ with $.Params.url_video }}
 <a class="btn btn-primary btn-outline{{ if $is_list }} btn-xs{{end}}" href="{{ . | absURL }}">
-  Video
+  {{ i18n "btn_video" }}
 </a>
 {{ end }}
 {{ range $.Params.url_custom }}

+ 2 - 2
layouts/partials/widgets/about.html

@@ -39,7 +39,7 @@
 
       {{ with $page.Params.interests }}
       <div class="col-sm-5">
-        <h3>{{ .title | default "Interests" | markdownify }}</h3>
+        <h3>{{ i18n "interests" | markdownify }}</h3>
         <ul class="ul-interests">
           {{ range .interests }}
           <li>{{ . }}</li>
@@ -50,7 +50,7 @@
 
       {{ with $page.Params.education }}
       <div class="col-sm-7">
-        <h3>{{ .title | default "Education" | markdownify }}</h3>
+        <h3>{{ i18n "education" | markdownify }}</h3>
         <ul class="ul-edu fa-ul">
           {{ range .courses }}
           <li>

+ 1 - 1
layouts/partials/widgets/posts.html

@@ -11,7 +11,7 @@
     {{ if gt $posts_len $page.Params.count }}
     <p class="view-all">
       <a href="{{ "/post/" | relURL }}">
-        {{ with $page.Params.str_all }}{{ . | markdownify }}{{ end }}
+        {{ i18n "more_posts" | markdownify }}
         <i class="fa fa-angle-double-right"></i>
       </a>
     </p>

+ 1 - 1
layouts/partials/widgets/publications.html

@@ -10,7 +10,7 @@
     {{ if gt $pubs_len $page.Params.count }}
     <p class="view-all">
       <a href="{{ $.Site.BaseURL }}publication/">
-        {{ with $page.Params.str_all }}{{ . | markdownify }}{{ end }}
+        {{ i18n "more_publications" | markdownify }}
         <i class="fa fa-angle-double-right"></i>
       </a>
     </p>

+ 1 - 1
layouts/partials/widgets/talks.html

@@ -10,7 +10,7 @@
     {{ if gt $talks_len $page.Params.count }}
     <p class="view-all">
       <a href="{{ $.Site.BaseURL }}talk/">
-        {{ with $page.Params.str_all }}{{ . | markdownify }}{{ end }}
+        {{ i18n "more_talks" | markdownify }}
         <i class="fa fa-angle-double-right"></i>
       </a>
     </p>

+ 1 - 1
layouts/project/single.html

@@ -10,7 +10,7 @@
     <h1 itemprop="name">{{ .Title }}</h1>
 
     {{ with .Params.external_link }}
-    <a class="btn btn-primary btn-outline" href="{{ . }}">Go to Project Site</a>
+    <a class="btn btn-primary btn-outline" href="{{ . }}">{{ i18n "open_project_site" }}</a>
     {{ end }}
 
     <div class="article-style" itemprop="articleBody">

+ 10 - 10
layouts/publication/single.html

@@ -6,27 +6,27 @@
     <div class="pub-title">
       <h1 itemprop="name">{{ .Title }}</h1>
       <span class="pub-authors" itemprop="author">
-                {{ with .Params.authors }}
-                {{ delimit . ", " }}
-                {{ end }}
-            </span>
+        {{ with .Params.authors }}
+        {{ delimit . ", " }}
+        {{ end }}
+      </span>
       <span class="pull-right">
-                {{ partial "share.html" . }}
-            </span>
+        {{ partial "share.html" . }}
+      </span>
     </div>
 
     {{ if .Params.image }}
     <img src="{{ $.Site.BaseURL }}img/{{ .Params.image }}" class="pub-banner" itemprop="image">
     {{end}}
 
-    <h3>Abstract</h3>
+    <h3>{{ i18n "abstract" }}</h3>
     <p class="pub-abstract" itemprop="text">{{ .Params.abstract }}</p>
 
     <div class="row">
       <div class="col-sm-1"></div>
       <div class="col-sm-10">
         <div class="row">
-          <div class="col-xs-12 col-sm-3 pub-row-heading">Publication</div>
+          <div class="col-xs-12 col-sm-3 pub-row-heading">{{ i18n "publication" }}</div>
           <div class="col-xs-12 col-sm-9">{{ .Params.publication | markdownify }}</div>
         </div>
       </div>
@@ -38,7 +38,7 @@
       <div class="col-sm-1"></div>
       <div class="col-sm-10">
         <div class="row">
-          <div class="col-xs-12 col-sm-3 pub-row-heading">Date</div>
+          <div class="col-xs-12 col-sm-3 pub-row-heading">{{ i18n "date" }}</div>
           <div class="col-xs-12 col-sm-9" itemprop="datePublished">
             {{ .Date.Format "January, 2006" }}
           </div>
@@ -52,7 +52,7 @@
       <div class="col-sm-1"></div>
       <div class="col-sm-10">
         <div class="row">
-          <div class="col-xs-12 col-sm-3 pub-row-heading" style="line-height:34px;">Links</div>
+          <div class="col-xs-12 col-sm-3 pub-row-heading" style="line-height:34px;">{{ i18n "links" }}</div>
           <div class="col-xs-12 col-sm-9">
 
             {{ partial "publication_links" (dict "content" . "is_list" 0) }}

+ 1 - 1
layouts/section/post.html

@@ -2,7 +2,7 @@
 {{ partial "navbar.html" . }}
 <div class="container">
 
-  <h1>Posts</h1>
+  <h1>{{ i18n "posts" }}</h1>
 
   {{ $paginator := .Paginate .Data.Pages }}
   {{ range $paginator.Pages }}

+ 1 - 1
layouts/section/publication.html

@@ -3,7 +3,7 @@
 <div class="container">
   <div class="row">
     <div class="col-md-12">
-      <h1>Publications</h1>
+      <h1>{{ i18n "publications" }}</h1>
 
       {{ range .Data.Pages.GroupByDate "2006" }}
       <div class="row" id="pub_list">

+ 1 - 1
layouts/section/talk.html

@@ -3,7 +3,7 @@
 <div class="container">
   <div class="row">
     <div class="col-md-12">
-      <h1>Talks</h1>
+      <h1>{{ i18n "talks" }}</h1>
 
       {{ range .Data.Pages.GroupByDate "2006" }}
       <div class="row" id="talk_list">

+ 4 - 4
layouts/talk/single.html

@@ -20,7 +20,7 @@
     {{end}}
 
     {{ if .Params.abstract }}
-      <h3>Abstract</h3>
+      <h3>{{ i18n "abstract" }}</h3>
       <p class="pub-abstract" itemprop="text">{{ .Params.abstract }}</p>
     {{ else }}
       <br>
@@ -30,7 +30,7 @@
       <div class="col-sm-1"></div>
       <div class="col-sm-10">
         <div class="row">
-          <div class="col-xs-12 col-sm-3 pub-row-heading">Event</div>
+          <div class="col-xs-12 col-sm-3 pub-row-heading">{{ i18n "event" }}</div>
           <div class="col-xs-12 col-sm-9">{{ .Params.event | markdownify }}</div>
         </div>
       </div>
@@ -42,7 +42,7 @@
       <div class="col-sm-1"></div>
       <div class="col-sm-10">
         <div class="row">
-          <div class="col-xs-12 col-sm-3 pub-row-heading">Date</div>
+          <div class="col-xs-12 col-sm-3 pub-row-heading">{{ i18n "date" }}</div>
           <div class="col-xs-12 col-sm-9" itemprop="datePublished">
             {{ .Date.Format "January, 2006" }}
           </div>
@@ -56,7 +56,7 @@
       <div class="col-sm-1"></div>
       <div class="col-sm-10">
         <div class="row">
-          <div class="col-xs-12 col-sm-3 pub-row-heading" style="line-height:34px;">Links</div>
+          <div class="col-xs-12 col-sm-3 pub-row-heading" style="line-height:34px;">{{ i18n "links" }}</div>
           <div class="col-xs-12 col-sm-9">
 
             {{ partial "publication_links" (dict "content" . "is_list" 0) }}