Skip to content

Haiku: get all preferred languages #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: haiku
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 12 additions & 25 deletions Source/WTF/wtf/haiku/LanguageHaiku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,26 @@
#include <wtf/text/WTFString.h>
#include "Language.h"

/* Can't include these the normal way, because WTF header names collide. */
#include <locale/Collator.h>
#include <support/Locker.h>

#include <Locale.h>
#include <LocaleRoster.h>
#include <stdio.h>
#include <Message.h>


namespace WTF {

void setPlatformUserPreferredLanguagesChangedCallback(void (*)()) { }

static String platformLanguage()
{
static BString locale;
static bool initialized = false;
if (!initialized) {
initialized = true;
BLanguage language;
if (BLocale::Default()->GetLanguage(&language) == B_OK)
locale = language.ID();
else
locale = "c";
locale.ReplaceAll('_', '-');
}
return String::fromUTF8(locale.String());
}

Vector<String> platformUserPreferredLanguages(WTF::ShouldMinimizeLanguages)
{
Vector<String> userPreferredLanguages;
userPreferredLanguages.append(platformLanguage());
BMessage languages;
if (BLocaleRoster::Default()->GetPreferredLanguages(&languages) == B_OK) {
BString language;
int32 i = 0;
while (languages.FindString("language", i++, &language) == B_OK) {
language.ReplaceAll('_', '-');
userPreferredLanguages.append(String::fromUTF8(language.String()));
}
}
if (userPreferredLanguages.isEmpty())
userPreferredLanguages.append("en"_s);
return userPreferredLanguages;
}

Expand Down