-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Localization of Widgets strings #426
Conversation
/// Specifies the languages currently available for localization and is required by [`crate::Context::set_localization`] as the parameter type. | ||
pub enum Language { | ||
English, | ||
BahasaMalaysia, |
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.
Do we need this list? Can't the user just call context.set_localization(Localization::malay());
instead? That way it is also easy for a user to add a new language without having to make a PR to egui.
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.
Localization::lang
could be changed to &'static str
too (e.g. "english")
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.
Localization::lang
could be changed to&'static str
too (e.g. "english")
Agree, some clarification: <language code>[_<territory code>]
should be used (en
, en_US
and so on)
@@ -53,6 +56,9 @@ pub struct Memory { | |||
/// new fonts that will be applied at the start of the next frame | |||
pub(crate) new_font_definitions: Option<epaint::text::FontDefinitions>, | |||
|
|||
/// new language that will be applied at the start of the next frame | |||
pub(crate) new_language: Option<Language>, |
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.
No need for this - let's make it instant instead.
/// Sets the current language of the default texts within [`crate::widgets`] and [`crate::containers`]. | ||
/// | ||
/// The languages available for localization can be seen in [`crate::localization::Language`]. | ||
pub fn set_localization(&self, lang: Language) { |
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.
pub fn set_localization(&self, lang: Language) { | |
pub fn set_localization(&self, localization: Localization) { |
I think perhaps we should instead remove strings from egui (like we did in #704) instead of going down this path, or let the user set the egui helper string directly, i.e. something like this, where the user of egui choses what goes where:
|
Closes #136.
I'm in the middle of something right now so my write-up will be limited.
Not sure if I'm doing anything right to be honest but here's the gist of it:
Localization
struct andLanguage
enumLocalization
has methods pertaining to the language to localize into. For example,malay()
returns a copy ofLocalization
with all fields filled with Bahasa Malaysia texts; English is a bit special as it is covered by thedefault()
Context
now has alocalization
field that storesLocalization
Context
can be used to set localization by using it in tandem with theLanguage
enumnew_language
as a field inMemory
; it works similarly (I think) tonew_font_definitions
andnew_pixels_per_point
wherein if available, it'll set the new language at the start of the next frameLocalization
struct supports two localized texts - English and Bahasa Malaysia. However, the extent of localization is only for the color picker widget; I'll add more if the current code is satisfactoryMy concerns:
clone()
; not sure if that's a good idea