Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
feat(i18n): add select-menu for i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed Mar 3, 2020
1 parent cbfc965 commit 1d1cae6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 35 deletions.
22 changes: 22 additions & 0 deletions assets/css/_partial/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ header {
.header-title {
font-weight: bold;
}

.select-language {
font-weight: $global-font-weight;
border: none;
box-shadow: none;
background: transparent;
background-image: none;
-webkit-appearance: none;
color: $global-font-color;

.dark-theme & {
color: $global-font-color-dark;
}

&:focus {
outline: none;
}

&:hover {
cursor: pointer;
}
}
}

#header-desktop {
Expand Down
23 changes: 5 additions & 18 deletions assets/css/_partial/_home/_summary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,6 @@
font-size: 1.6rem;
}

.post-meta {
a {
color: $global-font-secondary-color !important;

.dark-theme & {
color: $global-font-secondary-color-dark !important;
}

&:hover {
color: $global-link-hover-color !important;

.dark-theme & {
color: $global-link-hover-color-dark !important;
}
}
}
}

.content {
display: -moz-box;
display: -webkit-box;
Expand All @@ -59,6 +41,11 @@
overflow: hidden;
text-overflow: ellipsis;
overflow-wrap: break-word;
color: $global-font-secondary-color;

.dark-theme & {
color: $global-font-secondary-color-dark;
}

h2,
h3,
Expand Down
2 changes: 1 addition & 1 deletion assets/css/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Font and Line Height
$global-font-family: -apple-system, BlinkMacSystemFont, PingFang SC, Microsoft Yahei, Segoe UI, Helvetica, Arial, sans-serif, Segoe UI Emoji !default;
$global-font-size: 16px;
$global-font-weight: 300;
$global-font-weight: 400;
$global-line-height: 1.5rem;

// Color of the background
Expand Down
18 changes: 4 additions & 14 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ enableEmoji = true
languageCode = "en"
# website title
title = "LoveIt Theme"
# language name
languageName = "English"
# whether to include chinese/japanese/korean
hasCJKLanguage = false
# default amount of posts in each pages
Expand Down Expand Up @@ -58,13 +60,6 @@ enableEmoji = true
name = "About"
url = "/about/"
weight = 4
[[languages.en.menu.main]]
identifier = "zh"
pre = '<i class="fas fa-language fa-fw"></i>'
name = ""
title = "简体中文"
url = "/zh/"
weight = 5
[languages.en.params]
# site description
description = "About LoveIt Theme"
Expand Down Expand Up @@ -232,6 +227,8 @@ enableEmoji = true
languageCode = "zh"
# 网站标题
title = "LoveIt 主题"
# 语言名称
languageName = "简体中文"
# 是否包括中日韩文字
hasCJKLanguage = true
# 默认每页列表显示的文章数目
Expand Down Expand Up @@ -264,13 +261,6 @@ enableEmoji = true
name = "关于"
url = "/about/"
weight = 4
[[languages.zh.menu.main]]
identifier = "en"
pre = '<i class="fas fa-language fa-fw"></i>'
name = ""
title = "English"
url = "../"
weight = 5
[languages.zh.params]
# 网站描述
description = "关于 LoveIt 主题"
Expand Down
39 changes: 39 additions & 0 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
{{- .Pre | safeHTML }}{{ .Name -}}
</a>
{{- end -}}
{{- if .Site.IsMultiLingual -}}
&nbsp;|&nbsp;
<span class="menu-item">
<i class="fas fa-language fa-fw"></i>&nbsp;
<select class="select-language" onchange="location = this.value;">
{{- range .Page.AllTranslations -}}
{{- $translation := . -}}
{{- range $.Site.Languages -}}
{{- if eq $translation.Lang .Lang -}}
{{- if eq $.Page.Lang .Lang -}}
<option value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option>
{{- else -}}
<option value="{{ $translation.Permalink }}">{{ .LanguageName }}</option>
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
</select>
</span>
{{- end -}}
<a href="javascript:void(0);" class="theme-switch" title="{{ T "switchTheme" }}">
<i class="fas fa-adjust fa-rotate-180 fa-fw"></i>
</a>
Expand Down Expand Up @@ -39,6 +59,25 @@
{{- .Pre | safeHTML }}{{ .Name -}}
</a>
{{- end -}}
{{- if .Site.IsMultiLingual -}}
<span class="menu-item">
<i class="fas fa-language fa-fw"></i>&nbsp;
<select class="select-language" onchange="location = this.value;">
{{- range .Site.Home.AllTranslations -}}
{{- $translation := . -}}
{{- range $.Site.Languages -}}
{{- if eq $translation.Lang .Lang -}}
{{- if eq $.Page.Lang .Lang -}}
<option value="{{ $translation.Permalink }}" selected>{{ .LanguageName }}</option>
{{- else -}}
<option value="{{ $translation.Permalink }}">{{ .LanguageName }}</option>
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
</select>
</span>
{{- end -}}
<a href="javascript:void(0);" class="theme-switch" title="{{ T "switchTheme" }}">
<i class="fas fa-adjust fa-rotate-180 fa-fw"></i>
</a>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Target":"css/style.min.8d8ebcf734d4e8e32cab589f8df6e5bad5775d4d25d0cf2b66c6c5476831f18d.css","MediaType":"text/css","Data":{"Integrity":"sha256-jY689zTU6OMsq1ifjfblutV3XU0l0M8rZsbFR2gx8Y0="}}
{"Target":"css/style.min.52eef027334e2f9819adcad242e7298beefaf3f468d9085be0327f795ae0e4e5.css","MediaType":"text/css","Data":{"Integrity":"sha256-Uu7wJzNOL5gZrcrSQucpi+768/Ro2Qhb4DJ/eVrg5OU="}}

0 comments on commit 1d1cae6

Please sign in to comment.