-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1621 from ripcurlx/add-non-english-locale-warning
Add warning for languages not natively supported by arbitration
- Loading branch information
Showing
6 changed files
with
212 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/bisq/desktop/main/settings/preferences/PreferencesViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.desktop.main.settings.preferences; | ||
|
||
|
||
import bisq.desktop.common.model.ActivatableViewModel; | ||
|
||
import bisq.core.arbitration.ArbitratorManager; | ||
import bisq.core.locale.LanguageUtil; | ||
import bisq.core.user.Preferences; | ||
|
||
import com.google.inject.Inject; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
public class PreferencesViewModel extends ActivatableViewModel { | ||
|
||
private final ArbitratorManager arbitratorManager; | ||
private final Preferences preferences; | ||
|
||
@Inject | ||
public PreferencesViewModel(Preferences preferences, ArbitratorManager arbitratorManager) { | ||
this.preferences = preferences; | ||
this.arbitratorManager = arbitratorManager; | ||
} | ||
|
||
boolean needsArbitrationLanguageWarning() { | ||
return !arbitratorManager.isArbitratorAvailableForLanguage(preferences.getUserLanguage()); | ||
} | ||
|
||
String getArbitrationLanguages() { | ||
return arbitratorManager.getArbitratorsObservableMap().values().stream() | ||
.flatMap(arbitrator -> arbitrator.getLanguageCodes().stream()) | ||
.distinct() | ||
.map(languageCode -> LanguageUtil.getDisplayName(languageCode)) | ||
.collect(Collectors.joining(", ")); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/test/java/bisq/desktop/main/settings/preferences/PreferencesViewModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.desktop.main.settings.preferences; | ||
|
||
import bisq.core.arbitration.Arbitrator; | ||
import bisq.core.arbitration.ArbitratorManager; | ||
import bisq.core.user.PreferenceMakers; | ||
import bisq.core.user.Preferences; | ||
|
||
import bisq.network.p2p.NodeAddress; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableMap; | ||
|
||
import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
|
||
import java.security.Security; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest({ArbitratorManager.class, Preferences.class}) | ||
public class PreferencesViewModelTest { | ||
|
||
@Before | ||
public void setUp() { | ||
Security.addProvider(new BouncyCastleProvider()); | ||
} | ||
|
||
@Test | ||
public void testGetArbitrationLanguages() { | ||
|
||
ArbitratorManager arbitratorManager = mock(ArbitratorManager.class); | ||
|
||
final ObservableMap<NodeAddress, Arbitrator> arbitrators = FXCollections.observableHashMap(); | ||
|
||
ArrayList<String> languagesOne = new ArrayList<String>() {{ | ||
add("en"); | ||
add("de"); | ||
}}; | ||
|
||
ArrayList<String> languagesTwo = new ArrayList<String>() {{ | ||
add("en"); | ||
add("es"); | ||
}}; | ||
|
||
Arbitrator one = new Arbitrator(new NodeAddress("arbitrator:1"), null, null, null, | ||
languagesOne, 0L, null, "", null, | ||
null, null); | ||
|
||
Arbitrator two = new Arbitrator(new NodeAddress("arbitrator:2"), null, null, null, | ||
languagesTwo, 0L, null, "", null, | ||
null, null); | ||
|
||
arbitrators.put(one.getNodeAddress(), one); | ||
arbitrators.put(two.getNodeAddress(), two); | ||
|
||
Preferences preferences = PreferenceMakers.empty; | ||
|
||
when(arbitratorManager.getArbitratorsObservableMap()).thenReturn(arbitrators); | ||
|
||
PreferencesViewModel model = new PreferencesViewModel(preferences, arbitratorManager); | ||
|
||
assertEquals("English, Deutsch, español", model.getArbitrationLanguages()); | ||
} | ||
|
||
} |