From 20888bc58b8441bf399a83d612b18e9e3067daf4 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 24 Jun 2018 23:03:40 +0200 Subject: [PATCH] Attempt to clean up the multilingual setup --- config.toml | 15 ++-- i18n/cn.toml | 8 ++ i18n/en.toml | 8 ++ layouts/index.cn.html | 149 +++++++++++++++++++++++++++++++++++ layouts/index.html | 148 +--------------------------------- layouts/partials/header.html | 50 +++--------- static/css/actix.css | 56 ++++++++----- static/js/actix.js | 36 --------- 8 files changed, 221 insertions(+), 249 deletions(-) create mode 100644 i18n/cn.toml create mode 100644 i18n/en.toml create mode 100644 layouts/index.cn.html diff --git a/config.toml b/config.toml index 154dd23..e574e1c 100644 --- a/config.toml +++ b/config.toml @@ -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] diff --git a/i18n/cn.toml b/i18n/cn.toml new file mode 100644 index 0000000..86f2acf --- /dev/null +++ b/i18n/cn.toml @@ -0,0 +1,8 @@ +[home] +other = "首页" +[docs] +other = "文档" +[community] +other = "社区" +[code] +other = "源码" diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 0000000..9fddc1f --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,8 @@ +[home] +other = "Home" +[docs] +other = "Documentation" +[community] +other = "Community" +[code] +other = "Code" diff --git a/layouts/index.cn.html b/layouts/index.cn.html new file mode 100644 index 0000000..bb5e631 --- /dev/null +++ b/layouts/index.cn.html @@ -0,0 +1,149 @@ +{{ partial "header" . }} + +
+
+
+ +

Rust强大的actor系统和有趣的web框架

+
+
+ +
+
+
+
+

+ + 类型安全 +

+

忘记关于字符串类型的对象,从请求到响应,一切都有类型,异步。

+ +

+ + 特性丰富 +

+

Actix提供了丰富的特性开箱即用。WebSockets,HTTP/2,流,管道,SSL,异步HTTTP客户端等一应俱全.

+ +

+ + 扩展性强 +

+

轻松创建任何基于Actix应用的自己的特色库。

+ +

+ + 速度极快 +

+

Actix 具有顶级的速度. Check yourself.

+
+
+
+
+ {{ 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" "" }} +
+
+
+ + +
+
+
+

灵活的请求响应

+

+ Actix中的Handler函数可以返回实现该Respondert rait的各种对象。这使得从API返回一致的响应变得轻而易举。 +

+ {{ 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" "" }} +
+
+

强大的Extractors

+

+ Actix提供了一个强大的提取器系统,可以从传入的HTTP请求中提取数据并将其传递给您的视图函数。这不仅可以创建方便的API, + 而且还意味着您的视图函数可以是同步代码,并且仍然可以受益于异步IO处理。 +

+ {{ highlight `#[derive(Deserialize)] +struct Event { + timestamp: f64, + kind: String, + tags: Vec, +} + +fn capture_event(evt: Json) -> impl Responder { + let id = store_event_in_db(evt.timestamp, evt.kind, evt.tags); + format!("got event {}", id) +}` "rust" "" }} +
+
+

轻松处理表单

+

+ 处理multipart/ urlencoded表单数据很容易。只需定义一个可以反序列化的结构,actix就可以处理剩下的部分。 +

+ {{ highlight `#[derive(Deserialize)] +struct Register { + username: String, + country: String, +} + +fn register(data: Form) -> impl Responder { + format!("Hello {} from {}!", data.username, data.country) +}` "rust" "" }} +
+
+

请求路由

+

+ 一个actix应用程序带有一个URL路由系统,可以让你在URL上匹配并调用单个处理程序。为了获得额外的灵活性,可以使用域。 +

+ {{ highlight `fn index(req: HttpRequest) -> impl Responder { + "Hello from the index page" +} + +fn hello(path: Path) -> 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" "" }} +
+
+ + +
+
+
+ + +{{ partial "footer" . }} diff --git a/layouts/index.html b/layouts/index.html index 90f6ed0..55c5bbd 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -34,7 +34,7 @@ Blazingly Fast -

Actix is blazingly fast. Check yourself.

+

Actix is blazingly fast. See for yourself.

@@ -155,150 +155,4 @@ fn main() {
-
-
-
- -

Rust强大的actor系统和有趣的web框架

-
-
- -
-
-
-
-

- - 类型安全 -

-

忘记关于字符串类型的对象,从请求到响应,一切都有类型,异步。

- -

- - 特性丰富 -

-

Actix提供了丰富的特性开箱即用。WebSockets,HTTP/2,流,管道,SSL,异步HTTTP客户端等一应俱全.

- -

- - 扩展性强 -

-

轻松创建任何基于Actix应用的自己的特色库。

- -

- - 速度极快 -

-

Actix 具有顶级的速度. Check yourself.

-
-
-
-
- {{ 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" "" }} -
-
-
- - -
- -
-
-

灵活的请求响应

-

- Actix中的Handler函数可以返回实现该Respondert rait的各种对象。这使得从API返回一致的响应变得轻而易举。 -

- {{ 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" "" }} -
- - - -
- -
    -
  • 灵活的请求响应
  • -
  • 强大的Extractors
  • -
  • 轻松处理表单
  • -
  • 请求路由
  • -
-
- -
-
- - {{ partial "footer" . }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index f80692e..54467fe 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -28,55 +28,29 @@ diff --git a/static/css/actix.css b/static/css/actix.css index 3ebb6de..277b5c4 100644 --- a/static/css/actix.css +++ b/static/css/actix.css @@ -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%; } -} \ No newline at end of file +} diff --git a/static/js/actix.js b/static/js/actix.js index 0aa4782..ef2cb66 100644 --- a/static/js/actix.js +++ b/static/js/actix.js @@ -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(); }); })(); - -