Skip to content
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

Translate location names #6574

Merged
merged 4 commits into from
Aug 21, 2024
Merged

Conversation

Rawa
Copy link
Contributor

@Rawa Rawa commented Aug 6, 2024

Adds support for translations for different locations


This change is Reviewable

Copy link

linear bot commented Aug 6, 2024

@Rawa Rawa self-assigned this Aug 6, 2024
@Rawa Rawa added the Android Issues related to Android label Aug 6, 2024
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 29 of 34 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: 33 of 34 files reviewed, 1 unresolved discussion (waiting on @Rawa)


android/lib/resource/src/main/res/xml/relay_locations.xml line 152 at r2 (raw file):

    <string name="Valencia">Valencia</string>
    <string name="Vancouver">Vancouver</string>
    <string name="Vienna">Vienna</string>

Not sure if this is an error in the source data or in the translation script, but Vienna and Wien appear both, which is a bit weird.

@Rawa Rawa force-pushed the translate-location-names-droid-432 branch 4 times, most recently from 12b4322 to b9c0602 Compare August 7, 2024 16:46
@Rawa Rawa marked this pull request as ready for review August 7, 2024 16:46
@Rawa Rawa force-pushed the translate-location-names-droid-432 branch from b9c0602 to a321369 Compare August 7, 2024 16:49
Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 7 of 34 files reviewed, all discussions resolved (waiting on @Pururun)


android/lib/resource/src/main/res/xml/relay_locations.xml line 152 at r2 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Not sure if this is an error in the source data or in the translation script, but Vienna and Wien appear both, which is a bit weird.

The relay-locations.pot includes both, I've created DES-1122 to address this.

@Rawa Rawa force-pushed the translate-location-names-droid-432 branch from a321369 to 71d57de Compare August 9, 2024 06:13
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also sort the relay items based on the translated name. Currently they are sorted based on the english name so for example "Österrike" / "Österreich" will be close to the tope of the list even though it should be at the bottom.

Reviewed 29 of 29 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Rawa)


android/app/src/main/AndroidManifest.xml line 3 at r1 (raw file):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">

I think we should not have a lot of formatting in this file?

Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 53 at r3 (raw file):

                val translation = loadRelayTranslation(xml)

                translation.entries.associate { (id, name) -> defaultTranslation[id]!! to name }

Is there a way to get around this? I get that we have it because the keys of the default locale does not always match the string we get from the daemon, but it would be nice if did not need this step, feels like it is open for errors and crashes.

@Rawa Rawa force-pushed the translate-location-names-droid-432 branch 3 times, most recently from 0052301 to 7a3fe6c Compare August 9, 2024 13:02
Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Fixed!

Reviewed 1 of 2 files at r4.
Reviewable status: 32 of 35 files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/app/src/main/AndroidManifest.xml line 3 at r1 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

I think we should not have a lot of formatting in this file?

Done.


android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 53 at r3 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Is there a way to get around this? I get that we have it because the keys of the default locale does not always match the string we get from the daemon, but it would be nice if did not need this step, feels like it is open for errors and crashes.

Talked and address, thanks!

Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r5, all commit messages.
Reviewable status: 34 of 35 files reviewed, all discussions resolved (waiting on @Rawa)

@Pururun Pururun force-pushed the translate-location-names-droid-432 branch from 3b6bfb5 to 5e47ce1 Compare August 15, 2024 14:07
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 34 files at r1, 1 of 4 files at r2, 6 of 29 files at r3, 1 of 2 files at r4, 2 of 2 files at r5, 2 of 2 files at r6, 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @Rawa)


-- commits line 7 at r6:
nit: change to:

Add support for translated location names

Code quote:

Add support location translations

android/app/src/main/kotlin/net/mullvad/mullvadvpn/broadcastreceiver/LocaleChangedBroadcastReceiver.kt line 1 at r7 (raw file):

package net.mullvad.mullvadvpn.broadcastreceiver

nit: I suggest changing to just receiver since it's shorter and easier to read

Code quote:

broadcastreceiver

android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/RelayListRepository.kt line 43 at r7 (raw file):

            .stateIn(CoroutineScope(dispatcher), SharingStarted.WhileSubscribed(), emptyList())

    private fun List<RelayItem.Location.Country>.translateRelay(

I suggest changing to translateRelays or translateAllContainingLocationsAndRelays depending on how verbose we want to be

Code quote:

translateRelay

android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/StringExtensions.kt line 18 at r7 (raw file):

fun List<String>.trimAll() = map { it.trim() }

fun <T> List<T>.sortedByName(comparator: (T) -> String) =

I believe this function name is a bit too specific for such a generic file (StringExtensions.kt). Maybe the function belongs somewhere else or can be renamed?

Code quote:

sortedByName

android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 32 at r7 (raw file):

            .stateIn(externalScope, SharingStarted.Eagerly, emptyMap())

    private suspend fun loadTranslations(locale: Locale?): Translations =

Isn't it better the caller handle the nullable case?

Code quote:

Locale?

android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 34 at r7 (raw file):

    private suspend fun loadTranslations(locale: Locale?): Translations =
        withContext(dispatcher) {
            Logger.d("Updating translations based $locale")

typo?

Code quote:

Updating translations based $locale

android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 43 at r7 (raw file):

        }

    private fun loadRelayTranslation(xml: XmlResourceParser): Map<String, String> {

Seems like this can be made a bit more readable by letting this function be an extension function for XmlResourceParser?

@Pururun Pururun force-pushed the translate-location-names-droid-432 branch 2 times, most recently from ffa01b4 to 9734f04 Compare August 20, 2024 07:52
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 35 of 36 files reviewed, 6 unresolved discussions (waiting on @albin-mullvad and @Rawa)


-- commits line 7 at r6:

Previously, albin-mullvad wrote…

nit: change to:

Add support for translated location names

Done

@Pururun Pururun requested a review from albin-mullvad August 20, 2024 08:31
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r8, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @albin-mullvad)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/broadcastreceiver/LocaleChangedBroadcastReceiver.kt line 1 at r7 (raw file):

Previously, albin-mullvad wrote…

nit: I suggest changing to just receiver since it's shorter and easier to read

That is also what we use for the bootreceiver in the autostart branch so that is a good change for that reason as well.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/RelayListRepository.kt line 43 at r7 (raw file):

Previously, albin-mullvad wrote…

I suggest changing to translateRelays or translateAllContainingLocationsAndRelays depending on how verbose we want to be

Changed it to translateRelays


android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/StringExtensions.kt line 18 at r7 (raw file):

Previously, albin-mullvad wrote…

I believe this function name is a bit too specific for such a generic file (StringExtensions.kt). Maybe the function belongs somewhere else or can be renamed?

We named it as such since that is the expected behaviour when sorting something by name.

Since it is only used for relay list I moved it to RelayListExtensions and made it more specific.


android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 32 at r7 (raw file):

Previously, albin-mullvad wrote…

Isn't it better the caller handle the nullable case?

Done


android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 34 at r7 (raw file):

Previously, albin-mullvad wrote…

typo?

Done


android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/RelayLocationTranslationRepository.kt line 43 at r7 (raw file):

Previously, albin-mullvad wrote…

Seems like this can be made a bit more readable by letting this function be an extension function for XmlResourceParser?

Done

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r8, 6 of 6 files at r10, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


android/app/src/main/kotlin/net/mullvad/mullvadvpn/broadcastreceiver/LocaleChangedBroadcastReceiver.kt line 1 at r7 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

That is also what we use for the bootreceiver in the autostart branch so that is a good change for that reason as well.

👍

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest asking for someone with better rust knowledge to review the translation-converter. The rest looks good! :lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@Pururun Pururun force-pushed the translate-location-names-droid-432 branch from 0e1dd01 to 7d65cb4 Compare August 21, 2024 07:18
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/translations-converter/src/main.rs line 230 at r11 (raw file):

        .expect("Failed to open root locale directory")
        .filter_map(|dir_entry_result| dir_entry_result.ok().map(|dir_entry| dir_entry.path()))
        .filter(|dir_entry_path| dir_entry_path.is_dir())

Nit This could be split up further by introducing yet another map

        .filter_map(|dir_entry_result| dir_entry_result.ok())
        .map(|dir_entry| dir_entry.path())
        .filter(|dir_entry_path| dir_entry_path.is_dir())

Code quote:

        .filter_map(|dir_entry_result| dir_entry_result.ok().map(|dir_entry| dir_entry.path()))
        .filter(|dir_entry_path| dir_entry_path.is_dir())

android/translations-converter/src/main.rs line 278 at r11 (raw file):

/// `values-en-rUS`.
fn android_xml_directory(locale: &str) -> String {
    let mut directory = String::from("xml-");

Nit It seems to me like the comment doesn't actually line up with the implementation. I think the comment should say ".. gets correctly mapped to the directory name xml-en-rUS, right? 😊

Code quote:

/// This just makes sure a locale such as `en-US' gets correctly mapped to the directory name
/// `values-en-rUS`.
fn android_xml_directory(locale: &str) -> String {
    let mut directory = String::from("xml-");

@Pururun Pururun force-pushed the translate-location-names-droid-432 branch from 7d65cb4 to 7e83d40 Compare August 21, 2024 09:31
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 36 of 37 files reviewed, all discussions resolved


android/translations-converter/src/main.rs line 230 at r11 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Nit This could be split up further by introducing yet another map

        .filter_map(|dir_entry_result| dir_entry_result.ok())
        .map(|dir_entry| dir_entry.path())
        .filter(|dir_entry_path| dir_entry_path.is_dir())

Done


android/translations-converter/src/main.rs line 278 at r11 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Nit It seems to me like the comment doesn't actually line up with the implementation. I think the comment should say ".. gets correctly mapped to the directory name xml-en-rUS, right? 😊

Yes I think that it was values-en-rUS first and then it as changed to xml-en-rUS later but the comment was not updated. Good find!

Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 36 of 37 files reviewed, all discussions resolved (waiting on @Pururun)

@albin-mullvad albin-mullvad requested a review from Pururun August 21, 2024 09:42
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 36 of 37 files reviewed, all discussions resolved (waiting on @Pururun)

Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r12, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@albin-mullvad albin-mullvad force-pushed the translate-location-names-droid-432 branch from 7e83d40 to 8a9c8b1 Compare August 21, 2024 09:52
@albin-mullvad albin-mullvad merged commit d6771c2 into main Aug 21, 2024
44 checks passed
@albin-mullvad albin-mullvad deleted the translate-location-names-droid-432 branch August 21, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues related to Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants