-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding localisation logic #49
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||
use { | ||||||
serde::{ | ||||||
Deserialize, | ||||||
Serialize, | ||||||
}, std::fmt | ||||||
}; | ||||||
|
||||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, clap::ValueEnum)] | ||||||
#[clap(rename_all = "lower")] | ||||||
pub enum Locale { | ||||||
#[default] | ||||||
EN, | ||||||
FR, | ||||||
} | ||||||
|
||||||
impl Locale { | ||||||
pub const ALL: [Locale; 2] = [ | ||||||
Locale::EN, | ||||||
Locale::FR, | ||||||
]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of hardcoding this list, I recommend deriving |
||||||
|
||||||
pub fn message(&self, message: Message) -> &str { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support formatted strings, a good tradeoff between convenience and performance is the
Suggested change
You can then use |
||||||
match message { | ||||||
Message::InstallerReopenUAC => { //used in installer | ||||||
match self { | ||||||
Locale::EN => "The installer has been reopened with admin permissions. Please continue there.", | ||||||
Locale::FR => "L'installateur a été ré-ouvert avec les permissions administrateur. Veuillez continuer dans la nouvelle fenêtre.", | ||||||
} | ||||||
}, | ||||||
Message::OpenPj64Button => { // used in gui | ||||||
match self { | ||||||
Locale::EN => "Open Project64", | ||||||
Locale::FR => "Ouvrir Project64" | ||||||
} | ||||||
}, | ||||||
// TODO find a way to translate formatted text somehow | ||||||
//Message::AMessageWithParameter(my_int, my_string) => { | ||||||
// match self { | ||||||
// Locale::EN => format!("My integer is: {} and my string is: {}",my_int,my_string).as_str(), | ||||||
// Locale::FR => format!("My integer is: {} and my string is: {}",my_int,my_string).as_str(), | ||||||
// } | ||||||
//} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
impl fmt::Display for Locale { | ||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
match self { | ||||||
// add local formating for display | ||||||
Self::EN => write!(f, "English"), | ||||||
Self::FR => write!(f, "Français"), | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
pub enum Message { | ||||||
InstallerReopenUAC, | ||||||
OpenPj64Button, | ||||||
//AMessageWithParameter(i32,String), | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This text should probably be kept as simple as possible, so someone with minimal knowledge of English can understand it: