Skip to content

Commit

Permalink
feat(cli): Add language parameter and parse for supported languages
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Apr 27, 2020
1 parent 2a76465 commit afea579
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions resources/en-US/cli.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ flags-verbose =
subcommand-make =
Executes a make target
flags-language =
Set language
subcommand-make-target =
Target as defined in CaSILE makefile
Expand Down
27 changes: 27 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use fluent_langneg::{
accepted_languages, convert_vec_str_to_langids_lossy, negotiate_languages, NegotiationStrategy,
};
use fluent_resmgr::resource_manager::ResourceManager;
use git2::Repository;
use regex::Regex;
use std::fs;
use std::io;
use std::io::{Error, ErrorKind};
use std::path;
use std::vec;
use structopt::clap::AppSettings;
use structopt::StructOpt;
use unic_langid::LanguageIdentifier;

/// The command line interface to the CaSILE toolkit, a book publishing
/// workflow employing SILE and other wizardry
Expand All @@ -17,6 +23,10 @@ struct Cli {
#[structopt(short, long, env = "DEBUG")]
debug: bool,

/// Set language
#[structopt(short, long, env = "LANG")]
language: String,

/// Outputs verbose feedback where possible
#[structopt(short, long)]
verbose: bool,
Expand Down Expand Up @@ -56,6 +66,23 @@ fn main() -> io::Result<()> {
println!("User requested verbose output")
}

// TODO: scan i18n dir(s) at run time for available languages
let available = convert_vec_str_to_langids_lossy(&["en_US", "tr_TR"]);

let re = Regex::new(r"\..*$").unwrap();
let input = re.replace(&args.language, "");
let requested = accepted_languages::parse(&input);
let default: LanguageIdentifier = "en-US".parse().unwrap();

let language = negotiate_languages(
&requested,
&available,
Some(&default),
NegotiationStrategy::Filtering,
);

println!("Lang ended up {:?}", language[0]);

match args.subcommand {
Subcommand::Make { target } => make(target),
Subcommand::Setup { path } => setup(path),
Expand Down

0 comments on commit afea579

Please sign in to comment.