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

Add device localization on ios #532

Merged
merged 7 commits into from
Sep 19, 2024
Merged

Conversation

filip131311
Copy link
Collaborator

@filip131311 filip131311 commented Sep 10, 2024

This PR introduces a functionality for changing device localization on ios.

Screen.Recording.2024-09-10.at.17.51.32.mov

Copy link

vercel bot commented Sep 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2024 0:47am

Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

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

added a few comments inline. As they may impact parts of the implementation I'll be taking another look once you respond to the comments


type LocaleWithDescription = { localeIdentifier: Locale; Description: string };

export function DeviceLocalizationView() {
Copy link
Member

Choose a reason for hiding this comment

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

The filename is missing "n" packages/vscode-extension/src/webview/views/DeviceLocalizatioView.tsx

@@ -0,0 +1,318 @@
[
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? If so explain why in the PR. We can perhaps use some library or built-in localization APi for this, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the best solution I could think of there are libraries that do this kind of work but none is doing exactly what I need.
this one maps from country to codes not from language.
this one wasn't updated for a long time

and libraries responsible for localization management add unnecessary complexity.

I got the list in the pull request by taking a product of codes available on iOS and on android.

return (
<div className="localization-container">
<div className="search-bar">
<input
Copy link
Member

Choose a reason for hiding this comment

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

should we autofocus this when the modal is shown?

public async restart(
forceCleanBuild: boolean,
onlyReloadJSWhenPossible: boolean = true,
restartDevice?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

would be cleaner if this had a default value like the previous paameter, in this case if it was set to false it'd work the same way it does now but the type would be strict

Comment on lines 125 to 128
if (await this.device.checkLocale(deviceSettings.locale)) {
await this.device.changeLocale(deviceSettings.locale);
await this.device.resetDevice();
}
Copy link
Member

Choose a reason for hiding this comment

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

seems like this is implementation detail for a given device, shouldn't it be a part of changeSetting implementation that's specific to device rather than being handled in a generic way?

deviceSetLocation,
"spawn",
this.deviceUDID,
"defaults",
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could simplify the process and avoid restarts if we use the same method for updating defaults as we do for things like schemeapproval list (see below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately no, we could change the way we modify relavent, plist but we still have no way to modify what operating system keeps in memory at runtime.

Copy link
Member

Choose a reason for hiding this comment

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

ok, but we could still update that before the boot. Now we boot the device to only update this setting and the reboot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you were right I was able to avoid reset on on boot

Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

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

Leaving a couple more comments inline

return (
<div className="localization-container">
<div className="search-bar">
<input
Copy link
Member

Choose a reason for hiding this comment

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

can we automatically focus search field when the modal is open?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I already did that, there is a bug in the frontend that persist focus on deviceSettingsDropdown after it was closed, but it is outside of scope for this PR so I'll look into it in another one

here is an example of how the component works when deviceSettingsDropdown is not focused:
https://github.com/user-attachments/assets/b31fd863-c4c6-4062-8913-b20004683d00

packages/vscode-extension/src/project/project.ts Outdated Show resolved Hide resolved
packages/vscode-extension/src/project/project.ts Outdated Show resolved Hide resolved

if (await this.shouldUpdateLocale(deviceSettings.locale)) {
await this.changeLocale(deviceSettings.locale);
await this.resetDevice();
Copy link
Member

Choose a reason for hiding this comment

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

given we call internalBootDevice as a result of this call here, would it make sense to do that before the previous call to inernalBootDevice ? This way we can avoid booting it twice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is neccesery to boot it twice i added a coment explaining that, in short we use adb shell to change locale so device needs to be booted. The solution you provided (-change-locale) unfortunately has the same short comings as just using adb shell setprop persist.sys.locale and moreover boots device twice anyway (performs cold boot after changing locale).

// but if the user has more then languages set up then a setting in settings_system are created
// in such a case we need to change them too. It seems that if the setting exists in
// settings_system it is persistent even if the number of locales drops back to one.
await exec(ADB_PATH, ["-s", this.serial!, "shell", "setprop", "persist.sys.locale", locale]);
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried using -change-language and change-locale options from emulator:
image

I tried and they seem to work, although when used they trigger cold boot of the device. So perhaps worth combining with some cached information about the current language

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unfortunately, this approach won't work because it does the same thing as adb shell setprop persist.sys.locale ${locale} witch means it works only as long as locales are not set in /data/system/users/0/settings_system.xml (system settings) witch will override the persist.sys.locale prop. Moreover the approach with emulator cli tool does not provide significant benefits as it still turns on the device before reseting it agin to load changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The easiest way to reproduce this problem is to on device go to settings>system>languages and add more then one language that will ensure that /data/system/users/0/settings_system.xml has system_locales field

@filip131311 filip131311 force-pushed the @Filip131311/AddDeviceLocalization branch from baf62da to a75b756 Compare September 19, 2024 10:30
@filip131311 filip131311 changed the title Add device localization Add device localization on ios Sep 19, 2024
Copy link
Member

@kmagiera kmagiera left a comment

Choose a reason for hiding this comment

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

Added small comment about wording in the popup dialog. Otherwise looks good 👍

<h2 className="localization-change-title">
Are you sure you want to change the localization to <i>{locale.Description}</i>?
</h2>
<p className="localization-change-subtitle">This action will reset the device.</p>
Copy link
Member

Choose a reason for hiding this comment

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

"reset" is a wrong wording here. This may indicate we want to clear the device settings or something while we only want to reboot the device. I'd rather state it
"Changing localization requires rebooting the simulator"

@filip131311 filip131311 merged commit e6292db into main Sep 19, 2024
3 checks passed
@filip131311 filip131311 deleted the @Filip131311/AddDeviceLocalization branch September 19, 2024 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants