summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorFran├žois Revol <revol@free.fr>2018-08-21 21:16:06 +0200
committerFran├žois Revol <revol@free.fr>2018-08-21 21:17:12 +0200
commit579465df5003dfdecf74228557bd927557fb3b7a (patch)
tree100a0b3f4490430b24827053113730c01b6b9814 /frontends
parentbec6428c6c1ad720cc41a7b3428b9b2d26c1dbeb (diff)
downloadnetsurf-579465df5003dfdecf74228557bd927557fb3b7a.tar.gz
netsurf-579465df5003dfdecf74228557bd927557fb3b7a.tar.bz2
Haiku: use the native locale API to get the language name
We used getenv() on LC_MESSAGES but we currently set it incorrectly anyway... We keep this as a fallback.
Diffstat (limited to 'frontends')
-rw-r--r--frontends/beos/gui.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/frontends/beos/gui.cpp b/frontends/beos/gui.cpp
index 19f8eac49..e9ab9737a 100644
--- a/frontends/beos/gui.cpp
+++ b/frontends/beos/gui.cpp
@@ -42,6 +42,9 @@
#include <Roster.h>
#include <Screen.h>
#include <String.h>
+#ifdef __HAIKU__
+#include <LocaleRoster.h>
+#endif
extern "C" {
@@ -519,9 +522,18 @@ static BPath get_messages_path()
BPath p;
f.FindPath(B_FIND_PATH_APPS_DIRECTORY, "netsurf/res", p);
- // TODO: use Haiku's BLocale stuff
- BString lang(getenv("LC_MESSAGES"));
- lang.Truncate(2);
+ BString lang;
+#ifdef __HAIKU__
+ BMessage preferredLangs;
+ if (BLocaleRoster::Default()->GetPreferredLanguages(&preferredLangs) == B_OK) {
+ preferredLangs.FindString("language", 0, &lang);
+ lang.Truncate(2);
+ }
+#endif
+ if (lang.Length() < 1) {
+ lang.SetTo(getenv("LC_MESSAGES"));
+ lang.Truncate(2);
+ }
BDirectory d(p.Path());
if (!d.Contains(lang.String(), B_DIRECTORY_NODE))
lang = "en";
@@ -1040,9 +1052,19 @@ int main(int argc, char** argv)
BResources resources;
resources.SetToImage((const void*)main);
size_t size = 0;
-
+
+ BString lang;
+#ifdef __HAIKU__
+ BMessage preferredLangs;
+ if (BLocaleRoster::Default()->GetPreferredLanguages(&preferredLangs) == B_OK) {
+ preferredLangs.FindString("language", 0, &lang);
+ }
+#endif
+ if (lang.Length() < 1)
+ lang.SetTo(getenv("LC_MESSAGES"));
+
char path[12];
- sprintf(path,"%.2s/Messages", getenv("LC_MESSAGES"));
+ sprintf(path,"%.2s/Messages", lang.String());
NSLOG(netsurf, INFO, "Loading messages from resource %s\n", path);
const uint8_t* res = (const uint8_t*)resources.LoadResource('data', path, &size);