Skip to content

i18n in Yew #2924

Answered by CodingTil
CodingTil asked this question in Q&A
Oct 15, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

By the way, I kinda solved this for my use case, using Context Providers:

# localization.rs
use core::fmt::Display;

use stylist::yew::styled_component;
use yew::html::ImplicitClone;
use yew::prelude::*;

use std::default::Default;

#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Localization {
	DE,
	EN,
}

impl Default for Localization {
	fn default() -> Self {
		Localization::EN
	}
}

impl Display for Localization {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		match self {
			Localization::DE => write!(f, "Deutsch"),
			Localization::EN => write!(f, "English"),
		}
	}
}

impl ImplicitClone for Localization {}

#[derive(Debug, Clone)]
pub(crate) struct Local…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@CodingTil
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by CodingTil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants