@@ -57,20 +57,25 @@ defmodule Desktop do
57
57
# Preferring a full match 'xx_xx' == 'yy_yy'
58
58
best_match = Enum . find ( known_locales , fn l -> String . downcase ( l ) == language_code end )
59
59
60
- if best_match != nil do
61
- put_default_locale ( best_match )
62
- else
63
- # Looking for a prefix match 'xx' == 'yy'
64
- prefix = binary_part ( language_code , 0 , 2 )
60
+ cond do
61
+ best_match != nil ->
62
+ put_default_locale ( best_match )
63
+
64
+ # We have seen windows return an empty string for language_code
65
+ byte_size ( language_code ) >= 2 ->
66
+ # Looking for a prefix match 'xx' == 'yy'
67
+ prefix = binary_part ( language_code , 0 , 2 )
68
+
69
+ prefix_match =
70
+ Enum . find ( known_locales , fn l -> String . starts_with? ( String . downcase ( l ) , prefix ) end )
65
71
66
- prefix_match =
67
- Enum . find ( known_locales , fn l -> String . starts_with? ( String . downcase ( l ) , prefix ) end )
72
+ if prefix_match != nil do
73
+ put_default_locale ( prefix_match )
74
+ end
68
75
69
- if prefix_match != nil do
70
- put_default_locale ( prefix_match )
71
- else
76
+ true ->
72
77
# we're giving up, not updating the default locale
73
- end
78
+ nil
74
79
end
75
80
end
76
81
@@ -89,7 +94,8 @@ defmodule Desktop do
89
94
_ ->
90
95
:wx . set_env ( Desktop.Env . wx_env ( ) )
91
96
locale = :wxLocale . new ( :wxLocale . getSystemLanguage ( ) )
92
- # this is in the form "xx_XX"
97
+ # This is in the form "xx_XX"
98
+ # we have seen windows returns an empty string though...
93
99
:wxLocale . getCanonicalName ( locale ) |> List . to_string ( ) |> String . downcase ( )
94
100
end
95
101
end
0 commit comments