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

Fix localisation stipping in GTK, X11 and macos #1870

Merged
merged 5 commits into from
Jul 16, 2021

Conversation

JAicewizard
Copy link
Contributor

@JAicewizard JAicewizard commented Jul 11, 2021

on macos we already strip the modifiers, this extends this to all backends and also stripping the charset.

fixes #1864

@JAicewizard JAicewizard changed the title Fix localisation stipping in GTK and X11 Fix localisation stipping in GTK, X11 and macos Jul 11, 2021
@@ -778,14 +778,18 @@ impl Application {

// from gettext manual
// https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables
var_non_empty("LANGUAGE")
let mut locale = var_non_empty("LANGUAGE")
Copy link

@ColinPitrat ColinPitrat Jul 11, 2021

Choose a reason for hiding this comment

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

Would it be possible to make var_non_empty log some info (ideally at some verbose level if such a thing is available). It can be useful to the user to know which var is used and which value it has. Currently if the variable cannot be parse you just see "en_US". This could be in a different PR of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will leave this open for whoever is doing the final review. It does hinder readability but I can see its usefulness.

Copy link
Member

Choose a reason for hiding this comment

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

I think this would be welcome, but I'd make it a separate PR.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

@ColinPitrat can you confirm that this fixes the original issue? It looks like it should, but would like to be sure.

@@ -84,7 +84,12 @@ impl Application {
}

pub fn get_locale() -> String {
glib::get_language_names()[0].as_str().into()
let mut locale: String = glib::get_language_names()[0].as_str().into();
Copy link
Member

Choose a reason for hiding this comment

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

this index would panic if there get_language_names() is empty. Is that possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Computes a list of applicable locale names, which can be used to e.g. construct locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale "C".

If druid fails to parse the locale it will be "en_US" so this should work in all cases.

@@ -111,7 +111,8 @@ impl Application {
let locale: id = msg_send![nslocale_class, currentLocale];
let ident: id = msg_send![locale, localeIdentifier];
let mut locale = util::from_nsstring(ident);
if let Some(idx) = locale.chars().position(|c| c == '@') {
// This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale
if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is okay as-is, because macOS doesn't include encoding in the locale?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldnt find any documentation on this. Having the code be the same across the backends seems nice to me. It hasnt caused any problems so far so it should indeed be fine without.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left the comment in since I think it still applies and is helpful

@@ -778,14 +778,18 @@ impl Application {

// from gettext manual
// https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables
var_non_empty("LANGUAGE")
let mut locale = var_non_empty("LANGUAGE")
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be welcome, but I'd make it a separate PR.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@cmyr cmyr merged commit 173b560 into linebender:master Jul 16, 2021
maan2003 added a commit that referenced this pull request Jul 16, 2021
thanks @ColinPitrat

#1870 (comment)

Also changed the name and made it a function
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 fails with .utf8 suffixed locales
3 participants