Skip to content
Snippets Groups Projects
Commit 2b19b69f authored by Aline Gondim Santos's avatar Aline Gondim Santos Committed by Sébastien Blin
Browse files

plugins: use JAMI_LANG variable

To apply translations, first try to read if the JAMI_LANG variable is
set, if not, try to get the system language.

GitLab: #747

Change-Id: Ie458abcc07c0d0fd151172e172fe1418e5f06e7f
parent 5af1041b
No related branches found
No related tags found
No related merge requests found
......@@ -159,26 +159,34 @@ PluginPreferencesUtils::getPreferences(const std::string& rootPath, const std::s
std::vector<std::map<std::string, std::string>> preferences;
if (file) {
// Get preferences locale
#ifdef WIN32
std::string lang;
WCHAR localeBuffer[LOCALE_NAME_MAX_LENGTH];
if (GetUserDefaultLocaleName(localeBuffer, LOCALE_NAME_MAX_LENGTH) != 0) {
char utf8Buffer[LOCALE_NAME_MAX_LENGTH] {};
WideCharToMultiByte(CP_UTF8,
0,
localeBuffer,
LOCALE_NAME_MAX_LENGTH,
utf8Buffer,
LOCALE_NAME_MAX_LENGTH,
nullptr,
nullptr);
lang.append(utf8Buffer);
string_replace(lang, "-", "_");
}
if (auto envLang = std::getenv("JAMI_LANG"))
lang = envLang;
else
JAMI_ERR() << "Error getting JAMI_LANG env, trying to get system language";
// If language preference is empty, try to get from the system.
if (lang.empty()) {
#ifdef WIN32
WCHAR localeBuffer[LOCALE_NAME_MAX_LENGTH];
if (GetUserDefaultLocaleName(localeBuffer, LOCALE_NAME_MAX_LENGTH) != 0) {
char utf8Buffer[LOCALE_NAME_MAX_LENGTH] {};
WideCharToMultiByte(CP_UTF8,
0,
localeBuffer,
LOCALE_NAME_MAX_LENGTH,
utf8Buffer,
LOCALE_NAME_MAX_LENGTH,
nullptr,
nullptr);
lang.append(utf8Buffer);
string_replace(lang, "-", "_");
}
#else
std::string lang = std::locale("").name();
#endif //
// For Android this should not work since std::locale is not supported by the NDK.
lang = std::locale("").name();
#endif // WIN32
}
auto locales = getLocales(rootPath, std::string(string_remove_suffix(lang, '.')));
// Read the file to a json format
......
......@@ -119,6 +119,7 @@ private:
void testInstallAndLoad();
void testHandlers();
void testDetailsAndPreferences();
void testTranslations();
void testCall();
void testMessage();
......@@ -127,6 +128,7 @@ private:
CPPUNIT_TEST(testInstallAndLoad);
CPPUNIT_TEST(testHandlers);
CPPUNIT_TEST(testDetailsAndPreferences);
CPPUNIT_TEST(testTranslations);
CPPUNIT_TEST(testCall);
CPPUNIT_TEST(testMessage);
CPPUNIT_TEST_SUITE_END();
......@@ -388,8 +390,6 @@ PluginsTest::testDetailsAndPreferences()
CPPUNIT_ASSERT(preferencesValuesOrig[key] == preferencesValuesNew[key]);
CPPUNIT_ASSERT(preferencesValuesNew[key] != preferenceNewValue);
// Get-set-reset - alice account
preferences = Manager::instance().getJamiPluginManager().getPluginPreferences(installationPath_, aliceData.accountId_);
CPPUNIT_ASSERT(!preferences.empty());
......@@ -428,11 +428,30 @@ PluginsTest::testDetailsAndPreferences()
CPPUNIT_ASSERT(preferencesValuesNew[key] == preferencesValuesBobOrig[key]);
CPPUNIT_ASSERT(preferencesValuesNew[key] != preferenceNewValue);
// Test translations
CPPUNIT_ASSERT(!Manager::instance().getJamiPluginManager().uninstallPlugin(installationPath_));
}
void
PluginsTest::testTranslations()
{
Manager::instance().pluginPreferences.setPluginsEnabled(true);
setenv("JAMI_LANG", "en", true);
Manager::instance().getJamiPluginManager().installPlugin(jplPath_, true);
auto preferences = Manager::instance().getJamiPluginManager().getPluginPreferences(installationPath_, "");
CPPUNIT_ASSERT(!preferences.empty());
auto preferencesValuesEN = Manager::instance().getJamiPluginManager().getPluginPreferencesValuesMap(installationPath_, "");
setenv("JAMI_LANG", "fr", true);
CPPUNIT_ASSERT(Manager::instance().getJamiPluginManager().getPluginPreferencesValuesMap(installationPath_, "") != preferencesValuesEN);
setenv("JAMI_LANG", "en", true);
CPPUNIT_ASSERT(Manager::instance().getJamiPluginManager().getPluginPreferencesValuesMap(installationPath_, "") == preferencesValuesEN);
CPPUNIT_ASSERT(!Manager::instance().getJamiPluginManager().uninstallPlugin(installationPath_));
}
bool
PluginsTest::waitForSignal(CallData& callData,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment