Extractor

Struct Extractor 

Source
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

Source

pub fn new() -> Extractor

Create a new, empty extractor

Source

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.

Source

pub fn add_messages_from_file<P: AsRef<Path>>(&mut self, file: P) -> Result<()>

Add all the messages contained in a source file

Source

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)

Source

pub fn generate_pot_file(&self) -> String

Generate a pot-like file from the strings extracted from all files (if any)

Source

pub fn write_pot_file(&mut self, file: &str) -> Result<()>

Write a pot-like file to specified location

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.