localization
This commit is contained in:
parent
f3710d26f3
commit
d2e587cf42
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -105,7 +105,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dokugile"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"colorize",
|
||||
"dirs",
|
||||
|
@ -1,11 +1,11 @@
|
||||
_version: 1
|
||||
msg_01: 'Project name'
|
||||
msg_02: 'Project folder'
|
||||
msg_03: 'is the new location you are going to create. Is that okay?(y/n)[Y]'
|
||||
msg_04: 'has been created'
|
||||
msg_05: 'not found. Do you want to create it?(y/n)[Y]'
|
||||
msg_06: 'Now you can edit index.md file and create content'
|
||||
msg_07: 'found'
|
||||
Project name: 'Project name'
|
||||
Project location: 'Project location'
|
||||
Do you want to create a new location called %{s} for the documents?(y/n)[Y]: 'Do you want to create a new location called %{s} for the documents?(y/n)[Y]'
|
||||
Location %{s} has been created: 'Location %{s} has been created'
|
||||
The project %{s} has not been found. Do you want to create it?(y/n)[Y]: 'The project %{s} has not been found. Do you want to create it?(y/n)[Y]'
|
||||
Project %{s} has been created. Now you can edit index.md file and create content: 'Project %{s} has been created. Now you can edit index.md file and create content'
|
||||
found... %{s}: 'found... %{s}'
|
||||
msg_08: 'No markdown files found!'
|
||||
msg_09: 'Please edit first your documents in markdown format and come back to convert them to html. Bye!'
|
||||
msg_10: 'Processed markdown files'
|
||||
|
@ -1,11 +1,11 @@
|
||||
_version: 1
|
||||
msg_01: 'Proiektuaren izena'
|
||||
msg_02: 'Proiektuaren kokapena'
|
||||
msg_03: 'dokumentuentzako kokapen berria sortu nahi duzu?(b/e)[B]'
|
||||
msg_04: 'kokapena sortu da'
|
||||
msg_05: 'proiektua ez da aurkitu. Sortu egin nahi duzu?(b/e)[B]'
|
||||
msg_06: 'Orain index.md fitxategia editatu eta edukiak sor ditzakezu'
|
||||
msg_07: 'aurkitua'
|
||||
Project name: 'Proiektuaren izena'
|
||||
Project location: 'Proiektuaren kokapena'
|
||||
Do you want to create a new location called %{s} for the documents?(y/n)[Y]: 'Dokumentuentzako %{s} izeneko kokapen berria sortu nahi duzu?(b/e)[B]'
|
||||
Location %{s} has been created: '%{s} kokapena sortu da'
|
||||
The project %{s} has not been found. Do you want to create it?(y/n)[Y]: '%{s} proiektua ez da aurkitu. Sortu egin nahi duzu?(b/e)[B]'
|
||||
Project %{s} has been created. Now you can edit index.md file and create content: '%{s} proiektua sortu da. Orain index.md fitxategia editatu eta edukiak sor ditzakezu'
|
||||
found... %{s}: 'aurkitua... %{s}'
|
||||
msg_08: 'Ez da markdown fitxategirik aurkitu!'
|
||||
msg_09: 'Mesedez editatu lehenbizi zure dokumentuak markdown formatuan eta itzuli html-ra itzultzeko. Aioo!'
|
||||
msg_10: 'Prozesaturiko markdown fitxategiak'
|
||||
|
45
src/main.rs
45
src/main.rs
@ -9,7 +9,6 @@ use colorize::AnsiColor;
|
||||
use dirs;
|
||||
use pandoc::PandocError;
|
||||
use dokugile::template;
|
||||
use std::env;
|
||||
use rust_i18n::t;
|
||||
|
||||
rust_i18n::i18n!("locales");
|
||||
@ -33,6 +32,19 @@ impl Project {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
/*
|
||||
let default = String::from("en_US"); // default locale
|
||||
let locales = rust_i18n::available_locales!(); // available locales
|
||||
let lang:String = match env::var("LANG") { // find out user's lang
|
||||
Ok(val) => match val {
|
||||
v if !v.is_empty() && locales.iter().any(|e| v.contains(e)) => v[..5].to_string(),
|
||||
_ => default
|
||||
} ,
|
||||
Err(..) => default,
|
||||
};
|
||||
rust_i18n::set_locale(&lang); // set user lang
|
||||
*/
|
||||
let _ = set_lang();
|
||||
let mut wiki_path = String::new();
|
||||
let mut doc_path = String::new();
|
||||
let mut doc_title = String::new();
|
||||
@ -42,7 +54,7 @@ fn main() {
|
||||
while !Path::new(&doc_path).exists() || doc_title.trim().is_empty(){
|
||||
doc_path = String::new();
|
||||
let mut input = String::new();
|
||||
println!("Proiektuaren izena: ");
|
||||
println!("{}:", t!("Project name"));
|
||||
io::stdin().read_line(&mut input).expect("Failed to read line");
|
||||
let root = env::var("HOME").unwrap().to_string()+"/";
|
||||
let user_documents_path = dirs::document_dir().unwrap().display().to_string();
|
||||
@ -50,20 +62,22 @@ fn main() {
|
||||
|
||||
while !Path::new(&wiki_path).exists() {
|
||||
let mut project_dir = String::new();
|
||||
println!("Proiektuaren kokapena:[{}/Wiki] ", &user_doc_dir);
|
||||
println!("{}:[{}/Wiki] ", t!("Project location"), &user_doc_dir);
|
||||
io::stdin().read_line(&mut project_dir).expect("Failed to read line");
|
||||
if project_dir.trim().is_empty() { project_dir = String::from(user_doc_dir.clone()+"/Wiki") };
|
||||
wiki_path = root.clone()+project_dir.trim();
|
||||
|
||||
if !Path::new(&wiki_path).exists(){
|
||||
let mut ans = String::new();
|
||||
println!("{} dokumentuentzako kokapen berria sortu nahi duzu?(y/n)[Y]", &project_dir.trim().to_owned().green().bold());
|
||||
//println!("{} dokumentuentzako kokapen berria sortu nahi duzu?(y/n)[Y]", &project_dir.trim().to_owned().green().bold());
|
||||
println!("{}", t!("Do you want to create a new location called %{s} for the documents?(y/n)[Y]", s = &project_dir.trim().to_owned().green().bold()));
|
||||
io::stdin().read_line(&mut ans).expect("Failed to read line");
|
||||
if ans.trim().is_empty() { ans = String::from("Y") };
|
||||
match ans.trim() {
|
||||
"y" | "yes" | "Y" | "B" | "Bai" => { //let _ = fs::create_dir(&wiki_path);
|
||||
let _ = mkdir(&wiki_path);
|
||||
println!("{} kokapena sortu da.", &project_dir.trim().to_owned().green().bold());
|
||||
//println!("{} kokapena sortu da.", &project_dir.trim().to_owned().green().bold());
|
||||
println!("{}.", t!("Location %{s} has been created", s = &project_dir.trim().to_owned().green().bold()));
|
||||
},
|
||||
_ => continue,
|
||||
};
|
||||
@ -87,7 +101,7 @@ fn main() {
|
||||
if !Path::new(&doc_path).exists() || !Path::new(&res_path).exists(){
|
||||
let mut ans = String::new();
|
||||
if !Path::new(&doc_path).exists() {
|
||||
println!("{} proiektua ez da aurkitu. Sortu egin nahi duzu?(y/n)[Y]", &input.trim().to_owned().green().bold());
|
||||
println!("{}", t!("The project %{s} has not been found. Do you want to create it?(y/n)[Y]", s = &input.trim().to_owned().green().bold()));
|
||||
io::stdin().read_line(&mut ans).expect("Failed to read line");
|
||||
}
|
||||
if ans.trim().is_empty() { ans = String::from("Y") };
|
||||
@ -123,8 +137,9 @@ fn main() {
|
||||
};
|
||||
}
|
||||
}
|
||||
println!("{} proiektua sortu da. Orain index.md fitxategia editatu eta edukiak \
|
||||
sor ditzakezu", &input.trim().to_owned().green().bold());
|
||||
//println!("{} proiektua sortu da. Orain index.md fitxategia editatu eta edukiak \
|
||||
// sor ditzakezu", &input.trim().to_owned().green().bold());
|
||||
println!("{}.", t!("Project %{s} has been created. Now you can edit index.md file and create content", s = &input.trim().to_owned().green().bold()));
|
||||
},
|
||||
_ => continue,
|
||||
};
|
||||
@ -186,7 +201,7 @@ fn processing(project: Project) -> Result<String, String>{
|
||||
match extension {
|
||||
"md" => {
|
||||
//md_count += 1;
|
||||
println!("found: {}", entry.path().display());
|
||||
println!("{}", t!("found... %{s}", s = entry.path().display()));
|
||||
let conv = md_to_html(entry.path(), &project.doc_title, &project.output_dir, &project.wiki_path);
|
||||
match conv {
|
||||
Ok(()) => md_count += 1,
|
||||
@ -270,3 +285,15 @@ fn sanitize(index: &Path){
|
||||
};
|
||||
}
|
||||
|
||||
fn set_lang(){
|
||||
let default = String::from("en_US"); // default locale
|
||||
let locales = rust_i18n::available_locales!(); // available locales
|
||||
let lang:String = match env::var("LANG") { // find out user's lang
|
||||
Ok(val) => match val {
|
||||
v if !v.is_empty() && locales.iter().any(|e| v.contains(e)) => v[..5].to_string(),
|
||||
_ => default
|
||||
} ,
|
||||
Err(..) => default,
|
||||
};
|
||||
rust_i18n::set_locale(&lang); // set user lang
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user