Explorar o código

separate getLocale from get_lang

Nicolas Cannasse %!s(int64=5) %!d(string=hai) anos
pai
achega
4eafcb003f
Modificáronse 1 ficheiros con 16 adicións e 4 borrados
  1. 16 4
      hxd/System.hl.hx

+ 16 - 4
hxd/System.hl.hx

@@ -282,18 +282,30 @@ class System {
 		}
 	}
 
-	@:hlNative("std","sys_locale") static function getLocale() : hl.Bytes { return null; }
+	@:hlNative("std","sys_locale") static function sys_locale() : hl.Bytes { return null; }
 
 	static var _lang : String;
 	static function get_lang() : String {
 		if( _lang == null ) {
-			var str = @:privateAccess Sys.makePath(getLocale());
-			if( str == null ) str = "en";
-			_lang = ~/[.@_-]/g.split(str)[0];
+			var str = getLocale();
+			_lang = str.split("-").shift();
 		}
 		return _lang;
 	}
 
+	/**
+	 * Returns the locale including region code ()
+	**/
+	static var _loc : String;
+	public static function getLocale() {
+		if( _loc == null ) {
+			var str = @:privateAccess Sys.makePath(sys_locale());
+			if( str == null ) str = "en";
+			_loc = ~/[.@_]/g.split(str)[0];
+		}
+		return _loc;
+	}
+
 	// getters
 
 	#if usesys