Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

flawphobic
Copy link

@flawphobic flawphobic commented May 21, 2021

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:

  • Added a localization module containing the Localization struct and Language enum
  • Localization has methods pertaining to the language to localize into. For example, malay() returns a copy of Localization with all fields filled with Bahasa Malaysia texts; English is a bit special as it is covered by the default()
  • Context now has a localization field that stores Localization
  • Context can be used to set localization by using it in tandem with the Language enum
  • Added new_language as a field in Memory; it works similarly (I think) to new_font_definitions and new_pixels_per_point wherein if available, it'll set the new language at the start of the next frame
  • Localization 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 satisfactory
  • Updated the demo to include a language switcher (I might add a GIF to illustrate this)

My concerns:

  • I'm not familiar with mutexes, shared references, and the likes so it's very likely that a lot of my codes will be non-idiomatic
  • To overcome some snags with shared references, I used clone(); not sure if that's a good idea
  • No documentations/tests for now. I'll add them if this PR has the potential to be merged

@flawphobic flawphobic changed the title Localization starter Localization of Widgets strings May 21, 2021
/// Specifies the languages currently available for localization and is required by [`crate::Context::set_localization`] as the parameter type.
pub enum Language {
English,
BahasaMalaysia,
Copy link
Owner

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.

Copy link
Owner

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")

Copy link
Contributor

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>,
Copy link
Owner

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn set_localization(&self, lang: Language) {
pub fn set_localization(&self, localization: Localization) {

@emilk
Copy link
Owner

emilk commented Dec 28, 2021

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:

  • ctx.help_texts().drag_value = "Click to edit value";
  • ctx.help_texts().drag_value = "Klicka för att skriva in ett värde"; // if you are Swedish
  • ctx.help_texts().drag_value = ""; // show nothing

@emilk emilk closed this Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Localization of egui strings
3 participants