1
0
mirror of https://github.com/actix/actix-website synced 2024-11-24 00:41:07 +01:00

Attempt to clean up the multilingual setup

This commit is contained in:
Armin Ronacher 2018-06-24 23:03:40 +02:00
parent 513ef13784
commit 20888bc58b
8 changed files with 221 additions and 249 deletions

View File

@ -3,20 +3,19 @@ canonifyURLs = true
googleAnalytics = "UA-110322332-1"
pygmentsUseClasses = true
pygmentsCodeFences = true
defaultContentLanguageInSubdir = true
defaultContentLanguageInSubdir = false
enableRobotsTXT = true
enableMissingTranslationPlaceholders = true
DefaultContentLanguage = "en"
baseURL = "https://actix.rs"
[languages]
[languages.en]
baseURL = "https://actix.rs"
languageCode = "en-us"
languageCode = "en-US"
languageName = "English"
weight = 1
[languages.cn]
baseURL = "https://actix.rs/cn"
languageCode = "zh-cn"
languageCode = "zh-CN"
languageName = "中文"
weight = 2
[params]

8
i18n/cn.toml Normal file
View File

@ -0,0 +1,8 @@
[home]
other = "首页"
[docs]
other = "文档"
[community]
other = "社区"
[code]
other = "源码"

8
i18n/en.toml Normal file
View File

@ -0,0 +1,8 @@
[home]
other = "Home"
[docs]
other = "Documentation"
[community]
other = "Community"
[code]
other = "Code"

149
layouts/index.cn.html Normal file
View File

@ -0,0 +1,149 @@
{{ partial "header" . }}
<div id="act-home">
<div class="jumbotron">
<div class="actix-jumbotron">
<img src="/img/logo-large.png" class="align-middle actix-logo" alt="">
<p class="lead">Rust强大的actor系统和有趣的web框架</p>
</div>
</div>
<div class="container actix-home">
<div class="row">
<div class="col-md-4">
<div class="actix-features">
<h2>
<i class="fa fa-fw fa-shield" aria-hidden="true"></i>
类型安全
</h2>
<p>忘记关于字符串类型的对象,从请求到响应,一切都有类型,异步。</p>
<h2>
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
特性丰富
</h2>
<p>Actix提供了丰富的特性开箱即用。WebSocketsHTTP/2管道SSL异步HTTTP客户端等一应俱全.</p>
<h2>
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
扩展性强
</h2>
<p>轻松创建任何基于Actix应用的自己的特色库。</p>
<h2>
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
速度极快
</h2>
<p>Actix 具有顶级的速度. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">Check yourself</a>.</p>
</div>
</div>
<div class="col-md-8">
<div class="actix-content">
{{ highlight `extern crate actix_web;
use actix_web::{http::Method, server, App, Path, Responder};
fn index(info: Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0)
}
fn main() {
server::new(
|| App::new()
.route("/{id}/{name}/index.html", Method::GET, index))
.bind("127.0.0.1:8080").unwrap()
.run();
}` "rust" "" }}
</div>
</div>
</div>
<div class="actix-showcase">
<div class="col-md-9">
<div class="actix-feature" id="responders">
<h2>灵活的请求响应</h2>
<p>
Actix中的Handler函数可以返回实现该<code>Respondert</code> rait的各种对象。这使得从API返回一致的响应变得轻而易举。
</p>
{{ highlight `#[derive(Serialize)]
struct Measurement {
temperature: f32,
}
fn hello_world() -> impl Responder {
"Hello World!"
}
fn current_temperature(_req: HttpRequest) -> impl Responder {
Json(Measurement { temperature: 42.3 })
}` "rust" "" }}
</div>
<div class="actix-feature" id="extractors">
<h2>强大的Extractors</h2>
<p>
Actix提供了一个强大的提取器系统可以从传入的HTTP请求中提取数据并将其传递给您的视图函数。这不仅可以创建方便的API
而且还意味着您的视图函数可以是同步代码并且仍然可以受益于异步IO处理。
</p>
{{ highlight `#[derive(Deserialize)]
struct Event {
timestamp: f64,
kind: String,
tags: Vec<String>,
}
fn capture_event(evt: Json<Event>) -> impl Responder {
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
format!("got event {}", id)
}` "rust" "" }}
</div>
<div class="actix-feature" id="forms">
<h2>轻松处理表单</h2>
<p>
处理multipart/ urlencoded表单数据很容易。只需定义一个可以反序列化的结构actix就可以处理剩下的部分。
</p>
{{ highlight `#[derive(Deserialize)]
struct Register {
username: String,
country: String,
}
fn register(data: Form<Register>) -> impl Responder {
format!("Hello {} from {}!", data.username, data.country)
}` "rust" "" }}
</div>
<div class="actix-feature" id="routing">
<h2>请求路由</h2>
<p>
一个actix应用程序带有一个URL路由系统可以让你在URL上匹配并调用单个处理程序。为了获得额外的灵活性可以使用域。
</p>
{{ highlight `fn index(req: HttpRequest) -> impl Responder {
"Hello from the index page"
}
fn hello(path: Path<String>) -> impl Responder {
format!("Hello {}!", *path)
}
fn main() {
App::new()
.resource("/", |r| r.method(Method::Get).with(index))
.resource("/hello/{name}", |r| r.method(Method::Get).with(hello))
.finish();
}` "rust" "" }}
</div>
</div>
<div class="col-md-3 actix-feature-selectors">
<ul class="act-menu">
<li class="actix-feature-selector"><a href="#responders">灵活的请求响应</a></li>
<li class="actix-feature-selector"><a href="#extractors">强大的Extractors</a></li>
<li class="actix-feature-selector"><a href="#forms">轻松处理表单</a></li>
<li class="actix-feature-selector"><a href="#routing">请求路由</a></li>
</ul>
</div>
</div>
</div>
</div>
{{ partial "footer" . }}

View File

@ -34,7 +34,7 @@
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
Blazingly Fast
</h2>
<p>Actix is blazingly fast. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">Check yourself</a>.</p>
<p>Actix is blazingly fast. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">See for yourself</a>.</p>
</div>
</div>
<div class="col-md-8">
@ -155,150 +155,4 @@ fn main() {
</div>
</div>
<div id="act-home-cn">
<div class="jumbotron">
<div class="actix-jumbotron">
<img src="/img/logo-large.png" class="align-middle actix-logo" alt="">
<p class="lead">Rust强大的actor系统和有趣的web框架</p>
</div>
</div>
<div class="container actix-home">
<div class="row">
<div class="col-md-4">
<div class="actix-features">
<h2>
<i class="fa fa-fw fa-shield" aria-hidden="true"></i>
类型安全
</h2>
<p>忘记关于字符串类型的对象,从请求到响应,一切都有类型,异步。</p>
<h2>
<i class="fa fa-fw fa-battery-full" aria-hidden="true"></i>
特性丰富
</h2>
<p>Actix提供了丰富的特性开箱即用。WebSocketsHTTP/2管道SSL异步HTTTP客户端等一应俱全.</p>
<h2>
<i class="fa fa-fw fa-puzzle-piece" aria-hidden="true"></i>
扩展性强
</h2>
<p>轻松创建任何基于Actix应用的自己的特色库。</p>
<h2>
<i class="fa fa-fw fa-dashboard" aria-hidden="true"></i>
速度极快
</h2>
<p>Actix 具有顶级的速度. <a href="https://www.techempower.com/benchmarks/#section=data-r16&hw=ph&test=plaintext">Check yourself</a>.</p>
</div>
</div>
<div class="col-md-8">
<div class="actix-content">
{{ highlight `extern crate actix_web;
use actix_web::{http::Method, server, App, Path, Responder};
fn index(info: Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0)
}
fn main() {
server::new(
|| App::new()
.route("/{id}/{name}/index.html", Method::GET, index))
.bind("127.0.0.1:8080").unwrap()
.run();
}` "rust" "" }}
</div>
</div>
</div>
<div id="act-cn-tabs">
<div id="content">
<div id="con_one_1">
<h2>灵活的请求响应</h2>
<p>
Actix中的Handler函数可以返回实现该<code>Respondert</code> rait的各种对象。这使得从API返回一致的响应变得轻而易举。
</p>
{{ highlight `#[derive(Serialize)]
struct Measurement {
temperature: f32,
}
fn hello_world() -> impl Responder {
"Hello World!"
}
fn current_temperature(_req: HttpRequest) -> impl Responder {
Json(Measurement { temperature: 42.3 })
}` "rust" "" }}
</div>
<div id="con_one_2" style="display:none;">
<h2>强大的Extractors</h2>
<p>
Actix提供了一个强大的提取器系统可以从传入的HTTP请求中提取数据并将其传递给您的视图函数。这不仅可以创建方便的API
而且还意味着您的视图函数可以是同步代码并且仍然可以受益于异步IO处理。
</p>
{{ highlight `#[derive(Deserialize)]
struct Event {
timestamp: f64,
kind: String,
tags: Vec<String>,
}
fn capture_event(evt: Json<Event>) -> impl Responder {
let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags);
format!("got event {}", id)
}` "rust" "" }}
</div>
<div id="con_one_3" style="display:none;">
<h2>轻松处理表单</h2>
<p>
处理multipart/ urlencoded表单数据很容易。只需定义一个可以反序列化的结构actix就可以处理剩下的部分。
</p>
{{ highlight `#[derive(Deserialize)]
struct Register {
username: String,
country: String,
}
fn register(data: Form<Register>) -> impl Responder {
format!("Hello {} from {}!", data.username, data.country)
}` "rust" "" }}
</div>
<div id="con_one_4" style="display:none;">
<h2>请求路由</h2>
<p>
一个actix应用程序带有一个URL路由系统可以让你在URL上匹配并调用单个处理程序。为了获得额外的灵活性可以使用域。
</p>
{{ highlight `fn index(req: HttpRequest) -> impl Responder {
"Hello from the index page"
}
fn hello(path: Path<String>) -> impl Responder {
format!("Hello {}!", *path)
}
fn main() {
App::new()
.resource("/", |r| r.method(Method::Get).with(index))
.resource("/hello/{name}", |r| r.method(Method::Get).with(hello))
.finish();
}` "rust" "" }}
</div>
</div>
<ul class="act-menu">
<li id="one1" onclick="setTab('one',1)">灵活的请求响应</li>
<li id="one2" onclick="setTab('one',2)">强大的Extractors</li>
<li id="one3" onclick="setTab('one',3)">轻松处理表单</li>
<li id="one4" onclick="setTab('one',4)">请求路由</li>
</ul>
</div>
</div>
</div>
{{ partial "footer" . }}

View File

@ -28,55 +28,29 @@
<div class="navbar-collapse collapse" id="actix-main-nav">
<ul class="nav navbar-nav" id="ul-en">
<li class="nav-item hd-lg-down">
<a class="navbar-brand" href="/"><img src="/img/logo-nav.png" class="align-middle" alt=""></a>
<a class="navbar-brand" href="{{ "/" | absLangURL }}"><img src="/img/logo-nav.png" class="align-middle" alt=""></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
<a class="nav-link" href="{{ "/" | absLangURL }}">{{ T "home" }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/docs/">Documentation</a>
<a class="nav-link" href="{{ "/docs/" | absLangURL }}">{{ T "docs" }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/community/">Community</a>
<a class="nav-link" href="{{ "/community/" | absLangURL }}">{{ T "community" }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/code/">Code</a>
<a class="nav-link" href="{{ "/code/" | absLangURL }}">{{ T "code" }}</a>
</li>
<li class="nav-item" id="language">
<img src="/img/i18n.jpeg"/>
<ul class="subitem">
<li class="submenu-item"><a href="https://actix.rs">English</a></li>
<li class="submenu-item"><a href="https://actix.rs/cn" target="view_window">中文</a> </li>
</ul>
<li class="nav-item language-selector">
<i class="fa fa-fw fa-globe" aria-hidden="false"></i>
<ul class="subitem">
{{ range $.Site.Home.AllTranslations }}
<li class="submenu-item"><a href="{{ .Permalink }}">{{ .Language.LanguageName }}</a></li>
{{ end }}
</ul>
</li>
</ul>
<ul class="nav navbar-nav" id="ul-zh">
<li class="nav-item hd-lg-down">
<a class="navbar-brand" href="/"><img src="/img/logo-nav.png" class="align-middle" alt=""></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/">首页</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/docs/">文档</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/blog/">博客</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/community/">社区</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/code/">源码</a>
</li>
<li class="nav-item" id="language">
<img src="/img/i18n.jpeg"/>
<ul class="subitem">
<li class="submenu-item"><a href="https://actix.rs" target="view_window">English</a></li>
<li class="submenu-item"><a href="https://actix.rs/cn">中文</a> </li>
</ul>
</li>
</ul>
</div>
</nav>
</header>

View File

@ -171,30 +171,45 @@ img {
padding-top: 0;
list-style: none;
}
.navbar-nav #language img {
width: 25px;
height:22px;
.navbar-nav .language-selector {
position: relative;
}
.navbar-nav #language ul {
display: none;
.navbar-nav .language-selector ul.subitem {
display: none;
position: absolute;
right: 0;
}
.navbar-nav #language:hover .subitem {
margin: -1rem 0 0 -6.6rem;
display: block;
background-color: #dcfaf7;
.navbar-nav .language-selector:hover .subitem {
margin: 0;
padding: 0;
display: block;
background-color: #dcfaf7;
}
.navbar-nav #language ul li {
display: block;
.navbar-nav .language-selector ul li {
padding: 0;
margin: 0;
height: auto;
line-height: 1;
}
.navbar-nav .language-selector ul li a {
display: block;
padding: 1em;
}
.doctoggle {
margin: -1rem 0 2rem 0;
display: none;
}
margin: -1rem 0 2rem 0;
display: none;
}
.leftnav {
margin: 0 -1rem;
padding: 0 1rem;
}
.leftnav {
margin: 0 -1rem;
padding: 0 1rem;
}
.leftnav li {
margin: 1rem 0rem;
@ -592,12 +607,13 @@ h5:hover a {
.actix-footer-social a .fa-github {
margin-right: 1rem;
}
.navbar-nav #language:hover .subitem {
.navbar-nav .language-selector:hover .subitem {
margin: 0 -2rem 0 -1rem;
display: block;
background-color: #e8f9fc;
}
}
@media (min-width: 480px) and (max-width: 576px) {
header .nav {
width: 100%;
@ -666,4 +682,4 @@ h5:hover a {
#act-cn-tabs #content {
width: 77%;
}
}
}

View File

@ -1,37 +1,3 @@
window.onload = function(){
if (window.location.href.search("cn") != -1) {
if (document.getElementById("act-home")){
document.getElementById("act-home").style.display = "none"
}
}else{
if (document.getElementById("act-home-cn")){
document.getElementById("act-home-cn").style.display = "none"
}
}
if (window.location.href.search("cn") != -1) {
document.getElementById("ul-en").style.display = "none"
}else{
document.getElementById("ul-zh").style.display = "none"
}
}
function setTab(name,cursel){
let tlinks = document.getElementById("act-cn-tabs").getElementsByTagName('li')
for(var i=1; i<=tlinks.length; i++){
var menu = document.getElementById(name+i);
var menudiv = document.getElementById("con_"+name+"_"+i);
if(i==cursel){
menu.className="off";
menudiv.style.display="block";
}
else{
menu.className="";
menudiv.style.display="none";
}
}
}
(function() {
function activateFeature(sel) {
$('div.actix-feature').hide();
@ -70,5 +36,3 @@ function setTab(name,cursel){
initFeatureSelector();
});
})();