pub struct Extractor { /* private fields */ }Expand description
Struct that extracts all messages from source code and can print them
to a .pot file.
This file can then be used as a starting point to begin translation.
It should be relatively similar to gettext generated files.
§Example
use crowbook_intl::Extractor;
let mut extractor = Extractor::new();
extractor.add_messages_from_dir("src/").unwrap();
println!("{}", extractor.generate_pot_file());§Note
This struct only add messages that are considered as needing localization,
that is, the first argument of calls so lformat! macro.
Implementations§
Source§impl Extractor
impl Extractor
Sourcepub fn original_strings<'a>(&'a self) -> &'a HashMap<String, String>
pub fn original_strings<'a>(&'a self) -> &'a HashMap<String, String>
Returns a hashmap mapping the original strings (as used by lformat!)
to escaped strings. Only contains strings that are different and
must thus be handled.
Sourcepub fn add_messages_from_file<P: AsRef<Path>>(&mut self, file: P) -> Result<()>
pub fn add_messages_from_file<P: AsRef<Path>>(&mut self, file: P) -> Result<()>
Add all the messages contained in a source file
Sourcepub fn add_messages_from_dir<P: AsRef<Path>>(&mut self, dir: P) -> Result<()>
pub fn add_messages_from_dir<P: AsRef<Path>>(&mut self, dir: P) -> Result<()>
Add messages from all .rs files contained in a directory
(walks through subdirectories)
Sourcepub fn generate_pot_file(&self) -> String
pub fn generate_pot_file(&self) -> String
Generate a pot-like file from the strings extracted from all files (if any)
Sourcepub fn write_pot_file(&mut self, file: &str) -> Result<()>
pub fn write_pot_file(&mut self, file: &str) -> Result<()>
Write a pot-like file to specified location