Skip to content

Commit

Permalink
Merge pull request #108 from Shallowmallow/Locale
Browse files Browse the repository at this point in the history
Locale
  • Loading branch information
ianharrigan authored Oct 7, 2024
2 parents 4763e16 + b816b7f commit d40c1a5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/hx/widgets/App.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hx.widgets;

import cpp.Pointer;
import wx.widgets.Locale;
import hx.widgets.Locale;
import wx.widgets.App in WxApp;
import wx.widgets.WxString;

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

public static var instance:App;

Expand All @@ -22,9 +22,13 @@ class App extends AppConsole {
}

super();
var systemLanguage = Locale.getSystemLanguage();
var systemLanguage = Locale.systemLanguage;

if (systemLanguage != 1) {
_locale = Locale.createInstance(systemLanguage);
locale = new Locale(systemLanguage);
Locale.addCatalogLookupPathPrefix("locale");
locale.addCatalog("wxstd");
untyped __cpp__("setlocale(LC_NUMERIC, \"C\")");
}
//setCLocale();
}
Expand All @@ -39,7 +43,7 @@ class App extends AppConsole {
}

public function exit() {
_locale.destroy();
if (locale != null) locale.destroy();
appRef.ptr.exit();
Entry.cleanup();
}
Expand Down
36 changes: 34 additions & 2 deletions src/hx/widgets/Locale.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ package hx.widgets;

import wx.widgets.Locale in WxLocale;
import wx.widgets.WxString;
import cpp.Pointer;

class Locale {
class Locale extends Object {

public function new(language:Int) {
if (_ref == null) {
_ref = WxLocale.createInstance(language).reinterpret();
}
}

public static function getLanguageName(lang:Int):String {
var r:WxString = WxLocale.getLanguageName(lang);
Expand All @@ -29,5 +36,30 @@ class Locale {
public static function isAvailable(lang:Int):Bool {
return WxLocale.isAvailable(lang);
}


public static function addCatalogLookupPathPrefix(prefix:String):Void {
var s = WxString.createInstance(prefix);
WxLocale.addCatalogLookupPathPrefix(s.ref);
s.destroy();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Member functions
//////////////////////////////////////////////////////////////////////////////////////////////////////////

public function addCatalog(domain:String):Bool {
var s = WxString.createInstance(domain);
var b = localeRef.ptr.addCatalog(s.ref);
s.destroy();
return b;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////////////////////////////////////
private var localeRef(get, null):Pointer<WxLocale>;
private function get_localeRef():Pointer<WxLocale> {
return _ref.reinterpret();
}

}
4 changes: 3 additions & 1 deletion src/wx/widgets/Locale.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ extern class Locale {
@:native("wxLocale::GetSystemEncodingName") public static function getSystemEncodingName():WxString;
@:native("wxLocale::GetSystemLanguage") public static function getSystemLanguage():Int;
@:native("wxLocale::IsAvailable") public static function isAvailable(lang:Int):Bool;
}
@:native("wxLocale::AddCatalogLookupPathPrefix") public static function addCatalogLookupPathPrefix(prefix:WxString):Void;
@:native("wxLocale::AddCatalog") public function addCatalog(domain:WxString):Bool;
}

0 comments on commit d40c1a5

Please sign in to comment.