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,8 +159,14 @@ PluginPreferencesUtils::getPreferences(const std::string& rootPath, const std::s ...@@ -159,8 +159,14 @@ PluginPreferencesUtils::getPreferences(const std::string& rootPath, const std::s
std::vector<std::map<std::string, std::string>> preferences; std::vector<std::map<std::string, std::string>> preferences;
if (file) { if (file) {
// Get preferences locale // Get preferences locale
#ifdef WIN32
std::string lang; std::string 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]; WCHAR localeBuffer[LOCALE_NAME_MAX_LENGTH];
if (GetUserDefaultLocaleName(localeBuffer, LOCALE_NAME_MAX_LENGTH) != 0) { if (GetUserDefaultLocaleName(localeBuffer, LOCALE_NAME_MAX_LENGTH) != 0) {
char utf8Buffer[LOCALE_NAME_MAX_LENGTH] {}; char utf8Buffer[LOCALE_NAME_MAX_LENGTH] {};
...@@ -177,8 +183,10 @@ PluginPreferencesUtils::getPreferences(const std::string& rootPath, const std::s ...@@ -177,8 +183,10 @@ PluginPreferencesUtils::getPreferences(const std::string& rootPath, const std::s
string_replace(lang, "-", "_"); string_replace(lang, "-", "_");
} }
#else #else
std::string lang = std::locale("").name(); // For Android this should not work since std::locale is not supported by the NDK.
#endif // lang = std::locale("").name();
#endif // WIN32
}
auto locales = getLocales(rootPath, std::string(string_remove_suffix(lang, '.'))); auto locales = getLocales(rootPath, std::string(string_remove_suffix(lang, '.')));
// Read the file to a json format // Read the file to a json format
......
...@@ -119,6 +119,7 @@ private: ...@@ -119,6 +119,7 @@ private:
void testInstallAndLoad(); void testInstallAndLoad();
void testHandlers(); void testHandlers();
void testDetailsAndPreferences(); void testDetailsAndPreferences();
void testTranslations();
void testCall(); void testCall();
void testMessage(); void testMessage();
...@@ -127,6 +128,7 @@ private: ...@@ -127,6 +128,7 @@ private:
CPPUNIT_TEST(testInstallAndLoad); CPPUNIT_TEST(testInstallAndLoad);
CPPUNIT_TEST(testHandlers); CPPUNIT_TEST(testHandlers);
CPPUNIT_TEST(testDetailsAndPreferences); CPPUNIT_TEST(testDetailsAndPreferences);
CPPUNIT_TEST(testTranslations);
CPPUNIT_TEST(testCall); CPPUNIT_TEST(testCall);
CPPUNIT_TEST(testMessage); CPPUNIT_TEST(testMessage);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
...@@ -388,8 +390,6 @@ PluginsTest::testDetailsAndPreferences() ...@@ -388,8 +390,6 @@ PluginsTest::testDetailsAndPreferences()
CPPUNIT_ASSERT(preferencesValuesOrig[key] == preferencesValuesNew[key]); CPPUNIT_ASSERT(preferencesValuesOrig[key] == preferencesValuesNew[key]);
CPPUNIT_ASSERT(preferencesValuesNew[key] != preferenceNewValue); CPPUNIT_ASSERT(preferencesValuesNew[key] != preferenceNewValue);
// Get-set-reset - alice account // Get-set-reset - alice account
preferences = Manager::instance().getJamiPluginManager().getPluginPreferences(installationPath_, aliceData.accountId_); preferences = Manager::instance().getJamiPluginManager().getPluginPreferences(installationPath_, aliceData.accountId_);
CPPUNIT_ASSERT(!preferences.empty()); CPPUNIT_ASSERT(!preferences.empty());
...@@ -428,11 +428,30 @@ PluginsTest::testDetailsAndPreferences() ...@@ -428,11 +428,30 @@ PluginsTest::testDetailsAndPreferences()
CPPUNIT_ASSERT(preferencesValuesNew[key] == preferencesValuesBobOrig[key]); CPPUNIT_ASSERT(preferencesValuesNew[key] == preferencesValuesBobOrig[key]);
CPPUNIT_ASSERT(preferencesValuesNew[key] != preferenceNewValue); CPPUNIT_ASSERT(preferencesValuesNew[key] != preferenceNewValue);
// Test translations
CPPUNIT_ASSERT(!Manager::instance().getJamiPluginManager().uninstallPlugin(installationPath_)); 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 bool
PluginsTest::waitForSignal(CallData& callData, PluginsTest::waitForSignal(CallData& callData,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment