Translation support + french.

This commit is contained in:
Greg Burri 2025-01-06 16:04:48 +01:00
parent e9873c1943
commit f059d3c61f
16 changed files with 380 additions and 169 deletions

View file

@ -9,15 +9,21 @@ use crate::consts;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Clone)]
pub enum Sentence {
ProfileTitle,
MainTitle,
CreateNewRecipe,
UnpublishedRecipes,
UntitledRecipe,
Name,
EmailAddress,
Password,
SignOut,
Save,
NotLoggedIn,
DatabaseError,
// Sign in page.
SignInMenu,
SignInTitle,
@ -28,6 +34,11 @@ pub enum Sentence {
SignUpMenu,
SignUpTitle,
SignUpButton,
SignUpEmailSent,
SignUpFollowEmailLink,
SignUpEmailValidationSuccess,
SignUpValidationExpired,
SignUpValidationErrorTryAgain,
ChooseAPassword,
ReEnterPassword,
AccountMustBeValidatedFirst,
@ -37,9 +48,38 @@ pub enum Sentence {
EmailAlreadyTaken,
UnableToSendEmail,
// Validation.
ValidationSuccessful,
ValidationExpired,
ValidationErrorTryToSignUpAgain,
ValidationError,
ValidationUserAlreadyExists,
// Reset password page.
LostPassword,
AskResetButton,
AskResetAlreadyLoggedInError,
AskResetEmailAlreadyResetError,
AskResetFollowEmailLink,
AskResetEmailSent,
AskResetTokenMissing,
AskResetTokenExpired,
PasswordReset,
EmailUnknown,
UnableToSendResetEmail,
// Profile
ProfileTitle,
ProfileEmail,
ProfileNewPassword,
ProfileFollowEmailLink,
ProfileEmailSent,
ProfileSaved,
// Recipe.
RecipeNotAllowedToEdit,
RecipeNotAllowedToView,
RecipeNotFound,
}
#[derive(Clone)]
@ -74,7 +114,7 @@ impl Tr {
}
}
pub fn tp(&self, sentence: Sentence, params: &[Box<dyn ToString>]) -> String {
pub fn tp(&self, sentence: Sentence, params: &[Box<dyn ToString + Send>]) -> String {
match self.lang.translation.get(&sentence) {
Some(str) => {
let mut result = str.clone();
@ -90,6 +130,10 @@ impl Tr {
}
}
pub fn current_lang_code(&self) -> &str {
&self.lang.code
}
pub fn available_languages() -> Vec<(&'static str, &'static str)> {
TRANSLATIONS
.iter()