Skip to content

Commit

Permalink
Merge branch 'translate-location-names-droid-432'
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-mullvad committed Aug 21, 2024
2 parents 26e03f2 + 8a9c8b1 commit d6771c2
Show file tree
Hide file tree
Showing 34 changed files with 3,451 additions and 15 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ dependencies {
implementation(libs.androidx.lifecycle.viewmodel)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.arrow)
implementation(libs.arrow.optics)
implementation(libs.arrow.resilience)
implementation(libs.compose.constrainlayout)
implementation(libs.compose.foundation)
Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,11 @@
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<receiver android:name=".receiver.LocaleChangedBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.LOCALE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import net.mullvad.mullvadvpn.lib.model.BuildVersion
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
import net.mullvad.mullvadvpn.lib.shared.DeviceRepository
import net.mullvad.mullvadvpn.lib.shared.LocaleRepository
import net.mullvad.mullvadvpn.lib.shared.RelayLocationTranslationRepository
import net.mullvad.mullvadvpn.lib.shared.VpnPermissionRepository
import org.koin.android.ext.koin.androidContext
import org.koin.core.qualifier.named
Expand All @@ -32,5 +34,7 @@ val appModule = module {
single { AccountRepository(get(), get(), MainScope()) }
single { DeviceRepository(get()) }
single { VpnPermissionRepository(androidContext()) }
single { ConnectionProxy(get(), get()) }
single { ConnectionProxy(get(), get(), get()) }
single { LocaleRepository(get()) }
single { RelayLocationTranslationRepository(get(), get(), MainScope()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ val uiModule = module {
single { MullvadProblemReport(get()) }
single { RelayOverridesRepository(get()) }
single { CustomListsRepository(get()) }
single { RelayListRepository(get()) }
single { RelayListRepository(get(), get()) }
single { RelayListFilterRepository(get()) }
single { VoucherRepository(get(), get()) }
single { SplitTunnelingRepository(get()) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.mullvad.mullvadvpn.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import net.mullvad.mullvadvpn.lib.shared.LocaleRepository
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

class LocaleChangedBroadcastReceiver : BroadcastReceiver(), KoinComponent {
private val localeRepository by inject<LocaleRepository>()

override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == Intent.ACTION_LOCALE_CHANGED) {
localeRepository.refreshLocale()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ fun List<RelayItem.Location.Country>.getRelayItemsByCodes(
): List<RelayItem.Location> =
this.filter { codes.contains(it.id) } +
this.flatMap { it.descendants() }.filter { codes.contains(it.id) }

fun <T : RelayItem> List<T>.sortedByName() =
this.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name })
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package net.mullvad.mullvadvpn.repository

import arrow.optics.Every
import arrow.optics.copy
import arrow.optics.dsl.every
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
Expand All @@ -17,18 +21,45 @@ import net.mullvad.mullvadvpn.lib.model.RelayItem
import net.mullvad.mullvadvpn.lib.model.RelayItemId
import net.mullvad.mullvadvpn.lib.model.WireguardConstraints
import net.mullvad.mullvadvpn.lib.model.WireguardEndpointData
import net.mullvad.mullvadvpn.lib.model.cities
import net.mullvad.mullvadvpn.lib.model.name
import net.mullvad.mullvadvpn.lib.shared.RelayLocationTranslationRepository
import net.mullvad.mullvadvpn.relaylist.findByGeoLocationId
import net.mullvad.mullvadvpn.relaylist.sortedByName

class RelayListRepository(
private val managementService: ManagementService,
private val translationRepository: RelayLocationTranslationRepository,
dispatcher: CoroutineDispatcher = Dispatchers.IO
) {
val relayList: StateFlow<List<RelayItem.Location.Country>> =
managementService.relayCountries.stateIn(
CoroutineScope(dispatcher),
SharingStarted.WhileSubscribed(),
emptyList()
)
combine(managementService.relayCountries, translationRepository.translations) {
countries,
translations ->
countries.translateRelays(translations)
}
.stateIn(CoroutineScope(dispatcher), SharingStarted.WhileSubscribed(), emptyList())

private fun List<RelayItem.Location.Country>.translateRelays(
translations: Map<String, String>
): List<RelayItem.Location.Country> {
if (translations.isEmpty()) {
return this
}

return Every.list<RelayItem.Location.Country>()
.modify(this) {
it.copy {
RelayItem.Location.Country.name set translations.getOrDefault(it.name, it.name)
RelayItem.Location.Country.cities.every(Every.list()).name transform
{ cityName ->
translations.getOrDefault(cityName, cityName)
}
RelayItem.Location.Country.cities transform { cities -> cities.sortedByName() }
}
}
.sortedByName()
}

val wireguardEndpointData: StateFlow<WireguardEndpointData> =
managementService.wireguardEndpointData.stateIn(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.mullvad.mullvadvpn.lib.model

import arrow.optics.optics
import java.net.InetAddress

@optics
data class GeoIpLocation(
val ipv4: InetAddress?,
val ipv6: InetAddress?,
Expand All @@ -10,4 +12,6 @@ data class GeoIpLocation(
val latitude: Double,
val longitude: Double,
val hostname: String?,
)
) {
companion object
}
158 changes: 158 additions & 0 deletions android/lib/resource/src/main/res/xml-da/relay_locations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Adelaide">Adelaide</string>
<string name="Albania">Albanien</string>
<string name="Amsterdam">Amsterdam</string>
<string name="Ashburn, VA">Ashburn, VA</string>
<string name="Athens">Athen</string>
<string name="Atlanta, GA">Atlanta, GA</string>
<string name="Auckland">Auckland</string>
<string name="Australia">Australien</string>
<string name="Austria">Østrig</string>
<string name="Bangkok">Bangkok</string>
<string name="Barcelona">Barcelona</string>
<string name="Belgium">Belgien</string>
<string name="Belgrade">Beograd</string>
<string name="Berlin">Berlin</string>
<string name="Bogota">Bogota</string>
<string name="Bordeaux">Bordeaux</string>
<string name="Boston, MA">Boston, MA</string>
<string name="Bratislava">Bratislava</string>
<string name="Brazil">Brasilien</string>
<string name="Brisbane">Brisbane</string>
<string name="Brussels">Bruxelles</string>
<string name="Bucharest">Bukarest</string>
<string name="Budapest">Budapest</string>
<string name="Bulgaria">Bulgarien</string>
<string name="Calgary">Calgary</string>
<string name="Canada">Canada</string>
<string name="Canberra">Canberra</string>
<string name="Charlotte, NC">Charlotte, NC</string>
<string name="Chicago, IL">Chicago, IL</string>
<string name="Chile">Chile</string>
<string name="Chisinau">Chisinau</string>
<string name="Cleveland, OH">Cleveland, OH</string>
<string name="Colombia">Colombia</string>
<string name="Copenhagen">København</string>
<string name="Croatia">Kroatien</string>
<string name="Czech Republic">Tjekkiet</string>
<string name="Dallas, TX">Dallas, TX</string>
<string name="Denmark">Danmark</string>
<string name="Denver, CO">Denver, CO</string>
<string name="Detroit, MI">Detroit, MI</string>
<string name="Dubai">Dubai</string>
<string name="Dublin">Dublin</string>
<string name="Dusseldorf">Düsseldorf</string>
<string name="Estonia">Estland</string>
<string name="Finland">Finland</string>
<string name="France">Frankrig</string>
<string name="Frankfurt">Frankfurt</string>
<string name="Germany">Tyskland</string>
<string name="Glasgow">Glasgow</string>
<string name="Gothenburg">Gøteborg</string>
<string name="Greece">Grækenland</string>
<string name="Helsingborg">Helsingborg</string>
<string name="Helsinki">Helsinki</string>
<string name="Hong Kong">Hongkong</string>
<string name="Honolulu, HI">Honolulu, HI</string>
<string name="Houston, TX">Houston, TX</string>
<string name="Hungary">Ungarn</string>
<string name="India">Indien</string>
<string name="Indonesia">Indonesien</string>
<string name="Ireland">Irland</string>
<string name="Israel">Israel</string>
<string name="Italy">Italien</string>
<string name="Jackson, MS">Jackson, MS</string>
<string name="Jakarta">Jakarta</string>
<string name="Japan">Japan</string>
<string name="Johannesburg">Johannesburg</string>
<string name="Kiev">Kiev</string>
<string name="Kyiv">Kyiv</string>
<string name="Latvia">Letland</string>
<string name="Lisbon">Lissabon</string>
<string name="Ljubljana">Ljubljana</string>
<string name="London">London</string>
<string name="Los Angeles, CA">Los Angeles, Californien</string>
<string name="Louisville, KY">Louisville, KY</string>
<string name="Luxembourg">Luxembourg</string>
<string name="Madrid">Madrid</string>
<string name="Malmö">Malmø</string>
<string name="Manchester">Manchester</string>
<string name="Marseille">Marseille</string>
<string name="McAllen, TX">McAllen, TX</string>
<string name="Melbourne">Melbourne</string>
<string name="Mexico">Mexico</string>
<string name="Miami, FL">Miami, FL</string>
<string name="Milan">Milano</string>
<string name="Milwaukee, WI">Milwaukee, WI</string>
<string name="Minneapolis/St. Paul Apt, MN">Minneapolis/St. Paul Apt, MN</string>
<string name="Moldova">Moldova</string>
<string name="Montreal">Montreal</string>
<string name="Netherlands">Holland</string>
<string name="New York, NY">New York, NY</string>
<string name="New Zealand">New Zealand</string>
<string name="Nis">Nis</string>
<string name="North Macedonia">Nordmakedonien</string>
<string name="Norway">Norge</string>
<string name="Oklahoma City, OK">Oklahoma City, OK</string>
<string name="Osaka">Osaka</string>
<string name="Oslo">Oslo</string>
<string name="Palermo">Palermo</string>
<string name="Paris">Paris</string>
<string name="Perth">Perth</string>
<string name="Philadelphia, PA">Philadelphia, PA</string>
<string name="Phoenix, AZ">Phoenix, AZ</string>
<string name="Piscataway, NJ">Piscataway, NJ</string>
<string name="Poland">Polen</string>
<string name="Portland, OR">Portland, OR</string>
<string name="Portugal">Portugal</string>
<string name="Prague">Prag</string>
<string name="Pune">Pune</string>
<string name="Queretaro">Queretaro</string>
<string name="Raleigh, NC">Raleigh, NC</string>
<string name="Richmond, VA">Richmond, VA</string>
<string name="Riga">Riga</string>
<string name="Romania">Rumænien</string>
<string name="Rome">Rom</string>
<string name="Salt Lake City, UT">Salt Lake City, UT</string>
<string name="San Francisco, CA">San Francisco, Californien</string>
<string name="San Jose, CA">San Jose, Californien</string>
<string name="Santiago">Santiago</string>
<string name="Sao Paulo">Sao Paulo</string>
<string name="Seattle, WA">Seattle, WA</string>
<string name="Secaucus, NJ">Secaucus, NJ</string>
<string name="Serbia">Serbien</string>
<string name="Singapore">Singapore</string>
<string name="Sioux Falls, SD">Sioux Falls, SD</string>
<string name="Skopje">Skopje</string>
<string name="Slovakia">Slovakiet</string>
<string name="Slovenia">Slovenien</string>
<string name="Sofia">Sofia</string>
<string name="South Africa">Sydafrika</string>
<string name="Spain">Spanien</string>
<string name="St. Louis, MO">St. Louis, MO</string>
<string name="Stamford, CT">Stamford, CT</string>
<string name="Stavanger">Stavanger</string>
<string name="Stockholm">Stockholm</string>
<string name="Sweden">Sverige</string>
<string name="Switzerland">Schweiz</string>
<string name="Sydney">Sydney</string>
<string name="Tallinn">Tallinn</string>
<string name="Tel Aviv">Tel Aviv</string>
<string name="Thailand">Thailand</string>
<string name="Tirana">Tirana</string>
<string name="Tokyo">Tokyo</string>
<string name="Toronto">Toronto</string>
<string name="UK">UK</string>
<string name="USA">USA</string>
<string name="Ukraine">Ukraine</string>
<string name="United Arab Emirates">Forenede Arabiske Emirater</string>
<string name="Valencia">Valencia</string>
<string name="Vancouver">Vancouver</string>
<string name="Vienna">Wien</string>
<string name="Warsaw">Warszawa</string>
<string name="Washington DC">Washington DC</string>
<string name="Wien">Wien</string>
<string name="Zagreb">Zagreb</string>
<string name="Zurich">Zürich</string>
</resources>
Loading

0 comments on commit d6771c2

Please sign in to comment.