Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ro-RO Translation #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ro-RO/assets/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
practice.rs
156 changes: 156 additions & 0 deletions ro-RO/assets/custom3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
var initAll = function () {
var path = window.location.pathname;
if (path.endsWith("/print.html")) {
return;
}

var images = document.querySelectorAll("main img")
Array.prototype.forEach.call(images, function (img) {
img.addEventListener("click", function () {
BigPicture({
el: img,
});
});
});

// Un-active everything when you click it
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
el.addEventHandler("click", function () {
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
el.classList.remove("active");
});
el.classList.add("active");
});
});

var updateFunction = function () {
var id = null;
var elements = document.getElementsByClassName("header");
Array.prototype.forEach.call(elements, function (el) {
if (window.pageYOffset >= el.offsetTop) {
id = el;
}
});

Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
el.classList.remove("active");
});

Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
if (id == null) {
return;
}
if (id.href.localeCompare(el.href) == 0) {
el.classList.add("active");
}
});
};

var pagetoc = document.getElementsByClassName("pagetoc")[0];
var elements = document.getElementsByClassName("header");
Array.prototype.forEach.call(elements, function (el) {
var link = document.createElement("a");

// Indent shows hierarchy
var indent = "";
switch (el.parentElement.tagName) {
case "H1":
return;
case "H3":
indent = "20px";
break;
case "H4":
indent = "40px";
break;
default:
break;
}

link.appendChild(document.createTextNode(el.text));
link.style.paddingLeft = indent;
link.href = el.href;
pagetoc.appendChild(link);
});
updateFunction.call();

// Handle active elements on scroll
window.addEventListener("scroll", updateFunction);

document.getElementById("theme-list").addEventListener("click", function (e) {
var iframe = document.querySelector('.giscus-frame');
if (!iframe) return;
var theme;
if (e.target.className === "theme") {
theme = e.target.id;
} else {
return;
}

// 若当前 mdbook 主题不是 Light 或 Rust ,则将 giscuz 主题设置为 transparent_dark
var giscusTheme = "light"
if (theme != "light" && theme != "rust") {
giscusTheme = "transparent_dark";
}

var msg = {
setConfig: {
theme: giscusTheme
}
};
iframe.contentWindow.postMessage({ giscus: msg }, 'https://giscus.app');
});

pagePath = pagePath.replace("index.md", "");
pagePath = pagePath.replace(".md", "");
if (pagePath.length > 0) {
if (pagePath.charAt(pagePath.length-1) == "/"){
pagePath = pagePath.substring(0, pagePath.length-1)
}
}else {
pagePath = "index"
}

// add visitors count
var ele = document.createElement("div");
ele.setAttribute("align","center");
var count = document.createElement("img")
// count.setAttribute("src", "https://visitor-badge.glitch.me/badge?page_id=practice/en/" + path);
count.setAttribute("src", "https://api.visitorbadge.io/api/visitors?labelColor=%23595959&countColor=%230d81c3&style=flat-square&path=practice/en/" + path);
ele.appendChild(count);
var divider =document.createElement("hr")

document.getElementById("giscus-container").appendChild(ele);
document.getElementById("giscus-container").appendChild(divider);

// 选取浏览器默认使用的语言
const lang = navigator.language || navigator.userLanguage

// 若当前 mdbook 主题为 Light 或 Rust ,则将 giscuz 主题设置为 light
var theme = "transparent_dark";
const themeClass = document.getElementsByTagName("html")[0].className;
if (themeClass.indexOf("light") != -1 || themeClass.indexOf("rust") != -1) {
theme = "light"
}

var script = document.createElement("script")
script.type = "text/javascript";
script.src = "https://giscus.app/client.js";
script.async = true;
script.crossOrigin = "anonymous";
script.setAttribute("data-repo", "sunface/rust-by-practice");
script.setAttribute("data-repo-id", "MDEwOlJlcG9zaXRvcnkxMjk5OTAzOTY=");
script.setAttribute("data-category", "Book Comments");
script.setAttribute("data-category-id", "DIC_kwDOB79-_M4COQmx");
script.setAttribute("data-mapping", "specific");
script.setAttribute("data-term", pagePath);
script.setAttribute("data-reactions-enabled", "1");
script.setAttribute("data-emit-metadata", "0");
script.setAttribute("data-input-position", "top");
script.setAttribute("data-theme", theme);
script.setAttribute("data-lang", lang == 'en-US' ? 'en' : lang);
// 预先加载评论会更好,这样用户读到那边时,评论就加载好了
// script.setAttribute("data-loading", "lazy");
document.getElementById("giscus-container").appendChild(script);
};

window.addEventListener('load', initAll);
Binary file added ro-RO/assets/header.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ro-RO/assets/header1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions ro-RO/assets/lang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(function () {
var path = window.location.pathname;
var link = "https://practice.rs" + path;
var word = "English";
var lang = "zh-CN";
var changeLang = "切换到英语";

if (window.location.href.indexOf("zh.") == -1) {
link = "https://zh.practice.rs" + path;
word = "简体中文";
lang = "en";
changeLang = "Switch to Chinese"
}

var lang_node = '';
if (link != '') {
lang_node = '<a href="' + link + '" title="' + changeLang + '" aria-label="' + changeLang + '"><i id="change-language-button" class="fa fa-language"> ' + word + '</i></a>';
}

console.log(lang_node)
var insertNode = document.getElementsByClassName('right-buttons');
if (insertNode.length > 0) {
var html = insertNode[0].innerHTML;
insertNode[0].innerHTML = html + lang_node;
}
})()
Binary file added ro-RO/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions ro-RO/assets/temp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# 字符、布尔、单元类型

### 字符
🌟
```rust

use std::mem::size_of_val;
fn main() {
let c1 = 'a';
assert_eq!(size_of_val(&c1),1);

let c2 = '中';
assert_eq!(size_of_val(&c2),3);
}
```

🌟
```rust

fn main() {
let c1 = "中";
print_char(c1);
}

fn print_char(c : char) {
println!("{}", c);
}
```

### 布尔
🌟
```rust

// 让 println! 工作
fn main() {
let _f: bool = false;

let t = true;
if !t {
println!("hello, world");
}
}
```

🌟
```rust

fn main() {
let f = true;
let t = true && false;
assert_eq!(t, f);
}
```


### 单元类型
🌟🌟
```rust

// 让代码工作,但不要修改 `implicitly_ret_unit` !
fn main() {
let _v: () = ();

let v = (2, 3);
assert_eq!(v, implicitly_ret_unit())
}

fn implicitly_ret_unit() {
println!("I will returen a ()")
}

// 不要使用下面的函数,它只用于演示!
fn explicitly_ret_unit() -> () {
println!("I will returen a ()")
}
```

🌟🌟 单元类型占用的内存大小是多少?
```rust

// 让代码工作:修改 `assert!` 中的 `4`
use std::mem::size_of_val;
fn main() {
let unit: () = ();
assert!(size_of_val(&unit) == 4);
}
```
22 changes: 22 additions & 0 deletions ro-RO/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[book]
title = "Rust prin practică"
description = "Learn Rust with Example, Exercise and real Practice, written with ❤️ by https://course.rs team"
authors = ["sunface, https://im.dev"]
language = "en"

[output.html.playpen]
editable = true
editor = "ace"

[output.html.fold]
enable = true
level = 1

[output.html]
additional-css = ["theme/style1.css"]
additional-js = ["assets/custom3.js","assets/lang.js"]
git-repository-url = "https://github.com/sunface/rust-by-practice"
edit-url-template = "https://github.com/sunface/rust-by-practice/edit/master/ro-RO/{path}"

[rust]
edition = "2021"
23 changes: 23 additions & 0 deletions ro-RO/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## this script deploys the static website of course.rs to github pages

## build static website for book
mdbook build
## copy CNAME info to book dir
cp ./assets/CNAME ./book/

## init git repo
cd book
git init
git config user.name "sunface"
git config user.email "cto@188.com"
git add .
git commit -m 'deploy'
git branch -M gh-pages
git remote add origin https://github.com/sunface/rust-by-practice

## push to github pages
git push -u -f origin gh-pages

## deploy zh-CN
cd ../../zh-CN
./deploy
1 change: 1 addition & 0 deletions ro-RO/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book
Loading