Skip to content

Commit d40c1a5

Browse files
authored
Merge pull request #108 from Shallowmallow/Locale
Locale
2 parents 4763e16 + b816b7f commit d40c1a5

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/hx/widgets/App.hx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hx.widgets;
22

33
import cpp.Pointer;
4-
import wx.widgets.Locale;
4+
import hx.widgets.Locale;
55
import wx.widgets.App in WxApp;
66
import wx.widgets.WxString;
77

@@ -10,7 +10,7 @@ import wx.widgets.WxString;
1010
#undef RegisterClass
1111
")
1212
class App extends AppConsole {
13-
private var _locale:Pointer<Locale>;
13+
private var locale:Locale;
1414

1515
public static var instance:App;
1616

@@ -22,9 +22,13 @@ class App extends AppConsole {
2222
}
2323

2424
super();
25-
var systemLanguage = Locale.getSystemLanguage();
25+
var systemLanguage = Locale.systemLanguage;
26+
2627
if (systemLanguage != 1) {
27-
_locale = Locale.createInstance(systemLanguage);
28+
locale = new Locale(systemLanguage);
29+
Locale.addCatalogLookupPathPrefix("locale");
30+
locale.addCatalog("wxstd");
31+
untyped __cpp__("setlocale(LC_NUMERIC, \"C\")");
2832
}
2933
//setCLocale();
3034
}
@@ -39,7 +43,7 @@ class App extends AppConsole {
3943
}
4044

4145
public function exit() {
42-
_locale.destroy();
46+
if (locale != null) locale.destroy();
4347
appRef.ptr.exit();
4448
Entry.cleanup();
4549
}

src/hx/widgets/Locale.hx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ package hx.widgets;
22

33
import wx.widgets.Locale in WxLocale;
44
import wx.widgets.WxString;
5+
import cpp.Pointer;
56

6-
class Locale {
7+
class Locale extends Object {
8+
9+
public function new(language:Int) {
10+
if (_ref == null) {
11+
_ref = WxLocale.createInstance(language).reinterpret();
12+
}
13+
}
714

815
public static function getLanguageName(lang:Int):String {
916
var r:WxString = WxLocale.getLanguageName(lang);
@@ -29,5 +36,30 @@ class Locale {
2936
public static function isAvailable(lang:Int):Bool {
3037
return WxLocale.isAvailable(lang);
3138
}
32-
39+
40+
public static function addCatalogLookupPathPrefix(prefix:String):Void {
41+
var s = WxString.createInstance(prefix);
42+
WxLocale.addCatalogLookupPathPrefix(s.ref);
43+
s.destroy();
44+
}
45+
46+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
47+
// Member functions
48+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
49+
50+
public function addCatalog(domain:String):Bool {
51+
var s = WxString.createInstance(domain);
52+
var b = localeRef.ptr.addCatalog(s.ref);
53+
s.destroy();
54+
return b;
55+
}
56+
57+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
58+
// Helpers
59+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
60+
private var localeRef(get, null):Pointer<WxLocale>;
61+
private function get_localeRef():Pointer<WxLocale> {
62+
return _ref.reinterpret();
63+
}
64+
3365
}

src/wx/widgets/Locale.hx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ extern class Locale {
2222
@:native("wxLocale::GetSystemEncodingName") public static function getSystemEncodingName():WxString;
2323
@:native("wxLocale::GetSystemLanguage") public static function getSystemLanguage():Int;
2424
@:native("wxLocale::IsAvailable") public static function isAvailable(lang:Int):Bool;
25-
}
25+
@:native("wxLocale::AddCatalogLookupPathPrefix") public static function addCatalogLookupPathPrefix(prefix:WxString):Void;
26+
@:native("wxLocale::AddCatalog") public function addCatalog(domain:WxString):Bool;
27+
}

0 commit comments

Comments
 (0)