|
|
@ -11,15 +11,15 @@ use command_runner::CommandRunner; |
|
|
|
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
|
|
|
use resources::Resource;
|
|
|
|
|
|
|
|
pub struct WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: 'a + CommandRunner {
|
|
|
|
pub struct WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: 'a + CommandRunner {
|
|
|
|
path: D,
|
|
|
|
version: &'a str,
|
|
|
|
locale: C,
|
|
|
|
command_runner: &'a R
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str> + fmt::Display, R: CommandRunner {
|
|
|
|
pub fn new<D: AsRef<str> + fmt::Display>(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
|
|
|
|
impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str>, R: CommandRunner {
|
|
|
|
pub fn new<D: AsRef<str>>(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
|
|
|
|
WordpressTranslation {
|
|
|
|
path: Path::new(path.as_ref()).join("wp-content/languages").to_string_lossy().to_string(),
|
|
|
|
version: version,
|
|
|
@ -29,7 +29,7 @@ impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str> + fmt: |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {
|
|
|
|
impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
|
|
|
|
fn get_pairs(&self) -> Vec<(String, String)> {
|
|
|
|
let version_x = self.version.trim_right_matches(|c: char| c.is_digit(10)).to_owned() + "x";
|
|
|
|
let locale: &str = self.locale.as_ref();
|
|
|
@ -39,7 +39,7 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::D |
|
|
|
for format in ["po", "mo"].into_iter() {
|
|
|
|
res.push((
|
|
|
|
format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format),
|
|
|
|
format!("{}/{}{}.{}", self.path, out_slug, self.locale, format)
|
|
|
|
format!("{}/{}{}.{}", self.path.as_ref(), out_slug, self.locale.as_ref(), format)
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -47,7 +47,7 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::D |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {
|
|
|
|
impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
|
|
|
|
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
|
|
let mut newest = String::new();
|
|
|
|
let match_date = Regex::new("(?m)^\"PO-Revision-Date: (.+)\\+0000\\\\n\"$").unwrap();
|
|
|
@ -72,8 +72,8 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st |
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let upstream = try!(self.command_runner.get_output("curl", &[&format!("https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale)]));
|
|
|
|
Ok(try!(String::from_utf8(upstream)).contains(&format!(r###"language":"{}","version":"{}","updated":"{}"###, self.locale, self.version, newest)))
|
|
|
|
let upstream = try!(self.command_runner.get_output("curl", &[&format!("https://api.wordpress.org/core/version-check/1.7/?version={}&locale={}", self.version, self.locale.as_ref())]));
|
|
|
|
Ok(try!(String::from_utf8(upstream)).contains(&format!(r###"language":"{}","version":"{}","updated":"{}"###, self.locale.as_ref(), self.version, newest)))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn execute(&self) -> Result<(), Box<Error>> {
|
|
|
@ -96,9 +96,9 @@ impl<'a, C, D, R> Symbol for WordpressTranslation<'a, C, D, R> where C: AsRef<st |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, C, D, R> fmt::Display for WordpressTranslation<'a, C, D, R> where C: AsRef<str> + fmt::Display, D: AsRef<str> + fmt::Display, R: CommandRunner {
|
|
|
|
impl<'a, C, D, R> fmt::Display for WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRef<str>, R: CommandRunner {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>{
|
|
|
|
write!(f, "WordpressTranslation {}", self.path)
|
|
|
|
write!(f, "WordpressTranslation {}", self.path.as_ref())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|